【发布时间】:2018-09-24 23:19:30
【问题描述】:
我是 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”功能,但我不明白如何在这种情况下使用它。
【问题讨论】: