![](/img/trans.png)
[英]How to replace 0 in multiple columns and specific row with values from another dataframe
[英]How to replace multiple column values for specific row in python dataframe?
我有 dataframe 和千列,我想为特定行替换几列(我存储在字典中),我该怎么做?
my_dict={'a':2,'b':1} #total feature is more than this.
Df.loc[i]=my_dict #i is row index
如果您有另一种方法可以不考虑字典,那么请建议我,我会相应地修改我的代码。 我只想完成这个操作。
假设您有以下输入数据:
df = pd.DataFrame({'a':[1,2],'b':[3,4], 'c':[5,6]})
d = {'a':2,'b':1}
i = 0
然后你可以这样做:
df.loc[i,d.keys()] = d.values()
DF df
:
a b c
0 2 1 5
1 2 4 6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.