Ad3301-Data-Exploration-And-Visualization Lab Manual
Ad3301-Data-Exploration-And-Visualization Lab Manual
Ad3301-Data-Exploration-And-Visualization Lab Manual
AD3301
PRACTICAL EXERCISES:
1. Install the data Analysis and Visualization tool: R/ Python /Tableau Public/ Power BI.
2. Perform exploratory data analysis (EDA) on with datasets like email data set. Export all your emails as a
dataset, import them inside a pandas data frame, visualize them and get different insights from the data.
3. Working with Numpy arrays, Pandas data frames , Basic plots using Matplotlib.
4. Explore various variable and row filters in R for cleaning data. Apply various plot features in R on sample
data sets and visualize.
5. Perform Time Series Analysis and apply the various visualization techniques.
6. Perform Data Analysis and representation on a Map using various Map data sets with Mouse Rollover
effect, user interaction, etc..
7. Build cartographic visualization for multiple datasets involving various countries of the world;
states and districts in India etc.
8. Perform EDA on Wine Quality Data Set.
9. Use a case study on a data set and apply the various EDA and visualization techniques and present an
analysis report.
LIST OF EXPERIMENTS
S.NO EXPERIMENS PAGE NO MARKS SIGNATURE
EX NO: 1
DATE: INSTALLING DATA ANALYSIS AND VISUALIZATION TOOL
AIM:
To write a steps to install data Analysis and Visualization tool: R/ Python /Tableau Public/ Power BI.
PROCEDURE:
R:
R is a programming language and software environment specifically designed for statistical
computing and graphics.
Windows:
Download R from the official website: https://cran.r-project.org/mirrors.html
Run the installer and follow the installation instructions.
macOS:
Download R for macOS from the official website: https://cran.r-project.org/mirrors.html
Open the downloaded file and follow the installation instructions.
Linux:
You can typically install R using your distribution's package manager. For example, on Ubuntu, you
can use the following command:
csharp
Copy code
sudo apt-get install r-base
Python:
Python is a versatile programming language widely used for data analysis. You can install Python
and data analysis libraries using a package manager like conda or pip.
Windows:
Download Python from the official website: https://www.python.org/downloads/windows/
Run the installer, and make sure to check the "Add Python to PATH" option during installation.
You can install data analysis libraries like NumPy, pandas, and matplotlib using pip.
macOS:
macOS typically comes with Python pre-installed. You can install additional packages using pip or
set up a virtual environment using Ana
conda.
Linux:
Python is often pre-installed on Linux. Use your distribution's package manager to install Python if
it's not already installed. You can also use conda or pip to manage Python packages.
Tableau Public:
Tableau Public is a free version of Tableau for creating and sharing interactive data visualizations.
Go to the Tableau Public website: https://public.tableau.com/s/gallery
Download and install Tableau Public by following the instructions on the website.
Power BI:
Power BI is a business analytics service by Microsoft for creating interactive reports and dashboards.
Go to the Power BI website: https://powerbi.microsoft.com/en-us/downloads/
Download and install Power BI Desktop, which is the tool for creating reports and dashboards.
Please note that the installation steps may change over time, so it's a good idea to check the official
websites for the most up-to-date instructions and download links. Additionally, system requirements
may vary, so make sure your computer meets the necessary specifications for these tools.
Ex no: 2
Aim:
To Perform exploratory data analysis (EDA) on with datasets like email data set.
Procedure:
Exploratory Data Analysis (EDA) on email datasets involves importing the data, cleaning it, visualizing
it, and extracting insights. Here's a step-by-step guide on how to perform EDA on an email dataset using
Python and Pandas
1. Import Necessary Libraries:
Import the required Python libraries for data analysis and visualization.
2. Load Email Data:
Assuming you have a folder containing email files (e.g., .eml files), you can use the email library to
parse and extract the email contents.
3. Data Cleaning:
Depending on your dataset, you may need to clean and preprocess the data. Common
cleaning steps include handling missing values, converting dates to datetime format, and removing
duplicates.
4. Data Exploration:
Now, you can start exploring the dataset using various techniques. Here are some common EDA
tasks:
Basic Statistics:
Get summary statistics of the dataset.
Distribution of Dates:
Visualize the distribution of email dates.
5. Word Cloud for Subject or Message:
Create a word cloud to visualize common words in email subjects or messages.
6. Top Senders and Recipients:
Find the top email senders and recipients.
Depending on your dataset, you can explore further, analyze sentiment, perform network analysis, or
any other relevant analysis to gain insights from your email data.
Program:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import email
import os
email_dir = 'path_to_email_folder'
emails = []
for filename in os.listdir(email_dir):
with open(os.path.join(email_dir, filename), 'r', encoding='utf-8', errors='ignore') as f:
msg = email.message_from_file(f)
emails.append({ 'Subject': msg['Subject'],'From': msg['From'],'To': msg['To'],'Date': msg['Date'],
'Message': msg.get_payload(),})
df = pd.DataFrame(emails)
# Convert 'Date' column to datetime
df['Date'] = pd.to_datetime(df['Date'], infer_datetime_format=True)
# Drop duplicates if necessary
df.drop_duplicates(inplace=True)
# Handle missing values if necessary
df.dropna(subset=['Subject', 'From', 'Message'], inplace=True)
print(df.describe())
plt.figure(figsize=(12, 6))
df['Date'].hist(bins=50)
plt.title('Distribution of Email Dates')
plt.xlabel('Date')
plt.ylabel('Count')
plt.show()
from wordcloud import WordCloud
# Create a WordCloud for the message content
text = ' '.join(df['Message'].astype(str))
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.title('Word Cloud of Email Messages')
plt.show()
top_senders = df['From'].value_counts().head(10)
top_recipients = df['To'].value_counts().head(10)
print("Top Senders:\n", top_senders)
print("\nTop Recipients:\n", top_recipients)
OUT PUT:
Result:
The above Performing exploratory data analysis (EDA) on with datasets like email data set has been
performed successfully.
Ex no: 03
Date: Working with Numpy arrays, Pandas data frames , Basic plots using Matplotlib
Aim:
Write the steps for Working with Numpy arrays, Pandas data frames , Basic plots using Matplotlib
Procedure:
1. NumPy:
NumPy is a fundamental library for numerical computing in Python. It provides support for multi-
dimensional arrays and various mathematical functions. To get started, you'll first need to install NumPy if
you haven't already (you can use pip):
2. Pandas:
df = pd.DataFrame(data)
# Display the entire DataFrame
print("DataFrame:")
print(df)
# Accessing specific columns
print("\nAccessing 'Name' column:")
print(df['Name'])
# Adding a new column
df['Salary'] = [50000, 60000, 75000, 48000, 55000]
# Filtering data
print("\nPeople older than 30:")
print(df[df['Age'] > 30])
# Sorting by a column
print("\nSorting by 'Age' in descending order:")
print(df.sort_values(by='Age', ascending=False))
# Aggregating data
print("\nAverage age:")
print(df['Age'].mean())
# Grouping and aggregation
grouped_data = df.groupby('City')['Salary'].mean()
print("\nAverage salary by city:")
print(grouped_data)
# Applying a function to a column
df['Age_Squared'] = df['Age'].apply(lambda x: x ** 2)
# Removing a column
df = df.drop(columns=['Age_Squared'])
# Saving the DataFrame to a CSV file
df.to_csv('output.csv', index=False)
# Reading a CSV file into a DataFrame
new_df = pd.read_csv('output.csv')
print("\nDataFrame from CSV file:")
print(new_df)
OUTPUT:
3. Matplotlib:
Matplotlib is a popular library for creating static, animated, or interactive plots and graphs.
Install Matplotlib using pip:
pip install matplotlib
Here's a simple example of creating a basic plot:
import matplotlib.pyplot as plt
# Sample data
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Create a line plot
plt.figure(figsize=(8, 6))
plt.plot(x, y, label='Sine Wave')
plt.title('Sine Wave Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.grid(True)
plt.show()
OUTPUT:
RESULT:
Thus the above working with numpy, pandas, matplotlib has been completed successfully.
Ex no:4
Date: Exploring various variable and row filters in R for cleaning data
Aim:
Exploring various variable and row filters in R for cleaning data.
PROCEDURE:
Data Preparation and Cleaning
First, let's create a sample dataset and then explore various variable and row filters to clean the data
Variable Filters
1. Filtering by a Specific Value:
To filter rows based on a specific value in a variable (e.g., only show rows where Age is greater than
30):
filtered_data <- data[data$Age > 30, ]
You can filter rows based on multiple conditions using the & (AND) or | (OR) operators (e.g., show
rows where Age is greater than 30 and Gender is "Male"):
filtered_data <- data[data$Age > 30 & data$Gender == "Male", ]
Row Filters
1. Removing Duplicate Rows:
To remove duplicate rows based on certain columns (e.g., remove duplicates based on 'ID'):
cleaned_data <- unique(data[, c("ID", "Age", "Gender")])
2. Removing Rows with Missing Values:
To remove rows with missing values (NA):
cleaned_data <- na.omit(data)
Data Visualization
1. Apply various plot features using the ggplot2 package to visualize the cleaned data.
# Load the ggplot2 package
library(ggplot2)
# Create a scatterplot of Age vs. Score with points colored by Gender
ggplot(data = cleaned_data, aes(x = Age, y = Score, color = Gender)) +
geom_point() +
labs(title = "Scatterplot of Age vs. Score",
x = "Age",
y = "Score")
# Create a histogram of Age
ggplot(data = cleaned_data, aes(x = Age)) +
geom_histogram(binwidth = 5, fill = "blue", alpha = 0.5) +
labs(title = "Histogram of Age",
x = "Age",
y = "Frequency")
# Create a bar chart of Gender distribution
ggplot(data = cleaned_data, aes(x = Gender)) +
geom_bar(fill = "green", alpha = 0.7) +
labs(title = "Gender Distribution",
x = "Gender",
y = "Count")
RESULT:
Thus the above Exploring various variable and row filters in R for cleaning data.
OUTPUT:
RESULT:
Thus the above program to to Perform EDA on Wine Quality Data Set.
EX NO:6
DATE: TIME SERIES ANALYSIS USING VARIOUS VISULAIZATION
TECHNIQUES
AIM:
To perform time series analysis and apply the various visualization techniques.
DOWNLOADING DATASET:
Step 1: Open google and type the following path in the address bar and download a dataset.
http://github.com/jbrownlee/Datasets.
Step 2: write the following code to get the details.
from pandas import read_csv
from matplotlib import pyplot
series=read_csv(‘pathname')
print(series.head())
series.plot()
pyplot.show()
OUTPUT:
Step 4:
To create a Histogram:
series.hist()
pyplot.show()
Step 5:
To create density plot:
series.plot(kind='kde')
pyplot.show()
Result:
Thus the above time analysis has been checked with Various visualization techniques.