I have a pandas df that has one of the columns as a tuple. I would like to use query
to subset the df using the first entry of the tuple. What's the best way to do this? I'm on pandas .23.3, Python 3.6.6
MWE:
import pandas as pd
df = pd.DataFrame({"val": list(zip(range(9), range(9)[::-1]))})
df.query("val[0] > 3") #this line does not work!
I know that I can split the column up and then subset but I don't want to split it up.
update: for anyone who decides to go the route of unpacking the tuple and having two separate columns, here is a simple way to do this:
df["a"], df["b"] = list(zip(*df.val.tolist()))