I have 3 data-frames:
d1 = {'col1': [1, 2], 'col2': [3, 4]}
d2 = {'col1': [1,2,3], 'col2': [3,4,5]}
d3 = {'col1': [1,2,3,4,5], 'col2': [3,4,5,6,7]}
df1 = pd.DataFrame(data=d1)
df2 = pd.DataFrame(data=d2)
df3 = pd.DataFrame(data=d3)
Now i'm trying to count the amount of rows and columns of these 3 data-frames and place it in a new data-frame named my_dataframe
. This is the code I used:
dataframes = [df1, df2, df3]
number_rows = [df.shape[0] for df in dataframes]
number_columns = [df.shape[1] for df in dataframes]
my_data = {'df': dataframes, 'rows': number_rows, 'columns': number_columns}
my_dataframe = pd.DataFrame(my_data)
print(my_dataframe)
This is my output:
This is my expected output:
df - rows - columns
0 df1 - 2 - 2
1 df2 - 3 - 2
2 df3 - 5 - 2
Can someone explain me what went wrong and how I can fix this? Thank you all.