0% found this document useful (0 votes)
9 views4 pages

Practical Journal

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Practical Journal

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical Journal

Name: Aishwarya Sonawane

Roll No: 17

Practical No. 1: Data Visualization Using Series

# Import necessary libraries


import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# Create a sample Pandas Series


data = pd.Series([150, 200, 180, 220, 260, 300, 280, 330, 350, 400], index=range(2015,
2025))

# Line plot
plt.figure(figsize=(8, 6))
data.plot()
plt.title('Yearly Sales Data')
plt.xlabel('Year')
plt.ylabel('Sales (in units)')
plt.show()

# Bar chart
plt.figure(figsize=(8, 6))
data.plot(kind='bar')
plt.title('Yearly Sales Data')
plt.xlabel('Year')
plt.ylabel('Sales (in units)')
plt.show()

# Histogram
plt.figure(figsize=(8, 6))
data.plot.hist(bins=5, edgecolor='black')
plt.title('Sales Distribution')
plt.xlabel('Sales (in units)')
plt.ylabel('Frequency')
plt.show()

# Pie chart (top 5 values)


plt.figure(figsize=(8, 6))
data.nlargest(5).plot(kind='pie', autopct='%1.1f%%')
plt.title('Top 5 Yearly Sales')
plt.show()

Output:

1. Line plot showing yearly sales trends from 2015 to 2024.


2. Bar chart representing sales per year.
3. Histogram illustrating the frequency of sales within specified ranges.
4. Pie chart showing the contribution of the top 5 years to total sales.

Practical No. 2: Data Visualization Using DataFrames

# Import necessary libraries


import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# Create a sample DataFrame


data = {'City': ['Mumbai', 'Delhi', 'Bangalore', 'Hyderabad', 'Chennai'],
'Population': [20.4, 18.9, 12.7, 10.5, 8.2],
'Year': [2021, 2021, 2021, 2021, 2021]}
df = pd.DataFrame(data)

# Bar chart of city population


plt.figure(figsize=(8, 6))
sns.barplot(x='City', y='Population', data=df)
plt.title('City Population (2021)')
plt.xlabel('City')
plt.ylabel('Population (in millions)')
plt.show()

# Line plot of city population


plt.figure(figsize=(8, 6))
plt.plot(df['City'], df['Population'], marker='o')
plt.title('City Population (2021)')
plt.xlabel('City')
plt.ylabel('Population (in millions)')
plt.show()

# Pie chart of city population


plt.figure(figsize=(8, 6))
plt.pie(df['Population'], labels=df['City'], autopct='%1.1f%%')
plt.title('Population Distribution by City')
plt.show()

# Scatter plot of city population vs year


plt.figure(figsize=(8, 6))
plt.scatter(df['Year'], df['Population'])
plt.title('City Population in 2021')
plt.xlabel('Year')
plt.ylabel('Population (in millions)')
plt.show()

Output:

1. Bar chart displaying the population of major Indian cities in 2021.


2. Line plot depicting city-wise population trends.
3. Pie chart representing the proportion of population by city.
4. Scatter plot showing city population for the year 2021.

Practical No. 3: Data Visualization Using Matplotlib

# Import necessary libraries


import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
import pandas as pd
import numpy as np

# Load Iris dataset


iris = load_iris()
df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
df['target'] = iris.target

# Scatter plot of sepal length vs width


plt.figure(figsize=(8, 6))
plt.scatter(df['sepal length (cm)'], df['sepal width (cm)'], c=df['target'], cmap='viridis')
plt.xlabel('Sepal Length (cm)')
plt.ylabel('Sepal Width (cm)')
plt.title('Iris Dataset - Sepal Dimensions')
plt.show()

# Histogram of sepal length


plt.figure(figsize=(8, 6))
plt.hist(df['sepal length (cm)'], bins=10, edgecolor='black')
plt.xlabel('Sepal Length (cm)')
plt.ylabel('Count')
plt.title('Iris Dataset - Sepal Length Distribution')
plt.show()

# Bar chart of class distribution


plt.figure(figsize=(8, 6))
plt.bar(np.unique(df['target']), [len(df[df['target'] == i]) for i in np.unique(df['target'])])
plt.xlabel('Class')
plt.ylabel('Count')
plt.title('Iris Dataset - Class Distribution')
plt.show()

# Boxplot of petal length


plt.figure(figsize=(8, 6))
plt.boxplot(df['petal length (cm)'], vert=False)
plt.xlabel('Petal Length (cm)')
plt.title('Iris Dataset - Petal Length Boxplot')
plt.show()

# Violin plot of sepal width


plt.figure(figsize=(8, 6))
plt.violinplot(df['sepal width (cm)'], showmeans=True)
plt.xlabel('Sepal Width (cm)')
plt.title('Iris Dataset - Sepal Width Violin Plot')
plt.show()

Output:

1. Scatter plot illustrating sepal dimensions grouped by class.


2. Histogram showing distribution of sepal lengths.
3. Bar chart displaying the count of samples per Iris class.
4. Boxplot representing the spread of petal lengths.
5. Violin plot visualizing the distribution of sepal widths.

You might also like