Reputation: 109
I am using concat operation on two data-frame. But I am getting the value error: Shape of passed values is (14, 78692), indices imply (14, 78250) The dataframes has properties: [9935 rows x 6 columns] and [68316 rows x 8 columns] If we add both the rows we get 78250, but not sure why its giving this error.
final_df = pd.concat([df, tp_df],axis=1)
I have two other sets of data as well with same columns and different number of rows and its working fine on that data sets.
Upvotes: 1
Views: 790
Reputation: 25239
Without you sample data, I just make a guess. Normally, pd.concat
on axis=1
fails when there is duplicates index in either or both dataframe. Try to run these:
df.index.duplicated().any()
and
tp_df.index.duplicated().any()
If either or both return True
and you want to retain the current index of df
and tp_df
, you need outer join as follows
df.join(tp_df, how='outer')
If you don't want retain current index, just do as follows:
pd.concat([df.reset_index(drop=True), tp_df.reset_index(drop=True)],axis=1)
Note: pd.concat
with reset_index
will line-up rows and columns different than outer join, so it depends on your desired output and choose accordingly.
Upvotes: 2