I have a data frame that looks like this:
company Amazon Apple Yahoo
name
A 0 130 0
C 173 0 0
Z 0 0 150
It was created using this code:
import pandas as pd
df = pd.DataFrame({'name' : ['A', 'Z','C'],
'company' : ['Apple', 'Yahoo','Amazon'],
'height' : [130, 150,173]})
df = df.pivot(index="name", columns="company", values="height").fillna(0)
What I want to do is to sort the row (with index name
) according to a predefined list ["Z", "C", "A"]
. Resulting in this :
company Amazon Apple Yahoo
name
Z 0 0 150
C 173 0 0
A 0 130 0
How can I achieve that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…