I have a pandas script.
import pandas as pd
data = pd.read_csv('sample.csv',delimiter=',')
def mapping(df):
#work of data mapping
for column_name, column in df.transpose().iterrows():
df.rename(columns ={'first name' : 'FNAME', 'secret': 'CODE'}, inplace = True)
df.rename(columns ={'alias' : 'FNAME', 'code': 'CODE'}, inplace = True)
df.rename(columns ={'initial name' : 'FNAME', 'id': 'CODE'}, inplace = True)
final_df = mapping(data)
#If the code is greater than 12 digits, leave it blank
final_df.loc[final_df['CODE'].astype(str).str.len() >12, 'CODE']= ''
I'm getting the error as :
final_df.loc[final_df['CODE'].astype(str).str.len() >12, 'CODE']= ''
AttributeError: 'NoneType' object has no attribute 'loc'
Any fixes for this?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…