Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I store slicers in a variable? (Pandas/Python) [duplicate]

Tags:

python

pandas

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?

like image 415
cjm2671 Avatar asked Oct 27 '25 05:10

cjm2671


1 Answers

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

like image 190
skyking Avatar answered Oct 29 '25 18:10

skyking



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!