Suppose I have a DataFrame like so,
df = pd.DataFrame([['x', 1, 2], ['x', 1, 3], ['y', 2, 2]],
columns=['a', 'b', 'c'])
To select all rows where c == 2 and a == 'x', I could do something like,
df[(df['a'] == 'x') & (df['c'] == 2)]
Or I could iterative refine by making temporary variables,
df1 = df[df['a'] == 'x']
df2 = df1[df1['c'] == 2]
Is there a way to iterative refine on rows?
(
df
.refine(lambda row: row['a'] == 'x') # this method doesn't exist
.refine(lambda row: row['c'] == 2)
)