在 pandas python 中将指数或科学数转换为整数

新手上路,请多包涵

我是 python 的初学者,我试图从数据集中获取具有最高 idmb 评级和最高总计的行,但我的 gross_total 值不是整数。我怎样才能把它转换成整数?以及如何获得用于执行统计功能的特定值。

 import pandas as pd

dataset=pd.read_excel('movies.xls')

name=dataset['Title']
idmb=dataset['IMDB Score']

networth=dataset['Gross Earnings']

test_df=pd.DataFrame({'movie':name,
                  'rating':idmb,
                  'gross_total':networth})

 nds=test_df.dropna(axis=0,how='any')

 a=nds['gross_total'].astype(int)

 highest_rating =nds.loc[nds['rating'].idxmax()]

 highiest_networth=nds.loc[ nds['gross_total'].idxmax()]

 print(highest_rating)

 print(highiest_networth)

我得到这个输出

  gross_total                  2.83415e+07
  movie          The Shawshank Redemption
  rating                               9.3
  Name: 742, dtype: object

我已经搜索并开始了解“pd.to_numeric”和“astype”函数,但我无法理解如何在这种情况下使用它。

原文由 Muhammad Ahmed 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 560
1 个回答

这对我有用,值得一试:

 df['col_name'] = df['col_name'].astype('int64')

原文由 Shalini Baranwal 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题