0% found this document useful (0 votes)
15 views48 pages

EDA Lab Manual for IT Students 2023

The document is a lab manual for the CCS346 Exploratory Data Analysis course for the academic year 2023-2024, outlining the vision and mission of the Department of Information Technology. It includes program outcomes, educational objectives, and specific outcomes for computer science graduates, along with a detailed index of experiments and practical exercises related to data analysis using R and Python. The manual emphasizes the development of technical skills and ethical responsibilities in students to prepare them for professional challenges.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views48 pages

EDA Lab Manual for IT Students 2023

The document is a lab manual for the CCS346 Exploratory Data Analysis course for the academic year 2023-2024, outlining the vision and mission of the Department of Information Technology. It includes program outcomes, educational objectives, and specific outcomes for computer science graduates, along with a detailed index of experiments and practical exercises related to data analysis using R and Python. The manual emphasizes the development of technical skills and ethical responsibilities in students to prepare them for professional challenges.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DEPARTMENT OF INFORMATION TECHNOLOGY

ACADEMIC YEAR: 2023 - 2024

ODD SEMESTER

LAB MANUAL

(REGULATION-2021)

CCS346 EXPLORATORY DATA ANALYSIS


LABORATORY

NAME :

REGISTER NUMBER:

YEAR/SEM :

COURSE/BRANCH :
RECORD NOTE BOOK

REGISTER NUMBER: .……………………..……….

Certified that this is a Bonafide observation of Practical work done by Mr. /Ms. ........................................

of the ............................................ Semester ……………………………………….. Branch during the

Academic year ….......................................... in the………………………………………………………..

Laboratory.

Submitted for the University Practical Examination held on……………….

STAFF-IN-CHARGE HEAD OF THE DEPARTMENT

INTERNAL EXAMINER EXTERNAL EXAMINER


DEPARTMENT OF INFORMATION TECHNOLOGY
Vision and Mission of the Institute
VISION
Our founding ethos remains at the core of the Institution’s vision. To
be an institute of repute in all fields of education by implementing the
best practices akin to
global standards for fostering domain knowledge and developing research
attitude among students to make them globally competent.
MISSION
Achieving excellence in Teaching & Learning process using state-of-the-art
resources.
Extending opportunity to upgrade faculty knowledge and skills. Implementing
the best student training practices for requirements of industrial scenario of the
state. Motivating faculty and students in research activity for real time
application.
Vision and Mission of the Department
VISION
To create a conducive environment for the development of
academic and innovative technocrats employable at the global level,
socially responsible and professionally competent to sustain the
challenges
MISSION

M1: To develop competent and quality IT professionals by


imparting state-of the art technology learning methodologies.
M2: To promote Industry – Institution relationships among the
students to become more employable and better citizens to solve
societal issues
M3: To constantly upgrade the Faculty qualification with cutting
edge technology to achieve high status in technical and research
areas.
PROGRAMME OUTCOMES
The UG program in Computer Engineering will prepare students to attain:
PO1 Engineering knowledge: Apply the knowledge of mathematics, science,
engineering fundamentals and an engineering specialization to the solution
of complex engineering problems.
PO2 Problem analysis: Identify, formulate, review research literature, and
analyze complex engineering problems reaching substantiated conclusions
using first principles of mathematics, natural sciences and engineering
sciences.
PO3 Design/development of solutions: Design solutions for complex
engineering problems and design system components or processes that
meet the specified needs with appropriate consideration for the public
health, safety,
cultural, societal and environmental considerations.
PO4 Conduct investigations of complex problems: Use research-based
knowledge and research methods including design of experiments, analysis,
and interpretation of data and synthesis of the information to provide valid
conclusions.
PO5 Modern tool usage: Create, select, apply appropriate techniques,
resources, modern engineering and IT tools including prediction and
modeling to complex engineering activities with an understanding of the
limitations.
PO6 The engineer and society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal, cultural issues and the
consequent responsibilities relevant to the professional engineering
practice.
PO7 Environment and sustainability: Understand the impact of the
professional engineering solutions in societal, environmental contexts,
demonstrate the knowledge and need for sustainable development.
PO8 Ethics: Apply ethical principles, commit to professional ethics,
responsibilities and norms of the engineering practice.
PO9 Individual and team work: Function effectively as an individual, as a
member or leader in diverse teams and in multidisciplinary settings.
PO10 Communication: Communicate effectively on complex engineering
activities with the engineering community with society at large being able to
comprehend, write effective reports, design documentation, make effective
presentations and receive clear instructions.
PO11 Project management and finance: Demonstrate knowledge,
understanding of the engineering and management principles and apply these to
one’s own work, as a member and leader in a team, to manage projects and in
multidisciplinary environments.
PO12 Life-long learning: Recognize the need, ability to engage in independent
and life-long learning in the broadest context of technological change.
Program Educational objectives
(PEO’s) PEO1. Basic Skills:
Graduates work productively as successful Computer
Professionals with problem solving skills, core computing skills and soft
skills
with social awareness.
PEO2. Technical Knowledge: Graduates engage in everlasting endeavor
to promote research and development
PEO3. Technical Knowledge: Graduates communicate effectively,
recognize and incorporate the societal needs in their profession by
practicing their boundless
skills with high regard to ethical responsibilities
Program Specific Outcomes(PSO’S)
A graduates of computer Science and Engineering program of Sri Shanmugha
College of Engineering and Technology will demonstrate
PSO 1: An Ability to apply programming skills for solving real time problems in
the areas
related to algorithms, data structures, cloud computing and data science. PSO
2: An ability to develop high quality software products by using cutting edge
technology.
INDEX

[Link] Date Experiments Page NoRemarks Sign

01 INSTALL STANDALONE R

PERFORM EXPLORATORY DATA


02 ANALYSIS (EDA) ON WITH DATA
SETS LIKE EMAIL DATA SET

03. a WORKING WITH NUMPY ARRAYS

03. b WORKING WITH PANDAS DATA


FRAME

03. c BASIC PLOTS USING MATPLOT LIB

04. a EXPLORE VARIOUS VARIABLES


AND ROW FILTERS IN R FOR
CLEANING DATA

04. b VARIOUS PLOT FEATURES IN R

05 TIME SERIES ANALYSIS

06 REPRESENTATION ON A MAP
USING VARIOUS MAP DATA SETS

BUILD CARTOGRAPHIC
VISUALIZATION FOR MULTIPLE
07 DATA SETS INCLUDING VARIOUS
COUNTRIES OF THE WORLD

08 PERFORM EDA ON WINE QUALITY


SET

Use a case study on a data set and


apply the various EDA and v
09 isualization techniques and
present an analysis
EX. N0.:1 INSTALL STANDALONE R
Date:

AIM
To write a program to Install standalone R.

Steps to Install R, RStudio, and R Packages


Here we will discuss the simple steps to install RStudio. But, before installing RStudio, we will
have to install R. So, first, let's learn the process of R installation. We have to follow three basic
steps in the same order to run Rand RStudio on your system.
1. Install R
2. Then, install R Studio
3. Lastly, install R Packages

Install R

The process of installing R depends on the type of your operating system. R can be installedin
the following ways:
For Mac

• Download the latest version of the .pkg file from the following link: CRAN R Project

• Open the downloaded .pkg file and install R. Now, for Linux

• For Ubuntu with Apt-get installed, execute sudo apt-get install r-base in [Link], for
Windows
Step 1: Go to the website - CRAN R Project WindowsStep 2: Click on the "Download R 3.6.0
for Windows"

Result:
Thus the given Procedure was successfully executed.
EX. N0.:2 PERFORM EXPLORATORY DATA ANALYSIS (EDA) ON
Date: WITH DATA SETS LIKE EMAIL DATA SET

Aim:
To write a python program to perform exploratory data analysis (eda) on with data sets like
email data set.
Program:
import pandas as pd
df
pd.read_csv(E:\DEV\[Link]'
Output: ) [Link]()
Out[11]:
Email No. the to ect and for of a you hou ... connevey jay valued lay infrastructuredryPredicti

military allowing ff on0

0 Email1 0 0 1 0 0 0 2 0 0 ... (• 0 0 0 0 0 0 0 0 0

1 Email2 8 13 24 6 6 2 102 1 27 ... C• 0 0 0 0 0 0 1 0 2 Email3 0 0 1 0 0 0 8 0 0


0 ... C• 0 0 0 0 0 0 0 0 3 Email4 0 5 22 0 5 1 51 2 10 ... c, 0 0 0 0 0 0 0 0 4 0
Email5 7 6 17 1 5 2 57 0 9 ... (I 0 0 0 0 0 0 1 0 0

5rows x 3002columns
Finding Min value

import pandas as pd
df pd.read_csv('E:\DEV\[Link]')
[Link]()

Output
Out[12]: Emailllo. Email1
the 8
to 8
ect 1
and 8
military 8
allowing 8
ff 8
dry 0
Prediction 0
Length:3002,dtype: object
In[ ]:

Finding maximum value

Program:

import pandas as pd
df pd.read_csv('E:\DEV\[Link]')
[Link]()
Output

Out[14): Email No. Email 999


the 210
to 132
ect 344
and 89
military 4
allo11ing 3
ff 114
dry 4
Prediction 1
length: 3002, dtype: object

Finding count

value Program:

import pandas as pd
df
pd.read_csv('E:\DEV\[Link]'
) [Link](axis=O)
Output

Out[15]: Email No. 5172


9t0h e
to 72
ect 90
and 53
military 4
allowing 3
ff 23
dry 4
Prediction 2
length: 3002, dtype: int64

Program

import pandas as pd
df
pd.read_csv('E:\DEV\[Link]'
) [Link](axis=1)
Output
out[l6]: e 6
1 40
8
2
3 30
4 30
20
5167 43
5168 12
5169
5170 2544
5171
length: 5172, dtype: int64
Find the mean value

Program

import pandas as pd
df pd.read_csv('E:\DEV\[Link]')
[Link](axis= l)

Output
t lcl 0 0.017661
1 0.734089
2 0.037654
3 0.339553
4 0.358214
5167 0.168277
5168 0.979340
5169 0.059647
5170 0.262579
5171 0.905365
Length: 5172, dtype: float64

Program
import pandas as pd
df
pd.read_csv('E:\DEV\[Link]')
[Link](axis=O)

Out[l9]: the 6.640565


to 6.188128
ect 5.143852
and 3.875599
for 3.124710
military 0.006574
allowing 0.804060
ff 0.914733
dry 0.006961
Prediction 0.290023
Length: 3081, dtype: float64

Find the median

value Program

import pandas as pd
df
pd.read_csv('E:\DEV\[Link]'
) [Link](axis=O)
Output

Out[20]: the 3.0


to 3.0
ect 1.0
and 1.0
for 2.0
military 8.0
allosling 0.0
ff 0.0
dry 0.0
Prediction 0.0
Length: 3001, dtype: float64

Result:
Thus the given Program was successfully executed.
EX. N0.:3) a WORKING WITH NUMPY ARRAYS
Date:

AIM
To write a program to Working with Numpy arrays .

NUMPY:

NumPy is a Python library used for working with arrays. It also has functions for working in
domain of linear algebra, fourier transform, and matrices. NumPy was created in 2005 by Travis
Oliphant. It is an open source project and you can use it freely. NumPy stands for Numerical Python.

It is a general-purpose array-processing package. It provides a high-performance multi


dimensional array object, and tools for working with these arrays.

It is the fundamental package for scientific computing with Python. It contains various features
including these important ones:

• A powerful N-dimensional array object


• Sophisticated (broadcasting) functions
• Tools for integrating CIC++ and Fortran code
• Useful linear algebra, Fourier transform, and random number capabilities

Program

Import numpy as np
# Creating array object
arr= [Link]( [[ 1, 2, 3],
[ 4, 2, 5]] )

# Printing type of an· object


print("Array is of type: ", type(arr))
# Printing an·ay dimensions (axes)
print("No. of dimensions: ", [Link])
# Printing shape of array
print("Shape of array: ", [Link])
# Printing size (total number of elements) of array

print("Size of array: ", [Link])

# Printing type of elements in an·ay

print("Array stores elements of type: ", [Link])


Output

Array is of type: <class


'[Link]'> No. of dimensions:
2 Shape of array: (2, 3)Size of array: 6

Array stores elements of type: int32

Program to perform slicing operation

Program

Import numpy as np

a=[Link]·ay([[1,2,3],[3,4,5],[4,5,6]])

print(a)

print("After slicing")print(a[1:])

Output

((123]

(34 5]
(45 6]]

After slicing
((3 45]
(4 56]]

Result:
Thus the given Program was successfully executed.
EX. N0.:3) b WORKING WITH PANDAS DATA FRAME
Date:

AIM
To write a program to Working with Pandas data frame.

PANDAS:
It is a Python library. Pandas is used to analyze data. A Pandas DataFrame is a 2
dimensional datastructure, like a 2 dimensional array, or a table with rows and

[Link] can becreatedfrom thelists, dictionary andfrom a list

ofdictionaryetc.

Program
# import pandas as pd
importpandasas pd
#list of strings
lst=['A' 'B' 'C' 'D' 'E' 'F' 'G']
''''''
# Calling DataFrame constructor on list
df [Link](lst)
print(df)
Output

0 A
1B
2C
3D
4E
5 F
6G

Create a dataframe using the dictionary

DATAFRAME:
To create DataFrame from diet of narray/list, all the narray must be of same length. If index
is passedthen the length index should be equal to the length of arrays. If no index is passed, then by
default,indexwill be range(n)wheren is thearray length.
Program
Import pandas as pd
#intialize data of lists.
data= {'Name':['Tom', 'nick', 'krish', Jack'],'Age':[20,21, 19,
18]} #CreateDataFrame
df = [Link](data)
# Print the output.
print(df)

Output:

Name Age

0 Tom 20

1 nick 21

2 krish 19

3 jack 18

COLUMN SELECTION

Column Selection
A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows
and columns. We can perform basic operations on rows/columns like selecting, deleting, adding,
and renaming.

Column Selection: In Order to select a column in Pandas DataFrame, we can either access

the columns
by calling them by their columns name.

PROGRAM
import pandas as pd
# Define a dictionary containing employee data
data= {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'], 'Age':[27, 24, 22, 32],'Address':['Delhi',
'Kanpur', 'Allahabad', 'Kannauj'], 'Qualification':['Msc', 'MA', 'MCA', 'Phd']}
# Convert the dictionary into DataFrame
df = [Link](data)
print(df)
# select two columns print(df[['Narne', 'Qualification']])

Output:

10 tame Qualification
1 Jai l•lsc
2 Princi · 1A Gaurav
3 /·lCA Anuj Phd

CHECKING FOR MISSING VALOES USING ISNULL() AND NOTNULL() :


In order to check missing values in Pandas DataFrarne, we use a function isnull() and notnull().
Both function help in checking whether a value is NaN or [Link] function can also be used in
Pandas Series in order to find null values in a series.

Program
# importing pandas as pd
impo1t pandas as pd
# importing numpy as np
impo1tnumpy as np
# dictionary of lists
diet= {'First Score':[100, 90, [Link], 95],'Second Score': [30, 45, 56,
[Link]], 'Third Score':[[Link], 40, 80, 98]}
# creating a datafrarne from list
df = [Link](dict)
# using isnull() function
[Link]()

Output:

First Score Second Score Third Score


0 False False True
1 False False False
2 True False False
3 False True False
DROPPING MISSING VALUES USING DROPNA()
In order to drop a null values from a dataframe, we used dropna() function this function drop
Rows/Columns of datasets with Null values in different ways.

Program
Drop rows with at least one Nan value (Null value)
# importing pandas as pd
import pandas as pd
# importing numpy as np
import numpy as np
# dictionary of lists
diet= {'First Score':(100, 90, [Link], 95],'Second Score': (30, [Link], 45, 56],
'Third Score':(52, 40, 80, 98],'Fourth Score':[[Link], [Link], [Link], 65]}

# creating a dataframe from dictionary

df = [Link](dict)
# using dropna()function

[Link]()

Output:

First Score Second Score Third Score Fourth Score


3 95.0 56.0 98 65.0

Result:
Thus the given Program was successfully executed.
EX. N0.:3) C BASIC PLOTS USING MATPLOT LIB

AIM
To write a program to Basic plots using Matplot LIB .

Matplotlib:

It is a Python library that helps in visualizing and analyzing the data and helps in better
understanding of the data with the help of graphical, pictorial visualizations that can be simulated
using the matplotlib library. Matplotlib is a comprehensive library for static, animated and
interactivevisualizations
Program

Import [Link]
plot as plt
# x axis values
X = [1,2,3]

con·esponding y axis values


#y=2,4,1]
plotting the points
[Link](x, y)
# naming the x axis
[Link]('x - axis')
# naming the y axis
[Link]('y - axis')

# giving a title to my graph

[Link]('My first graph!')

# function to show the plot


[Link]()
Output:
My first graph!

3.5

3.0

"' 2.5

>,

2.0

LS

LO

LOO L2 5 LSO L 75 2.00 2.25 2.50 2.75 3.00


COMPUTE THE X AND Y COORDINATES AND CREATE A PLOT
Program

Import numpy as np
Import [Link]
Plot as plt
x =[Link](O, 3*[Link], O.l)y
=[Link](x) [Link](x, y)
[Link]()

Output

LOO
0.75
0.50
0.25
0.00
-0.25
-0.50
-0.75
-1.00

0 2 4 8
6

DRAWING MULTIPLE LINES USING PLOT FUNCTION


Program

Import numpy as np
Import [Link]
plot as plt
# Compute the x and y coordinates for points on sine and cosine curves
x = [Link](O, 3 * [Link], 0.1)
y_sin = [Link](x) y_cos = [Link](x)
# Plot the points using matplotlib
[Link](x, y_sin)
[Link](x, y_cos)
[Link]('x axis label')
[Link]('y axis label')
[Link]('Sine and Cosine')
[Link](['Sine',
'Cosine']) [Link]()

Output
Sine and Cosine
LOO
0.75

0.50
0.25

0
>.00

-0.25

-0.50
I
-0.75
Sine
Cosine
-1.00
0 2 4 6 8
X axis label

BASIC PLOT USING MATPLOTLIB


Program
Line plot:
from matplotlib
impo1t pyplot as plt
X = [5, 2, 9, 4, 7]
y = [10, 5, 8, 4, 2]
[Link](x,y)
[Link]()

10
9

7
6

s
4

2
2 3 4 s 6 7 8 9
Bar plot:
from matplotlib
import pyplot as plt
X = [5, 2, 9, 4,
7] y = [10, 5, 8,
4, 2]
[Link](x,y
)
[Link]()
10

0.8

0.6

0.4

0.2

2 3 4 5 6 7 8 9 10

Histogram:
from matplotlib
import pyplot as plt
y= [10, 5, 8, 4, 2]

[Link](y)
[Link]()

10

2 3 4 s 6 7 8 9
Scatter Plot :
from matplotlib
import pyplot as plt

X = (5, 2, 9, 4,
7] (10,
=
y 5, 8, 4, 2]
[Link](x, y)[Link]()

Output

10

9

8 •
7

5· • •
4

2 • ' ' '


'3 '
2' 4' 5' 6 8 9
7

Result:
Thus the given Program was successfully executed
EX. N0.:4) a EXPLORE VARIOUS VARIABLES AND ROW FILTERS IN
Date: R FOR CLEANING DATA

AIM
To write a program to Explore various variables & row filters in R for cleaning data .

Program 1:

# using equal to operator


varl = "hello"
print(varl)
# using leftward operator
var2 < - "hello"
print(var2)
# using rightward operator
"hello"- > var3
print(var3)

Output:
[I] "hello"
[ 1] "hello"
[ 1] "hello"
rm() function Syntax:
rm(variable)
Program2
# using equal to operator
varl = "hello"
# using leftward operator

var2 < - "hello"


# using rightward operator
"hello" -> var3
# Removing variable
rm(var3)
print(var3)
Output:
Error in print(var3) : object 'var3' not foundExecution halted
Data types in R

• Logical Data Type.


• Numeric Data Type.
• Integer Data Type.
Complex Data Type.

Character Data Type.

Raw Data Type.

1. Logical Data Type


The logical data typein R is also boolean data type. It can only have two values: TRUE
known as and FALSE.

2. N11meric Data Type


In R, the numeric data type represents all real numbers with or without decimal values.

[Link] Data Type


The integer data type specifies real values without decimal points. We use the L to specify
suffix integer data.

4. Complex Data Type


The complex data type is used to specify purely imaginary values in R. We use the suffix
i to specify the imaginary part.

5. Character Data Type


The character data type is used to specify character or string values in a variable.
In programming, a string is a set of characters. For example, 'A' is a single
character and "Apple" isa string.
You can use single quotes "or double quotes "" to represent strings. In general, we use:
• " for character variables
• "" for string variables

6. Raw Data Type


A raw data type specifies values as raw bytes. You can use the following methods to
convert character data types to a raw data type and vice-versa:
• charToRaw() - converts character data to raw data
• rawToChar() - converts raw data to character data
Program:

booll <- TRUE


print(bool1)
print(class(bool1))
bool2 <- FALSE
print(bool2)
print(class(bool2))
weight<- 63.5
print(weight)
print(class(weight))
height <- 182
print(height)
print(class(height))
integer_variable <- 186L
print(class(integer_variable))
complex_value <- 3 + 2i

print(class(complex_value))
fruit <- "Apple"
print(class(fruit))
my_char <- 'A'
print(class(my_char))
raw_variable <- charToRaw("Welcome to
Programiz") print(raw_variable)
print(class(raw_variable))
char_variable <- rawToChar(raw_variable)
print(char_variable)
print(class(char_variable))

Output:

TRUE
"logical"
FALSE

"loIo: >ical"
63.5
"numeric"
182
"numeric"
"integer"
"complex"
"character"
"character"
57 65 6c 63 6f 6d 65 20 74 6f20 5072 6f 67 72 61 6d
69 7a "raw"
"Welcome to Programiz"
"character"

Result:
Thus the given Program was successfully executed.
EX. N0.:4) b VARIOUS PLOT FEATURES IN R
Date:

AIM
To write a program to various plot features in R .

Line plot
linel= c(l,2,3,4,5,10)

line2 <- c(2,5,7,8,9,10)


plot(linel,type = "l",col - "blue",lwd=2,main="My Graph",xlab="The x-axis",ylab="The y
axis") lines(line2, type="l", col = "red")
Output
My Graph

.,

1 2 4 5 6
3
The x•axls

Scatter plot
X <- c(5,7,8,7,2,2,9,4,11,12,9,6)
y <- c(99,86,87,88,111,103,87,94,78,77,85,86)
plot(x, y, main="Observation of Cars", xlab="Car age", ylab="Car speed")

Output:
Observation of cars

-0 0-
-0

--
g
i! 0

:£ -
0

is g-
0
0 0

-
0 0 0

:il -
'
0
' • ' ' •
0

2 4 6 8 ,o ,2
car age
Pie Chart
x <- c(l0,20,30,40)
# Create a vector of labels
mylabel <- c("Apples", "Bananas", "Cherries", "Dates")
# Display the pie chart with labels
pie(x, label= mylabel, main= "Fruits")

Output:

Fruits

---.i_Bananas

Cherries Apples

Dates

Bar Chart

x <- c(" A" "B""C""D")


' ' '
y c(2, 4, 6, 8)
<-
barplot(y, [Link] = x, col= "red",density=lO)

Output:

C0

"'

B C D
A

Result:
Thus the given Program was successfully executed.
[Link].:5 TIME SERIES ANALYSIS
Date:

AIM
To write a program to Time series analysis .

PROGRAM
from [Link]
.
1n,port par e
import maLplotJib
as mpl
import
matplollib.p plot as
y pit

import seaborn asns


import numpy as
op import pandas
as pd
[Link]({'[Link] ize': (10,
120})
7), '[Link]':

# Import as Dataframe
csv('btlps://ra\.[Link].co111/selva86/dalasets/masLer/[Link]
df=pd.read_
', par e_dates=['date'])
[Link]()
# dataset source: [Link]
pd.read_csv('[Link]
[Link]/selva86/datasets/master/[Link]') d
f = [Link][[Link]='MUMBA1', :][Link]()
# Time series data source: fpp pacakge in [Link] [Link] as pit
df=pd.read_c: //[Link]/v('hLLp

e#lv Dar8a6,v/Pdlaotta Sets/master/a I0.c


def plot_df(df,i2e=(J6.5),

Lille='"', xJabel='Date', ylabel='VaJue', dpi=JOO):[Link](fig


v', par e_dates=[y',d ate'], index_col='date')
x. dpi=dpi)
[Link](x, y, color='tab:red')
[Link]().set(ti Ue=title, x1abel=x1abel, ylabel=ylabel)[Link]()
plot_df(<lf, x=[Link], y=[Link]. tille='Monthly anli-djabetic drug salesin Australja
froml992 to 2008.')

Output

date value

0 1991-07-01 3.526591ser =

1 1991-08-01 3.180891

2 1991-09-01 3.252221

3 1991-10-01 3.611003

4 1991-11-01 3.565869

pd.read_csv(•[Link]
e_ dates=['date'], index_col='date')
[Link]

date

1991-07-01 3.526591

1991-08-01 3.180891

1991-09-01 3.252221

1991-10-01 3-611003

# dataset source: [Link]


elf=pd.read_csv([Link]
[Link]/selva86/datasets/master/Market:[Link]') <.If= [Link].:
[[Link]='MUMBAf, :]
[Link]() market month year quantity priceMln priceMax
priceMod state city date
6664 MUMBAI January 2004 267100 719 971 849 MS MUMBAI January-2004

6665 MUMBAI January 2005 275845 261 513 387 MS MUMBAI January-2005

MUMBAI January 2006 228000 315 488 402 MS MUMBAI January-2006


6656
6657 MUMBAI January 2007 205200 866 113 997 MS MUMBAI January-2007
6658 MUMBAI January 2008 267550 348 6 448 MS MUMBAI January-2008

550
# Time series data source:
fpp pacakge in R.
import [Link] as pit
df=pd.read_csv('[Link]
parse_dates=['date'], index_col='date')
# Draw Plot
def plot_df(df, x, y, title="", xlabel='Date', ylabel='Value', dpi 100): [Link](figsize=(l6,S),
dpi=dpi)
[Link](x, y, color='tab:red')
[Link]().set(title=title, x]abel=xlabel, ylabel=ylabel)[Link]\v()

plot_df(df, x=[Link], y=[Link], title='Monthly anti-diabetic drug sales in Australia from


I992 to 2008.')
# Import data
df = pd.read_csv('datasets/[Link]', parse_dates=['date'])

x = df['date'].values

yl = df['value'].values
#Plot
fig, ax= [Link](l, I, figsize=(l 6,5), dpi= 120)
plt.fill_between(x, yl=yl, y2=-yl, alpha=0.5, linewidtb=2, color='seagreen')
[Link](-800, 800)
[Link]('Air Passengers (Two Side View)', fontsize=16)
[Link](y=O, xmin=[Link]([Link]), x..rnax=[Link]([Link]), linewidlh=.5)
plt.sl1owO

JO

#
20

10

1994 19')8 2000 2002 2004 2006


l992
Dito
Impo1tData
df =
pd.read_csv('[Link]
parse_dates=['date'], index_col='date')
df.reset_index(inplace True)
# Prepare data
df['year'] = [[Link] for d in [Link]] df['rnontb']
= [[Link]('%b') ford jn [Link]] years =
df['[Link]()
# Prep Colors
[Link](J00)
mycolors = [Link](]ist([Link].XKCD_COLORS.keysO), len(years),
replace=False)
#Draw Plot
[Link](figsize=(l6,12), dpi= 80)for i, yin enumerate(years):

if i > 0:
[Link]('month', 'value', data=[Link][[Link]=y, :], color=mycolors[i], label=y)

[Link]([Link][[Link]-y, :].shape[0]-.9, [Link][[Link]-y, 'value'][-1:].values[O], y,


fontsize=l 2, color=mycolors[i])
# Decoration
[Link]().set(xlim-(-0.3, 11), ylim=(2, 30), ylabel='$Drug Sales$', xlabel='$Month$')
[Link](fontsize=12, alpha=.7)
[Link]("Seasonal Plot of Drug Sales Time Series", fontsize=20)
pltsl1ow()

df = pd.read_csv('[Link]

II YEAR / III SEM


parse_dates=['date'], index_col='date')
df.reset_index(inplace=True)
# Prepare data
df['year'] = [[Link] ford in [Link]]
df['montb'] = ([Link]('%b') ford in [Link]]
years= df('year'].unique()
#Draw Plot
fig, axes= [Link](l, 2, figsize=(20,7), dpi= 80)
[Link](x='year', y='value', data=df, ax=axes[O])

n .boxplot(x='month', y='value', data=[Link][~[Link].i in([1991, 2008]), :])


# Set Title
axes[O].set_title('Year-wise Box Plot\n(The Trend)', fontsize=l 8);
axes[l].set_title('Montb-wise Box Plot\n(The Seasonality)', fontsize=l8)
[Link]()

Year-wiseBox Plot Month-wiseBox Plot


eTrend l
(The Seasonall
• t

-
II

-M
-•
I

Ml -l J I
,.,,

Result:
Thus the given Program was successfully executed
EX. N0.:6 REPRESENTATION ON A MAP USING VARIOUS MAP DATA SETS
Date:
AIM
To write a program to Representation on a map using various map data sets.

Program
Import numpy as np
import pandas as pd
import foiium as fo
data= pd.read_csv("E:\DEV\[Link]")
print([Link]())
lat= list(data["Latitude"])
Ion= list(data["Longitude"])
[Link] = Iist(data["City"])
worldcitiespop = [Link](name="worldcitiespop")
for a, b, c in zip(lat, Ion, name):
worldcitiespop.add_chiid([Link](Region=[a, b], popup=c, icon=[Link](coior='blue')))
[Link]().add_child(worldcitiespop)

Output

+
-

Result:
Thus the given Program was successfully executed
EX. N0.:7 BUILD CARTOGRAPHIC VISUALIZATION FOR MULTIPLE DATA SETS
Date: INCLUDING VARIOUS COUNTRIES OF THE WORLD

AIM
To write a program to Build cartographic visualization for multiple data sets including
various counties of the world.
Program:
import geoplot as gplt
import geopandas as gpd
import [Link] as gcrs
import imageio
import pandas as pd
import pathlib
import [Link] as plt
import mapclassify as me
import numpy as np
usa = gpd.read_file("maps/cb_2018_us_state_20m.shp")
[Link]()
pop_states = [Link](state_pop, left_on="NAME", right_on="NAME")
pop_states.head()
pop_states[pop_states.NAME=="Califomia"].plot()

Output
path= [Link].get_path("contiguous_usa")
contiguous_usa = gpd.read_file(path)
[Link](contiguous_usa)
Output

Result:
Thus the given Program was successfully executed
EX. N0.:8 PERFORM EDA ON WINE QUALITY SET
Date:

AIM
To write a program to perform EDA on wine quality set .
Program:
import numpy as np # linear algebra

import pandas as pd# data processing, CSV file 1/0 (e.g. pd.read_csv)
import seabom as sns
import [Link] as plt
import os
print([Link]("../input"))
[Link]('fivethirtyeight')
df = pd.read_csv('../input/red-wine-quality-cortez-et-al-
2009/winequality- [Link]') [Link]()
fig, ax= [Link](figsize=(15,7))
[Link]([Link](),cmap='viridis', annot T1ue)

OUTPUT

fixed acidity
0.9
volatile aad,ty

citric acid
0.6
residual sugar

chlorides

ftte sulfur dioxide 0.3

total

sulfurdioxide
0.0
density

pH
-0.3
sulphates

alcohol

(Jlality
-0.6
., :2
.", '
'6 .2 ; .2 -
:.,; -6 ,2 ol
:,
!! .",' "'
.'!!
B

Program

1 = [Link]
number of columns=12
number_of_rows = len(l)-1/number_of_columns
[Link](figsize=(number_of_columns,5*number_of_rows))
for i in range(O,len(l)):
30
[Link](number_of_rows + 1,number_of_columns,i+1)
sns.set_style('whitegrid')
[Link](df[l[i]],color='green',orient='v')
plt.tight_layout()

Output

'6 L6 16
1

LLO 14
300 4•0 164 ' ♦ ♦
♦♦♦♦
♦ ♦
♦ ♦
L004 15

L2: ♦

70♦ ♦ i
L002 14 8•
08 12 0 4.0 L75

♦ 2.00

.5 0 25
'"0 3.8
LOOO 3.6 7
I
200 • L50 13
'"0
60
12 ...10so 0.4
(IJ (IJ

6
- '"-0 LO :"5! 06 (C1)\ t/1 0'i< .2
X 0.998 t/1

u:"5! u
(1)
u t/1
::, (IJ
"
... '"0 a 2l L25 0J- :0. 12 ..>..,,
ru 10 ::(1,) 8 3.4
u(
,::,:,C, .. 4=0 .. 150
(1)
(IJ ''C"0:0.3 J(:1. )
:; 0.8 .b
1) '"0 0 u
·- fj C.
iil LOO 6-
..(t/1I .J
'"0 (1)

QXI 0>
u
0.4 0t./99:61 C: : iii 11
5
l;:: t/1 .I.(l.1.l,)
.3.2
8
0.6 6 0.2 -(I
300 . 2J .
.(I8J
100
0.75 10
4 4
0.4 0.2
0.1 10 so 0.992
0.994
6
2 3.0 0.50 9

-
u
02 2.8
♦ t
-•
0.0 0 0
0.990 3•
0.25
00

Result:
Thus the given Program was successfully executed

31
[Link] Use a case study on a data set and apply the various
DATE : EDA and visualization techniques and present an
analysis

AIM
To write a program to use a case study on a data set and apply the various EDA and
visualization techiques and present an analysis
Exploratory Data Analysis (EDA) is a technique to analyze data using some
visual
Techniques. With this technique, we can get detailed information about the statistical
summary of the data. We will also be able to deal with the duplicate's values, outliers, and
also see some trends or patterns present in the dataset.
Use a case study on a data set: Iris Dataset
Iris Dataset is considered as the Hello World for data science. It contains five columns
namely - Petal Length, Petal Width, Sepal Length, Sepal Width, and Species Type. Iris is
a flowering plant; the researchers have measured various features of the different iris
flowers and recorded them digitally.

Step1: Download the dataset

[Link]

Step 2: Import package and read dataset

import pandas as pd
# Reading the CSV file df =
pd.read_csv("/content/[Link]") #Printing top 5 rows
[Link]()
Step 2.1Getting Information about the Dataset

[Link]
[Link]()
[Link]()

Step 3: view dataframe contains 6 columns and 150 rows.

Df
Step 4: Checking Missing Values

[Link]().sum()

Step 5: Checking Duplicates

data =
df.drop_duplicates('class') data

Step 6: counts of unique values.

df.value_counts('class')

Step 7: Visualizing the target column

import seaborn as sns


import [Link] as plt
[Link](x='class', data=df, )
[Link]()

Step 8: Relation between variables Comparing Sepal Length and Sepal Width

import seaborn as sns


import [Link] as plt
[Link](x='sepallength', y='sepalwidth',hue='class',
data=df,) #Placing Legend outside the Figure
[Link](bbox_to_anchor=(1, 1), loc=2)
[Link]()

Step 9: Comparing Petal Length and Petal Width


import seaborn as sns
import [Link] as plt
[Link](x='petallength', y='petalwidth', hue='class',
data=df,) #Placing Legend outside the Figure
[Link](bbox_to_anchor=(1, 1), loc=2)
[Link]()

Step 10: plot all the column's relationships using a pairplot. It can be used for
multivariate analysis.

import seaborn as sns


import [Link] as plt
[Link]([Link]([], axis = 1),hue='class', height=2)

Step 11: Histograms


import seaborn as sns
import [Link] as plt
fig, axes = [Link](2, 2, figsize=(10,10))
axes[0,0].set_title("Sepal Length")
axes[0,0].hist(df['sepallength'], bins=7)
axes[0,1].set_title("Sepal Width")
axes[0,1].hist(df['sepalwidth'], bins=5);
axes[1,0].set_title("Petal Length")
axes[1,0].hist(df['petallength'], bins=6);
axes[1,1].set_title("Petal Width")
axes[1,1].hist(df['petalwidth'], bins=6);

Step 12: Histograms with Distplot Plot


import seaborn as sns

import [Link] as plt


plot = [Link](df, hue="class")
[Link]([Link], "sepallength").add_legend()
plot = [Link](df, hue="class")
[Link]([Link], "sepalwidth").add_legend()
plot = [Link](df, hue="class")
[Link]([Link], "petallength").add_legend()
plot = [Link](df, hue="class")
[Link]([Link], "petalwidth").add_legend()
[Link]()

Step 13: Handling Correlation

[Link](method='pearson')

Step 14: Heatmaps

#importing packages
import seaborn as sns
import [Link] as plt
[Link]([Link](method='pearson').drop([], axis=1).drop([], axis=0), annot = True);
[Link]()
Step 15: Box Plots

import seaborn as sns


import [Link] as plt
def graph(y):
[Link](x="class", y=y,
data=df) [Link](figsize=(10,10))
# Adding the subplot at the
specified #grid position
[Link](221)
graph('sepallength")
[Link](222)
graph('sepalwidth')
[Link](223)
graph('petallength')
[Link](224)
graph('petalwidth')
[Link]()

Step 16: Handling Outliers

Outlier is a data-item/object that deviates significantly from the rest of the (so- called
normal)objects. They can be caused by measurement or execution errors. The analysis for
outlier detection is referred to as outlier mining. There are many ways to detect the outliers,
and the removal process is the data frame same as removing a data item from the
panda's dataframe.
import seaborn as sns
import [Link] as plt
# Load the dataset
df = pd.read_csv('/content/[Link]')
[Link](x='sepalwidth', data=df)

Step 17: Removing Outliers

import sklearn
from [Link] import load_boston
import pandas as pd
import seaborn as sns
import numpy as np
# Load the dataset
df= pd.read_csv('/content/[Link]')
#IQR
Q1 = [Link](df['sepalwidth'], 25,interpolation =
'midpoint') Q3 = [Link](df['sepalwidth'], 75, interpolation
= 'midpoint') IQR = Q3- QI
print("Old Shape: ", [Link])
# Upper bound
upper = [Link](df['sepalwidth'] >=
(Q3+1.5*IQR)) # Lower bound
lower = [Link](df['sepalwidth'] <= (Q1-
1.5*IQR)) # Removing the Outliers
[Link](upper[0], inplace = True)
[Link](lower[0], inplace = True)
print("New Shape: ", [Link])
[Link](x='sepalwidth', data=df)

Result
Thus the given program is executed sucessfully.

You might also like