Python Dataframe完整价值

时间:2017-02-08 21:49:14

标签: python pandas dataframe

我有一个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

可以用df1.Notional填写df.Notional而不用说明吗?

1 个答案:

答案 0 :(得分:1)

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