Topic 6 :Data Analysis and Visualisation
Learning Outcomes:
(a) Identify basic Pandas methods for data analysis (indexing, describe(), max(), min() and mean())
CP125
Topic 6 :Data Analysis and Visualisation
Table of Contents
CP125
iris.csv
Datasource for Analysis
link to site : https://www.kaggle.com/datasets/uciml/iris?select=Iris.csv
Information about datasets
the datasets using info() method
Datasets contain:
Use own file directory
Indicates whether there is an empty data or net
2. View the first 5 rows
3. Indexing from DataFrame
Indexing a pandas dataframe means selecting particular subsets of data (such as rows, columns, individual cells) from that dataframe
a. selecting specific columns
b. selecting specific rows
c. selecting specific rows and column
Indexing
Ways to Indexing
Native Python Accessor
Column Selection Only
Pandas DataFrame Method
Column and Row Selection
Integer Based Indexing
Label based Indexing
Indexing Operator
Single and Multiple Column
Attribute accessor
Single Column Only
dot Operator
[ ] bracket Operator
loc[row_label,col_label]
iloc[row_indices,col_indices]
3a
3b & 3c
3a.1 dot operator
select single Column data based on header name
3a.2
[ ] operator
select Single Column data based on header name
3a.3
[ ] operator
Selecting
Multiple Columns
To select multiple columns, the columns name is passed as a list.
3b. Using Pandas loc() method
Use to select rows and columns from a DataFrame using their labels.
How does loc work?
df.loc[row_labels,column_labels]
3b.1 Selecting one row
To select a single row, passed the row index value.
eg: row 100
It return single record with index of 100
3b.2
Selecting
multiple rows
pass the row
start_index : end_index
to the loc operator
eg: loc[10:100]
It return the record with index of 10 until 100 inclusive .
[10:100] return 91 rows
3c.1
Selecting
multiple rows
of specific columns
It return the record with index of
10 until 100 inclusive
and only columns
3c.2
Selecting specific rows
and columns using
relational/comparison operators
return
that has SepalLengthCm > 5.0
Summary