Reputation: 4009
This has to be really easy but Google isn't helping. What is the Pandas/Python3 version of:
UPDATE table
SET column1 = 'value'
WHERE column2 LIKE 'some value%'
UPDATE: Sorry, it's more than just update. It's update with a wildcard.
Upvotes: 1
Views: 756
Reputation: 323396
Using str.startwith
here , this is just condition assign with basic .loc
df.loc[df.column2.str.startswith('some value'),'column1']='value'
Upvotes: 2
Reputation: 42946
use np.where
with pandas.Series.str.startswith
:
df['column1'] = np.where(df['column2'].str.startswith('some value'), 'value', df['column1'])
np.where
works as follows: np.where(condition, value if true, value if false)
Upvotes: 2