0% found this document useful (0 votes)
7 views3 pages

Python Sales Data Analysis Guide

The document outlines a Python programming assignment focused on data analysis using Pandas and NumPy. It includes functions for loading data, analyzing sales, generating reports, and implementing object-oriented programming concepts. The assignment emphasizes data manipulation and statistical calculations based on sales records.

Uploaded by

santosh
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)
7 views3 pages

Python Sales Data Analysis Guide

The document outlines a Python programming assignment focused on data analysis using Pandas and NumPy. It includes functions for loading data, analyzing sales, generating reports, and implementing object-oriented programming concepts. The assignment emphasizes data manipulation and statistical calculations based on sales records.

Uploaded by

santosh
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

NAME:SANTOSH SINGH

SAP ID:500126930
PYTHON PROGRAMMING
ASSIGNMENT NO-2
import pandas as pd
import numpy as np

# Step 1: Python Fundamentals and Language


Philosophy def load_data(file_path):
return pd.read_csv(file_path)

def analyze_data(data):
sales_amounts =
[Link](data['amount']) return {
'mean': [Link](sales_amounts),
'total': [Link](sales_amounts)
}

def generate_report(analysis):
report = f"Total Sales: {analysis['total']}\nMean
Sales:
{analysis['mean']}"
return report

# Step 2: Python Data Structures and Operations


sales_records = [
{'item': 'B',
{'item': 'A','amount':
'amount': 100,
150, 'date':'2024-01-
'date': '2024-01-01'},
02'},
{'item': 'C', 'amount': 200, 'date': '2024-01-
03'},
{'item': 'D', 'amount': 250, 'date': '2024-01-
04'},
{'item': 'E', 'amount': 300, 'date': '2024-01-
item_details = { 05'}
] 'A': {'name': 'Item A', 'price':
10},
'B': {'name': 'Item B', 'price':
15},
'C': {'name': 'Item C', 'price':
20},
'D': {'name': 'Item D', 'price':
25},
'E': {'name': 'Item E', 'price':
def filter_sales(sales, threshold):
return [sale for sale in sales if sale['amount'] > threshold]

def calculate_statistics(sales):
total_sales = sum(sale['amount'] for sale in
sales) mean_sales = total_sales / len(sales)
return {'total': total_sales, 'mean': mean_sales}

# Step 4: Object-Oriented Programming


Concepts class SalesData:
def init (self, data):
[Link] = data

def load_data(self, file_path):


[Link] =
pd.read_csv(file_path)

def analyze_data(self):
sales_amounts = [Link]([Link]['amount'])
return {
'mean': [Link](sales_amounts),
'total': [Link](sales_amounts)
}

class Report:
def init (self, sales_data):
self.sales_data = sales_data

def generate_report(self):
analysis = self.sales_data.analyze_data()
report = f"Total Sales: {analysis['total']}\nMean Sales:
{analysis['mean']}"
return report

# Step 5: Data Manipulation with NumPy and


Pandas # Example usage
file_path = 'sales_data.csv' # Replace with your actual file path
sales_data = SalesData(load_data(file_path))
report = Report(sales_data)
print(report.generate_report())

Explanation:
1. Loading Data: The load_data function reads sales data from a CSV
file using Pan das.
2. Analyzing Data: The analyze_data function calculates the mean
and total sales using NumPy.
3. Generating Reports: The generate_report function creates a
summary report ba sed on the analysis.
4. Data Structures: Lists and dictionaries are used to store sales
records and item details.
5. Control Flow: Functions are implemented to filter sales and calculate
statistics.
6. OOP Concepts: Classes SalesData and Report are created to
manage data and operations.
7. Data Manipulation: NumPy and Pandas are used for numerical
operations and d ata manipulation.

You might also like