0

I have a data frame df1 like this:

 A B C ... mean 10 100 1 std 11 110 2 median 12 120 3 

I want to make another df with separate col for each df1 col. header-row name pair:

A-mean A-std A-median B-mean B-std B-median C-mean C-std C-median ... 10 11 12 100 110 120 1 2 3 

Basically I have used the pandas.DataFrame.describe function and now I would like to transpose it this way.

2

1 Answer 1

2

You can unstack your DataFrame into a Series, flatten the Index, turn it back into a DataFrame and transpose the result.

out = ( df.unstack() .pipe(lambda s: s.set_axis(s.index.map('-'.join)) ) .to_frame().T ) print(out) A-mean A-std A-median B-mean B-std B-median C-mean C-std C-median 0 10 11 12 100 110 120 1 2 3 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.