df:
name score
A 1
A 2
A 3
A 4
A 5
B 2
B 4
B 6
B 8
Want to get the following new dataframe in
import pandas as pd
import io
import numpy as np
data = """
name score
A 1
A 2
A 3
A 4
A 5
B 2
B 4
B 6
B 8
"""
df = pd.read_csv(io.StringIO(data), delimiter='\s+')
df2 = df.groupby('name').describe().reset_index().T.drop('name')
arr = np.array(df2).reshape((4,8))
df2 = pd.DataFrame(arr[1:], index=['name','A','B'])
print(df2)
That will give you df2 as:
0 1 2 3 4 5 6 7
name count mean std min 25% 50% 75% max
A 5 3 1.58114 1 2 3 4 5
B 4 5 2.58199 2 3.5 5 6.5 8