【发布时间】:2020-02-05 19:58:13
【问题描述】:
数据帧 1:
index col1
03-05-2018 12:00:00 3
03-05-2018 13:00:00 4
03-05-2018 14:00:00 3
03-05-2018 15:00:00 3
....... ..
数据帧2
index col2
03-05-2018 12:00:00 1
03-05-2018 13:00:00 3
03-05-2018 13:30:00 4
03-05-2018 14:30:00 2
03-05-2018 15:00:00 3
..... ..
我想合并这些数据框并删除索引不匹配的值:
数据帧 3:
index col1 col2
03-05-2018 12:00:00 3 1
03-05-2018 13:00:00 4 3
03-05-2018 15:00:00 3 3
......... .. ..
有没有像 pd.merge 这样的函数来实现这个? (这是一个熊猫数据框,索引是 DateTime 对象) 谢谢!
编辑:我使用了 pd.merge(dataFrame1, dataFrame2, how = 'inner', on='index', left_index=True, right_index=True) 并且出现错误“无法将类型 'Timestamp' 与类型'进行比较诠释”。我真的很确定这两个索引都是时间戳
【问题讨论】:
-
您的数据框是 pandas、pyspark 还是其他?
-
pd.merge(df_1, df_2, how = 'inner') -
我尝试了你的方法,它确实有效,但我最终得到了更多的值(预计数字大约在 55000 左右,但我得到了 523916715)