我有这两个相框
DF1
| 出生日期|仪式编号|
| --|--|
| 一八九五年九月三十日|月1|
| 一八八四年七月二十三日|月1|
| 一八八九年三月二十九日|第2|
| 一八六八年十月四日|第3|
| 一八九二年八月四日|第2|
DF2
| 指数|日期|
| --|--|
| 1 |1929-05-16|
| 2 |1930-04-03|
| 3 |1930-11-05|
我的想法是根据df 1处的ceremony_number列将两者合并。我的意思是,如果df 1“ceremony_number”]与df 2“index”]匹配,则获取df 2“dates”]并将其添加到新列df 1“date_oscar”]。新列应如下所示
DF1
| 出生日期|日期_奥斯卡|
| --|--|
| 1895年9月30日|1929-05-16|
| 1884年7月23日|1929-05-16|
| 1889年3月29日|1930-04-03|
| 1868-04-10| 1930-11-05|
| 1892-8-4| 1930-04-03|
我一直在努力,但是没有用
award_year = []
for index, row in df.iterrows():
award_year.append(df1[(row['ceremony_number'] == df2['index'])])
df1['date_oscar'] = award_year
字符串
这就是错误:
Empty DataFrame Columns: [index, fechas] Index...
型
有什么建议吗?提前感谢!
1条答案
按热度按时间mzsu5hc01#
您可以在提取数字到
df2
index
后map
ceremony_number
:字符串
输出量:
型
最小工作示例
型