1

I'm relatively new to python and in need of your help. I have a long DataFrame in which one column is a succession of dates. I used a pd.datetime function to translate all this column to a datetime format, as it is easier to sort them by date. I want to save this DataFrame, transformed and sorted to gain some time on the future data processing. Do you have an idea on how I should manage that issue ? My code so far is this :

import pandas as pd


df1['DATE'] = pd.to_datetime(df1.DATE)     
df1 = df1.sort_values(by=['NAME', 'DATE']) 
df1.to_csv('df1_sorted.csv')
Martin Gergov
  • 1,556
  • 4
  • 20
  • 29
marcloarec
  • 11
  • 1
  • 1
    refer [here](https://stackoverflow.com/questions/13999850/how-to-specify-date-format-when-using-pandas-to-csv) – Shijith Dec 17 '19 at 07:24
  • Hello, my problem is when I read the csv file I just saved with pd.read_csv, the type of my DATE column has been changed from "pandas._libs.tslibs.timestamps.Timestamp" to "str" – marcloarec Dec 17 '19 at 08:43
  • you can make use of the `parse_dates` argument in pandas.read_csv (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html), ie `pd.read_csv('filename.csv',parse_dates =['date_column_name'] )` – Shijith Dec 17 '19 at 08:52

0 Answers0