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]:









share|improve this question





















  • 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




    I used astype :D tks for your comment!
    – spacegoing
    Nov 11 at 7:32














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]:









share|improve this question





















  • 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




    I used astype :D tks for your comment!
    – spacegoing
    Nov 11 at 7:32












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]:









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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




    I used astype :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






  • 1




    I used astype :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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo