Я пытаюсь пометить уникальное значение комментарием, но получаю TypeError: строковые индексы должны быть целыми числами
Введите
Ключ
аЬ
Ьс
DF
аЬ
выход
Ключ | Комментарий
ab | Проверьте это
до н.э.
df |
ab | Проверьте это
condition_2= lambda x: "Check it" if x["Key"].nunique()>=1 else 0
df["Comments"]=semi_final_df.Key.apply(condition_2)
Ошибка:
TypeError Traceback (most recent call last)
<ipython-input-175-dc8d1ac8148f> in <module>
----> 1 semi_final_df["Comments"]=semi_final_df.Key.apply(condition_2)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
3192 else:
3193 values = self.astype(object).values
-> 3194 mapped = lib.map_infer(values, f, convert=convert_dtype)
3195
3196 if len(mapped) and isinstance(mapped[0], Series):
pandas/_libs/src\inference.pyx in pandas._libs.lib.map_infer()
<ipython-input-174-cf54900ff760> in <lambda>(x)
----> 1 condition_2= lambda x: " Check it" if x["Key"].nunique()>=1 else 0
TypeError: string indices must be integers```