Python - Basics of Pandas Using Iris Dataset - GeeksforGeeks
Python - Basics of Pandas Using Iris Dataset - GeeksforGeeks
Python - Basics of Pandas Using Iris Dataset - GeeksforGeeks
GfG O line Programs Free Python 3 Tutorial Data Types Control Flow Functions List String Set Tuple Dictionary Oops Exception Handling Python Programs Python Projects Python Interview Q
Summarize
Explore Our Geeks Community
Python – Basics of Pandas using Iris Dataset Chat With This Website
C o u rs e s
Write an Interview Experience
Read Courses Practice Jobs
Predicting Air Quality Index using Python So if you are new to practice Pandas, then firstly you should install Pandas on your
system.
Vehicle Count Prediction From Sensor Go to Command Prompt and run it as administrator. Make sure you are connected with an
Data
internet connection to download and install it on your system.
Python – Categorical Encoding using Then type “pip install pandas“, then press Enter key.
Sunbird
▲
Wine Quality Prediction - Machine
Learning
Python3
import pandas as pd
Python3
Code: Displaying up the top rows of the dataset with their columns
The function head() will display the top rows of the dataset, the default value of this
function is 5, that is it will show top 5 rows when no argument is given to it.
Python3
data.head()
Output:
Python3
data.sample(10)
Output:
Python3
data.columns
Output:
Python3
Output:
Python3
print(data)
Output:
Python3
#data[start:end]
#start is inclusive whereas end is exclusive
print(data[10:21])
# it will print the rows from 10 to 20.
Output:
Python3
specific_data=data[["Id","Species"]]
#data[["column_name1","column_name2","column_name3"]]
Output:
The “loc” functions use the index name of the row to display the particular row of the
dataset.
The “iloc” functions use the index integer of the row, which gives complete information
about the row.
Code:
Python3
data.iloc[5]
#it will display records only with species "Iris-setosa".
data.loc[data["Species"] == "Iris-setosa"]
Output:
iloc()[/caption]
loc()
Python3
#In this dataset we will work on the Species column, it will count number of ti
data["Species"].value_counts()
#it will display in descending order.
Output:
Python3
# data["column_name"].sum()
sum_data = data["SepalLengthCm"].sum()
mean_data = data["SepalLengthCm"].mean()
median_data = data["SepalLengthCm"].median()
Output:
Python3
min_data=data["SepalLengthCm"].min()
max_data=data["SepalLengthCm"].max()
Output:
Python3
Output:
Python3
newcols={
"Id":"id",
"SepalLengthCm":"sepallength"
"SepalWidthCm":"sepalwidth"}
data.rename(columns=newcols,inplace=True)
print(data.head())
Output:
Python3
Output:
Now we will highlight the maximum and minimum column-wise, row-wise, and the whole
dataframe wise using Styler.apply function. The Styler.apply function passes each column
or row of the dataframe depending upon the keyword argument axis. For column-wise use
axis=0, row-wise use axis=1, and for the entire table at once use axis=None.
Python3
data.head(10).style.highlight_max(color='lightgreen', axis=0)
data.head(10).style.highlight_max(color='lightgreen', axis=1)
data.head(10).style.highlight_max(color='lightgreen', axis=None)
Output:
for axis=0
for axis=1
for axis=None
Python3
data.isnull()
#if there is data is missing, it will display True else False.
Output:
isnull()
Python3
data.isnull.sum()
Output:
Python3
iris = sns.load_dataset("iris")
sns.heatmap(iris.corr(),camp = "YlGnBu", linecolor = 'white', linewidths = 1)
Output:
Code: Annotate each cell with the numeric value using integer formatting
Python3
Output:
Python3
data.corr(method='pearson')
Output:
data.corr()
The output dataframe can be seen as for any cell, row variable correlation with the column
variable is the value of the cell. The correlation of a variable with itself is 1. For that
reason, all the diagonal values are 1.00.
Multivariate Analysis:
Pair plot is used to visualize the relationship between each type of column variable. It is
implemented only by one line code, which is as follows :
Code:
Python3
g = sns.pairplot(data,hue="Species")
Output:
Don't miss your chance to ride the wave of the data revolution! Every industry is scaling
new heights by tapping into the power of data. Sharpen your skills, become a part of the
hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data
Science Program by GeeksforGeeks and stay ahead of the curve.
Previous Next
Building an Auxiliary GAN using Keras PyQt5 QSpinBox - Getting Style Name
and Tensorflow
Similar Reads
Plotting graph For IRIS Dataset Using Seaborn Analyzing Decision Tree and K-means
And Matplotlib Clustering using Iris dataset
Python Bokeh – Visualizing the Iris Dataset Exploratory Data Analysis on Iris Dataset
Comparison of LDA and PCA 2D projection of How can Tensorflow be used with Estimators
Iris dataset in Scikit Learn to split the iris dataset?
Complete Tutorials
Python API Tutorial: Getting Started with APIs Advanced Python Tutorials
K kashishlo…
Additional Information
Company Explore Languages DSA Data Science & ML HTML & CSS
A-143, 9th Floor, Sovereign Corporate About Us Job-A-Thon Hiring Python Data Structures Data Science With HTML
Tower, Sector-136, Noida, Uttar Pradesh - Challenge Python
Legal Java Algorithms CSS
201305
Careers Hack-A-Thon C++ DSA for Beginners Data Science For Bootstrap
GfG Weekly Contest Beginner
In Media PHP Basic DSA Problems Tailwind CSS
O line Classes Machine Learning
Contact Us GoLang DSA Roadmap SASS
(Delhi/NCR) Tutorial
Advertise with us SQL Top 100 DSA Interview LESS
DSA in JAVA/C++ ML Maths
GFG Corporate Solution R Language Problems Web Design
Master System Design Data Visualisation
Placement Training Android Tutorial DSA Roadmap by
Tutorial
Program Master CP Sandeep Jain
Pandas Tutorial
Apply for Mentor GeeksforGeeks Videos All Cheat Sheets
NumPy Tutorial
NLP Tutorial
Python Programming GATE CS Notes Git Programming What is System Design TypeScript
Examples Operating Systems AWS Top DS or Algo for CP Monolithic and ReactJS
Django Tutorial Computer Network Docker Top 50 Tree Distributed SD NextJS
Python Projects Database Management Kubernetes Top 50 Graph High Level Design or AngularJS
Python Tkinter System HLD
Azure Top 50 Array NodeJS
Web Scraping So ware Engineering Low Level Design or LLD
GCP Top 50 String Express.js
OpenCV Python Tutorial Digital Logic Design Crack System Design
DevOps Roadmap Top 50 DP Lodash
Round
Python Interview Engineering Maths Top 15 Websites for CP Web Browser
Question System Design
Interview Questions
Grokking Modern
System Design
NCERT Solutions School Subjects Commerce Management & UPSC Study SSC/ BANKING
Class 10 Chemistry Indian Economics HR Managament Geography Notes SBI Clerk Syllabus
Class 8 Social Science Microeconimics Finance Science and Technology IBPS Clerk Syllabus
Complete Study English Grammar Statistics for Economics Economics Notes SSC CGL Practice Papers
Material Economy Notes
Ethics Notes
Indian Colleges IT Companies Corner JEE Mains So ware Development Write an Article
Admission & Campus So ware Development Company Wise JEE Advanced So ware Testing Improve an Article
Experiences Companies Preparation GATE CS Product Management Pick Topics to Write
Top Engineering Artificial Intelligence(AI) Preparation for SDE NEET SAP Share your Experiences
Colleges Companies Experienced Interviews UGC NET SEO Internships
Top BCA Colleges CyberSecurity Internship Interviews Linux
Top MBA Colleges Companies
Competitive Excel
Top Architecture Service Based Programming
College Companies
Aptitude Preparation
Choose College For Product Based
Puzzles
Graduation Companies