0

Below is the script that I am using

dfs = [df2,df3,df4,df5,df6]
for i in dfs:
    df_merge = pd.merge(df1,i,how='left',on='Date')
print("Shape of df_merge = ",df_merge.shape)

Let us assume the shape of each individual dataframes is (100,2). 'Date' is the common column in all. After using above script and printing I am getting a shape of (100,3) i.e only df6 is getting merged with df1. I need to merge all in one. Any suggestion will be appreciated?

1 Answer 1

1

It is because you save every thing in df_merge. df_merge is always the latest merged, not the sum of all merged dataframes.

I would suggest to set df_merge to a value first, like this.

dfs = [df2,df3,df4,df5,df6]
df_merge = df1
for i in dfs:
    df_merge = pd.merge(df_merge,i,how='left',on='Date')
print("Shape of df_merge = ",df_merge.shape)
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.