![](/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.