Python 在dataframe列上使用cleanco

Python 在dataframe列上使用cleanco,python,pandas,Python,Pandas,我正在尝试使用Python中的cleanco模块创建一个脚本来清理公司名称 cleanco有一个例子如下: business_name = "Some Big Pharma, LLC" x = cleanco(business_name) x.clean_name() 这导致了“一些大型制药公司” 我正在尝试对熊猫数据帧中的列执行相同的操作 到目前为止,我的代码是: #Importing Packages import pandas as pd from cleanco import cle

我正在尝试使用Python中的cleanco模块创建一个脚本来清理公司名称

cleanco有一个例子如下:

business_name = "Some Big Pharma, LLC"
x = cleanco(business_name)
x.clean_name()
这导致了“一些大型制药公司”

我正在尝试对熊猫数据帧中的列执行相同的操作

到目前为止,我的代码是:

#Importing Packages

import pandas as pd
from cleanco import cleanco

#Create a data frame for testing purposes

columns = ['emp'] #Define column names
new_col = ['emp2'] #Define column names for second dataframe


df=pd.DataFrame(columns=columns) #Create an empty data frame
df2=pd.DataFrame(columns=new_col)


df['emp'] = ['ABC, Inc.', 'XYZ LTD']#populate the data frame with dummy values

df["emp"] = [x.strip().replace('.','').replace('''''', '').replace('-', '').replace(',','') for x in df['emp'].str.lower()]

df2['emp2'] = df['emp'].apply(cleanco,1)

df['emp'].apply(cleanco.clean_name()) #This is where the error lies
调用clean_name函数时遇到问题

我的第一个数据帧:

ABC公司

1 XYZ有限公司

我希望df2看起来像:

0 abc


1 xyz

我使用lambda函数从新创建的列中提取“clean”名称

试试这个:

df2['emp3'] = df2['emp2'].apply(lambda x: x.clean_name())