Home > Software design >  Why cannot replace (.) in pandas replace
Why cannot replace (.) in pandas replace

Time:10-07

so i have a data that contain something like . Nomor cs tidak dapat dihubungi . Tempat saya tidak bisa pickup padahal dekat kantor pos . Tidak ada panduan co But when I try replace it by regex=True or regex=False it didnt change anything.In my dataframe also have some emoticon is this also make it failed?.This is my code

data = pd.read_excel('pos indonesia.xlsx')
data1 = data['content']
datacek = data1.replace({'.':'',',':'','"':''},regex =True)

CodePudding user response:

Because it is special regex expression for match any character, need escape it by \:

datacek = data1.replace({'\.':'',',':'','"':''},regex =True)

Or:

datacek = data1.replace('[\.:"]','',regex =True)

CodePudding user response:

It's a regex expression, escape it:

datacek = data1.replace({'\.':'',',':'','"':''},regex =True)

CodePudding user response:

Try this:

data = pd.read_excel('pos indonesia.xlsx')
data1 = data['content']
datacek = data1.replace('\.', '', regex=True)
  • Related