方法1 :
reset_index()
>>> g uses books sum sumtoken year xanthos 1830 3 3 1840 3 3 1868 2 2 1875 1 1[4 rows x 2 columns]>>> g = g.reset_index()>>> g token year uses books sum sum0 xanthos 1830 3 31 xanthos 1840 3 32 xanthos 1868 2 23 xanthos 1875 1 1[4 rows x 4 columns]
方法2 :首先不要使用索引
as_index=False
>>> g = dfalph[['token', 'year', 'uses', 'books']].groupby(['token', 'year'], as_index=False).sum()>>> g token year uses books0 xanthos 1830 3 31 xanthos 1840 3 32 xanthos 1868 2 23 xanthos 1875 1 1[4 rows x 4 columns]



