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)后无错误
The Safest Way to Get what you Want is to Try and Deserve What you Want.
原文地址:https://www.cnblogs.com/Shinered/p/9242597.html