remove characters from pandas column
pandas, python, regex
Solution
Working example
df = pd.DataFrame(dict(location=['(hello)']))
print(df)
location
0 (hello)
@Psidom's Solution `str.strip`
df.location.str.strip('()')
0 hello
Name: location, dtype: object
Option 2 `str.extract`
df.location.str.extract('\((.*)\)', expand=False)
0 hello
Name: location, dtype: object
Option 3 `str.replace`
df.location.str.replace('\(|\)', '')
0 hello
Name: location, dtype: object
Option 4 `replace`
df.location.replace('\(|\)', '', regex=True)
0 hello
Name: location, dtype: object
Problem
I'm trying to simply remove the '(' and ')' from the beginning and end of the pandas column series. This is my best guess so far but it just returns empty strings with () intact. ``` postings['location'].replace('[^\(.*\)?]','', regex=True) ``` The column looks like this: screenshot of jupyter notebook