我正在尝试在Pandas数据框中过滤22到28周之间的星期窗口,但出现KeyError错误。我在这里做什么错了?
import pandas as pd
data = {
'Year': [2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019],
'Week': [21, 22, 23, 24, 25, 26, 27, 28, 29, 30],
'Product': ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A'],
'Value': [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
}
df = pd.DataFrame(data)
df.set_index(['Year', 'Week', 'Product'])
print(df)
df = df.loc[df['Week'] > 22 | df['Week'] < 28]
print(df)