-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPython_Sales_Data_Analysis.py
More file actions
268 lines (115 loc) · 3.59 KB
/
Python_Sales_Data_Analysis.py
File metadata and controls
268 lines (115 loc) · 3.59 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/usr/bin/env python
# coding: utf-8
# # Sales Analysis
# ### Import required libraries
# In[6]:
import numpy as np
import matplotlib.pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')
import seaborn as sns
# ### Read data set
# In[4]:
import pandas as pd
df=pd.read_csv(r'C:\Users\SPECTRE\Desktop\DataAnalysis_DataSets\Sales_Analysis\Sales_Data.csv' , header= 0,
encoding= 'unicode_escape')
# In[5]:
df
# In[7]:
df.shape
# In[8]:
df.head()
# In[9]:
df.info()
# In[11]:
df.drop(['Status','unnamed1'], axis=1, inplace=True)
#drop blank columns
# In[12]:
df.info()
# In[13]:
pd.isnull(df)
# In[14]:
pd.isnull(df).sum() # check for null values
# In[15]:
df.shape
# In[16]:
#drop null values
df.dropna(inplace=True)
# In[17]:
pd.isnull(df).sum()
# In[21]:
df['Amount']=df['Amount'].astype('int')
# In[22]:
df['Amount'].dtypes
# In[23]:
df.columns
# In[24]:
#rename columns
df.rename(columns={'Marital_Status':'Married'})
# In[25]:
#statistics
df.describe()
# In[26]:
df[['Age','Orders','Amount']].describe()
# ## Explorartory Data Analysis
# ### Gender
# In[27]:
df.columns
# In[29]:
ax = sns.countplot(x='Gender',data=df)
for bars in ax.containers:
ax.bar_label(bars)
# In[31]:
sales_gen = df.groupby(['Gender'], as_index=False)['Amount'].sum().sort_values(by='Amount',ascending=False)
sales_gen
# In[32]:
sns.barplot(x='Gender' , y='Amount' ,data=sales_gen)
# ### Age
# In[33]:
ax=sns.countplot(data = df, x='Age Group', hue='Gender')
for bars in ax.containers:
ax.bar_label(bars)
# ### State
# In[35]:
# total number of orders from top 10 states
sales_state = df.groupby(['State'], as_index=False)['Orders'].sum().sort_values(by='Orders',ascending=False).head(10)
sns.set(rc={'figure.figsize':(15,5)})
sns.barplot(data=sales_state, x='State', y='Orders')
# In[36]:
# total amount/sales from top 10 states
sales_state = df.groupby(['State'], as_index=False)['Amount'].sum().sort_values(by='Amount',ascending=False).head(10)
sns.set(rc={'figure.figsize':(15,5)}) #height width
sns.barplot(data=sales_state, x='State', y='Amount')
# ### Marital Status:
# In[42]:
ax= sns.countplot(data=df, x='Marital_Status')
sns.set(rc={'figure.figsize':(7,5)})
for bars in ax.containers:
ax.bar_label(bars)
# In[44]:
sales_state = df.groupby(['Marital_Status','Gender'], as_index=False)['Amount'].sum().sort_values(by='Amount',ascending=False).head(10)
sns.set(rc={'figure.figsize':(6,5)})
sns.barplot(data=sales_state, x='Marital_Status', y='Amount',hue='Gender')
# ### Occupation
# In[52]:
ax= sns.countplot(data=df, x='Occupation')
sns.set(rc={'figure.figsize':(30,5)})
for bars in ax.containers:
ax.bar_label(bars)
# In[47]:
sales_state = df.groupby(['Occupation'], as_index=False)['Amount'].sum().sort_values(by='Amount',ascending=False).head(10)
sns.set(rc={'figure.figsize':(20,5)})
sns.barplot(data=sales_state, x='Occupation', y='Amount')
# ### Product Category
# In[51]:
ax= sns.countplot(data=df, x='Product_Category')
sns.set(rc={'figure.figsize':(30,5)})
for bars in ax.containers:
ax.bar_label(bars)
# In[49]:
sales_state = df.groupby(['Product_Category'], as_index=False)['Amount'].sum().sort_values(by='Amount',ascending=False).head(10)
sns.set(rc={'figure.figsize':(20,5)})
sns.barplot(data=sales_state, x='Product_Category', y='Amount')
# ## Insights:
# #### Married women in the age group 26-35 yrs from UP, Maharashtra and Karnataka working in IT, Healthcare and aviation are more likely to buy products from food, clothing and electronics category.
#
# In[ ]: