Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
Remove Multiple Blanks In DataFrame

How do I remove multiple spaces between two strings in python.

e.g:-

"Bertug 'here multiple blanks' Mete" => "Bertug        Mete"

to

"Bertug Mete" 

Input is read from an .xls file. I have tried using split() but it doesn't seem to work as expected.

import pandas as pd , string , re

dataFrame = pd.read_excel("C:\\Users\\Bertug\\Desktop\\example.xlsx")

#names1 =  ''.join(dataFrame.Name.to_string().split()) 

print(type(dataFrame.Name))

#print(dataFrame.Name.str.split())

Let me know where I'm doing wrong.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I think use replace:

df.Name = df.Name.replace(r'\s+', ' ', regex=True)

Sample:

df = pd.DataFrame({'Name':['Bertug     Mete','a','Joe    Black']})
print (df)
              Name
0  Bertug     Mete
1                a
2     Joe    Black

df.Name = df.Name.replace(r'\s+', ' ', regex=True)
#similar solution
#df.Name = df.Name.str.replace(r'\s+', ' ')
print (df)
          Name
0  Bertug Mete
1            a
2    Joe Black
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!