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)
i get this output
gross_total 2.83415e+07
movie The Shawshank Redemption
rating 9.3
Name: 742, dtype: object
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.
Convert Column to int (Integer)Use pandas DataFrame. astype() function to convert column to int (integer), you can apply this on a specific column or on an entire DataFrame. To cast the data type to 64-bit signed integer, you can use numpy. int64 , numpy.
This worked for me, worth giving a try:
df['col_name'] = df['col_name'].astype('int64')
I had the same problem. Use
df['Tata'].map(int)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With