Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting exponent or scientific number into integer in pandas python

Tags:

python

pandas

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.

like image 465
Muhammad Ahmed Avatar asked Apr 14 '18 22:04

Muhammad Ahmed


People also ask

How do I change to INT in pandas?

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.


2 Answers

This worked for me, worth giving a try:

df['col_name'] = df['col_name'].astype('int64') 
like image 141
Shalini Baranwal Avatar answered Oct 05 '22 23:10

Shalini Baranwal


I had the same problem. Use

df['Tata'].map(int)
like image 23
Li Wang Avatar answered Oct 05 '22 22:10

Li Wang