pandas astype()错误

由于数据出现错误
DataError: No numeric types to aggregate

改正以后才认识到astype的重要性。

Top15['populations'] = Top15['Energy Supply'].div(Top15['Energy Supply per Capita']).astype(float)
df_mean = ((df.set_index('Continent').groupby(level=0)['populations'].agg({'mean' : np.mean})))
#加了astype(float)后无错误

 

posted @ 2018-06-29 11:31  卷积  阅读(694)  评论(0编辑  收藏  举报