我有一个CSV文件,其中几行n/a。当我将其加载为pandas数据框时,显示为nan。当我使用类似功能这会导致问题split,lower等这些几行。data_df['column'][104]>>> nandata_df['column'][104].split()>>> AttributeError Traceback (most recent call last)<ipython-input-38-6efe06f0a4ec> in <module>()----> 1 data_df['column'][104].split()AttributeError: 'float' object has no attribute 'split'data_df['column'][104].lower()>>>AttributeError Traceback (most recent call last)<ipython-input-41-c80cc9ae0712> in <module>()----> 1 data_df['column'][104].lower()AttributeError: 'float' object has no attribute 'lower'当我尝试nan用空格替换s(不会导致这些错误)时,使用该fillna方法不会执行任何操作:data_df.fillna('')data_df['column'][104]>>> nan所以我尝试将其替换为字符串:for i in range(len(data_df)): if data_df['column'][i]=='nan': data_df['column'][i]=''data_df['column'][104]>>> nanfor i in range(len(data_df)): if data_df['column'][i]=='n/a': data_df['column'][i]=''data_df['column'][104]>>> nan以下内容不打印任何内容:for i in range(len(data_df)): if (data_df['column'][i]=='nan' or data_df['column'][i]=='n/a'): print(data_df['column'][i])为什么我无法捕捉和替换nans或n/as?以及我该如何解决?
添加回答
举报
0/150
提交
取消