EDA Lab Manual for IT Students 2023
EDA Lab Manual for IT Students 2023
ODD SEMESTER
LAB MANUAL
(REGULATION-2021)
NAME :
REGISTER NUMBER:
YEAR/SEM :
COURSE/BRANCH :
RECORD NOTE BOOK
Certified that this is a Bonafide observation of Practical work done by Mr. /Ms. ........................................
Laboratory.
01 INSTALL STANDALONE R
06 REPRESENTATION ON A MAP
USING VARIOUS MAP DATA SETS
BUILD CARTOGRAPHIC
VISUALIZATION FOR MULTIPLE
07 DATA SETS INCLUDING VARIOUS
COUNTRIES OF THE WORLD
AIM
To write a program to Install standalone R.
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
0 Email1 0 0 1 0 0 0 2 0 0 ... (• 0 0 0 0 0 0 0 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[ ]:
Program:
import pandas as pd
df pd.read_csv('E:\DEV\[Link]')
[Link]()
Output
Finding count
value Program:
import pandas as pd
df
pd.read_csv('E:\DEV\[Link]'
) [Link](axis=O)
Output
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)
value Program
import pandas as pd
df
pd.read_csv('E:\DEV\[Link]'
) [Link](axis=O)
Output
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 the fundamental package for scientific computing with Python. It contains various features
including these important ones:
Program
Import numpy as np
# Creating array object
arr= [Link]( [[ 1, 2, 3],
[ 4, 2, 5]] )
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
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
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
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:
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]}
df = [Link](dict)
# using dropna()function
[Link]()
Output:
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]
3.5
3.0
"' 2.5
•
>,
2.0
LS
LO
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
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
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
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:
Output:
[I] "hello"
[ 1] "hello"
[ 1] "hello"
rm() function Syntax:
rm(variable)
Program2
# using equal to operator
varl = "hello"
# using leftward operator
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)
.,
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
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 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
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
6665 MUMBAI January 2005 275845 261 513 387 MS MUMBAI January-2005
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()
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
if i > 0:
[Link]('month', 'value', data=[Link][[Link]=y, :], color=mycolors[i], label=y)
df = pd.read_csv('[Link]
-
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
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.
[Link]
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]()
Df
Step 4: Checking Missing Values
[Link]().sum()
data =
df.drop_duplicates('class') data
df.value_counts('class')
Step 8: Relation between variables Comparing Sepal Length and Sepal Width
Step 10: plot all the column's relationships using a pairplot. It can be used for
multivariate analysis.
[Link](method='pearson')
#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
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)
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.