python - How to replace character in row of dataframe? -


i open raw data using pandas

df=pd.read_cvs(file) 

here's part of dataframe like:

37280  7092|156|laboratory data|a648c751-a4dd-4cz2-85                                47981  7092|156|laboratory data|z22cd01c-8z4b-4zcb-8b                                57982  7092|156|laboratory data|c12ce01c-8f4b-4czb-8b 

i'd replace pipe('|') tab ('\t') tried :

df.replace('|','\t') 

but never works. how this? many thanks!

the replace method on data frame default meant replace values match string provided; need specify regex=true replace patterns, , since | special character in regex, escape needed here:

df1 = df.replace("\|", "\t", regex=true) df1 #       0                                                   1 #0  37280   7092\t156\tlaboratory data\ta648c751-a4dd-4cz2-85 #1  47981   7092\t156\tlaboratory data\tz22cd01c-8z4b-4zcb-8b #2  57982   7092\t156\tlaboratory data\tc12ce01c-8f4b-4czb-8b 

if print cell, tab printed expected:

print(df1[1].iat[0]) # 7092  156 laboratory data a648c751-a4dd-4cz2-85 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -