0

I'm trying to read a json file that contains an attribute like "registration":1540558108796.0. When pandas read, it converts the number to 1.54056e+12

I've tried to set dtypes:

df = pd.read_json(filepath, dtype={'registration': object}, lines=True)

But still printing same value 1.54056e+12.

How can I fix it?

1 Answers1

0

Try this

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

Try This one

 df['registration']=df.registration.map(lambda x: '{:.3f}'.format(x))
Alkesh Mahajan
  • 469
  • 6
  • 17
  • It truncates the number and returns 1540558108796, when original is 1540558108796.0. If you try with a number like 1540558108796.36, it returns 1540558108796. It's not a good solution. – powerPixie Dec 17 '19 at 12:33
  • 1
    Try 2nd option in above answer. you can replace 3f with any number. – Alkesh Mahajan Dec 17 '19 at 12:44