-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinalreport.tex
More file actions
423 lines (364 loc) · 16.7 KB
/
finalreport.tex
File metadata and controls
423 lines (364 loc) · 16.7 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\usepackage[margin=1in]{geometry}
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\ifLuaTeX
\usepackage{selnolig} % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
pdftitle={Chipotle Case Study},
pdfauthor={Shu Liu},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\title{Chipotle Case Study}
\author{Shu Liu}
\date{2023-06-02}
\begin{document}
\maketitle
\hypertarget{chiptole-sales}{%
\subsection{Chiptole Sales}\label{chiptole-sales}}
This is Data in Motion data analysis challenge \#1 More details click
here
\href{https://d-i-motion.com/lessons/challenge-1-chipotle-sales/}{link}
\hypertarget{scenario}{%
\subsubsection{Scenario}\label{scenario}}
You are a financial data analyst at Chipotle and your manager has tasked
you with analyzing the most recent sales numbers. She has provided the
following set of questions she would like answered.
\hypertarget{get-the-data}{%
\subsubsection{Get the data}\label{get-the-data}}
Link to dataset: Link to
\href{https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv}{dataset}
\hypertarget{challenge-questions}{%
\subsubsection{Challenge Questions}\label{challenge-questions}}
\begin{quote}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
Which was the most-ordered item?
\item
For the most-ordered item, how many items were ordered?
\item
What was the most ordered item in the choice\_description column?
\item
How many items were ordered in total?
\item
Turn the item price into a float
\item
How much was the revenue for the period in the dataset?
\item
How many orders were made in the period?
\item
What is the average revenue amount per order?
\item
How many different items are sold?
\end{enumerate}
\end{quote}
\hypertarget{steps}{%
\subsection{Steps}\label{steps}}
\hypertarget{set-up-environments}{%
\subsubsection{Set up environments}\label{set-up-environments}}
Notes: install package ``tidyverse''
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{install.packages}\NormalTok{(}\StringTok{"tidyverse"}\NormalTok{, }\AttributeTok{repos =} \StringTok{"http://cran.us.r{-}project.org"}\NormalTok{) }\CommentTok{\#an argument is added to the function that gives it the web address of the repository. Once the data file is downloaded into the proper directory you will then be able to access your newly installed package.}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Installing package into 'C:/Users/liuch/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
\end{verbatim}
\begin{verbatim}
## package 'tidyverse' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\liuch\AppData\Local\Temp\RtmpYBrEy0\downloaded_packages
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(tidyverse)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## -- Attaching core tidyverse packages ------------------------ tidyverse 2.0.0 --
## v dplyr 1.1.2 v readr 2.1.4
## v forcats 1.0.0 v stringr 1.5.0
## v ggplot2 3.4.2 v tibble 3.2.1
## v lubridate 1.9.2 v tidyr 1.3.0
## v purrr 1.0.1
\end{verbatim}
\begin{verbatim}
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## i Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(ggplot2)}
\FunctionTok{library}\NormalTok{(dplyr) }\CommentTok{\#for sorting}
\end{Highlighting}
\end{Shaded}
\hypertarget{load-data}{%
\subsubsection{Load data}\label{load-data}}
Save the dataset into local file directory. change working directory to
where the file is. load the data into dataframe chipotle\_sales.
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{setwd}\NormalTok{(}\StringTok{"C:/Users/liuch/OneDrive/文档/DataAnalytics/Portfolio/case\_study\_1"}\NormalTok{)}
\NormalTok{chipotle\_sales }\OtherTok{\textless{}{-}} \FunctionTok{read\_tsv}\NormalTok{(}\StringTok{"chipotle.tsv"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Rows: 4622 Columns: 5
## -- Column specification --------------------------------------------------------
## Delimiter: "\t"
## chr (3): item_name, choice_description, item_price
## dbl (2): order_id, quantity
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
\end{verbatim}
Now the chiptole\_sales has the data. Let's take a glimpse.
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{glimpse}\NormalTok{(chipotle\_sales)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Rows: 4,622
## Columns: 5
## $ order_id <dbl> 1, 1, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, ~
## $ quantity <dbl> 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ~
## $ item_name <chr> "Chips and Fresh Tomato Salsa", "Izze", "Nantucket ~
## $ choice_description <chr> "NULL", "[Clementine]", "[Apple]", "NULL", "[Tomati~
## $ item_price <chr> "$2.39", "$3.39", "$3.39", "$2.39", "$16.98", "$10.~
\end{verbatim}
\hypertarget{analyze-data-and-answer-questions}{%
\subsubsection{Analyze data and answer
questions}\label{analyze-data-and-answer-questions}}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
Which was the most-ordered item? 2. For the most-ordered item, how
many items were ordered?
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{chipotle\_sales\_sum }\OtherTok{\textless{}{-}}\NormalTok{ chipotle\_sales }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(item\_name) }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarise}\NormalTok{(}\AttributeTok{ordered\_num=}\FunctionTok{sum}\NormalTok{(quantity)) }\CommentTok{\#created a new dataframe for each item and its ordered sum. }
\NormalTok{chipotle\_sales\_sum }\SpecialCharTok{\%\textgreater{}\%} \FunctionTok{arrange}\NormalTok{(}\FunctionTok{desc}\NormalTok{(ordered\_num)) }\CommentTok{\#use arrange() and desc() to sort desc. }
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## # A tibble: 50 x 2
## item_name ordered_num
## <chr> <dbl>
## 1 Chicken Bowl 761
## 2 Chicken Burrito 591
## 3 Chips and Guacamole 506
## 4 Steak Burrito 386
## 5 Canned Soft Drink 351
## 6 Chips 230
## 7 Steak Bowl 221
## 8 Bottled Water 211
## 9 Chips and Fresh Tomato Salsa 130
## 10 Canned Soda 126
## # i 40 more rows
\end{verbatim}
\textbf{Chicken Bowl} was the most-ordered item. \textbf{761} were
ordered.
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{2}
\tightlist
\item
What was the most ordered item in the choice\_description column?
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{chipotle\_sales\_choice }\OtherTok{\textless{}{-}}\NormalTok{ chipotle\_sales }\SpecialCharTok{\%\textgreater{}\%} \FunctionTok{group\_by}\NormalTok{(choice\_description) }\SpecialCharTok{\%\textgreater{}\%} \FunctionTok{summarise}\NormalTok{(}\AttributeTok{ordered\_num=}\FunctionTok{sum}\NormalTok{(quantity))}\CommentTok{\# create a new dataframe chipotle\_sales\_choice for calculating total ordered number for each different choice.}
\NormalTok{chipotle\_sales\_choice }\SpecialCharTok{\%\textgreater{}\%} \FunctionTok{filter}\NormalTok{(choice\_description}\SpecialCharTok{!=}\StringTok{"NULL"}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%} \FunctionTok{arrange}\NormalTok{(}\FunctionTok{desc}\NormalTok{(ordered\_num))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## # A tibble: 1,043 x 2
## choice_description ordered_num
## <chr> <dbl>
## 1 [Diet Coke] 159
## 2 [Coke] 143
## 3 [Sprite] 89
## 4 [Fresh Tomato Salsa, [Rice, Black Beans, Cheese, Sour Cream, Let~ 49
## 5 [Fresh Tomato Salsa, [Rice, Black Beans, Cheese, Sour Cream]] 42
## 6 [Fresh Tomato Salsa, [Rice, Black Beans, Cheese, Sour Cream, Gua~ 40
## 7 [Fresh Tomato Salsa (Mild), [Pinto Beans, Rice, Cheese, Sour Cre~ 36
## 8 [Lemonade] 36
## 9 [Coca Cola] 32
## 10 [Fresh Tomato Salsa, [Rice, Black Beans, Cheese]] 30
## # i 1,033 more rows
\end{verbatim}
** Diet Coke ** is the most ordered item in the choice\_description
column
4.How many items were ordered in total?
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{summarise}\NormalTok{(chipotle\_sales, }\AttributeTok{item\_sold=}\FunctionTok{sum}\NormalTok{(quantity))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## # A tibble: 1 x 1
## item_sold
## <dbl>
## 1 4972
\end{verbatim}
** 4972 ``\,'' items were ordered in total.
5.Turn the item price into a float First duplicate the item\_price
column to item\_price\_db in case make any mistake.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{chipotle\_sales }\OtherTok{\textless{}{-}} \FunctionTok{mutate}\NormalTok{(chipotle\_sales, }\AttributeTok{item\_price\_db=}\NormalTok{item\_price)}
\end{Highlighting}
\end{Shaded}
Then covert the item\_price\_db to float.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{chipotle\_sales}\SpecialCharTok{$}\NormalTok{item\_price\_db }\OtherTok{\textless{}{-}} \FunctionTok{as.numeric}\NormalTok{(}\FunctionTok{gsub}\NormalTok{(}\StringTok{"[\^{}0{-}9.]"}\NormalTok{,}\StringTok{""}\NormalTok{,chipotle\_sales}\SpecialCharTok{$}\NormalTok{item\_price\_db))}
\end{Highlighting}
\end{Shaded}
Now we can see item\_price\_db is float data type.
6.How much was the revenue for the period in the dataset? To do this we
need to know multiply item\_price\_db and quantity then get revenue.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{chipotle\_sales }\OtherTok{\textless{}{-}} \FunctionTok{mutate}\NormalTok{(chipotle\_sales, }\AttributeTok{total =}\NormalTok{ quantity }\SpecialCharTok{*}\NormalTok{ item\_price\_db) }\CommentTok{\#add a new column total for total price sold for each order}
\NormalTok{revenue }\OtherTok{\textless{}{-}}\NormalTok{ chipotle\_sales }\SpecialCharTok{\%\textgreater{}\%} \FunctionTok{summarise}\NormalTok{(}\FunctionTok{sum}\NormalTok{(total)) }\CommentTok{\#calculate the total by summarise(sum(total))}
\end{Highlighting}
\end{Shaded}
The revenue for the period is \textbf{\$39,237}
7.How many orders were made in the period?
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{total\_orders }\OtherTok{\textless{}{-}}\NormalTok{chipotle\_sales }\SpecialCharTok{\%\textgreater{}\%} \FunctionTok{summarise}\NormalTok{(}\FunctionTok{n\_distinct}\NormalTok{(order\_id)) }\CommentTok{\#n\_distinct() is count distinct value}
\end{Highlighting}
\end{Shaded}
\textbf{1834} orders were made in the period
8.What is the average revenue amount per order? To calculate the average
revenue amount per order = revenue/total\_orders.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{revenue}\SpecialCharTok{/}\NormalTok{total\_orders}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## sum(total)
## 1 21.39423
\end{verbatim}
So the average revenue per order is \$21.39.
9.How many different items are sold?
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{summarise}\NormalTok{(chipotle\_sales,}\AttributeTok{items\_kind=}\FunctionTok{n\_distinct}\NormalTok{(item\_name))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## # A tibble: 1 x 1
## items_kind
## <int>
## 1 50
\end{verbatim}
\end{document}