Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress Scientific Format in a Dataframe Column

I have a column called accountnumber with values similar to 4.11889000e+11 in a pandas dataframe. I want to suppress the scientific notation and convert the values to 4118890000. I have tried the following method and did not work.

df = pd.read_csv(data.csv)
pd.options.display.float_format = '{:,.3f}'.format

Please recommend.

like image 252
iprof0214 Avatar asked Apr 18 '18 22:04

iprof0214


People also ask

How do I get rid of scientific notation in Python?

Use a string literal to suppress scientific notation Use the string literal syntax f"{num:. nf}" to represent num in decimal format with n places following the decimal point.

How do I print without scientific notation in Python?

Within a given f-string, you can use the {...:f} format specifier to tell Python to use floating point notation for the number preceding the :f suffix. Thus, to print the number my_float = 0.00001 non-scientifically, use the expression print(f'{my_float:f}') .

How do you stop scientific notation in Pyspark?

There is no direct way to configure and stop scientific notation in spark however you can apply format_number function to display number in proper decimal format rather than exponential format.


1 Answers

I assume the exponential notation for the account numbers must come from the data file. If I create a small csv with the full account numbers, pandas will interpret them as integers.

     acct_num
0  4118890000
1  9876543210

df['acct_num'].dtype
Out[51]: dtype('int64')

However, if the account numbers in the csv are represented in exponential notation then pandas will read them as floats.

       acct_num
0  4.118890e+11
1  9.876543e+11

df['acct_num'].dtype
Out[54]: dtype('float64')

You have 2 options. First, correct the process that creates the csv so the account numbers are written out correctly. The second is to change the data type of the acct_num column to integer.

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

df
Out[66]: 
       acct_num
0  411889000000
1  987654321000
like image 59
floydn Avatar answered Sep 20 '22 22:09

floydn