我有一个 df 数据框,如下所示:
Item Notional
0 .decash NaN
1 .decash NaN
2 usdjpy NaN
3 .decash NaN
4 usdjpy NaN
第二个 df1 数据帧如下:
Item Notional
0 .decash 10 000
1 usdjpy 100 000
是否可以在没有 for 指令的情况下用 df1.Notional 填充 df.Notional?
最佳答案
In [33]: df['Notional'] = df.Item.map(df1.set_index('Item').Notional)
In [34]: df
Out[34]:
Item Notional
0 .decash 10000
1 .decash 10000
2 usdjpy 100000
3 .decash 10000
4 usdjpy 100000
或者:
In [36]: df.drop('Notional',1).merge(df1, on='Item', how='left')
Out[36]:
Item Notional
0 .decash 10000
1 .decash 10000
2 usdjpy 100000
3 .decash 10000
4 usdjpy 100000
关于Python Dataframe 完整值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42124296/