Home > OS >  Losing the last 4 numbers when saving dataframe to csv in python
Losing the last 4 numbers when saving dataframe to csv in python

Time:03-28

I am trying to save twitter data is being organized in an excel file (CSV file). To do this, I've written the following code:

df.to_csv(r'C:\Users\path\tweets.csv')

This code works fine and through Jupyter.

However, I am facing a problem when attempting to save this dataframe to a csv file. I'm losing the last 4 numbers of the values as follows.

on jupyter notebook: e.g., 1368350628343205888, 1368345015873835017 Import Number as Text

Code to Generate Sample CSV:

import pandas as pd
df = pd.DataFrame({"tweet_id":[1368350628343205888,1368345015873835017]})
df.to_csv('C:\\python_work_area\\test.csv',index=False)

CodePudding user response:

setting excel column datatype to "text" may help. please check out the link below: set excel datatypes

  • Related