在大 pandas 数据框中替换字符串 [英] replace string in pandas dataframe
本文介绍了在大 pandas 数据框中替换字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
我的建议:
df ['col'] = ['new string'if'@'in x else x for x in df ['col']]
不知道哪个更快。
I have a dataframe with multiple columns. I want to look at one column and if any of the strings in the column contain @, I want to replace them with another string. How would I go about doing this?
解决方案
My suggestion:
df['col'] = ['new string' if '@' in x else x for x in df['col']]
not sure which is faster.
这篇关于在大 pandas 数据框中替换字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文