如果这是你的 df:
Home_team Away_team Home_score Away_score
GameID Date
1 2013-01-23 Team A Team B 5 1
2 2013-01-23 Team C Team D 3 3
3 2013-01-30 Team A Team C 1 2
4 2013-01-30 Team B Team D 2 3
您可以按日期切片,例如:
start = pd.datetime(2013,1,20)
end = pd.datetime(2013,1,25)
selection = (df.index.get_level_values('Date') >= start) & (df.index.get_level_values('Date') <= end)
df[selection]
Home_team Away_team Home_score Away_score
GameID Date
1 2013-01-23 Team A Team B 5 1
2 2013-01-23 Team C Team D 3 3
并由团队:
team = ['Team C']
df[df.apply(lambda x: x.isin(team)).max(axis=1)]
或多个团队:
team = ['Team A','Team C']
df[df.apply(lambda x: x.isin(team)).max(axis=1)]
Home_team Away_team Home_score Away_score
GameID Date
1 2013-01-23 Team A Team B 5 1
2 2013-01-23 Team C Team D 3 3
3 2013-01-30 Team A Team C 1 2
您可以稍微重新排列列和索引,但绝对不需要为此类查询使用两个 DF。