"\...">

Check for a character in the string list.

Python indoes not work for whole columns:

> dfTrain['name'][22]
  'McGowan, Miss. Anna "Annie"'

> "\"" in dfTrain['name'][22]
  True

> "\"" in dfTrain['name']
False

How to check if a character is in the string list?

+4
source share
3 answers

There may be several ways:

1) One of the things you can do is

"\"" in dfTrain['name'].to_string()

This returns Trueif any of the names in df contains ".

2) Another way could be not dfTrain[dfTrain['name'].str.contains('"')].empty

, , ". , ", , dataframe . dataframe (True), ", , "False" (, "" )

+1

"\" " dfTrain ['name'] [22] - " , "Annie", "\"

dfTrain ['name'] - , "\"

:

>>> nested_list_example = ["abhishek","ralesh","wr'"]
>>> "wr'" in nested_list_example
True
>>> "'" in nested_list_example
False
>>> "'" in nested_list_example[2]
True
+3

join() contains(), , ":

In [11]: df
Out[11]:
                                      name
0                           [test1, test2]
1                           [another test]
2                      [yet, another test]
3  [McGowan, Miss. Anna "Annie", aaa, bbb]

In [12]: df['name'].str.join('').str.contains('"')
Out[12]:
0    False
1    False
2    False
3     True
Name: name, dtype: bool
0

All Articles