Can I store slicers in a variable? (Pandas/Python) [duplicate]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: This question already has an answer here: Python slice how-to, I know the Python slice but how can I use built-in slice object for it? 4 answers 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: Yes, but you don't write slices like that. You write slice('1900', '2000', None) instead. 转载请标明出处: Can I store slicers in a variable? (Pandas/Python) [duplicate]