I'm planning improve readability for non Pandas developers;
I have the following working Python code using .loc
:
new_value = 'stackoverflow'
s_query = 'nbc'
SUGGESTED = 'suggested'
QUERY = 'query'
df.loc[(df[QUERY] == s_query), [SUGGESTED]] = new_value
Also have an option to:
new_value = 'stackoverflow'
s_query = 'nbc'
SUGGESTED = 'suggested'
QUERY = 'query'
df[SUGGESTED] = df[SUGGESTED].mask(df[QUERY] == s_query, new_value)
In this case df[SUGGESTED]
column will be updated with 'stackoverflow'
value for the row(s) matching df[QUERY] == s_query
.
Wondering if there is other options in Pandas to achieve same results.