user3423407
user3423407

Reputation: 341

Display DataFrame as Columns

I have a set of calculations that I need to do on a set of data. I know how to get the values of each of these individually

For eg

This is the dataframe

Name Score#
Joe   10
Mary  30
Joe   20
James 50
Dan   40
Joe   50

If i want the mean, max etc

df.groupby('Name').mean()
df.groupby('Name').max()

Now this does get me what I need but I ideally want to display it as columns. So for eg

Name    Mean   Max
Joe     26.67   50
Mary    30      30
James   50      50
Dan     40      40

I get it now as

 Name    Mean   
Joe     26.67   
Mary    30      
James   50      
Dan     40      

Name    Max
Joe     50
Mary    30
James   50
Dan     40

I thought if I place it side by side like

print(df_mean+df_max)

But this throws an error

Any help will be much appreciated. Thanks

Upvotes: 0

Views: 42

Answers (1)

Camille K
Camille K

Reputation: 50

Try pandas.concat([df_mean, df_max], axis = 1)

See the pandas documentation here: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.concat.html

Upvotes: 1

Related Questions