Search
 
SCRIPT & CODE EXAMPLE
 

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

PREVIOUS NEXT
Code Example
Python :: how to make program speak in python 
Python :: python download file from url requests 
Python :: how to put legend outside pie plot in python 
Python :: get column index of maximum value in each row pandas 
Python :: print A to z vy using loop in python 
Python :: if name == main 
Python :: get last 3 in array python 
Python :: add cooldown to command discord.py 
Python :: os.execl 
Python :: set permissions role discord.py 
Python :: cv2 blue color range 
Python :: tensor.numpy() pytorch gpu 
Python :: input in python 
Python :: php datatables serverside 
Python :: sentence similarity spacy 
Python :: add key if not exists python 
Python :: at=error code=H10 desc="App crashed" django 
Python :: python pd.Timestamp add days 
Python :: infinite while python 
Python :: drop row with condition dataframe 
Python :: print random integers py 
Python :: how to create dictionary in python from csv 
Python :: quick sort python 
Python :: hashlib sha 256 
Python :: Python program to combine each line from first file with the corresponding line in second file 
Python :: python game 
Python :: remove leading and lagging spaces dataframe python 
Python :: python join dict 
Python :: insert single value in dataframe using index 
Python :: saleor docker development 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =