0

When one of columns contains target value, I write code following.

df['address'].str.contains('\t')

In my question, I would like to find multiple space which is more than 2 spaces. I think I should use Regular expression.

How can I write code? Please give me an advice.

tajihiro
  • 1,633
  • 1
  • 24
  • 40

3 Answers3

1

Would this be a good example

df = pd.DataFrame({'col': ['a', 'b  ', 'c', '   d', '  e    ']})
         col
0        a
1      b
2        c
3        d
4    e
df['col'].str.contains('  *', regex=True)
0    False
1     True
2    False
3     True
4     True
Kenan
  • 10,163
  • 8
  • 32
  • 47
0

One way use

s=pd.Series(['one ','more   than two','only  two'])
s.str.contains('  ')
0    False
1     True
2     True
dtype: bool

If we would like find the single space freq we could do count

s.str.count(' ')
0    1
1    4
2    2
dtype: int64
BENY
  • 258,262
  • 17
  • 121
  • 165
0

A regex based approach for any consecutive (potentially duplicate) words I posted is here: Regular Expression For Consecutive Duplicate Words

synaptikon
  • 659
  • 1
  • 6
  • 15