Skip to content

Commit 73f111e

Browse files
authored
Add files via upload
1 parent c77b302 commit 73f111e

File tree

1 file changed

+276
-0
lines changed

1 file changed

+276
-0
lines changed
Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"id": "e537072d",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import pandas as pd\n",
11+
"import numpy as np"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 5,
17+
"id": "31af5d6d",
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"# step no 1 create a sales data\n",
22+
"data = {\n",
23+
" \"order_id\":[1,2,3,4,5,6,7,8],\n",
24+
" \"customer\":['john','joy','rahul','rohan','riya','tiya','heena','nishant'],\n",
25+
" \"product\":['laptop','phone','mouse','tablet','phone','tablet','laptop','laptop'],\n",
26+
" \"quantity\":[4,5,2,1,2,1,1,3],\n",
27+
" \"price\": [1000,300,4500,500,760,980,780,7000],\n",
28+
" \"date\":['2023-01-03','2023-01-04','2023-01-01','2023-01-04','2023-01-05','2023-01-8','2023-01-23','2023-01-12'] \n",
29+
"}"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 8,
35+
"id": "03332933",
36+
"metadata": {},
37+
"outputs": [],
38+
"source": [
39+
"# step no 2 create a dataframe\n",
40+
"df = pd.DataFrame(data)"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": 9,
46+
"id": "8f1ce269",
47+
"metadata": {},
48+
"outputs": [
49+
{
50+
"name": "stdout",
51+
"output_type": "stream",
52+
"text": [
53+
" order_id customer product quantity price date\n",
54+
"0 1 john laptop 4 1000 2023-01-03\n",
55+
"1 2 joy phone 5 300 2023-01-04\n",
56+
"2 3 rahul mouse 2 4500 2023-01-01\n",
57+
"3 4 rohan tablet 1 500 2023-01-04\n",
58+
"4 5 riya phone 2 760 2023-01-05\n"
59+
]
60+
}
61+
],
62+
"source": [
63+
"# step no 3 print first 5 row\n",
64+
"print(df.head())"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": 11,
70+
"id": "a3c4e939",
71+
"metadata": {},
72+
"outputs": [
73+
{
74+
"name": "stdout",
75+
"output_type": "stream",
76+
"text": [
77+
" order_id quantity price\n",
78+
"count 8.00000 8.000000 8.000000\n",
79+
"mean 4.50000 2.375000 1977.500000\n",
80+
"std 2.44949 1.505941 2433.467544\n",
81+
"min 1.00000 1.000000 300.000000\n",
82+
"25% 2.75000 1.000000 695.000000\n",
83+
"50% 4.50000 2.000000 880.000000\n",
84+
"75% 6.25000 3.250000 1875.000000\n",
85+
"max 8.00000 5.000000 7000.000000\n"
86+
]
87+
}
88+
],
89+
"source": [
90+
"# step no 4 data cleaning\n",
91+
"print(df.describe())"
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": 13,
97+
"id": "c55d74ee",
98+
"metadata": {},
99+
"outputs": [
100+
{
101+
"name": "stdout",
102+
"output_type": "stream",
103+
"text": [
104+
"order_id int64\n",
105+
"customer object\n",
106+
"product object\n",
107+
"quantity int64\n",
108+
"price int64\n",
109+
"date object\n",
110+
"dtype: object\n"
111+
]
112+
}
113+
],
114+
"source": [
115+
"print(df.dtypes)"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": 16,
121+
"id": "8fb82fa7",
122+
"metadata": {},
123+
"outputs": [
124+
{
125+
"name": "stdout",
126+
"output_type": "stream",
127+
"text": [
128+
"order_id int64\n",
129+
"customer object\n",
130+
"product object\n",
131+
"quantity int64\n",
132+
"price int64\n",
133+
"date datetime64[ns]\n",
134+
"dtype: object\n"
135+
]
136+
}
137+
],
138+
"source": [
139+
"# convert date column to datetime\n",
140+
"# print(df['date'])\n",
141+
"\n",
142+
"df['date'] = pd.to_datetime(df['date'])\n",
143+
"print(df.dtypes)"
144+
]
145+
},
146+
{
147+
"cell_type": "code",
148+
"execution_count": 18,
149+
"id": "d7cef0c7",
150+
"metadata": {},
151+
"outputs": [
152+
{
153+
"name": "stdout",
154+
"output_type": "stream",
155+
"text": [
156+
"order_id 0\n",
157+
"customer 0\n",
158+
"product 0\n",
159+
"quantity 0\n",
160+
"price 0\n",
161+
"date 0\n",
162+
"dtype: int64\n"
163+
]
164+
}
165+
],
166+
"source": [
167+
"# check for missing values\n",
168+
"print(df.isnull().sum())"
169+
]
170+
},
171+
{
172+
"cell_type": "code",
173+
"execution_count": 22,
174+
"id": "663ad189",
175+
"metadata": {},
176+
"outputs": [
177+
{
178+
"name": "stdout",
179+
"output_type": "stream",
180+
"text": [
181+
" order_id customer product quantity price date total_revenue\n",
182+
"0 1 john laptop 4 1000 2023-01-03 4000\n",
183+
"1 2 joy phone 5 300 2023-01-04 1500\n",
184+
"2 3 rahul mouse 2 4500 2023-01-01 9000\n",
185+
"3 4 rohan tablet 1 500 2023-01-04 500\n",
186+
"4 5 riya phone 2 760 2023-01-05 1520\n"
187+
]
188+
}
189+
],
190+
"source": [
191+
"# step no. 5 Basic data analysis\n",
192+
"# calculate total revenue per order\n",
193+
"\n",
194+
"df['total_revenue'] = df['quantity'] * df['price']\n",
195+
"print(df.head())\n",
196+
"\n"
197+
]
198+
},
199+
{
200+
"cell_type": "code",
201+
"execution_count": 27,
202+
"id": "5a897f16",
203+
"metadata": {},
204+
"outputs": [
205+
{
206+
"name": "stdout",
207+
"output_type": "stream",
208+
"text": [
209+
" customer total_revenue\n",
210+
"0 heena 780\n",
211+
"1 john 4000\n",
212+
"2 joy 1500\n",
213+
"3 nishant 21000\n",
214+
"4 rahul 9000\n",
215+
"5 riya 1520\n",
216+
"6 rohan 500\n",
217+
"7 tiya 980\n"
218+
]
219+
}
220+
],
221+
"source": [
222+
"#step no. 6 total revenue by customer (grouping and aggregation)\n",
223+
"customer_revenue = df.groupby('customer')['total_revenue'].sum().reset_index()\n",
224+
"print(customer_revenue)"
225+
]
226+
},
227+
{
228+
"cell_type": "code",
229+
"execution_count": 28,
230+
"id": "1d97a64d",
231+
"metadata": {},
232+
"outputs": [
233+
{
234+
"name": "stdout",
235+
"output_type": "stream",
236+
"text": [
237+
"\n",
238+
" product sales = \n",
239+
" product quantity\n",
240+
"0 laptop 8\n",
241+
"1 mouse 2\n",
242+
"2 phone 7\n",
243+
"3 tablet 2\n"
244+
]
245+
}
246+
],
247+
"source": [
248+
"# step no. 7 Product analysis\n",
249+
"# most popular product by quantity sold \n",
250+
"product_sales = df.groupby('product')['quantity'].sum().reset_index()\n",
251+
"print('\\n product sales = \\n ',product_sales)"
252+
]
253+
}
254+
],
255+
"metadata": {
256+
"kernelspec": {
257+
"display_name": "Python 3",
258+
"language": "python",
259+
"name": "python3"
260+
},
261+
"language_info": {
262+
"codemirror_mode": {
263+
"name": "ipython",
264+
"version": 3
265+
},
266+
"file_extension": ".py",
267+
"mimetype": "text/x-python",
268+
"name": "python",
269+
"nbconvert_exporter": "python",
270+
"pygments_lexer": "ipython3",
271+
"version": "3.11.4"
272+
}
273+
},
274+
"nbformat": 4,
275+
"nbformat_minor": 5
276+
}

0 commit comments

Comments
 (0)