我正在尝试两个数据帧之间的合并.每个数据框都有两个索引级别(日期,cusip).例如,在列中,某些列匹配两者(货币,adj日期).
通过索引合并这些的最佳方法是什么,但不要取两份货币和约会日期.
每个数据框是90列,所以我试图避免手动编写所有内容.
df:                 currency  adj_date   data_col1 ...
date        cusip
2012-01-01  XSDP      USD      2012-01-03   0.45
...
df2:                currency  adj_date   data_col2 ...
date        cusip
2012-01-01  XSDP      USD      2012-01-03   0.45
...
如果我做:
dfNew = merge(df, df2, left_index=True, right_index=True, how='outer')
我明白了
dfNew:              currency_x  adj_date_x   data_col2 ... currency_y adj_date_y
date        cusip
2012-01-01  XSDP      USD      2012-01-03   0.45             USD         2012-01-03
谢谢!...