Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

create new column pandas lambda function assign apply

-- creating and initializing a list
values= [['Rohan',455],['Elvish',250],['Deepak',495],
         ['Soni',400],['Radhika',350],['Vansh',450]]
 
-- creating a pandas dataframe
df = pd.DataFrame(values,columns=['Name','Total_Marks'])
 
-- Applying lambda function to find
-- percentage of 'Total_Marks' column
-- using df.assign()
df = df.assign(Percentage = lambda x: (x['Total_Marks'] /500 * 100))
 
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #create #column #pandas #lambda #function #assign #apply
ADD COMMENT
Topic
Name
7+9 =