![](/img/trans.png)
[英]convert year and month name into datetime column for pandas dataframe
[英]Convert month(name) year to date in dataframe
我的日期列有這樣的值
Date
1971 FEB
1971 MAR
.
.
如何將其轉換為 YYYY-MM-DD 格式?
這是我試過的
df['Date'] = pd.to_datetime(df['Date'] , format='%y%b')
但我收到一條錯誤消息
ValueError: time data '1971 FEB' does not match format '%y%b' (match)
嘗試使用格式'%Y %b'
而不是'%y%b'
:
df['Date']=pd.to_datetime(df['Date'],format='%Y %b',errors='coerce')
有關格式代碼的更多信息, 請訪問此處
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.