Refer the following code
# import
import pandas as pd
import numpy as np
import string
# create data frame
data = {'Name': ['Jas,on', 'Mo.lly', 'Ti;na', 'J:ake', '!Amy', "Myself"]}
df = pd.DataFrame(data, columns = ['Name'])
df
# get cleanName - Function
def getCleanName(pName):
vRetVals = pName.translate(str.maketrans(" ", " ", string.punctuation))
return(vRetVals)
# clean Name
print("PreClean Good Rows", df.shape[0] - df.Name.map(lambda v:v.isalpha()).sum())
df['Name'] = [getCleanName for n in df.Name]
print("PostClean Good Rows", df.shape[0] - df.Name.map(lambda v: v.isalpha()).sum())
Issue
When the below line is run for the first time, it runs properly:
print("PreClean Good Rows", df.shape[0] - df.Name.map(lambda v: v.isalpha()).sum())
when the same line is run for the second time, it gives the following error
AttributeError: 'function' object has no attribute 'isalpha'
Any ideas, what is causing the issue?