0

How can I get the datetime format from a pandas dataframe column? Format Can be anything "%Y-%m-%d", "%Y-%m", "%m-%Y", etc.

Vic13
  • 451
  • 1
  • 4
  • 16
  • you can transform any object to the date format that you want, you can just use the one you want – DanCor Feb 10 '21 at 12:07
  • Series can be np.datetime64 type or object type depending on the person who has given the input. Now I want to know its format. – Vic13 Feb 10 '21 at 12:10
  • @DanCor that's not what I want. – Vic13 Feb 10 '21 at 12:13
  • I datetime in pandas only format is `"%Y-%m-%d"`, so if there are nother formats like "%Y-%m", "%m-%Y" it is strings repr of datetimes – jezrael Feb 10 '21 at 12:17
  • @jezrael Suppose format is "%Y-%m", how can I detect this format without hardcoding as there can be different kinds of format. – Vic13 Feb 10 '21 at 12:20
  • 2
    I guess regex, but It is more complicated, if need `%Y-%m"` vs `%Y-%d"` for `2000-05` it is parse `5` for day? or for month? This is really complicated and problematic, the best is change data in question with [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and add expected output – jezrael Feb 10 '21 at 12:23
  • @jezrael Yes, that's why wanted to get a confirmation from an expert. Thanks – Vic13 Feb 10 '21 at 12:25

0 Answers0