0

How can I alter/specify the output of the following call?

import pandas as pd
pd.to_datetime('now')

Gives me e.g.

Timestamp('2018-05-09 09:56:36')

.to_datetime has a format parameter, but

pd.to_datetime('now', format='%Y%m%d-%H%M%S')

but this gives me a

ValueError: time data 'now' does not match format '%Y%m%d-%H%M%S' (match)

I also tried

pd.to_datetime('now').dt_strftime('%Y%m%d-%H%M%S')

but I end up with

AttributeError: 'Timestamp' object has no attribute 'dt_strftime'

How can achieve an output '%Y%m%d-%H%M%S' here?

I am using Python 3.6.4 and Pandas 0.22.0.

absurd
  • 1,035
  • 3
  • 14
  • 35
  • 3
    You can't change the display format for datetimes, you can only do this by converting to a string so `pd.to_datetime('now').strftime( '%Y%m%d-%H%M%S' )` but this defeats the point of having datetimes. Currently pandas does not have an option to change the way that datetimes are displayed in the output – EdChum May 09 '18 at 10:06
  • I have marked this as a duplicate of an identical question. The answer there won't help, though, for reasons explained by @EdChum. – jpp May 09 '18 at 10:27
  • @EdChum Thank you for explaining this. – absurd May 09 '18 at 11:04
  • @jpp Well, it is similar, but still I think somewhat different as I use 'now' here, i.e. and ad hoc generated timestamp. – absurd May 09 '18 at 11:06

0 Answers0