top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Lambda expression in python and its usage in data science

Writer's picture: TEMFACK DERICKTEMFACK DERICK

image from https://i1.faceprep.in/



Python, the famous programming language created by Guido van Rossum is a muli-paradigm language. It supports Object Oriented programming, procedural programming, and functional programming.


According to Wikipedia,

Functional programming is a programming paradigm where programs are constructs by applying and composing functions.

Python follows these principles and the usage of functional programming in this language is by using the keyword lambda.


The lambda keyword is used to create an anonymous function that accepts any number of the argument. The signature of this function is :

lambda <parameter_list>: <expression_to_evaluate>

Example of lambda function:

list_name =['atangana','paul','amidou','omar','hasan']

list(map(lambda name : name.capitalize(), list_name))

In this example, we apply the lambda function

lambda name : name.capitalize() that take each word in list_name and capitalize it.


After discovering the lambda function, let's do some manipulation with it using the Malaria dataset in Africa download from Kaggle with this link.


After downloading this dataset, let's explore it with some useful pandas functions to know our data.


Apply head(), info() and describe() method

import pandas as pd
data = pd.read_csv('DatasetAfricaMalaria.csv')

data.head()
data.info()
data.describe()

Application of lambda function in Malaria dataset


List of the country in the dataset that the country name starts with "C"


filtering_cond = data['Country Name'].apply(lambda country: country.startswith('C'))
data[filtering_cond]
 

List of the country without malaria cases reported


filtering_cond = data['Malaria cases reported'].apply(lambda nbre_malaria_case: nbre_malaria_case==0) 
data[filtering_cond]

These two previous examples show you some applications of lambda function in python with a pandas data frame.

You can find the source code of this blog post here.

0 comments

Recent Posts

See All

留言


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page