当我从文件中读取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
所以我想知道,删除数据的正确方法是什么?