我有一個(gè)CSV文件,其中幾行n/a。當(dāng)我將其加載為pandas數(shù)據(jù)框時(shí),顯示為nan。當(dāng)我使用類似功能這會(huì)導(dǎo)致問題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'當(dāng)我嘗試nan用空格替換s(不會(huì)導(dǎo)致這些錯(cuò)誤)時(shí),使用該fillna方法不會(huì)執(zhí)行任何操作: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以下內(nèi)容不打印任何內(nèi)容: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?以及我該如何解決?
如何處理這種情況:“ n / a”在熊貓數(shù)據(jù)框中顯示為“ nan”,但無法對(duì)其進(jìn)行字符串匹配和替換
ibeautiful
2021-04-08 14:15:59