Remove all quotes within values in Pandas

dataframe, pandas, python

Solution

You can do this on each Series/column using str.replace:

In [11]: s = pd.Series(['potatoes are "great"', 'they are'])

In [12]: s
Out[12]: 
0    potatoes are "great"
1                they are
dtype: object

In [13]: s.str.replace('"', '')
Out[13]: 
0    potatoes are great
1              they are
dtype: object

I would be wary of doing this across the entire DataFrame, because it will also change columns of non-strings to strings, however you could iterate over each column:

for i, col in enumerate(df.columns):
    df.iloc[:, i] = df.iloc[:, i].str.replace('"', '')

If you were sure every item was a string, you could use applymap:

df.applymap(lambda x: x.replace('"', ''))

Problem

I want to remove all double quotes within all columns and all values in a dataframe. So if I have a value such as ``` potatoes are "great" ``` I want to return ``` potatoes are great ``` DataFrame.replace() lets me do this if I know the entire value I'm changing, but is there a way to remove individual characters?

Original source