I have a DataFrame where a column is filled with strings. I want to remove any appearance of single letters from the column. So far, I have tried:
df['STRI'] = df['STRI'].map(lambda x: " ".join(x.split() if len(x) >1)
I wish to input ABCD X WYZ
and get ABCD WYZ
.
Try this:
df['STRI'] = npi['STRI'].str.replace(r'\b\w\b', '').str.replace(r'\s+', ' ')
Eg:
import pandas as pd
df = pd.DataFrame(data=['X ABCD X X WEB X'], columns=['c1'])
print df, '\n'
df.c1 = df.c1.str.replace(r'\b\w\b', '').str.replace(r'\s+', ' ')
print df
Output:
c1
0 X ABCD X X WEB X
c1
0 ABCD WEB
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With