我有两个包含[{datetime.datetime: int}...]
的字典列表。我使用pd.Series(list_of_dict)
将其转换为系列对象。但是,对于一个列表,它将其转换为具有pd.series
类型索引的Index
。另一个是DatetimeIndex
索引。造成这种不一致的原因可能是什么?
我想要一个DatetimeIndex
索引btw:P非常感谢!
示例:ss=pd.Series(d)
s=pd.Series(datetime_counter)
In [120]: list(d.keys())[0]
Out[123]: datetime.datetime(2018, 11, 9, 3, 47, 57)
In [124]: list(datetime_counter.keys())[0]
Out[132]: datetime.datetime(2018, 11, 7, 7, 35, 38)
In [133]: ss.index
Out[136]:
DatetimeIndex(['2018-11-09 03:47:57', '2018-11-09 09:12:19',
'2018-11-09 09:02:42', '2018-11-09 09:02:37',
'2018-11-09 09:02:23', '2018-11-09 09:00:42',
'2018-11-09 08:38:37', '2018-11-09 06:50:53',
'2018-11-08 10:24:49', '2018-11-08 10:31:28',
...
'2017-09-25 12:27:12', '2017-09-25 12:19:55',
'2017-09-25 11:34:57', '2017-09-25 11:31:55',
'2017-09-25 11:24:56', '2017-09-25 11:23:58',
'2017-09-25 11:08:29', '2017-09-25 11:02:00',
'2017-09-26 00:24:13', '2017-09-26 06:51:14'],
dtype='datetime64[ns]', length=56639, freq=None)
In [137]: s.index
Out[137]:
Index([2018-11-07 07:35:38, 2018-11-05 17:52:32, 2018-11-06 20:37:20,
2018-11-06 14:19:13, 2018-11-06 09:50:49, 2018-11-06 09:32:45,
2018-11-05 18:43:29, 2018-11-05 18:27:14, 2018-11-05 18:00:52,
2018-11-05 17:57:05,
...
2011-03-16 10:35:50, 2011-03-15 21:52:00, 2017-10-31 23:03:20,
2017-10-20 10:00:11, 2017-10-18 20:35:47, 2017-10-19 22:16:08,
2017-10-19 15:40:42, 2017-10-19 09:33:22, 2017-10-19 07:12:23,
2017-10-18 22:53:12],
dtype='object', length=83539)
In [138]: