python - Remove Multiple Blanks In DataFrame -
how remove multiple spaces between 2 strings in python.
e.g:-
"bertug 'here multiple blanks' mete" => "bertug mete"
to
"bertug mete"
input read .xls file. have tried using split() doesn't seem work expected.
import pandas 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 i'm doing wrong.
i think use replace
:
df.name = df.name.replace('\s+', ' ', regex=true)
sample:
df = pd.dataframe({'name':['bertug mete','a','joe black']}) print (df) name 0 bertug mete 1 2 joe black df.name = df.name.replace('\s+', ' ', regex=true) #similar solution #df.name = df.name.str.replace('\s+', ' ') print (df) name 0 bertug mete 1 2 joe black
Comments
Post a Comment