月份缩写python_用法语月份缩写解析日期
一個解決方案是import pandas as pd
df = pd.DataFrame({'french datetime':[u'18-oct.-2015',u'12-nov.-2015',u'02-d\xe9c.-2015',u'26-janv.-2016',u'02-f\xe9vr.-2016',u'31-mai-2016',u'01-juin-2016']})
# make a dictionary that maps the month name in french to a number
frenc_to_eng = {u'oct.': u'10', u'nov.':u'11',u'janv.':u'1',u'd\xe9c.':u'12',u'f\xe9vr.':u'2',u'mai':u'5',u'juin':u'6'}
# make new columsn for day month and year. FOr month, map the french name to month numbers
df['day'] = df['french datetime'].apply(lambda x : x.split('-')[0])
df['month'] = df['french datetime'].apply(lambda x : x.split('-')[1]).map(frenc_to_eng)
df['year'] = df['french datetime'].apply(lambda x : x.split('-')[2])
# make date time column from year, month and day.
df['date'] = pd.to_datetime(df['year']+'-'+df['month']+'-'+df['day'],format='%Y-%m-%d', errors='ignore')
print df
結果
^{pr2}$
總結
以上是生活随笔為你收集整理的月份缩写python_用法语月份缩写解析日期的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 万圣节习俗南瓜灯Jack-o’-lant
- 下一篇: C#时间格式转换问题(12小时制和24小