1 of 15

Topic 6 :Data Analysis and Visualisation

Learning Outcomes:

(a) Identify basic Pandas methods for data analysis (indexing, describe(), max(), min() and mean())

CP125

2 of 15

Topic 6 :Data Analysis and Visualisation

Table of Contents

  • row selection with iloc[ ] operator
  • row and column selection with iloc[ ] operator
  • Pandas method for basic statistical Summary
  • Basic visualisation using pyplot module in Matplotlib

​

CP125

3 of 15

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

Recap :

4 of 15

4. Using iloc()- Using Index instead of label/header name

It allows you to select specific rows and columns from a DataFrame using their integer positions. The i stand for Integer index.

How does iloc work?

  • For rows: You specify the integer index position(s) you want to select.
  • For columns: You specify the integer index position(s) you want to select.

df.iloc[row_index,column_index]

5 of 15

4b.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

6 of 15

4b.2

Selecting

multiple rows

​

pass the row

start_index: end_index

to the iloc operator

​

eg: loc[10:100]

It return the record start from index of 10 until 99.

index 100 is exclusive

[10:100] return 90 rows

7 of 15

4c.1

Selecting

multiple rows

and specific columns

It return rows of index 10 until 100 exclusive and only columns 1 until 3.

​

column index

Column

1

SepalLengthCm

2

SepalWidthCm

3

PetalLengthCm

4

not included

8 of 15

Basic Statistical Analysis

  1. describe() # return basic statistical summary

​

2. mean() # return average value of the selected columns

​

3. max() # return highest value in the selected columns

​

4. min() # return lowest value in the selected columns

Statistical analysis must only be applied to numerical columns

9 of 15

6. Describing

Dataframe

df.describe()

Return statistical

summary of all

numerical columns

​

​

​

​

10 of 15

7a

Max for

all

Species

df.max()

​

​

​

  1. : in the loc operator indicate we want to select all rows
  2. 4 columns is selected
  3. max() method return maximum value in the selected columns

11 of 15

7b

Max

for

specific

Species

​

​

  1. df.Species == ‘Iris-Versicolor’ is use to select only Iris-Versicolor rows.
  2. 4 Columns is selected
  3. max() method will return the maximum values for the selected columns

​

​

​

​

df.max()

12 of 15

8a

Min for

all Species

df.min()

  1. : in the loc operator indicate we want to select all rows
  2. 4 columns is selected
  3. min() method return min value in the selected columns

13 of 15

8b

Min

for

specific

Species

df.min()

​

​

​

​

​

​

  1. df.Species == ‘Iris-Versicolor’ is use to select only Iris-Versicolor rows.
  2. 4 Columns is selected
  3. min() method will return the minimum values for the selected columns

​

​

​

​

14 of 15

9a

Mean for

all

Species

df.mean()

​

​

  1. : in the loc operator indicate we want to select all rows
  2. 4 columns is selected
  3. mean() method return mean value in the selected columns

15 of 15

9b Mean

for a

specific

Species

df.mean()

  1. df.Species == ‘Iris-Versicolor’ is use to select only Iris-Versicolor rows.
  2. 4 Columns is selected
  3. mean() method will return the mean values for the selected columns specific for Iris-Versicolor

​

​

​

​