Repository navigation
Expand file tree
/
Copy pathsalesDataAnalyzer.py
More file actions
89 lines (62 loc) · 2.82 KB
/
Copy pathsalesDataAnalyzer.py
File metadata and controls
89 lines (62 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
df = pd.read_csv('enfield_bikes_5yrs_data.csv')
#print(df)
#PHASE 2: DATA EXPLORATION or UNDERSTANDING
#print(df.shape)#prints the shape of the data frame, which is the number of rows and columns
#print(df.columns)#prints the column names of the data frame
#print(df.info())#prints the information about the data frame, including the number of non-null values and the data types of each column
#print(df.describe())#prints the statistical summary of the data frame, including the count, mean, standard deviation, minimum, and maximum values for each column
#print(df.isnull().sum())#prints the number of null values in each column of the data frame
#PHASE 3: DATA CLEANING
#Convert Date
df['Purchase_Date'] = pd.to_datetime(df['Purchase_Date'])#converts the purchase date column to a datetime object
#print(df['Purchase_Date'])
df['Year']=df['Purchase_Date'].dt.year
#print(df['Year'])
#Remove duplicates
df = df.drop_duplicates()#removes duplicate rows from the data frame
#Validate data
#print(df['Model'].unique())#prints the unique values in the model column
#print(df['State'].unique())#prints the unique values in the state column
#PHASE 4: DATA ANALYSIS
#1. Total sales by year
yearly_sales = (df.groupby('Year')['Price_INR'].sum())#groups the data by year and sums the price column to get the total sales for each year
#print(f'Number of sales by year: {yearly_sales}')
#2. Total sales by model
model_sales = df['Model'].value_counts()#No of sales per model
#print(f'Number of sales by Model: {model_sales}')
#3. State wise sales
#sales_by_state = df['State'].value_counts()#no of vechicles sold by state
sales_by_state = df.groupby('State')['Price_INR'].sum().sort_values(ascending=False)#no of revenue generated by state
#print(f'Sales by State: {sales_by_state}')
#4. Customer Insights by Age
age_model = df.groupby('Model')['Buyer_Age'].mean()
#print(f'Age of the buyer: {age_model}')
#5. Loan vs cash
payments = df['Purchase_Type'].value_counts()
#print(f'Modes of payment: {payments}')
#6. Depreciation
df['Depreciation'] = df['Price_INR']- df['Resale_Value'] #depreciation = initial_price - resale_value
#print(df[['Model','Depreciation']].head()) #head function first five row of the table
#print(df[['Customer_ID','State','Model','Resale_Value']].max())
#print(df.to_string())
#PHASE 5: DATA VISUALIZATION(MATPLOTLIB)
#SALES TREND
'''
yearly_sales.plot(kind='line')#plots the yearly sales as a line graph
plt.title('Yearly Sales Revenue')
plt.xlabel('Year')
plt.ylabel('Revenue')
'''
#plt.show()#displays the plot
#MODEL POPULARITY
model_sales.plot(kind='pie', autopct='%1.1f%%')#plots the model sales as a pie chart with percentage labels
plt.title('Model Popularity')
#STATE WISE SALES
'''
sales_by_state.plot(kind='barh')
plt.title('State wise sales')
'''
plt.show()