I would like to use the modern way of Pandas method chaining to assign values to a subset of a column.
Let's say I have the following dataframe
df = pd.DataFrame({'a': [1, 0, 0, 1]})
a
0 1
1 0
2 0
3 1
I would like to achieve the equivalent of
df.loc[df.a == 1, 'a'] = 2
with something like
df.query('a == 1').assign(a=2)
However, the above creates a subset dataframe and does not modify the whole dataframe. Is that somehow possible to achieve?