Given this dataframe
df = pd.DataFrame({'x': range(10,51,10),
'y': [False]*5})
print(df)
--------
x y
0 10 False
1 20 False
2 30 False
3 40 False
4 50 False
Is there a way to query that dataframe on x
and force pandas to return a view that I can modify sometime in the future?
view = df.loc[df.x <= 20]
print(view._is_view) # returns False
# ... life goes by for a while
view.y = True # does not modify original df
I know I could do this
df.loc[df.x <=20, 'y'] = True
but in my case, the query and the assignment need to be separated by time and code space. My current workaround is to grab the indexes from the query, and just modify the original dataframe instead of messing with the view.
Note I have omitted this for simplicity, but in my actual app, I need to assign each row of the view one by one, separated by time. The view would be slick if I could get it to work.