Home > Mobile >  Amount of rows copied into new DataFrame is limited by exisitng number of rows
Amount of rows copied into new DataFrame is limited by exisitng number of rows

Time:09-27

I have several excel files from which I want to extract the data of given colum (each of different size) of each of them and copy it to a new Data Frame. The way I did is to convert each excel to a data frame and then just copy them to the new df as follows:

df_final['Column_name'] = df_i['Column_name']  # df_final is the final dataframe, whereas df_i is one of the initial dataframes

I have observed that the amount of rows of the final dataframe is limited to the amount of columns of the first dataframe that I copied, so if the rest og dataframes have more rows of data, this information is not copied into the final data frame. Why is this happening? How can I solve the issue?

CodePudding user response:

You could try pd.concat:


import pandas as pd

pd1 = pd.DataFrame({'a': [1]})
pd2 = pd.DataFrame({'a': [1, 2]})
pd3 = pd.DataFrame({'a': [1, 2, 3]})
your_dfs= [pd1, pd2, pd3]

pd_final = pd.concat(your_dfs, axis=1)

print(pd_final)

  • Related