在大熊猫中使用.apply
时,是否可以传递给处理异常的函数,该异常将迭代行索引,因此该函数可以通知行的用户意外数据所在的位置?
import os
def split(filename):
try:
return os.path.splitext(filename)
except Exception as e:
print(f'Error ({e})')
# Would be nice to know the row index of df
# Make it 'jpg' rather than '.jpg'
df['File Extension'] = df['File Name'].apply(lambda x: split(x)[1][1:])