Skip to content Skip to sidebar Skip to footer

Pandas To_csv Makes Timestamps Into Tuples

I have a dataframe with a column of timestamps that I'd like to write to a CSV file, but running into some problems as it seems to be outputting a tuple. print df['mydate'].loc[0],

Solution 1:

If your goal is to get a date that is recognised by Excel, try doing df['mydate'] = df.mydate.dt.date.astype(str) before saving it as a csv.

If you wanted the time too, you can leave out the .dt.date part. For completeness, you can use .dt.strftime to get things according to some custom format, although this is probably not necessary in this particular case.

Post a Comment for "Pandas To_csv Makes Timestamps Into Tuples"