I'm working in forecasting the demand of a product using many scenarios per year. I have a MulitiIndexed dataframe (Simulation, Year, Month) and need to filter by one of them (let's say Simulation).
import pandas as pd
idx = pd.MultiIndex.from_tuples([(1,2020,1), (1,2020,2), (2,2020,1), (2,2020,2)],
names=['Simulation', 'Year', 'Month'])
d = {'Apples': [1,2,3,4], 'Organes': [4,5,6,8], 'Lemons': [9,10,11,12]}
df = pd.DataFrame(d, index=idx)
print(df)
Simulation Year Month Apples Oranges Lemons
1 2020 1 1 4 9
1 2 2 5 10
2 2020 1 3 6 11
2 2 4 8 12
How can I filter by Simulation?
Expected output for filtering by simulation number 1 only
Simulation Year Month Apples Oranges Lemons
1 2020 1 1 4 9
1 2 2 5 10