0

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')
quamrana
  • 37,849
  • 12
  • 53
  • 71
inspiredd
  • 195
  • 2
  • 11

1 Answers1

1

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.

Daweo
  • 31,313
  • 3
  • 12
  • 25