熊猫:我如何删除非空数据?

时间:2017-03-23 08:40:38

标签: python pandas

当我从文件中读取csv时,由于数据文件的错误,有时最后会有不必要的列,所以我把它们读作

df = pd.read_csv(StringIO(all_data_file), skipinitialspace=True, sep=' ', error_bad_lines=False, names = ['stationID', .... ,'unknown'])

稍后,如果unknow有数据

,我会抛出数据
# Drop if has too many field
df = df[df['unknown'].isnull()]
df.drop('unknown', axis=1, inplace=True)

问题是,它给了我错误

SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

所以我想知道,删除数据的正确方法是什么?

0 个答案:

没有答案