Need help in writing this SQL update statement in python using the pandas library.
UPDATE example_table
SET NEW_COLUMN = EXISITNG_COLUMN *2
WHERE SOME_OTHER_EXISTING_COLUMN IN ('Value1','Value2','Value3','Value4')
Just to clarify, I want to create a NEW_COLUMN
which a multiplication of values in the existing_column
belonging to example_table
SQLtable/dataframe. The values of NEW_COLUMN
don't update if the condition in the where
clause is not met. This is important because I would want to multiply with a different number for a another set of values in where condition. Also, it important to know that I am checking the condition on SOME_OTHER_EXISTING_COLUMN
in the same SQLtable/dataframe.
I tried the following in python, but somehow it did not work:
value_list = ['Value1','Value2','Value3','Value4']
example_table["NEW_COLUMN"] = pd.DataFrame.where( cond= example_table['SOME_OTHER_EXISTING_COLUMN'].isin(value_list), self= example_table['EXISITNG_COLUMN']*2)
Side note: EXISITNG_COLUMN
is float, SOME_OTHER_EXISTING_COLUMN
is string
/object
and NEW_COLUMN
should be a float
datatype.