在 pandas python中将指数或科学数转换为整数 [英] converting exponent or scientific number into integer in pandas python

查看:256
本文介绍了在 pandas python中将指数或科学数转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的初学者,试图从具有最高idmb等级和最高总值的数据集中获取该行,但我想得到的值不是整数.我如何将其转换为整数?以及如何获得用于执行统计功能的特定值.

i am a beginner in python and trying to get the row from the data set which has highest idmb rating and highest gross total which i have manged to get but my value of gross_total isn't in integer. how i can convert it into integer? and how to get that specific value for performing statistical functions.

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"功能,但是我不明白如何在此情况下使用它.

i have searched and came to know about the "pd.to_numeric" and "astype" functions but i couldnt understand how to use this in this sitution.

推荐答案

这对我有用,值得一试:

This worked for me, worth giving a try:

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

这篇关于在 pandas python中将指数或科学数转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆