删除 pandas 值中的所有引号 [英] Remove all quotes within values in Pandas

查看:187
本文介绍了删除 pandas 值中的所有引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除数据框中所有列中的所有双引号和所有值.因此,如果我有一个值,例如

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"

我想回来

potatoes are great

如果我知道要更改的整个值,DataFrame.replace()允许我执行此操作,但是有没有办法删除单个字符?

DataFrame.replace() lets me do this if I know the entire value I'm changing, but is there a way to remove individual characters?

推荐答案

您可以使用

对于在整个DataFrame上执行此操作,我会保持警惕,因为它还会将非字符串的列更改为字符串,但是您可以遍历每列:

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('"', ''))

这篇关于删除 pandas 值中的所有引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆