Why does Pandas inner join give ValueError: len(left_on) must equal the number of levels in the index of “right”?

use merge if you are not joining on the index:

merged = pd.merge(DataFrameA,DataFrameB, on=['Code','Date'])

Follow up to question below:

Here is a reproducible example:

import pandas as pd
# create some timestamps for date column
i = pd.to_datetime(pd.date_range('20140601',periods=2))

#create two dataframes to merge
df = pd.DataFrame({'code': ['ABC','EFG'], 'date':i,'col1': [10,100]})
df2 = pd.DataFrame({'code': ['ABC','EFG'], 'date':i,'col2': [10,200]})

#merge on columns (default join is inner)
pd.merge(df, df2, on =['code','date'])

This results is:

    code    col1    date    col2
0   ABC     10      2014-06-01  10
1   EFG     100     2014-06-02  200

What happens when you run this code?

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)