Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在数据帧上使用lambda、apply和join函数_Python 3.x_Pandas_Join_Lambda_Apply - Fatal编程技术网

Python 3.x 在数据帧上使用lambda、apply和join函数

Python 3.x 在数据帧上使用lambda、apply和join函数,python-3.x,pandas,join,lambda,apply,Python 3.x,Pandas,Join,Lambda,Apply,目标 将deid\u notes函数应用于df import pandas as pd df = pd.DataFrame({'Text' : ['there are many different types of crayons', 'i like a lot of sports cares', 'the middle east has many ca

目标

deid\u notes
函数应用于
df

import pandas as pd
df = pd.DataFrame({'Text' : ['there are many different types of crayons', 
                                   'i like a lot of sports cares', 
                                   'the middle east has many camels '], 

                      'P_ID': [1,2,3], 
                      'Word' : ['crayons', 'cars', 'camels'],
                      'P_Name' : ['John', 'Mary', 'Jacob'],
                      'N_ID' : ['A1', 'A2', 'A3']

                     })

#rearrange columns
df = df[['Text','N_ID', 'P_ID', 'P_Name', 'Word']]
df

    Text                  N_ID P_ID P_Name  Word
0   many types of crayons   A1  1    John   crayons
1   i like sports cars      A2  2    Mary   cars
2   has many camels         A3  3    Jacob  camels
背景

我有一个类似于此示例的
df

import pandas as pd
df = pd.DataFrame({'Text' : ['there are many different types of crayons', 
                                   'i like a lot of sports cares', 
                                   'the middle east has many camels '], 

                      'P_ID': [1,2,3], 
                      'Word' : ['crayons', 'cars', 'camels'],
                      'P_Name' : ['John', 'Mary', 'Jacob'],
                      'N_ID' : ['A1', 'A2', 'A3']

                     })

#rearrange columns
df = df[['Text','N_ID', 'P_ID', 'P_Name', 'Word']]
df

    Text                  N_ID P_ID P_Name  Word
0   many types of crayons   A1  1    John   crayons
1   i like sports cars      A2  2    Mary   cars
2   has many camels         A3  3    Jacob  camels
我使用以下函数使用NeuroNER来识别
文本
列中的某些单词

问题

我使用以下代码将
deid_notes
功能应用于我的
df

fx = lambda x: deid_notes(x.Text,axis=1)
df.join(df.apply(fx))
但是我得到了以下错误

AttributeError: ("'Series' object has no attribute 'Text'", 'occurred at index Text')
问题


如何让
deid_notes
函数在我的
df
上工作?

假设您从
deid_notes
函数返回一个熊猫系列作为输出,并将
text
作为唯一的输入参数。将
axis=1
参数传递给
apply
而不是
dead\u notes
。例如

# Dummy function
def deid_notes(text):
    deid = 'prediction to: ' + text
    return pd.Series(deid, index = ['Deid'])

fx = lambda x: deid_notes(x.Text)
df.join(df.apply(fx, axis =1))

在这种情况下,
n1
是什么?
n1=neuromodel.NeuroNER(train\u model=False,use\u pretrained\u model=True,dataset\u text\u folder=“./data/example\u unnotated\u text”,pretrained\u model\u folder=“/trained\u models/mimic\u globle\u stanford\u bios”)
Try
df.join(df.apply(fx,axis=1))
我得到一个错误
TypeError:(“deid_notes()得到一个意外的关键字参数'axis',发生在索引0')