Py学习  »  Python

Python创建一个函数,其中包含一个链

jvqp • 3 年前 • 1341 次点击  

我来自R,我们喜欢管道,这让代码更容易理解,我尽量应用它。然而,我正在尝试创建一个函数,它在一个字符串中执行许多操作。它们单独工作,但当我试图将它们设置为函数的链时,它们不起作用:

def funtest(df, x):
    (
        df
        .replace({x: {'ä': 'ae', 'ö': 'oe', 'ü': 'ue', 'β': 'ss'}}, regex = True, inplace = True)
        .replace({x: '\s{2,}'}, ' ')
        .replace({x: '^\s+'}, ' ')
        .replace({x: '\s+$'}, ' ')
    )
    return df

 funteste(df, 'strings')

enter image description here

谁能告诉我怎么解决这个问题吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/133663
文章 [ 2 ]  |  最新文章 3 年前