user13623188
user13623188

Reputation:

Filtering punctuation in dataframe

I tried to extract all punctuation in this list ['!',';','?','...','<<','>>'] as follows:

my_data['My_Column'].str.findall(r'[?!.,?;...<<>>]*') 

For instance

df['Test']
I really like Python!!
I don't like Gordon Ramsey...
He said: << I do not agree with you >>

Expected output:

df['Test']
[!!]
[...]
[<<,>>]

I'd appreciate if you can tell me how to fix my code.

Upvotes: 1

Views: 54

Answers (2)

BENY
BENY

Reputation: 323356

Check with

df.Test.str.findall(r'[?!.<>]+') 
Out[133]: 
0        [!!]
1       [...]
2    [<<, >>]
Name: Test, dtype: object

Upvotes: 1

wwnde
wwnde

Reputation: 26676

Lets try

df.Test.str.findall('[?!.<>]+')

0        [!!]
1       [...]
2    [<<, >>]

Upvotes: 2

Related Questions