Python Dataframe 完整值

标签 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

是否可以在没有 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/

相关文章:

python - 按特定值选择行时出现棘手错误

Python 原始 IPv6 套接字错误

python - PySerial 写入超时——传输了多少数据?

python - 从 pandas 生成 QVD 文件?

python - Pandas:DataFrame 差异函数

python - 在 wxPython 中引发 wx.EVT_CLOSE 后如何阻止窗口关闭?

python - Pandas 堆叠条形图具有不同的形状

python - 过滤掉包含非字母数字字符的行

python - Pandas df 操作 : new column with list of values if other column rows repeated

r - 查找值等于您的值的子集