pandas技巧:用一列的非空值填充另一列对应行的空值

利用数据框df的name列中的非空值,去填充df的features_1列中对应的NaN。

很容易写出df[df['features_1'].isnull()]['features_1'']=df[df['features_1'].isnull()][‘name’] ,但是会给出以下警告:

A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

最后发现并没有赋值成功,最后改进为:df.loc[df['features_1'].isnull(),'features_1']=df[df['features_1'].isnull()][‘name’]  ,赋值成功。

参考的链接:https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas

 

你可能感兴趣的:(数据)