我有一个带有两个索引的pandas系列:
df_agg=df.groupby(['yearID','teamID']).sum()['Salary']
df_agg.head()
yearID teamID
1985 ATL 14807000
BAL 11560712
BOS 10897560
CAL 14427894
CHA 9846178
我希望你能将int转换成类似以下的pandas数据框:
yearID teamID Salary
1985 ATL 14807000
1985 BAL 11560712
1985 BOS 10897560
1985 CAL 14427894
1985 CHA 9846178
我尝试使用:
df_new=df_agg.reset_index(inplace=True)
但是我收到了以下错误:
类型错误 追踪 (最近的调用在最上面) in () ----> 1 df_new=df_agg.reset_index(inplace=True)
在C:\Users\ameimand\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\series.py中,重置索引时出现了问题。您可以尝试修改参数 level、drop 或 name,或者使用 inplace 参数来直接修改原始数据。
index=new_index).__finalize__(self)
967 elif inplace:
--> 968 raise TypeError('Cannot reset_index inplace on a Series '
969 'to create a DataFrame')
970 else:
TypeError: Cannot reset_index inplace on a Series to create a DataFrame