If I have a pandas dataframe with a multi level index, how can I filter by one of the levels of that index. For example:
df = pd.DataFrame({"id": [1,2,1,2], "time": [1, 1, 2, 2], "val": [1,2,3,4]})
df.set_index(keys=["id", "time"], inplace=True)
I would like to do something like:
df[df["time"] > 1]
but time
is no longer a column. I could keep it as a column but I don't want to drag around copies of data.