4

I'm just wondering if I can do something like:

df.loc['1990':'2000'] 

by doing something like:

my_slice = '1990':'2000' df.loc[my_slice] 

What I've written doesn't work, but is there something similar that does?

1
  • 2
    You can create a slice('1990', '2000') Commented Jul 4, 2016 at 7:30

1 Answer 1

3

Yes, but you don't write slices like that. You write slice('1900', '2000', None) instead.

Sign up to request clarification or add additional context in comments.

2 Comments

What's the 'None' part? (can't find slice in the docs) Thanks!
@cjm2671 that's the step, just like the : notation - None is the default, so redundant. As for the docs: docs.python.org/2/library/functions.html#slice

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.