Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas apply lambda function with assign

-- 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))
 
Comment

PREVIOUS NEXT
Code Example
Python :: print from within funciton with multiprocessing 
Python :: BeautifulSoup(raw_html 
Python :: cardano 
Python :: input in one line python 
Python :: how to prepare independent and dependent variables from dataframe 
Python :: Python string to var 
Python :: get last n in array python 
Python :: how do you change a string to only uppercase in python 
Python :: access list items in python 
Python :: how to give a role permissions discord py 
Python :: the python libraries to master for machine learning 
Python :: how to print correlation to a feature in pyhton 
Python :: Find unique values in all columns in Pandas DataFrame 
Python :: pd.merge remove duplicate columns 
Python :: numpy array unique value counts 
Python :: python program to check if binary representation is a palindrome 
Python :: use the index of a dataframe for another dataframe 
Python :: how to stop a program after 1 second in python 
Python :: fetch data from excel in python 
Python :: reverse python 
Python :: print random integers python 
Python :: cors python 
Python :: making a return from your views 
Python :: how to repeat if statement in python 
Python :: unique combinations in python 
Python :: python example 
Python :: how to run shell command in python 
Python :: find value in dictionary python 
Python :: pandas df sample 
Python :: copy content from one file to another in python 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =