将Dataframe对象转换为datepython

2024-09-30 04:31:09 发布

您现在位置:Python中文网/ 问答频道 /正文

包含从SAS导入的数据的python数据框“dff”具有日期字段,其类型由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

我正在尝试将此日期转换为日期类型,如下所示:

^{pr2}$

显示此错误

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

因为我是python新手,需要帮助。在


Tags: 数据name类型object错误outargumenthead
1条回答
网友
1楼 · 发布于 2024-09-30 04:31:09

错误TypeError: strptime() argument 1 must be str, not bytes提供了您需要知道的信息!d以字节为单位,不是字符串。你应该把d放在弦上。在

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

应该行得通。在

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

相关问题 更多 >

    热门问题