I have pandas dataframe with string columns. I need to find string which includes double quotation but I don't know how to find "toString": "Ready"
:
df1['column2'] = np.where(df1["column1"].str.contains(""toString": "Ready""), 'abc', 'def')
I have pandas dataframe with string columns. I need to find string which includes double quotation but I don't know how to find "toString": "Ready"
:
df1['column2'] = np.where(df1["column1"].str.contains(""toString": "Ready""), 'abc', 'def')
Just use '
as terminators to be able to use literal "
as follows:
df1['column2'] = np.where(df1["column1"].str.contains('"toString": "Ready"'), 'abc', 'def')
or do escape "
if you must use "
as terminators:
df1['column2'] = np.where(df1["column1"].str.contains("\"toString\": \"Ready\""), 'abc', 'def')
Note that first is more readable, but need to escape "
might arise if you need to use literal "
and literal '
in 1 str
.