0% found this document useful (0 votes)
3 views2 pages

Practical8 Py

The document outlines a Python program designed to analyze a sales dataset from a CSV file. It includes steps to read the data, display basic information, and generate various visualizations to analyze sales trends over time and by category. The program utilizes libraries such as pandas for data manipulation and matplotlib for creating visualizations.

Uploaded by

vvllb87
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)
3 views2 pages

Practical8 Py

The document outlines a Python program designed to analyze a sales dataset from a CSV file. It includes steps to read the data, display basic information, and generate various visualizations to analyze sales trends over time and by category. The program utilizes libraries such as pandas for data manipulation and matplotlib for creating visualizations.

Uploaded by

vvllb87
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

EXPERIMENT 8

Aim: You are given a dataset


(Create a program that uses regular expressions to find all instances of a specific
pattern in a text file.
sales-dataset)
containing monthly sales data of different product
categories for a company.
Write a Python program that:
1. Reads data from this CSV file.
2. Displays basic information about the dataset.
3. Generates appropriate visualizations to analyze
sales trends.

Program Code:
import pandas as pd
import [Link] as plt

# 1. Read data from CSV file


file_path = "retail_sales_dataset.csv" # change path if needed
df = pd.read_csv(file_path)

# 2. Display basic information


print("----- Dataset Head -----")
print([Link]())

print("\n----- Dataset Info -----")


print([Link]())

print("\n----- Statistical Summary -----")


print([Link]())

print("\n----- Missing Values -----")


print([Link]().sum())

# 3. Data Preprocessing (if needed)


# Convert Date column to datetime (if exists)
if 'Date' in [Link]:
df['Date'] = pd.to_datetime(df['Date'])
# 4. Visualization 1: Sales Trend Over Time
if 'Date' in [Link] and 'Sales' in [Link]:
[Link]()
[Link]('Date')['Sales'].sum().plot()
[Link]("Total Sales Over Time")
[Link]("Date")
[Link]("Sales")
[Link](rotation=45)
[Link]()

# 5. Visualization 2: Sales by Category


if 'Category' in [Link] and 'Sales' in [Link]:
[Link]()
[Link]('Category')['Sales'].sum().plot(kind='bar')
[Link]("Sales by Category")
[Link]("Category")
[Link]("Total Sales")
[Link](rotation=45)
[Link]()

# 6. Visualization 3: Monthly Sales Trend


if 'Date' in [Link] and 'Sales' in [Link]:
df['Month'] = df['Date'].dt.to_period('M')

[Link]()
[Link]('Month')['Sales'].sum().plot()
[Link]("Monthly Sales Trend")
[Link]("Month")
[Link]("Sales")
[Link](rotation=45)
[Link]()

# 7. Visualization 4: Pie Chart (Category Distribution)


if 'Category' in [Link] and 'Sales' in [Link]:
[Link]()
[Link]('Category')['Sales'].sum().plot(kind='pie', autopct='%1.1f%%')
[Link]("Sales Distribution by Category")
[Link]("")
[Link]()

You might also like