【发布时间】:2017-01-21 04:31:12
【问题描述】:
我确定以前有人问过这个问题,但我找不到。我想将一个系列作为新列添加到 DataFrame。所有 Series 索引名称都包含在 DataFrame 的一列中,但 Dataframe 的行数比 Series 多。
DataFrame:
0 London 231
1 Beijing 328
12 New York 920
3 Singapore 1003
Series:
London AB
New York AC
Singapore B
结果应该是这样的
0 London 231 AB
1 Beijing 328 NaN
12 New York 920 AC
3 Singapore 1003 B
如何在没有循环的情况下做到这一点?谢谢!
【问题讨论】:
-
您正在寻找合并:df.merge(pd.DataFrame('name of series'), on = 'city', how='left')
-
DataFrame 中列的名称是什么?
标签: python pandas dataframe merge series