Python Forum

Full Version: Dealing with Exponential data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Yes opened in notepad++ my records are as
2229708157109620
2204081406354340
892984837048418000 respectively

Issue raised for me when i tried to join the records after reading it to pandas to my database records with database table, not able to join here as it has not different records
in csv 2229708157109620 have changed to 2229708157109627
in csv 2204081406354340 have changed to 2204081406354342
in csv 892984837048418000 have changed to 892984837048418304

database table has record as below
2229708157109620
2204081406354340
892984837048418000
To close the thread once and for all

spam.csv - view it in notepad++

Output:
2229708157109627 2204081406354342 892984837048418304 2229708157109620 2204081406354340 892984837048418000
# using csv
import csv
print('Print the file using csv module')
with open('spam.csv') as f:
    rdr =  csv.reader(f)
    for line in rdr:
        num, =  line
        print(num) # here it prints it as str
        print(int(num)) # convert it to number


# and using pandas        
print('\nPrint the file as pandas dataframe')    
import pandas as pd
df = pd.read_csv('spam.csv',index_col=None, header=None)
print(df)
output
Output:
Print the file using csv module 2229708157109627 2229708157109627 2204081406354342 2204081406354342 892984837048418304 892984837048418304 2229708157109620 2229708157109620 2204081406354340 2204081406354340 892984837048418000 892984837048418000 Print the file as pandas dataframe 0 0 2229708157109627 1 2204081406354342 2 892984837048418304 3 2229708157109620 4 2204081406354340 5 892984837048418000
and here is what you will see in Excel when open the same file

[attachment=642]

e.g. in cell A3 you see 892984837048418000 but in fact in the file the value is 892984837048418304
Pages: 1 2