0

I'm trying to put together two multi-index dataframes. The original dataframes have the same exact columns and similar values and are then grouped by the same columns.

original dataframe example like below (I'm making the columns since actual data is confidential)

receiver product_name sent_time receive_time product_count subcomponent_count_1 subcomponent_count_2 packer
John LLC Apple watch 2021-10-20 2021-10-21 20 10 15 employee1
Sam LLC Apple pencil 2021-10-05 2021-10-06 10 7 2 employee1
.. .. .. .. .. .. .. ..

the steps I took to transform the dataframes:

df3 = df1.groupby(['receiver','product_name','sent_time','receive_time','product_count']...
df4 = df2.groupby(['receiver','product_name','sent_time','receive_time','product_count']...

df_i_want = pd.concat([df_3,df_4])

However, df_i_want does not have the multi-index structure and is putting all the groupby columns in the same column.

what can do I to put these two multi-index df together (It's not an option to concat df1 and df2 and then do groupby)?

Thanks y'all!

1
  • What is the purpose of groupby? If you simply want to have a dataframe with all rows of df1 and df2, you can just do df_i_want = df1.append(df2)? Commented Oct 28, 2021 at 12:38

1 Answer 1

0
df_you_want = df_3.join(df_4.reindex(df_3.index, level=0))

Source: Merge two dataframes with multi-index

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.