我想对特定系列执行多项操作。有没有一种方法可以在不连续编写 .str
的情况下将它们链接起来?即,如果我的系列名为 s
而我想做
s.str.replace("hi", "bye").str.strip().str.lower()
这是做事的正确方法吗?相对于 R 来说似乎很冗长,所以我想也许有更好的语法。
最佳答案
理解
是的(有点)。使用理解
[x.replace('hi', 'bye').strip().lower() for x in s]
再次将其总结成一个系列。
pd.Series([x.replace('hi', 'bye').strip().lower() for x in s], s.index)
map
s.map(lambda x: x.replace('hi', 'bye').strip().lower())
关于python - 在 pandas Series/DataFrame 上执行多个字符串操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50494216/