首页 > 解决方案 > KeyError: 'date' while set date column as a index with pandas

问题描述

file.csv 有一个带有“日期”列的 CSV 文件,并希望将其值设置为索引,但出现错误 KeyError:“日期”

试过:

file=pd.read_csv('file.csv',sep='delimiter' , encoding='latin-1')
file=file.set_index(pd.DatetimeIndex(file['date'].values))

日期列如下所示:

05/02/2017
06/02/2017
07/02/2017

标签: pythonpandascsvdatetimedatetime-format

解决方案


推荐阅读