a = df.groupby('actor_1_name')['gross'].sum()
b = df.groupby('actor_2_name')['gross'].sum()
c = df.groupby('actor_3_name')['gross'].sum()
x = pd.concat([a,b,c]).nlargest(3)
x
如何让它看起来像这样:
Jezrael的新产品:
答案 0 :(得分:0)
从print(i,"!=", n)
- DataFrame
添加Series
index
创建新列:
x = pd.concat([a,b,c]).nlargest(3).rename_axis('name').reset_index()
样品:
s = pd.Series([3.71,3.39,3.26],index=['Johny Depp','Harrison Ford','tom Hanks'],name='gross')
print (s)
Johny Depp 3.71
Harrison Ford 3.39
tom Hanks 3.26
Name: gross, dtype: float64
df = s.rename_axis('name').reset_index()
print (df)
name gross
0 Johny Depp 3.71
1 Harrison Ford 3.39
2 tom Hanks 3.26
df = s.reset_index().rename(columns={'index':'name'})
print (df)
name gross
0 Johny Depp 3.71
1 Harrison Ford 3.39
2 tom Hanks 3.26