pandas 加入具有不同索引级别/日期时间的数据帧? [英] Pandas joining dataframes with different index levels/datetime?

查看:40
本文介绍了 pandas 加入具有不同索引级别/日期时间的数据帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 DataFrame,它们看起来像这样:

Hi I have two DataFrames which look like this:

-------------------------------------------------
|      | dineType | menuName | unique | columns |
-------------------------------------------------
| date |          |          |        |         |
-------------------------------------------------
|%y%m%d|          |          |        |         |
-------------------------------------------------
...


-------------------------------------------------
|   | dineDate | dineType | menuName |         |
-------------------------------------------------
| 0 |  %Y%m%d  |          |          |         |
-------------------------------------------------
| 1 |          |          |          |         |
-------------------------------------------------
...

我想将两个数据帧合并为一个输出.如您所见,主要问题是每个表的索引彼此不同.我希望输出遵循第二个表的格式.每张桌子开始的日期也不同.我将如何加入这两个数据框?

I want to join the two dataframes into one output. As you can see, the main problem is that the indexes from each table are different from each other. I want the output to follow the second table's format. Also the dates which each table starts from are different. How would I join these two dataframes?

推荐答案

如果你看一下 文档,它说你可以使用 left_onright_onleft_index, right_index 属性用于基于数据框中的列和索引进行连接.

If you look at the documentation, it says you can use left_on, right_on and left_index, right_index attributes for joining based on columns and index in data frame.

pd.merge(df1, df2, left_index=True, right_on='dineDate')

这篇关于 pandas 加入具有不同索引级别/日期时间的数据帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆