0

I have a column df['Date] which is a datetime64[ns] type and after doing the

sheets= sorted(df['Date'].unique(), reverse =True)

I get a numpy.datetime64('2022-04-20T00:00:00.000000000') format, but I want it to be of this format datetime.date(2022, 2, 16).

  • May be try the most upvoted answer from https://stackoverflow.com/questions/16176996/keep-only-date-part-when-using-pandas-to-datetime? – medium-dimensional May 01 '22 at 16:59
  • maybe you should use `df.sort_values()` instead of `sorted()` and then you would still have `DataFrame` so you could use `.apply()`. OR you should use `.apply` before `.unique` – furas May 01 '22 at 18:03

1 Answers1

0

try to use something like this :

test = datetime.datetime.strptime("2022-04-20T00:00:00.000Z","%Y-%m-%dT%H:%M:%S.%fZ")
new_format = "%Y-%m-%d"
test.strftime(new_format)
DataSciRookie
  • 798
  • 1
  • 3
  • 12