0

In SAS, there is a compress function, which , when used without arguments on a string, will remove all white spaces, leading , trailing and in between. Is there a equivalent function in pandas? So:

have: ABC XYZ
want:ABCXYZ
Victor
  • 16,609
  • 71
  • 229
  • 409
  • What data structure is `ABC XYZ`? A string, a `Series` of characters, one of it a blank? Something else? – timgeb Jan 18 '19 at 17:15

1 Answers1

2

Using replace

pd.Series(['ABC XYZ']).str.replace(' ','')
Out[695]: 
0    ABCXYZ
dtype: object
BENY
  • 317,841
  • 20
  • 164
  • 234
  • What about tabs, or other invisible characters? Will it compress all white space? – Reeza Jan 18 '19 at 18:07
  • @Reeza https://stackoverflow.com/questions/50444346/fast-punctuation-removal-with-pandas/50444347#50444347 – BENY Jan 18 '19 at 18:23