Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_level_values() method for MultiIndex containing dates #2449

Closed
aldanor opened this issue Dec 7, 2012 · 2 comments
Closed

get_level_values() method for MultiIndex containing dates #2449

aldanor opened this issue Dec 7, 2012 · 2 comments
Assignees
Milestone

Comments

@aldanor
Copy link
Contributor

aldanor commented Dec 7, 2012

I was wondering if it was possible to elegantly extract the values of a MultiIndex which contains dates as datetime (and not an ndarray of datetime64[ns] which screws things up)?

>>> print df

                  numtrades
date       id              
2012-01-03 11891          1
           14259          2
2012-01-05 14259          1
2012-01-06 11891          7
2012-01-09 11891          2
2012-01-10 11891         12
           14259          4
           10304          2
2012-01-11 11891         11
           14259          8

>>>  df.index[0]

(<Timestamp: 2012-01-03 00:00:00>, 11891)

>>> df.index.get_level_values('date')

array([1970-01-16 16:00:00, 1970-01-16 16:00:00, 1970-01-16 64:00:00,
       1970-01-16 88:00:00, 1970-01-16 160:00:00, 1970-01-16 184:00:00,
       1970-01-16 184:00:00, 1970-01-16 184:00:00, 1970-01-16 208:00:00,
       1970-01-16 208:00:00], dtype=datetime64[ns])

Of course, we can always use to_datetime and then to_pydatetime, is that the preferred method? Am I missing something?

@wesm
Copy link
Member

wesm commented Dec 7, 2012

Yeah, this should be reasonably simple to work around

@aldanor
Copy link
Contributor Author

aldanor commented Dec 7, 2012

Yea. It just looks a bit inconsistent, I guess.

@ghost ghost assigned wesm Dec 7, 2012
@wesm wesm closed this as completed in d010899 Dec 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants