1

I'm trying to concat two dataframes, df y df_multindex:

df:

COL1   COL2    COL1   COL2
 10     a       20     a
 21     w2      21     w2

df_multindex:

  0      0     1      1
COL1   COL2   COL1   COL2
  1     a       1     a
 21     w2     21     w2
  1. df_multinidex has to be concat below df.
  2. df_multinidex has to remain their column name levels.
  3. So the column names of the new dataframe has to be the multindex names from df_multindex

What I have tried:

 dftotal = pd.concat([df,df_multindex], axis = 0)  

What i got was:

 TypeError: Expected tuple, got str    

What I want is:

   0      0     1      1
COL1   COL2   COL1   COL2
 10     a      20     a
 21     w2     21     w2
  1     a       1     a
 21     w2     21     w2

Thank you

1 Answer 1

1

You need MultiIndex in both DataFrames, so use:

df.columns = df_multindex.columns

dftotal = pd.concat([df,df_multindex])  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.