我是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”函数,但我无法理解如何在这种情况下使用它。
这对我有用,值得一试:
df['col_name'] = df['col_name'].astype('int64')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)