Home > Software engineering >  Get mean of specific columns with same name from multiple dataframe and put into a list
Get mean of specific columns with same name from multiple dataframe and put into a list

Time:06-12

I have multiple data frames with the same column names. How can I get the mean of specific columns ( let's say the column name I want to get is similarity ) from all data frames and put them into a list?

DF1

   similarity     count
0     0.2           2
1     0.1           3
2     0.46          4
3     0.12          8
4     0.6           10

DF2


   similarity     count
0     0.2           4
1     0.1           3
2     0.46          5
3     0.12          6
4     0.6           9

Expected Output

[ 0.296, 0.296 ]

CodePudding user response:

I'd use a list comprehension.

[df.similarity.mean() for df in [df1, df2]]
  • Related