[英]Combine DataFrames on non-equal dt indices?
I have 2 dataframes / series;我有 2 个数据帧/系列;
DF1
2018-01-20 10:04:19.20 1088.30
2018-01-25 16:20:09.60 1102.40
and和
DF2
2018-01-19 13:00:00 1032.60
2018-01-20 01:00:00 1146.30
2018-01-20 13:00:00 1047.70
2018-01-21 01:00:00 997.52
2018-01-21 13:00:00 981.80
2018-01-24 01:00:00 1061.60
2018-01-25 01:00:00 1048.20
2018-01-25 09:00:00 1046.90
2018-01-25 17:00:00 1113.90
2018-01-26 01:00:00 1245.50
How can I create a 3rd DataFrame with DF2's index and only values on the rows given in DF1, like:如何使用 DF2 的索引和仅在 DF1 中给出的行上的值创建第三个 DataFrame,例如:
DF3
2018-01-19 13:00:00 NaN
2018-01-20 01:00:00 1146.30
2018-01-20 13:00:00 NaN
2018-01-21 01:00:00 NaN
2018-01-21 13:00:00 NaN
2018-01-24 01:00:00 NaN
2018-01-25 01:00:00 NaN
2018-01-25 09:00:00 1046.90
2018-01-25 17:00:00 NaN
2018-01-26 01:00:00 NaN
Thx谢谢
you can use the merge function with a right join.您可以使用带有右连接的合并功能。
So the code would look something like this:所以代码看起来像这样:
df_merge = df1.merge(df2, on='column1', how='right')
df_merge.columns = ['column1', 'right_column2']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.