1

I Can not remove white spaces from DataFrame. Tried next path without success: .replace(' ', '')

The csv file - https://drive.google.com/file/d/1AjlFYxGPUqVFkxW6QXA6hNRjkLR8eTFP/view?usp=sharing

Please, help me solve that. The problematic column is 'gdp_per_capita'

1 Answers1

1

For replacing the white space from a string in series or dataframe object use the str.replace() method.

For Ex:

>>> import pandas as pd
>>> ser = pd.Series(['aaa ','aac vf','cc  '])
>>> ser
0      aaa 
1    aac vf
2      cc  
dtype: object

>>> ser[0]
'aaa '

>>> len(ser[0])
4

>>> ser.str.replace(" ", "")
0      aaa
1    aacvf
2       cc
dtype: object

As you can see, the replace method removed the white spaces form string.

Rushikesh Sabde
  • 1,376
  • 1
  • 8
  • 24