python-2.7 – Pandas.replace不从数据中删除字符

我有一个pandas数据框,字符“在某些地方(
Python 2.7).

我想从数据中删除所有“我正在使用以下方法:

data_frame.replace(to_replace'"', value = '')

但是,数据框保持不变,并且不会执行操作.
任何关于问题的建议将不胜感激.

最佳答案 您可以使用regex = True尝试
replace

import pandas as pd

df = pd.DataFrame({'ItemID': {0: 8988, 1: 8988, 2: 6547, 3: 6547}, 
                   'Description': {0: 'Tall Chair', 1: 'Tall Chair', 2: 'Big" Pillow', 3: 'Big Pillow'}, 
                   'Feedback': {0: 'I hated it""', 1: 'Best chair" ever', 2: 'Soft and amazing', 3: 'Horrific color'}})
print df
   Description          Feedback  ItemID
0   Tall Chair      I hated it""    8988
1   Tall Chair  Best chair" ever    8988
2  Big" Pillow  Soft and amazing    6547
3   Big Pillow    Horrific color    6547

print df.replace({'"': ''}, regex=True)
  Description          Feedback  ItemID
0  Tall Chair        I hated it    8988
1  Tall Chair   Best chair ever    8988
2  Big Pillow  Soft and amazing    6547
3  Big Pillow    Horrific color    6547
点赞