300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > pandas技巧:用一列的非空值填充另一列对应行的空值

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

时间:2019-01-23 15:45:38

相关推荐

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: /pandas-docs/stable/indexing.html#indexing-view-versus-copy

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

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。