我有一个字符串"Mai 2, 2018 6:35:52 AM"
。
我将当地人设置为德语(只有一个我能上班的人是deu_deu) 尝试格式化后,我得到的数据仍然错误。
import pandas as pd
import locale
locale.setlocale(locale.LC_ALL, 'deu_deu')
input_file_path = 'C:\\Users\\xxx'
customer_file_path = pd.read_csv(input_file_path,sep='\t', warn_bad_lines=True, error_bad_lines=False)
customer_file_path['RECEIVED_DATE'] = customer_file_path['RECEIVED_DATE'].str.replace(',', '')
customer_file_path['RECEIVED_DATE'] = customer_file_path['RECEIVED_DATE'].str.replace('AM', 'am')
customer_file_path['RECEIVED_DATE'] = customer_file_path['RECEIVED_DATE'].str.replace('PM', 'pm')
customer_file_path['RECEIVED_DATE'] = pd.to_datetime(customer_file_path['RECEIVED_DATE'] ,format='%b %d %Y %I:%M:%S %p')
customer_file_path['RECEIVED_DATE'] = pd.to_datetime(customer_file_path['RECEIVED_DATE'] ,format='%b %d %Y %I:%M:%S %p').dt.strftime('%Y-%m-%d %H:%M:%S.%f')
任何一个都失败,并显示相同的消息:
getlocale returns
locale.setlocale(locale.LC_ALL, 'deu_deu')
Out[167]: 'German_Germany.1252'