Python Pandas-使用一系列值筛选行

Python Pandas-使用一系列值筛选行,python,pandas,Python,Pandas,我有以下数据帧df: DF_TEMP Date Home or Away Position GameWeek ... Price Goal Threat Assists Threat Goal Involvment Threat Player ...

我有以下数据帧
df

DF_TEMP                           Date Home or Away Position  GameWeek  ... Price Goal Threat  Assists Threat  Goal Involvment Threat
Player                                                          ...                                                          
Andrew Robertson    2019-08-09         Home      DEF         1  ...   7.0    0.095392        0.076136                0.171528
Dejan Lovren        2019-08-09         Home      DEF         1  ...   5.5    0.000000        0.000000                0.000000
Joel Matip          2019-08-09         Home      DEF         1  ...   5.5    0.000000        0.000000                0.000000
Joseph Gomez        2019-08-09         Home      DEF         1  ...   5.5    0.000000        0.035294                0.035294
Nathaniel Phillips  2019-08-09         Home      DEF         1  ...   0.0    0.000000        0.000000                0.000000
...                        ...          ...      ...       ...  ...   ...         ...             ...                     ...
Michail Antonio     2020-02-24         Away      MID        27  ...   6.9    0.000000        0.448161                0.448161
Nathan Holland      2020-02-24         Away      MID        27  ...   4.4    0.000000        0.000000                0.000000
Pablo Fornals       2020-02-24         Away      MID        27  ...   6.0    0.427723        0.000000                0.427723
Robert Snodgrass    2020-02-24         Away      MID        27  ...   5.2    0.000000        0.226054                0.226054
Tomas Soucek        2020-02-24         Away      MID        27  ...   5.0    0.000000        0.000000                0.000000
如果我想根据“GameWeek”值过滤它,传递一个变量,如下所示:

gameweek = 15
简单地做:

filtered_df = df[df['GameWeek']==gameweek]
我将获得所有行,其中“游戏周”为15


问题:

但是如果我传递相同的变量
gameweek
,那么从“gameweek”1到15行的
pandas
方式是什么


我所有的查询都应该是这样的:
[:gameweek]
使用,它基本上小于等于(
你的意思是你想得到
gameweek
的值从1到15?一种可能的方法是在
.isin()
方法中查询
range()

filtered_df = df[df['GameWeek'].isin(range(1,16))
filtered_df = df[df['GameWeek'] <= gameweek]
filtered_df = df[df['GameWeek'].isin(range(1,16))