1

I want to find the week number of a date column in my datasets. The date is in the format "2020-09-27 07:14:01.114051200". However I could not convert to week number.

I tried the below code:

date=mydate.strftime("%W")

I'm getting this error: AttributeError: 'Series' object has no attribute 'strftime'

C. Fennell
  • 992
  • 12
  • 20
Yogesh Govindan
  • 339
  • 2
  • 12

1 Answers1

4

You need to first convert your date in string form to a datetime object. Then you can ask for the week number from that object.

import datetime
datestr = "2020-09-27 07:14:01.114051200"
mydate = datetime.datetime.strptime(datestr.split('.')[0] , '%Y-%m-%d %H:%M:%S')
date=mydate.strftime("%W")
print(date)

Result:

38
CryptoFool
  • 21,719
  • 5
  • 26
  • 44