Skip to content
Advertisement

Use aggregate computations to obtain mean and std between two dataframes

I have two dataframes: df1 and df2. I want to use aggregates to obtain the mean and std between the s_values in both dataframes and put those results in a new dataframe called new_df

in df1 =

JavaScript

in df 2 =

JavaScript

The result that I am trying to get would look something like this. desired output new_df =

JavaScript

I have managed to build a dataframe with a column with the difference in values using the code

JavaScript

this gives me this output but I do not know how to add the columns for the aggregate mean and std

JavaScript

Any help is much appreciated

Advertisement

Answer

If i am understanding you right, you want to join the two dataframes and compute the mean and std dev

Can you try this?

JavaScript

You could also try this if you want a groupby solution as mentioned in your comments

pd.concat([df1[['difference']], df2[['difference']]]).groupby(level=0).std()

pd.concat([df1[['difference']], df2[['difference']]]).groupby(level=0).mean()

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement