python 将函数应用于pandas数据帧中的两列

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 将函数应用于pandas数据帧中的两列相关的知识,希望对你有一定的参考价值。

def t_error(row):
    """func to calcuate the edit distance of a translation from the original sentence
    only works when called from df.apply"""
    if row[e] is not None:
        return ed.eval(row['sentence'], row[e])
    else:
        return None
    
def apply_scores(data=data):
    """takes in a dataframe and adds a score column for each translation"""
    for e in list(speech_engines.keys()):
        data[f'{e}_score'] = data.apply(t_error, axis=1)
    return data

data = apply_scores(data)
data

以上是关于python 将函数应用于pandas数据帧中的两列的主要内容,如果未能解决你的问题,请参考以下文章