Answers:
使用该to_datetime
函数,指定一种格式以匹配您的数据。
raw_data['Mycol'] = pd.to_datetime(raw_data['Mycol'], format='%d%b%Y:%H:%M:%S.%f')
SettingWithCopyWarning
使用@达斯- behfans stackoverflow.com/a/42773096/4487805
您可以使用DataFrame方法.apply()
对Mycol中的值进行操作:
>>> df = pd.DataFrame(['05SEP2014:00:00:00.000'],columns=['Mycol'])
>>> df
Mycol
0 05SEP2014:00:00:00.000
>>> import datetime as dt
>>> df['Mycol'] = df['Mycol'].apply(lambda x:
dt.datetime.strptime(x,'%d%b%Y:%H:%M:%S.%f'))
>>> df
Mycol
0 2014-09-05
raw_data['Mycol'] = pd.to_datetime(raw_data['Mycol'], format='%d%b%Y:%H:%M:%S.%f')
可以,但是会导致Python警告:试图在DataFrame的切片副本上设置一个值。尝试.loc[row_indexer,col_indexer] = value
改用
我猜这是由于一些链接索引。
format
参数不是必需的。to_datetime
很聪明 继续尝试,而不尝试匹配您的数据。