def categorize_floor(row): floor = row['floor'] total = row['floors_total'] try: if floor == 1: return 'первый' if floor == total: return 'последний' return 'другой' except: return 'нет категории' df['floor_type'] = df['floor'].apply(categorize_floor) df['floor_type'].unique() TypeError Traceback (most recent call last) /tmp/ipykernel_228/3077829014.py in ----> 1 df['floor_type'] = df['floor'].apply(categorize_floor).astype({'floor_type':str}) 2 df['floor_type'].unique() /opt/conda/lib/python3.9/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds) 4136 else: 4137 values = self.astype(object)._values -> 4138 mapped = lib.map_infer(values, f, convert=convert_dtype) 4139 4140 if len(mapped) and isinstance(mapped[0], Series): pandas/_libs/lib.pyx in pandas._libs.lib.map_infer() /tmp/ipykernel_228/2479482430.py in categorize_floor(row) 1 def categorize_floor(row): ----> 2 floor = row['floor'] 3 total = row['floors_total'] 4 try: 5 if floor == 1: TypeError: 'int' object is not subscriptable