Reputation: 516
I am trying to assign the value by creating empty dataframe. But the value is not getting assigned to the columns.
col_names = ['Col1','Col2','Col3','Col4','Col5','Col6']
df_stats=pd.DataFrame(columns = col_names)
df_stats['Col1']=df_1.shape[0]
df_stats['Col2']=df_2.shape[0]
I would like to get the row count of df_1 and df_2 of other dataframes and assign them to df_Stats columns. I can see the values for df_1.shape[0] and df_2.shape[0] when I print them but it is not getting assigned in the df_stats columns and returning me empty dataframe. What is the mistake I am doing here ?
Upvotes: 1
Views: 718
Reputation: 120439
Convert the scalar value to a list of one element:
df_stats['Col1']=[df1.shape[0]]
df_stats['Col2']=[df2.shape[0]]
>>> df_stats
Col1 Col2 Col3 Col4 Col5 Col6
0 5000000 10000 NaN NaN NaN NaN
Upvotes: 3