pandas技巧:用一列的非空值填充另一列对应行的空值
金蝶云社区-云社区用户Ac2F7071
云社区用户Ac2F7071
0人赞赏了该文章 2,739次浏览 未经作者许可,禁止转载编辑于2018年12月21日 11:03:41

利用数据框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’] ,赋值成功。
---------------------
作者:秦梦秋
来源:CSDN
原文:https://blog.csdn.net/qinxiaowen2014/article/details/81083267
版权声明:本文为博主原创文章,转载请附上博文链接!