0

A python dataframe 'dff' containing data imported from SAS is having a date field whose type is showing as below by python:

dff.effvdate.head()
Out[47]: 
0    b'09JUL2013'
1    b'17OCT2013'
2    b'03MAR2014'
3    b'08MAY2014'
4    b'10MAR2015'
Name: effvdate, dtype: object

I am trying to convert this date to datetype as below:

dff['REPORT_MONTH'] =[dt.datetime.strptime(d,"%d%b%Y").date() for d in dff['effvdate']]

showing this error

TypeError: strptime() argument 1 must be str, not bytes

As i am new to python, need help on this.

FarrukhJ
  • 139
  • 1
  • 8

1 Answers1

0

The error TypeError: strptime() argument 1 must be str, not bytes gives you the information you need to know! d is in bytes, not a string. you should cast d to string.

dff['REPORT_MONTH'] =[dt.datetime.strptime(d.decode('UTF-8'),"%d%b%Y").date() for d in dff['effvdate']]

should work.

see What does the 'b' character do in front of a string literal?

Community
  • 1
  • 1
honi
  • 946
  • 1
  • 7
  • 18