I have find the unique value of "NAME" column and assign the numeric value to each name in the csv file ( as given in the dictionary) . I am able to finish that with the below code. can somebody help to achieve the same using lambda function. How can I achieve the same using lambda function.
import pandas as pd
import sys
def dictionaryWithNormalFunction():
file_loc1= 'filepath'
# load the data with pd.read_csv
record = pd.read_csv(file_loc1)
nameDic ={}
nameDic={'Rosy':0,'Pinky':1,'Johncy':2,'Mary':3}
for name,value in nameDic.items():
record.loc[record['NAME'].astype(str).str.lower() == name.lower(), "NAME"] = value
record.to_csv(file_loc1)
dictionaryWithNormalFunction()
The csv data will be as below,
I want to replace the name with student id from the dictionaries,
nameDic={'Rosy':0,'Pinky':1,'Johncy':2,'Mary':3}# this dictionaries data would be in the same case as in csv file. student id and name mapping will be manually added in the dictionary
Replace the name with student id in the csv file using lambda function. how to achieve this using lambda function?
The csv file content should be like below