Pandas: Inconsistency in converting from datetime.datetime object to Index / DatetimeIndex
up vote
0
down vote
favorite
I have two lists of dictionarys both contain [datetime.datetime: int...]
. I use pd.Series(list_of_dict)
to convert it to a series object. However, for one list it converts it to a pd.series
with Index
type index. Another is DatetimeIndex
index. What could reasons be for this inconsistency?
I want a DatetimeIndex
index btw:P Many thanks!
A sample: 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]:
python pandas
add a comment |
up vote
0
down vote
favorite
I have two lists of dictionarys both contain [datetime.datetime: int...]
. I use pd.Series(list_of_dict)
to convert it to a series object. However, for one list it converts it to a pd.series
with Index
type index. Another is DatetimeIndex
index. What could reasons be for this inconsistency?
I want a DatetimeIndex
index btw:P Many thanks!
A sample: 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]:
python pandas
I have run into similar situations in the past, thats why now I always uses.index = pd.to_datetime(s.index)
every time I create one to ensure I haveDatetimeIndex
and notIndex
. Don't know the reason though.
– Pankaj Joshi
Nov 10 at 5:53
1
I usedastype
:D tks for your comment!
– spacegoing
Nov 11 at 7:32
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have two lists of dictionarys both contain [datetime.datetime: int...]
. I use pd.Series(list_of_dict)
to convert it to a series object. However, for one list it converts it to a pd.series
with Index
type index. Another is DatetimeIndex
index. What could reasons be for this inconsistency?
I want a DatetimeIndex
index btw:P Many thanks!
A sample: 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]:
python pandas
I have two lists of dictionarys both contain [datetime.datetime: int...]
. I use pd.Series(list_of_dict)
to convert it to a series object. However, for one list it converts it to a pd.series
with Index
type index. Another is DatetimeIndex
index. What could reasons be for this inconsistency?
I want a DatetimeIndex
index btw:P Many thanks!
A sample: 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]:
python pandas
python pandas
asked Nov 10 at 3:01
spacegoing
1,39321026
1,39321026
I have run into similar situations in the past, thats why now I always uses.index = pd.to_datetime(s.index)
every time I create one to ensure I haveDatetimeIndex
and notIndex
. Don't know the reason though.
– Pankaj Joshi
Nov 10 at 5:53
1
I usedastype
:D tks for your comment!
– spacegoing
Nov 11 at 7:32
add a comment |
I have run into similar situations in the past, thats why now I always uses.index = pd.to_datetime(s.index)
every time I create one to ensure I haveDatetimeIndex
and notIndex
. Don't know the reason though.
– Pankaj Joshi
Nov 10 at 5:53
1
I usedastype
:D tks for your comment!
– spacegoing
Nov 11 at 7:32
I have run into similar situations in the past, thats why now I always use
s.index = pd.to_datetime(s.index)
every time I create one to ensure I have DatetimeIndex
and not Index
. Don't know the reason though.– Pankaj Joshi
Nov 10 at 5:53
I have run into similar situations in the past, thats why now I always use
s.index = pd.to_datetime(s.index)
every time I create one to ensure I have DatetimeIndex
and not Index
. Don't know the reason though.– Pankaj Joshi
Nov 10 at 5:53
1
1
I used
astype
:D tks for your comment!– spacegoing
Nov 11 at 7:32
I used
astype
:D tks for your comment!– spacegoing
Nov 11 at 7:32
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235663%2fpandas-inconsistency-in-converting-from-datetime-datetime-object-to-index-dat%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I have run into similar situations in the past, thats why now I always use
s.index = pd.to_datetime(s.index)
every time I create one to ensure I haveDatetimeIndex
and notIndex
. Don't know the reason though.– Pankaj Joshi
Nov 10 at 5:53
1
I used
astype
:D tks for your comment!– spacegoing
Nov 11 at 7:32