我想用datetime set_index dateFrame
作者:互联网
poorList = [datetime.date(2016, 5, 2),
datetime.date(2016, 8, 26),
datetime.date(2016, 6, 9),
datetime.date(2016, 3, 4)]
dateForm.set_index(poorList)
那是错误的:
File “pandas\index.pyx”, line 137, in pandas.index.IndexEngine.get_loc
(pandas\index.c:4066)
File “pandas\index.pyx”, line 159, in pandas.index.IndexEngine.get_loc (pandas\index.c:3930)
File “pandas\hashtable.pyx”, line 675, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12408)
File “pandas\hashtable.pyx”, line 683, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12359)
KeyError: datetime.date(2016, 5, 2)
请告诉我该怎么做?
解决方法:
DataFrame.set_index()需要将列名或列列表作为参数,因此您应该执行以下操作:
dateForm['date'] = poorList
dateForm.set_index('date', inplace=True)
标签:pandas,list,datetimeindex,python,date 来源: https://codeday.me/bug/20191026/1938462.html