question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

partial slicing FAILS with a datetimeindex

See original GitHub issue

Hi,

I have a simple dataframe with a multiindex.

stats.index.names
Out[67]: FrozenList([u'day', u'category'])

day is a time variable, category is a string.

stats.index.inferred_type
Out[69]: 'mixed'

stats.index.dtype_str
Out[68]: 'object'

if I type

idx=pd.IndexSlice
stats.loc[idx['2015-01-01',:],:]

I get the correct slice at ‘2015-01-01’, that is all the observations for all the categories on that day.

If I type

idx=pd.IndexSlice
stats.loc[idx['2015',:],:] 

I get back (almost) all my observations, even for years other than 2015.

What can be the problem here? I cannot paste the data unfortunately but I am happy to help in any way.

Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Jul 1, 2016

@randomgambit But anyway, thanks for reporting!

0reactions
randomgambitcommented, Jul 1, 2016

damn I was proud of finding a cool bug, you destroyed my dreams

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrong DateTimeIndex slicing when freq is None #2389 - GitHub
When Dask DataFrame is constructed from Pandas DataFrame with DateTimeIndex but freq is None, dask loc slicing fails.
Read more >
How to subscript / slice / select a datetime index dataframe ...
You can continue to subscript by partial date string to specify a date range, e.g. df.loc['2020-01'] # for date range within a month....
Read more >
Pandas Tutorial-Indexing, Slicing, Date & Times - Medium
We can slice partial datetime strings by providing a Start and Stop string separated by a Colon : . This Slices all the...
Read more >
Indexing time series data in pandas - wrighters.io
In pandas, a DatetimeIndex is used to provide indexing for pandas Series and ... Index types first, then talk about the basics of...
Read more >
Indexing and selecting data — pandas 1.5.2 documentation
In this section, we will focus on the final point: namely, how to slice, dice, and generally get and set subsets of pandas...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found