YouTube2Text

2026 FREE Data Analyst Bootcamp [24 Hours+] for FREE | SQL, Excel, Python, Power BI, GitHub, AWS — Transcript

by Alex The Analyst · 334,400 words · 45,258 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hello everybody and welcome to the 2026
  2. 0:02data analyst boot camp. Back in 2024, I
  3. 0:04released the first ever data analyst
  4. 0:06boot camp on YouTube. It was about 24 or
  5. 0:0825 hours worth of content that I've been
  6. 0:10creating for the past four, five, or
  7. 0:12even 6 years. Believe it or not, since
  8. 0:14then, I've been creating even more
  9. 0:16content. And so, I'm adding a lot of
  10. 0:17those new things into this boot camp to
  11. 0:19make it even longer and cover even more
  12. 0:21things. In the original boot camp, we
  13. 0:23covered a ton of stuff already. And I'm
  14. 0:24going to read it because it's too many
  15. 0:26things. Uh we covered my SQL, Excel,
  16. 0:28Tableau, PowerBI, Python, Pandas, Python
  17. 0:31projects, building a portfolio website,
  18. 0:33creating a resume, practicing for
  19. 0:35technical interviews, Azure, AWS, and
  20. 0:38then how to use LinkedIn to land a job.
  21. 0:40That is a ton of stuff. And those are
  22. 0:42just videos I've been making for the
  23. 0:43past several years, and I put it into
  24. 0:45one really long video. In the boot camp
  25. 0:47that you're watching right now, we are
  26. 0:48adding a ton of new content. The first
  27. 0:50thing being a data fundamentals
  28. 0:52playlist. These videos cover things like
  29. 0:54what is data, what are data types, what
  30. 0:56is data cleaning. A lot of things that
  31. 0:57data analysts need to know. We're also
  32. 0:59going to be adding in our entire Git and
  33. 1:01GitHub series because Git and GitHub are
  34. 1:03just really useful to know and they're
  35. 1:04being used more and more especially with
  36. 1:06AI becoming so popular. I'm also adding
  37. 1:09in the R for data analyst series which
  38. 1:11is basically just R programming for data
  39. 1:13analysts. And so if you like R, you are
  40. 1:15in luck. I am adding it to this boot
  41. 1:17camp. Lastly, we're going to be adding
  42. 1:19in data bicks. And data bicks is a
  43. 1:21phenomenal data platform to know how to
  44. 1:23use. It's super popular and a lot of
  45. 1:25people say you either choose data bricks
  46. 1:26or snowflake and I'm going to create a
  47. 1:28snowflake series in the future, but
  48. 1:29we're adding in the data bricks series
  49. 1:31and so that's going to cover how to use
  50. 1:32data bricks and how to create ETL
  51. 1:34pipelines within data bricks as well. So
  52. 1:36there's a ton of new things that we're
  53. 1:37adding to this boot camp and it all is
  54. 1:40here just to help you learn the skills
  55. 1:41that you need in order to become a data
  56. 1:43analyst. If you did not know, I also
  57. 1:45have a paid platform called Analyst
  58. 1:47Builder. Analyst Builder is where I have
  59. 1:48all of my full courses. It is my paid
  60. 1:50platform and so all the things that
  61. 1:52we're covering within this boot camp, I
  62. 1:54have full courses that dive even more in
  63. 1:56depth and have more advanced projects
  64. 1:58within Analyst Builder. We also have a
  65. 2:00part of the platform where you can
  66. 2:01practice for interviews. So you can
  67. 2:03practice SQL and Python and R all within
  68. 2:06the platform. And there's also general
  69. 2:08technical interview questions. If you
  70. 2:10don't know how to answer some of these
  71. 2:11questions, we have an entire part of the
  72. 2:13platform where you can practice and get
  73. 2:15better at answering those questions. And
  74. 2:17if you are looking for projects to
  75. 2:19build, we have a whole section on the
  76. 2:20platform where you can find projects and
  77. 2:22you can build them out and share them
  78. 2:24with others. Analyst Builder is my paid
  79. 2:26platform. YouTube is where I have all of
  80. 2:27my free content. So, they're two
  81. 2:29separate things. If you just want to
  82. 2:31stick to the free content, this boot
  83. 2:32camp is the best boot camp you are going
  84. 2:34to find on YouTube. Hands down. I
  85. 2:37promise. But if you're wanting to go
  86. 2:38even more in depth and you're willing to
  87. 2:40spend a little bit of money, Analyst
  88. 2:41Builder is where I would go. I truly
  89. 2:43hope that you learn a ton from this boot
  90. 2:45camp. I have spent years creating the
  91. 2:47content to put into this boot camp and I
  92. 2:49hope that you really enjoy it. I have no
  93. 2:51idea how long this boot camp is going to
  94. 2:53be. The last one was like 25 hours. So,
  95. 2:55I hope you enjoy the somewhere between
  96. 2:5725 and 30ome hours worth of learning.
  97. 3:00We're [music] going to start at the very
  98. 3:01beginning assuming you haven't started
  99. 3:03this process at all of becoming a data
  100. 3:05analyst. If you already have, you can
  101. 3:07kind of find and identify where you are
  102. 3:09in this process and then go from there.
  103. 3:11Now, before we dive into everything, I
  104. 3:13want to warn you I will be mentioning my
  105. 3:15own channel a lot in this video. I have
  106. 3:17videos and playlists on just about every
  107. 3:19single topic that we're going to be
  108. 3:20talking about today. I'll have all the
  109. 3:22links to those videos in the description
  110. 3:23so you can dive into those topics more
  111. 3:25in depth. So, I hope that's okay. And
  112. 3:27it's all completely free. I've been
  113. 3:28building this out for the past 3 years
  114. 3:30and honestly, you can probably get 90%
  115. 3:33of the way to learning everything you
  116. 3:34need for data analytics just on my
  117. 3:36channel. So, now that I've warned you,
  118. 3:37let's jump to number one and that is
  119. 3:39learn the data analyst skills. Now,
  120. 3:41there are literally a hundred different
  121. 3:42things that you can learn for data
  122. 3:43analytics. You can learn things like
  123. 3:44AlterX or a cloud platform or different
  124. 3:46programming languages, but there are
  125. 3:48some core skills that I recommend you
  126. 3:50start out with before kind of branching
  127. 3:51into some of those other skills. The
  128. 3:53number one skill that I always recommend
  129. 3:55people start with is SQL. SQL is just
  130. 3:57one of those fundamental skills I think
  131. 3:59everybody should learn. Even if you
  132. 4:00don't use SQL, you'll use some variation
  133. 4:03of SQL if your company has a large
  134. 4:05enough data set. SQL is used to actually
  135. 4:07query and retrieve data from a database.
  136. 4:09So, if your company collects data, which
  137. 4:11every company does, they're going to put
  138. 4:13it somewhere to store. It's usually
  139. 4:14stored in a database, and SQL is how you
  140. 4:17get that data from the database. I think
  141. 4:19SQL is also fairly easy to learn, which
  142. 4:21makes it really good when you're just
  143. 4:22starting out. I have several playlists
  144. 4:24dedicated to SQL, starting from beginner
  145. 4:26all the way to advanced, and you can
  146. 4:27learn all of that for free. One other
  147. 4:29reason why I think you should learn SQL
  148. 4:30first, is that a lot of companies
  149. 4:32interview or have a technical interview
  150. 4:34during the interview process on SQL.
  151. 4:36That's something that really caught me
  152. 4:37off guard when I was first starting out
  153. 4:38because I thought it was going to be
  154. 4:39more behavioral. I didn't even know what
  155. 4:41a technical interview was. So, knowing
  156. 4:43SQL actually became a really important
  157. 4:45part of interviewing and getting a job
  158. 4:47as a data analyst. The second skill that
  159. 4:49I will learn is a business intelligence
  160. 4:50tool like Tableau or PowerBI. Now, there
  161. 4:53are a ton of different BI tools. I can
  162. 4:55literally name 10 off the top of my head
  163. 4:56that I've used throughout my career. But
  164. 4:58what I will say is that learning
  165. 4:59something like Tableau or PowerBI is
  166. 5:01pretty transferable to almost all those
  167. 5:03other BI tools. They're all fairly
  168. 5:05similar in how they do things and how
  169. 5:08they show and display the data. You most
  170. 5:10likely won't have a technical interview
  171. 5:11asking you about Tableau or PowerBI like
  172. 5:13to build something for them. That
  173. 5:15usually does not happen. But the
  174. 5:17combination of SQL where you can query
  175. 5:19your data and then taking that data to
  176. 5:20build something that is a really really
  177. 5:23great combination to learn right away. I
  178. 5:25have entire series on both Tableau and
  179. 5:26PowerBI with projects on my channel. The
  180. 5:29third skill that I would learn is Excel.
  181. 5:31Now most people have used Excel. They
  182. 5:33know what Excel is and how it's used,
  183. 5:34but it can be used a little bit
  184. 5:36differently for a data analyst. For
  185. 5:38example, in Excel, a lot of people
  186. 5:39haven't cleaned data in Excel or built
  187. 5:42charts and graphs using Excel, and those
  188. 5:44are things that data analysts would
  189. 5:45probably do. Excel is also just a
  190. 5:47fundamental skill that every company is
  191. 5:49going to expect you to know. So, I have
  192. 5:51an entire playlist dedicated to Excel to
  193. 5:53actually walk you through how to use it
  194. 5:55for data analysis. The fourth skill that
  195. 5:57I recommend you learn is Python. Now, a
  196. 5:59lot of people will have Python higher up
  197. 6:00on their list. They only use Python.
  198. 6:02They don't use SQL or a BI tool. They
  199. 6:05just do everything in Python. Now,
  200. 6:06Python is a fantastic tool. You can use
  201. 6:08it to manipulate your data to create
  202. 6:10data visualizations and a ton more like
  203. 6:13web scraping and regular expression and
  204. 6:15100 different other things. But it can
  205. 6:17be kind of hard to learn. It took me a
  206. 6:19long time to really learn the basics
  207. 6:21very well. That's really the only reason
  208. 6:23why it is farther back. I feel like SQL
  209. 6:25and a BI tool are really easy to learn
  210. 6:27and really pack a big punch. Whereas
  211. 6:30Python can be quite tough to learn in my
  212. 6:32experience and you may not use it as
  213. 6:34often as you would something like SQL or
  214. 6:36a BI tool. If you're interested in
  215. 6:38learning Python, I have an entire series
  216. 6:40dedicated to Python as well as projects
  217. 6:42that you can build. Again, I warned you
  218. 6:43there's going to be a lot of
  219. 6:44self-promotion in this video. I have
  220. 6:46videos on just about every single one of
  221. 6:47these topics. The fifth and the last
  222. 6:50skill that I recommend you learning, and
  223. 6:51this is the only one that I don't have a
  224. 6:53series on yet, and I will make those, is
  225. 6:56learning a cloud platform like AWS,
  226. 6:58Google Cloud Platform, or Azure. There's
  227. 7:00no denying that these platforms have
  228. 7:02played a huge impact on how we use data
  229. 7:04as a whole in the data analyst industry.
  230. 7:06They can be kind of tough to learn,
  231. 7:08though, if you aren't using it hands-on
  232. 7:10in an actual job. I think that learning
  233. 7:12a cloud platform is already something
  234. 7:14that most people should start working
  235. 7:15towards because in the future it's only
  236. 7:17going to become more prevalent. After
  237. 7:19you learn all of these skills, the next
  238. 7:20thing that I recommend you do is
  239. 7:22actually build projects with those
  240. 7:23skills. Now, what does building a
  241. 7:25project actually mean? It means taking a
  242. 7:27skill and then building something out of
  243. 7:29it that you can then show a potential
  244. 7:31employer. For example, if you went
  245. 7:33through and learned Tableau, you could
  246. 7:34go and take a data set and you could
  247. 7:36build a visualization and a dashboard in
  248. 7:38Tableau and that would be a project.
  249. 7:41With these projects, you can build
  250. 7:42something called a portfolio. And I
  251. 7:44usually call it a portfolio website. A
  252. 7:46portfolio website is a website that you
  253. 7:48create where you store all of your
  254. 7:49projects and then you can share that
  255. 7:51with recruiters and hiring managers so
  256. 7:53that they can see all of your work. Now,
  257. 7:55do you absolutely need a portfolio to
  258. 7:57show employers? No, you don't. But it
  259. 8:00does help in two different ways. The
  260. 8:02first thing that it may do is actually
  261. 8:03help you land the interview. If you have
  262. 8:05a link on your resume and they click on
  263. 8:06it, they may see your skills and see
  264. 8:08your projects and be like, "Man, this
  265. 8:10person really knows what they're doing.
  266. 8:11This is exactly what we need." The
  267. 8:13second reason that I recommend building
  268. 8:15projects is because most likely during
  269. 8:17your interview, you're going to get
  270. 8:18asked questions like, "How have you used
  271. 8:20SQL? How have you used Tableau?" And if
  272. 8:23you don't have any experience in that,
  273. 8:25you're just going to say, "Well, you
  274. 8:26know, I've taken courses to learn it."
  275. 8:28But with a project, you can be a lot
  276. 8:30more specific. You'll be able to say,
  277. 8:32"Well, I actually just built out this
  278. 8:33project in Tableau. I took the data and
  279. 8:36cleaned it in Excel and then I put it in
  280. 8:38Tableau and built out this dashboard and
  281. 8:39here are the insights that I found from
  282. 8:41this data set." It's just a much better
  283. 8:43answer. And as a hiring manager myself,
  284. 8:45I can tell you that it is definitely
  285. 8:47beneficial to build out these projects.
  286. 8:49The next step that I recommend you take
  287. 8:50in becoming a data analyst is building a
  288. 8:53data analyst resume. The resume, to say
  289. 8:55the least, is extremely important. It's
  290. 8:58what's going to actually allow you to
  291. 8:59land an interview to potentially get a
  292. 9:01job. Now, if you were like me when I was
  293. 9:03first starting out, I had a resume. It
  294. 9:06just had nothing to do with data
  295. 9:07analytics. So, how do you make a data
  296. 9:10analyst resume if you don't have any
  297. 9:12experience as a data analyst? Well, you
  298. 9:14are asking the perfect questions because
  299. 9:16the very first things that we talked
  300. 9:18about are what are going to go on your
  301. 9:19resume, those skills, and those
  302. 9:21projects. If you have no experience or
  303. 9:24degree, like myself who has a
  304. 9:26recreational therapy degree, if you have
  305. 9:28no background in this, it can be really
  306. 9:29daunting to kind of display that you
  307. 9:31know what you're doing and that a
  308. 9:33company should hire you. So, what I
  309. 9:35usually recommend is right beneath your
  310. 9:36contact at the top, you put your skills
  311. 9:38and your projects that you built out on
  312. 9:41your resume. Things like work experience
  313. 9:43and education should go on your resume
  314. 9:44as well, but just a little bit lower.
  315. 9:47You want them to see those things before
  316. 9:49they see that your last work experience
  317. 9:50was at Domino's and you have a degree in
  318. 9:52marine biology. It's just not relevant
  319. 9:55to data analysis. And if you put those
  320. 9:57things at the top, they're probably
  321. 9:58going to rule you out right away. The
  322. 10:00fourth step to become a data analyst is
  323. 10:02actually applying. You have the skills,
  324. 10:04you have the projects, you have the
  325. 10:05resume, now you're ready to start
  326. 10:07applying for those data analyst jobs.
  327. 10:09Now, there's a lot of different opinions
  328. 10:10on how you need to go about applying for
  329. 10:12data analyst jobs, but I'll give you my
  330. 10:14take on it, and this has been the most
  331. 10:16successful for me and my career. The
  332. 10:17first thing that I want to mention is
  333. 10:18actually what I would not do, which is
  334. 10:20just blindly apply on Glass Door,
  335. 10:22Monster, Zip Recruiter, and all these
  336. 10:24other platforms to just any data analyst
  337. 10:26job that you can find. Now, I'm not
  338. 10:28against this. I think you should do
  339. 10:30that, but I don't think that's the only
  340. 10:31thing that you should do because the
  341. 10:33chances of you getting a call back or
  342. 10:35actually hearing something back are
  343. 10:36extremely low. To really increase your
  344. 10:39chances of becoming a data analyst, I
  345. 10:41highly, highly, highly recommend working
  346. 10:42with a recruiter. A recruiter is
  347. 10:44literally someone who is there to help
  348. 10:46you find a job. Now, when I first
  349. 10:47started out, I didn't understand what a
  350. 10:49technical recruiter was at all. I was
  351. 10:51kind of nervous or scared to work with
  352. 10:53them. But it's actually pretty simple. A
  353. 10:56company has a position that they want to
  354. 10:57fill and they don't want to spend hours
  355. 10:59and hours and hours to find someone to
  356. 11:01fill that position. So, they hire a
  357. 11:03recruiter. a recruiter is going to go
  358. 11:04out and try to find someone to fill that
  359. 11:06position, aka you. And so if you go and
  360. 11:09talk to that recruiter and they have a
  361. 11:10position that opens up, they will help
  362. 11:12you get that interview. And then if you
  363. 11:14get a job, let's say for $50,000, the
  364. 11:17company is going to pay that recruiter,
  365. 11:18let's say, 10% of your salary. So
  366. 11:20they'll give them $5,000. So you don't
  367. 11:23actually lose or have anything to lose
  368. 11:25using a recruiter. You can reach out to
  369. 11:27recruiters in several ways, and I've
  370. 11:29done every variation, but I'll tell you
  371. 11:31my most successful way, which was using
  372. 11:33LinkedIn. There are tens of thousands of
  373. 11:35recruiters on LinkedIn. I made an entire
  374. 11:37video of how you can reach out to
  375. 11:38recruiters and what to say to recruiters
  376. 11:40on LinkedIn to help you land a job. So,
  377. 11:42be sure to check out that video when you
  378. 11:44actually get to that point. But, you can
  379. 11:46also just cold email and cold call these
  380. 11:48recruiting companies. But to me, it's
  381. 11:50just not as effective as reaching out
  382. 11:52directly on LinkedIn. And this is just a
  383. 11:54bonus one. The last thing that you need
  384. 11:56to do is accept a job offer. So, in step
  385. 11:58number four, after you apply to those
  386. 12:00jobs, you do actually have to go in,
  387. 12:01interview, and then get a job offer,
  388. 12:03which you will accept. I just thought
  389. 12:05I'd mention that just in case that was
  390. 12:06not super clear. Now, that was a lot of
  391. 12:09stuff. Let's talk about time frames to
  392. 12:11actually complete all of these things.
  393. 12:13Now, doing all of these things from
  394. 12:15scratch is going to take a while, but
  395. 12:16let's break it down by each step and see
  396. 12:18how long I generally think it's going to
  397. 12:20take. Let's start with step number one,
  398. 12:22which is actually learning the skills.
  399. 12:23Now, just to be upfront, this one
  400. 12:25probably is going to take the longest
  401. 12:26for most people. For most people to
  402. 12:29learn all of these skills, it's going to
  403. 12:30take around 3 to four months. Now, if
  404. 12:32you don't learn a cloud platform and
  405. 12:34Python, which are the last ones that I
  406. 12:36recommend, and you just focus on SQL,
  407. 12:38ABI tool, and Excel, I think you can do
  408. 12:40that in under 3 months. That is very
  409. 12:43dependent though on how much time you
  410. 12:44have to study. That time frame is more
  411. 12:47for someone who has several hours per
  412. 12:49day, maybe 3 hours in the end of the
  413. 12:51night after you go to work. That is
  414. 12:52someone who has quite a bit of time to
  415. 12:54dedicate to learning during their week.
  416. 12:56Of course, that time frame is going to
  417. 12:57take longer if you don't have as much
  418. 12:58time to dedicate to learning. Now, let's
  419. 13:00look at number two, which was creating
  420. 13:02projects and a portfolio of projects.
  421. 13:04From my experience, when you're first
  422. 13:05starting out, it takes a lot longer to
  423. 13:07actually create these projects. It can
  424. 13:08take one or two weeks per project. I
  425. 13:11usually recommend people doing three to
  426. 13:12five projects in their portfolio before
  427. 13:14they start applying. And since they can
  428. 13:16take anywhere from 1 to two weeks,
  429. 13:18you're looking at anywhere from 3 to 6
  430. 13:20weeks. The next step was to create a
  431. 13:22data analyst resume. Now, in my opinion,
  432. 13:24this one should take the shortest out of
  433. 13:25every single step here because you're
  434. 13:27really just kind of reformatting a
  435. 13:29resume or creating a resume. You're just
  436. 13:31adding skills, you're adding your
  437. 13:32projects, and then kind of reformatting
  438. 13:34it to make it look nice. This should
  439. 13:36hopefully take under a week, but if you
  440. 13:37use something like a professional
  441. 13:39service where they help you build a
  442. 13:40resume, it can take one to two weeks.
  443. 13:42The two last steps which kind of go hand
  444. 13:44inand are step four and five, which is
  445. 13:46actually applying for jobs and then
  446. 13:48landing a job. Now, this process can
  447. 13:50take as little as a month, or it can
  448. 13:52take as long as 6 months or a year. It
  449. 13:54really depends on how you're applying,
  450. 13:56where you're applying, and just the kind
  451. 13:59of luck that you're having with actually
  452. 14:00landing interviews. I've seen people who
  453. 14:02have never had any experience land a job
  454. 14:04within a month of starting to apply. And
  455. 14:06it's incredible. It's amazing, but it
  456. 14:08doesn't happen too often. You're usually
  457. 14:10looking at around 2 to four months on
  458. 14:13average to land your first data analyst
  459. 14:15job. If you put all of those together
  460. 14:17and kind of average everything out,
  461. 14:19you're looking at around six months
  462. 14:20total for the entire process. Now, I
  463. 14:22don't want that to discourage you, okay?
  464. 14:242023 is a long year. You have a lot of
  465. 14:27time and it doesn't have to take 6
  466. 14:29months. You could do it faster. You
  467. 14:30could do it in 3 months and just prove
  468. 14:32me wrong. But if you are really focused
  469. 14:34and you are really driven to become a
  470. 14:35data analyst this year, I know that you
  471. 14:37can do it. Now, to maybe boost your
  472. 14:39spirits and make you feel a little bit
  473. 14:40better, I didn't know any of these
  474. 14:42things when I first started out. I
  475. 14:43didn't have anyone telling me kind of a
  476. 14:44plan on what to do. I had to go out and
  477. 14:47figure all these things out by myself
  478. 14:48and it took me almost a year to land my
  479. 14:50first real data analyst job. So, with
  480. 14:52all that being said, I hope that this
  481. 14:53video is helpful. I hope you now have a
  482. 14:55path on how to become a data analyst
  483. 14:57this year and that my channel can be a
  484. 14:59big part of that. What's going on
  485. 15:00everybody? Welcome back to another
  486. 15:01video. Today, we're going to be starting
  487. 15:03our data fundamentals series. [music]
  488. 15:10>> [music]
  489. 15:10>> Now, in this series, I'm going to be
  490. 15:12walking through some really core
  491. 15:13fundamental concepts about data. If
  492. 15:15you've been on my YouTube channel for
  493. 15:16any amount of time, you know that we
  494. 15:17talk a lot about data, specifically
  495. 15:20about how to use tools to work with your
  496. 15:23data. But up until now, I haven't really
  497. 15:24dived in and broken down the core
  498. 15:26concepts of what data is and how it's
  499. 15:28used in the real world. So, in this
  500. 15:30series, that's what I aim to do. And in
  501. 15:32this video, we're going to be starting
  502. 15:33off with what is data. Let's jump over
  503. 15:35to my screen and take a look. All right.
  504. 15:36Right. So, in this lesson, we're going
  505. 15:37to be talking about what data is. Again,
  506. 15:38we're starting from the very basics.
  507. 15:41We're working our way up through this
  508. 15:43series. So, by definition, data is just
  509. 15:45raw facts and figures. It doesn't even
  510. 15:48necessarily have to be on a computer. It
  511. 15:50could be on a notepad. If you're writing
  512. 15:52down 1 2 3 4 5, that is data that you're
  513. 15:54writing down. That's going to be harder
  514. 15:56to use that data necessarily because,
  515. 15:59you know, on a computer, it's easier to
  516. 16:00process and use data. But that is data.
  517. 16:04Some examples of data are things like a
  518. 16:07number, the number 45, that is a piece
  519. 16:09of data. A word could be data. Just the
  520. 16:12word completed or a sentence that is
  521. 16:14also data. And then a date could be data
  522. 16:16as well. So we have 1210 of 2024. This
  523. 16:20is a piece of data. Now the thing about
  524. 16:23data is is that data is everywhere. It's
  525. 16:26in everything we do all the time. But
  526. 16:29without collecting it, without context
  527. 16:31of what this data actually means, it's
  528. 16:33basically useless. Look at some examples
  529. 16:36of how data is used in the real world.
  530. 16:38Something that a lot of you will use
  531. 16:40almost every single day. So, let's take
  532. 16:42a look at this first one. This is a
  533. 16:43weather app. I use my weather app almost
  534. 16:46all the time. I got to send my kids to
  535. 16:47school and I want to check if it's
  536. 16:49rainy, if it's hot, if it's cold, if
  537. 16:50they need a jacket, if they don't. And
  538. 16:52that is something that requires a lot of
  539. 16:54data. Meteorologists use tools to
  540. 16:57collect data on all of these things.
  541. 16:59Then they're presented in these apps. So
  542. 17:01they collect data about weather,
  543. 17:03temperature, humidity, location, time,
  544. 17:05and they take all of this and they
  545. 17:07aggregate it. That just means they bring
  546. 17:09all of it together into one place and
  547. 17:11they aggregate these numbers. And
  548. 17:13finally, they'll present it to you based
  549. 17:15off of your data, your location, where
  550. 17:17you actually are. And so that is
  551. 17:19something that is extremely data
  552. 17:20dependent. They typically will process
  553. 17:22this as well as forecast, which means
  554. 17:24they're going to kind of predict out
  555. 17:26what they think is going to happen in
  556. 17:27the next hour, two hours, maybe it's a
  557. 17:29day or several days ahead. They can also
  558. 17:31use this data to predict what might
  559. 17:34happen in your location. Another example
  560. 17:36would be a bank app. So, I go on my
  561. 17:38phone all the time to check my banking
  562. 17:40statements to make sure that, you know,
  563. 17:41I didn't spend too much money. And
  564. 17:43everything in your banking app is data.
  565. 17:46And so when you go on this app, like you
  566. 17:48can see in this image down here, you can
  567. 17:50see where you spent your money, you can
  568. 17:51see the amount you spent your money, the
  569. 17:53date and the time that you spent your
  570. 17:54money. These are all different points of
  571. 17:57data that the bank has collected. Banks
  572. 17:59collect hundreds, if not thousands of
  573. 18:01data points, but really common ones are
  574. 18:02things like bank deposits and
  575. 18:04transactions and payments that you've
  576. 18:05made. All of these things so they can
  577. 18:07put it in your dashboard so that you can
  578. 18:09track your money. Now, let's take a look
  579. 18:10at different types of data because there
  580. 18:13isn't just one type of data. Data isn't
  581. 18:15just one thing. Data is really complex
  582. 18:18and there's a lot of different things to
  583. 18:20it. So, really briefly, I'm going to
  584. 18:21touch on structured, semistructured, and
  585. 18:23unstructured data. Structured data is
  586. 18:26really neat and really easy to visualize
  587. 18:29and see, as you can see in this uh image
  588. 18:31right here. That typically refers to
  589. 18:32something that has columns and rows,
  590. 18:34something like an Excel file.
  591. 18:36Everybody's used an Excel file before,
  592. 18:38and so that is something that is very
  593. 18:40structured, very easy to kind of
  594. 18:42visualize and use and understand. The
  595. 18:44exact opposite side of this, we have
  596. 18:46unstructured data. Unstructured data is
  597. 18:49kind of all over the place and it might
  598. 18:51be a lot harder to use. For example,
  599. 18:53that could be something like a
  600. 18:55photograph that you took or maybe a
  601. 18:57video or an audio file. These are all
  602. 18:59examples of unstructured data that you
  603. 19:01can't really put into something like an
  604. 19:03Excel file for it to be in columns and
  605. 19:05rows. Then we have something called
  606. 19:06semistructured data. Semi-structured
  607. 19:08data is closer to structured data than
  608. 19:11it is unstructured data, but it is more
  609. 19:14complex than something like an Excel
  610. 19:16file. For example, semiructured data
  611. 19:18might be something like a JSON file.
  612. 19:20Now, we haven't gotten to file formats
  613. 19:22and file types yet in this series, but
  614. 19:24when we do, I'll dive into what JSON
  615. 19:26files are because JSON files store
  616. 19:29things differently than something like
  617. 19:30structured data where they nest data in
  618. 19:32kind of these hierarchies. Let's take a
  619. 19:34look at the two main ones. Structured
  620. 19:36versus unstructured data. Structured
  621. 19:38data is the data that I primarily work
  622. 19:40with as a data analyst. This is
  623. 19:42typically going to be something like a
  624. 19:44row and column in an Excel file or a CSV
  625. 19:46file or in something like a relational
  626. 19:49database. A database is just a place
  627. 19:51where you will store a lot of data and
  628. 19:53all of that data typically connects in
  629. 19:55some way. So you can work with a lot of
  630. 19:57it. Structured data is also quantitative
  631. 19:59versus qualitative like unstructured
  632. 20:02data. Structured data is numbers based
  633. 20:04and it's measurable and so you can
  634. 20:05easily kind of track it and use it.
  635. 20:07Whereas qualitative could be something
  636. 20:09like a survey where it might be free
  637. 20:11text where it's someone saying you know
  638. 20:13I had a really great experience at this
  639. 20:15and I really liked this and I liked
  640. 20:16this. That's a little bit harder to
  641. 20:18actually put into numbers how much that
  642. 20:21person liked. But quantitative may be
  643. 20:23hey how much did you like this on a
  644. 20:25scale of 1 to 10? And if the person puts
  645. 20:27a seven that's a very specific answer.
  646. 20:29Now the amount of data that sits as
  647. 20:31structured data is significantly less
  648. 20:34than unstructured data. Structured data
  649. 20:35is only about 20% of enterprise data
  650. 20:38compared to 80% of unstructured data.
  651. 20:41And so there's a lot more unstructured
  652. 20:43data in the world. And so what a lot of
  653. 20:45people in the data world do is they try
  654. 20:47to take that unstructured data and they
  655. 20:49try to make it structured. And so that
  656. 20:52is a big part of what a lot of data
  657. 20:54professionals do. Lastly, and we just
  658. 20:55touched on this, but structured data
  659. 20:57tends to be things like numbers, dates,
  660. 20:59strings, which are things like words and
  661. 21:01text, versus unstructured data, which is
  662. 21:03things like images, audio, video, and
  663. 21:05others. That being said, data is
  664. 21:07everywhere. It is all around us all the
  665. 21:09time, and especially in this
  666. 21:11technological world we live in, it is
  667. 21:13literally in everything we do. But the
  668. 21:16challenge especially for people in data
  669. 21:18who are working with data, the challenge
  670. 21:20is to collect it, to organize and
  671. 21:23analyze it so that you can then use that
  672. 21:25data. What's going on everybody? Welcome
  673. 21:27back to another video. Today we're going
  674. 21:29to be taking a look at KPIs and metrics.
  675. 21:31[music]
  676. 21:37Now, if you've worked in the data world,
  677. 21:38you've probably heard these terms before
  678. 21:40because they are very popular to throw
  679. 21:42around and use. but you may not know
  680. 21:44exactly what they mean. So, in this
  681. 21:46lesson, we're going to be diving into
  682. 21:47KPIs and metrics. So, with that being
  683. 21:49said, let's jump over to my screen. So,
  684. 21:51let's dive into KPIs and metrics. And
  685. 21:54let's start off with metrics. So, what
  686. 21:57exactly is a metric? A metric is
  687. 22:00something that, by the way, people throw
  688. 22:01out all the time and they typically get
  689. 22:03metrics and KPIs confused. And so, we
  690. 22:06will be really good going through this.
  691. 22:07I'm going to talk about metrics first
  692. 22:08and then how metrics relate to KPIs. So
  693. 22:12a metric is any measurement that
  694. 22:14provides information using data. So if
  695. 22:17you're taking data and you're tracking
  696. 22:19that data and you're measuring that
  697. 22:20data, that is a metric. It can be
  698. 22:22anything. For example, let's say we have
  699. 22:25a website and we sell things on this
  700. 22:27website. It's like an e-commerce
  701. 22:28platform. A metric that we might have is
  702. 22:31website visits. How many visits per
  703. 22:34month do we actually have? And let's say
  704. 22:36this month we had 15,000 monthly
  705. 22:39visitors. We also could look at sales
  706. 22:41numbers. So, we sold 500 units of
  707. 22:43whatever product we're selling. So,
  708. 22:45these are core metrics. Now, if you look
  709. 22:48over on this right hand side, we have
  710. 22:50this dashboard. This is something that a
  711. 22:51lot of companies will have. It'll be
  712. 22:53something to track their metrics or at
  713. 22:55least visualize their metrics. It could
  714. 22:57be on revenue or margins or all these
  715. 22:59different things. This is something that
  716. 23:01when you're working with data, people
  717. 23:03want to know. They want to be able to
  718. 23:04measure and track specific data. Now
  719. 23:07let's see how this compares to a KPI.
  720. 23:10KPI stands for key performance indicator
  721. 23:13and this is a specific metric that
  722. 23:15directly measures progress towards a
  723. 23:18goal. So every single KPI is going to be
  724. 23:21a metric but not every metric is going
  725. 23:24to be a KPI. For example, let's look
  726. 23:26over on this image on the right hand
  727. 23:28side. We start with all of our data and
  728. 23:30then we take that data and we say what
  729. 23:32metrics do we want to look at within
  730. 23:34this data? Then we determine what
  731. 23:36metrics do we actually want to track.
  732. 23:38Which metrics align with our goals. So
  733. 23:41for example, in our website that we
  734. 23:43have, we have 15,000 monthly visitors.
  735. 23:45But let's say our target KPI is going to
  736. 23:47be those monthly visitors, but our goal
  737. 23:49is 20,000. And so we have a metric that
  738. 23:53we're tracking. And now we're saying we
  739. 23:55want this to be a goal that we achieve.
  740. 23:57And it's also measurable. For our sales
  741. 23:59numbers, we have 500 units sold. One of
  742. 24:01our sales KPI could be, okay, this month
  743. 24:04we're selling 500, but next month we
  744. 24:06want to increase our sales by 2% each
  745. 24:09month going forward. So that could also
  746. 24:11be a KPI. You may be asking, how do you
  747. 24:13choose a good KPI? And this is a very
  748. 24:16good question because I've worked with a
  749. 24:18lot of different data teams and they
  750. 24:20just sometimes randomly choose KPIs.
  751. 24:22They're like, this seems like a good one
  752. 24:24to achieve or get better at. That may be
  753. 24:26true, but it may not actually progress
  754. 24:28you towards the goal that you're
  755. 24:30wanting. And so when you're trying to
  756. 24:31choose a good KPI, let's say you're
  757. 24:33tracking these metrics, you're saying I
  758. 24:35want to progress towards a goal. How do
  759. 24:37we choose what KPIs we want? The first
  760. 24:40thing you have to ask is what is your
  761. 24:41goal? Maybe for our website it was we
  762. 24:44want to increase sales. That's our
  763. 24:45number one thing. Then we have to
  764. 24:47identify which metric actually best
  765. 24:49tracks our progress towards that goal.
  766. 24:51On a website there are a ton of
  767. 24:52different data points that you can do.
  768. 24:54For example, you can see how long a user
  769. 24:56is actually on your website. You can see
  770. 24:58how many times one user gets onto your
  771. 25:00platform every day. Maybe they get on
  772. 25:02three or four or five times a day. Those
  773. 25:04are metrics, but that may not be what
  774. 25:06your goal actually is to sell your
  775. 25:08products. And then lastly, you have to
  776. 25:09say, is this metric actionable? Maybe
  777. 25:11you can't make people sign onto your
  778. 25:13website 3, four, five times a day if
  779. 25:15that's what you're wanting to do. That
  780. 25:16may not be an actionable metric to
  781. 25:18actually track, but something like the
  782. 25:20daily users is because maybe you could
  783. 25:22send out a daily email or you can do
  784. 25:24some type of marketing to get more
  785. 25:25people on your platform. These are
  786. 25:27things that you have control over and
  787. 25:29that are actionable. So, really quickly,
  788. 25:30let's just break down key performance
  789. 25:32indicators versus business metrics. A
  790. 25:34KPI is going to provide a direct line of
  791. 25:36action to a business goal. Whereas
  792. 25:38business metrics don't necessarily
  793. 25:40contribute directly towards a goal. KPIs
  794. 25:42are measured actively as a benchmark to
  795. 25:44a goal. Whereas business metrics can be
  796. 25:47measured, but they aren't typically
  797. 25:48checked and monitored. For example, at a
  798. 25:50previous company I was working with, we
  799. 25:51had lots of metrics that we kept kind of
  800. 25:54tabs on, but we only put the key
  801. 25:56performance indicators or the most
  802. 25:58important ones into dashboards or maybe
  803. 26:00into reports that we would then provide
  804. 26:02to our users. Next, KPIs are a set of
  805. 26:05standards that are vital to the
  806. 26:06business. Whereas metrics may or may not
  807. 26:08be vital to the business. Again, could
  808. 26:10be anything versus KPIs are like the
  809. 26:12core things that you want to track and
  810. 26:13get better at. And then lastly, this is
  811. 26:15something I mentioned before. All KPIs
  812. 26:18are business metrics, but not all
  813. 26:19business metrics are KPIs. You specify
  814. 26:22exactly what metrics you want to be KPIs
  815. 26:25to help move your business or grow your
  816. 26:27business, however you want to do that.
  817. 26:29So, in a nutshell, a metric helps us
  818. 26:31understand what's happening in our data.
  819. 26:32And KPIs show us whether we're reaching
  820. 26:34our goals using our data. I hope that
  821. 26:37this was helpful. This was not something
  822. 26:38that I knew when I first started uh
  823. 26:40working in data. It's something I kind
  824. 26:42of figured out along the way. But if you
  825. 26:44are just getting into data, or maybe you
  826. 26:46already are and you don't know what this
  827. 26:47is, now you know. And now you can go
  828. 26:49into business meetings and you can go
  829. 26:50into conversations being a little bit
  830. 26:52more knowledgeable. What's going on
  831. 26:54everybody? Welcome back to another
  832. 26:55video. Today we're going to be taking a
  833. 26:57look at data types.
  834. 27:04If you've worked with data at all, you
  835. 27:05know that data types are very important.
  836. 27:07And if you haven't, you're in the right
  837. 27:08place cuz we're going to talk a lot
  838. 27:10about what data types are and how they
  839. 27:12are used. So with that being said, let's
  840. 27:13jump onto my screen and take a look. So
  841. 27:15let's dive into it. Let's take a look at
  842. 27:17what data types are. Now data types,
  843. 27:20really quickly before we jump into the
  844. 27:22definition, data types are something
  845. 27:23that if you work with any data in any
  846. 27:26way, data types do pertain to you. These
  847. 27:29are things that you need to know. These
  848. 27:31are things that eventually will either
  849. 27:33help you or hinder you on whatever
  850. 27:35you're trying to get done. So a data
  851. 27:38type is an attribute associated with a
  852. 27:40piece of data that tells a computer
  853. 27:42system how to interpret its value. Every
  854. 27:44single programming language, every
  855. 27:46database has similar but slightly
  856. 27:48different data types. I've worked with
  857. 27:50all types of programming languages and
  858. 27:52lots of different databases and they all
  859. 27:54act somewhat similarly, but they can be
  860. 27:56different at times. So knowing the core
  861. 27:58concepts that we're going to cover in
  862. 28:00this lesson can be really helpful to
  863. 28:02kind of traverse the different types of
  864. 28:04data types in different systems. To get
  865. 28:05started, there are a ton of different
  866. 28:08data types. I mean, there's probably 50,
  867. 28:0960, 70 different data types. I'm just
  868. 28:11throwing out random numbers, but they
  869. 28:13all fall under certain categories.
  870. 28:16They're usually either strings, which
  871. 28:18are things like free text, numbers, like
  872. 28:201 2 3 or date and time. So, January 1st
  873. 28:23of 2024 at 6 p.m. These are kind of the
  874. 28:26core fundamental data types. But under
  875. 28:29each of these are a lot of other data
  876. 28:31types as well. Now within string you
  877. 28:33could have something like a name. John
  878. 28:35Smith, Emma Johnson. This is very simple
  879. 28:38data that you can categorize and you can
  880. 28:40use. Next it could be an address. 123
  881. 28:42Main Street, New York, New York. This is
  882. 28:44something that can determine a location.
  883. 28:46Then we have something like product
  884. 28:47categories, electronics, furniture, etc.
  885. 28:49These product categories are all
  886. 28:51strings, but then can be used later on
  887. 28:53in the data process for things like
  888. 28:55aggregation. Maybe you want to see how
  889. 28:56many customers are buying electronics at
  890. 28:58your store versus furniture at your
  891. 29:00store. You have to collect that data.
  892. 29:02You do that with string data. Next, we
  893. 29:04have numerical or numbers. This is
  894. 29:07probably the most simple data type. It's
  895. 29:09integers. 25 100 - 15. Then we also have
  896. 29:13decimals. These are both two separate
  897. 29:15data types. So decimals is like 12.5
  898. 29:1899.99.
  899. 29:20Now within certain systems, especially
  900. 29:21databases, they'll have something like a
  901. 29:24big integer for really large numbers.
  902. 29:26They'll have something like a small
  903. 29:27integer. They'll also have just a
  904. 29:29regular integer. Within decimals, they
  905. 29:30may have something like a double point
  906. 29:32system or a decimal data type. So within
  907. 29:35each of these, they may have even
  908. 29:37subcategories of data types. Next, we
  909. 29:39have date time. The dates could be
  910. 29:41something simple like 1210 of 2024. We
  911. 29:44have a day, a month, and a year or it
  912. 29:46could be month day year. There are
  913. 29:48different formats within dates. Then we
  914. 29:51have times or timestamps. So times just
  915. 29:54indicate the time of the day. Then
  916. 29:56timestamps are both date and time
  917. 29:58combined. So the timestamps tend to be
  918. 30:01very specific. Then we have dates which
  919. 30:03give a general day and then times that
  920. 30:06just give a specific time. Timestamps
  921. 30:08can be very useful, but often times when
  922. 30:11you're working with it in the real
  923. 30:13world, you'll break out these two data
  924. 30:15into separate columns. You have date in
  925. 30:17one, time in another, and that may allow
  926. 30:19you to do more advanced things with this
  927. 30:21data. So understanding what data type
  928. 30:24your data is is really important because
  929. 30:26that allows you to work with it and
  930. 30:28analyze that data in different ways. For
  931. 30:30example, if we're working with numerical
  932. 30:32data, we can use that to calculate
  933. 30:34averages. You can say the average person
  934. 30:36is spending this much on our website per
  935. 30:38day. That would be an example of how you
  936. 30:40can use numerical data. Or with string
  937. 30:42data types or categorical data, you can
  938. 30:45group it and count on those occurrences.
  939. 30:47Or you can do any type of aggregation.
  940. 30:49sum, max, min, average, median, all
  941. 30:52these different things. You can see how
  942. 30:54many people are buying things in our
  943. 30:56electrical department versus our
  944. 30:57furniture department. And that is
  945. 30:59worthwhile data to use. That really is
  946. 31:01the basics of data types. Now, if you go
  947. 31:04into specific things like if you go into
  948. 31:06SQL or if you go into Python or Excel, I
  949. 31:09have a lot of lessons specifically for
  950. 31:11data types in those systems and then it
  951. 31:13gets a little bit more complex. And so
  952. 31:15if you want to really dive into data
  953. 31:17types in a specific system, go into any
  954. 31:19of my playlists, whether it's SQL,
  955. 31:21Excel, uh PowerBI, Tableau, they all
  956. 31:23have different data types and you can
  957. 31:25learn a lot more about data types within
  958. 31:27that specific tool. What's going on
  959. 31:29everybody? Welcome back to another
  960. 31:30video. Today we're going to be taking a
  961. 31:31look at file types.
  962. 31:39Now, file types or file formats are
  963. 31:41everywhere. If you've saved any type of
  964. 31:43file ever to your computer, you had to
  965. 31:44save that as a specific file type. So,
  966. 31:47in this lesson, we're going to be diving
  967. 31:48into exactly what file types and file
  968. 31:50formats are and how they are used. So,
  969. 31:52with that being said, let's jump over to
  970. 31:53my screen and take a look. All right, so
  971. 31:54let's take a look at what file types
  972. 31:57are. File types refer to the format in
  973. 31:59which data is stored in a file. And
  974. 32:01you're going to see even in the next
  975. 32:02slide, there are so many different file
  976. 32:05types out there. There are a lot. And
  977. 32:07we're going to get into specific file
  978. 32:08types in this video that you can see a
  979. 32:10lot of the different types of files that
  980. 32:12are very commonly used. Each file type
  981. 32:14is designed for a specific purpose and
  982. 32:16it depends on what kind of data it's
  983. 32:18holding and how it's going to be used or
  984. 32:20shared. You really can think of these
  985. 32:21like a container, whether it's a bowl or
  986. 32:24a plate or it's a vase. Each one of
  987. 32:26these containers is designed to hold
  988. 32:29different things. And that's kind of
  989. 32:30like what a file type is used for. Now,
  990. 32:32if you go right now, you look at your
  991. 32:34file explorer if you're using a Windows
  992. 32:36machine. If you go to your view and you
  993. 32:37look at the details, the view is right
  994. 32:39next to the sort button up there, you
  995. 32:41can see the different type of file type.
  996. 32:44And with all this is my actual, you
  997. 32:46know, file explorer right now. If you go
  998. 32:47look in my downloads, we have a lot of
  999. 32:50different stuff. I have MP4 files. I
  1000. 32:52have different file folders that holds
  1001. 32:53different files. I have PGs, I have
  1002. 32:55CSVs, I have PDFs, I have all sorts of
  1003. 32:58stuff. To the right of this you can see
  1004. 33:00the size as well. All these different
  1005. 33:03file types hold the data differently and
  1006. 33:06some take a lot more data than others.
  1007. 33:08So that size is how much data is
  1008. 33:11actually stored within that file. Let's
  1009. 33:12take a look at probably the most simple
  1010. 33:14type of data file or data format that
  1011. 33:16you'll see which is a text file. A text
  1012. 33:18file is super simple and just stores
  1013. 33:20data as plain text often used for
  1014. 33:23unformatted or tabular data. This is
  1015. 33:25data that I would work with all the time
  1016. 33:27as a data analyst. We would work with
  1017. 33:29text files and CSV which stands for
  1018. 33:32commaepparated values. This image on the
  1019. 33:34right hand side is being stored right
  1020. 33:36now as a text file. But if I then went
  1021. 33:38and saved it as a CSV, it would separate
  1022. 33:41these values based off of the commas. So
  1023. 33:44country, salesperson, order amount,
  1024. 33:45quarter, this data would be separated
  1025. 33:48and all the commas going down on each
  1026. 33:50row would be separated into basically
  1027. 33:51columns and rows. DSV and text files are
  1028. 33:54super common and they can store a lot of
  1029. 33:56data very simply because they're just
  1030. 33:59storing plain text and so it doesn't get
  1031. 34:01super complex and so it's a very popular
  1032. 34:03type of file format. Next we have
  1033. 34:05structured file types. Now these are
  1034. 34:07files that store data in a predefined
  1035. 34:10structure typically rows and columns or
  1036. 34:12in a hierarchal format. One of the most
  1037. 34:15common types is one that I'm sure almost
  1038. 34:16everyone has used. That's an XLSX.
  1039. 34:19That's going to be an Excel file. your
  1040. 34:21typical Excel workbook. And so right
  1041. 34:23here on the right hand side, this is
  1042. 34:24your standard workbook. You're going to
  1043. 34:26have columns and rows and different
  1044. 34:27worksheets and you'll be able to do
  1045. 34:29different things with that data in these
  1046. 34:31Excel files. We also have a DB file and
  1047. 34:34this stands for a database file. So
  1048. 34:37oftent times in the data world, if
  1049. 34:39you're working with a customer or a
  1050. 34:40client, they might give you an entire
  1051. 34:42backup of their database and you can go
  1052. 34:44and use that. And within that database,
  1053. 34:47they're going to have columns and rows,
  1054. 34:48especially if it's a relational
  1055. 34:50database. They're going to have columns
  1056. 34:51and rows just like an Excel file, but on
  1057. 34:54a much larger scale. It typically can
  1058. 34:56hold a lot more data. And then, of
  1059. 34:58course, you get more complex things
  1060. 34:59within a database file, like database
  1061. 35:02schemas to connect and bring all that
  1062. 35:04data together. Next, we have
  1063. 35:05semistructured file types. Now, these
  1064. 35:08get a little bit more complex. These
  1065. 35:10file types have a loose structure, often
  1066. 35:11used to store complex data
  1067. 35:13relationships. Some common formats for
  1068. 35:15this are JSON and XML files. Now, these
  1069. 35:17can get a lot more complex than just
  1070. 35:19columns and rows because in columns and
  1071. 35:21rows, it's pretty simple. It's pretty
  1072. 35:22straightforward. But something like a
  1073. 35:24JSON file, which we have on the right
  1074. 35:26hand side, you can have data nested
  1075. 35:27within other data, which just means data
  1076. 35:29within data within data. And so, there
  1077. 35:31can be lots of layers to this data. This
  1078. 35:33is another one that's just really
  1079. 35:34popular and really common within data
  1080. 35:36professionals. And they are really great
  1081. 35:38for storing data that's a little bit too
  1082. 35:40complex for something that's really
  1083. 35:41simple like columns and rows. Next, we
  1084. 35:43have unstructured file types. Now, you
  1085. 35:45saw this within my file explorer. These
  1086. 35:47are files that don't follow a specific
  1087. 35:49format. They don't have columns and
  1088. 35:51rows. They're often just raw data or
  1089. 35:53multimedia data. For example, this video
  1090. 35:55that I'm recording right now, I'm
  1091. 35:56recording onto an MP4 file. This image
  1092. 35:59on the right of this beautiful little
  1093. 36:01hummingbird is apng or there's actually
  1094. 36:04lots of different formats for images,
  1095. 36:06but PNG is probably the most common one.
  1096. 36:08Lastly, we have big data and specialized
  1097. 36:11file types. So, these file types are
  1098. 36:13designed specifically to handle really
  1099. 36:15largecale data efficiently. One of the
  1100. 36:18most common and one that if you've
  1101. 36:19worked in the data world or you've
  1102. 36:20worked in Azure or maybe even AWS that
  1103. 36:23you might be familiar with, it's
  1104. 36:24something called a parquet file. Paret
  1105. 36:27files are very common, especially if
  1106. 36:29you're working in something like Spark.
  1107. 36:30That's something where I've used it
  1108. 36:32quite a bit or even data bricks where
  1109. 36:33you're bringing in massive amounts of
  1110. 36:35data and you want to do that in a really
  1111. 36:37efficient manner. So, it has all these
  1112. 36:39different properties that they bring in
  1113. 36:40to these paret files that a normal CSV
  1114. 36:43file would never be able to do or
  1115. 36:45handle. Now, what file type you choose
  1116. 36:46can be extremely extremely important.
  1117. 36:49And I've made a lot of mistakes over my
  1118. 36:51years as a data analyst storing data in,
  1119. 36:53you know, one file format versus
  1120. 36:54another. And that has caused issues. And
  1121. 36:57so, and so knowing how data actually is
  1122. 36:59collected and used and stored and
  1123. 37:01analyzed and shared, you have to take
  1124. 37:03all these things into account when
  1125. 37:05you're determining what kind of file
  1126. 37:06type you want. Now, in the next lesson,
  1127. 37:09we're going to be looking at data
  1128. 37:10collection. And we're going to address
  1129. 37:12this exact thing because if you store
  1130. 37:14data in a specific way and then you want
  1131. 37:16to put it in a database, it may not be
  1132. 37:17possible if you store it incorrectly.
  1133. 37:19And so, there are a lot of things to
  1134. 37:20consider within just data collection.
  1135. 37:23But this has been our lesson on file
  1136. 37:25types. What's going on everybody?
  1137. 37:26Welcome back to another video. Today
  1138. 37:28we're going to be talking all about data
  1139. 37:29collection. [music]
  1140. 37:36Now, data collection is an extremely
  1141. 37:38part of getting data. In fact, I was on
  1142. 37:40a data collection team for over 3 years.
  1143. 37:42I absolutely love data collection and so
  1144. 37:44I'm really excited to talk about this
  1145. 37:46topic. Let's not waste any time. Let's
  1146. 37:48jump on my screen and take a look. Let's
  1147. 37:49take a look at data collection. Now,
  1148. 37:52what exactly is data collection? Just as
  1149. 37:54a definition, data collection is the
  1150. 37:56process of gathering data from different
  1151. 37:58data sources to use in analysis,
  1152. 38:00decision-m and problem solving. A data
  1153. 38:03source means where the data is actually
  1154. 38:05being created. And data is created all
  1155. 38:07around us. It could be in a hospital ehr
  1156. 38:09system. It could be in your bank
  1157. 38:11account. It could be through APIs. It
  1158. 38:13could be through a website or it could
  1159. 38:14be in a CSV file. So why is data
  1160. 38:16collection important? And what I really
  1161. 38:18should say is why is it really
  1162. 38:20important? One, it ensures that you have
  1163. 38:22raw material or the raw data needed to
  1164. 38:25make informed decisions. You can then
  1165. 38:26use that data to identify trends,
  1166. 38:29patterns, and opportunities within that
  1167. 38:31data. And it also lays the foundation
  1168. 38:32for data quality. This is something that
  1169. 38:35we're going to cover actually in our
  1170. 38:36next lesson when we look at data
  1171. 38:37cleaning. So, if you collect data poorly
  1172. 38:40or if you do not process that data
  1173. 38:41correctly, that can lead to bad data,
  1174. 38:44which can give you incorrect results and
  1175. 38:45then of course you're going to make bad
  1176. 38:47decisions with bad data. Now, data
  1177. 38:49collection does not just happen. It
  1178. 38:50doesn't just magically appear. This is a
  1179. 38:52very calculated and specific process
  1180. 38:54that needs to happen in order for you to
  1181. 38:56get that data. Let's take just a really
  1182. 38:58quick example. You are actually running
  1183. 39:00an online shop. You have a website.
  1184. 39:02You're selling stuff. On the right,
  1185. 39:03you're selling t-shirts and jackets and
  1186. 39:05other clothes. I'm assuming now you want
  1187. 39:08to track how many customers actually put
  1188. 39:10something into their cart. You might be
  1189. 39:12able to compare how many customers put
  1190. 39:14something into their cart versus how
  1191. 39:16many customers actually bought
  1192. 39:17something. And that could be useful
  1193. 39:18information to you. that data just
  1194. 39:20doesn't appear. A data collection system
  1195. 39:22is set up to collect that data and place
  1196. 39:24it into something like a database so it
  1197. 39:26can be analyzed and used. Now these data
  1198. 39:28collection systems can be something that
  1199. 39:29you manually create and we'll talk about
  1200. 39:31that in a little bit or it could be
  1201. 39:33something that you just pay for. So it
  1202. 39:34could be a system that you say, "Hey, I
  1203. 39:36want you to collect this data." They go
  1204. 39:38and do it for you and you don't have to
  1205. 39:39actually do the work, but there is a
  1206. 39:41data collection system in place. Now
  1207. 39:43whether it's you or some system you paid
  1208. 39:45for, all this data is going to be
  1209. 39:47processed via a data pipeline. Now this
  1210. 39:50is a system that's going to automate the
  1211. 39:51movement of data from one place to
  1212. 39:53another while often transforming it
  1213. 39:55along the way. Let's take a look at this
  1214. 39:57ETL pipeline. ETL stands for extract,
  1215. 40:01transform and load. And you can see that
  1216. 40:03uh through this process. So on the left
  1217. 40:05hand side we have all these different
  1218. 40:06data sources. It could be different
  1219. 40:08parts of your website or it could be
  1220. 40:10different websites or it could be
  1221. 40:11different locations of the data
  1222. 40:12entirely. We're going to extract that
  1223. 40:14raw data and we're going to put it into
  1224. 40:17a staging area. This staging area is
  1225. 40:19kind of like a temporary hold for your
  1226. 40:21data where then you can work with data
  1227. 40:22professionals like data engineers,
  1228. 40:24database developers, data analysts, data
  1229. 40:26scientists who can then determine how we
  1230. 40:28want to transform that data. Now
  1231. 40:30transforming data is something we'll
  1232. 40:32cover again in the next lesson when we
  1233. 40:34talk about data cleaning. But
  1234. 40:35transforming the data makes that raw
  1235. 40:37data more usable for whatever you're
  1236. 40:39trying to use it for. After we transform
  1237. 40:41that data, we're going to load that data
  1238. 40:42into something like a data warehouse, a
  1239. 40:44database, maybe it could even be an
  1240. 40:46Excel file. It could be as simple as
  1241. 40:48that. But then from there, we can use
  1242. 40:50that to analyze our data. And that's
  1243. 40:52really what data collection is in a
  1244. 40:54nutshell. Now, I worked on a data
  1245. 40:56collection team for many years, and I
  1246. 40:58was a data analyst, and I would often
  1247. 41:00work at every single step of this
  1248. 41:02process. I would have to go and talk to
  1249. 41:03the client and see exactly what data
  1250. 41:05they had available and sometimes they
  1251. 41:07didn't even have data available and so
  1252. 41:09they said hey we want to collect this
  1253. 41:10new type of data as part of my job is I
  1254. 41:13would help them understand how to start
  1255. 41:14collecting that data so then we could
  1256. 41:16create these data pipelines to then
  1257. 41:18transfer it into a database to use data
  1258. 41:20collection is not a one-time thing
  1259. 41:22either data collection is always
  1260. 41:24happening these ETL pipelines they break
  1261. 41:27or they need new ones or the source data
  1262. 41:29changed on the left hand side of this
  1263. 41:31diagram the source data changed from one
  1264. 41:33part of the website to another. And so
  1265. 41:34you need to go back and you need to fix
  1266. 41:36that data pipeline to correctly collect
  1267. 41:38all the data that you're wanting. And so
  1268. 41:40this is a very active process. This
  1269. 41:42typically doesn't just happen one time
  1270. 41:44and then it's done. It typically happens
  1271. 41:46one time, then you adapt it and you keep
  1272. 41:48changing or maybe fixing it over time.
  1273. 41:50What's going on everybody? Welcome back
  1274. 41:51to another video. Today we're going to
  1275. 41:53be talking all about data cleaning.
  1276. 42:00Now data cleaning is an essential part
  1277. 42:02of working with any [music] data and so
  1278. 42:03this is a very core fundamental concept
  1279. 42:06that anybody who works with data will
  1280. 42:07need to know. As a data analyst I've
  1281. 42:09cleaned data in almost any way that you
  1282. 42:11can imagine. So I am very excited to
  1283. 42:13talk about this topic. Let's not waste
  1284. 42:14any time. Let's jump on my screen and
  1285. 42:16take a look. All right. So let's take a
  1286. 42:17look at what data cleaning actually is.
  1287. 42:20Data cleaning is the process of
  1288. 42:22identifying and fixing issues aka dirty
  1289. 42:25data in your data to ensure it's
  1290. 42:27accurate, consistent, and complete.
  1291. 42:29Let's take a look at these patient names
  1292. 42:31on the right hand side really quickly.
  1293. 42:33These are all my names, but just in
  1294. 42:35different versions or variations. This
  1295. 42:37is very dirty. So, we have Alex
  1296. 42:39Freeberg, Alexander Freeberg, Alex F,
  1297. 42:41Alexander F, Alex Freeberg with a U,
  1298. 42:43Alejandro Freeberg. These are all the
  1299. 42:46same person. That's all me. But if
  1300. 42:49you're looking at this in a database,
  1301. 42:50it's going to consider all these people
  1302. 42:52different. And so what we would have to
  1303. 42:54do to clean up this data is we would
  1304. 42:56have to make all of these names
  1305. 42:57consistent and the same. Maybe we do
  1306. 42:59that by saying, okay, all these people
  1307. 43:01have the same date of birth. They're all
  1308. 43:03male. They all have the same social
  1309. 43:05security number. But with all of those
  1310. 43:07things, we could say, yes, these are all
  1311. 43:09the same person. We can make all of
  1312. 43:10these patient names Alex Freeberg with
  1313. 43:13an E. That would really clean up this
  1314. 43:14data a lot. Why do we need to clean data
  1315. 43:17at all? What is the reason that we do
  1316. 43:19this? One is to ensure accuracy because
  1317. 43:22you're going to be giving this data to
  1318. 43:24stakeholders or your boss or a customer
  1319. 43:27and they're going to expect that this
  1320. 43:28data is accurate. But if you're giving
  1321. 43:31them bad data, then they may make bad
  1322. 43:32decisions with that data and that's
  1323. 43:34going to come back on you. Next, it
  1324. 43:36improves efficiency. When you are
  1325. 43:38working with clean data, it is 10 times
  1326. 43:40easier to analyze and use that data in
  1327. 43:43any way you need rather than it being
  1328. 43:45really messy and really difficult to
  1329. 43:47work with. Lastly, it builds trust and
  1330. 43:49stakeholders and customers and clients,
  1331. 43:51they want to be able to trust that what
  1332. 43:54you're giving them, the data that you're
  1333. 43:55using is actually accurate and complete.
  1334. 43:58And so those stakeholders are really
  1335. 43:59going to trust you if that data is clean
  1336. 44:00and accurate and you can find insights
  1337. 44:02with that data. Now, let's take a look
  1338. 44:04at some other examples of dirty data.
  1339. 44:06And these are not all of the examples,
  1340. 44:09but these are many of them. Here in this
  1341. 44:10data, we have columns and rows like an
  1342. 44:12Excel file. We have a name, a phone
  1343. 44:14number, an email address, and an
  1344. 44:16address. In each of these, you can see a
  1345. 44:18lot of mistakes. Take for example in the
  1346. 44:20name column. We have things like
  1347. 44:22punctuation marks and abbreviations.
  1348. 44:25These are the same person, just like we
  1349. 44:26looked at in the example with my name.
  1350. 44:28These are all the same person, but each
  1351. 44:30of these records requires a different
  1352. 44:31row of data because it isn't
  1353. 44:32standardized or cleaned. Let's look at
  1354. 44:34phone number. This one shows us missing
  1355. 44:37data. And this is a very common one
  1356. 44:39where you're collecting phone numbers
  1357. 44:41and all of a sudden you just don't have
  1358. 44:42a phone number. So you're missing that
  1359. 44:44data. Now, what are you going to do with
  1360. 44:45that when you're cleaning it? Maybe you
  1361. 44:47need to populate that data. Maybe that
  1362. 44:49is something that you can get from
  1363. 44:50another data source or you know it and
  1364. 44:52you can actually put it in there. That
  1365. 44:54is a way you can clean that data up.
  1366. 44:56Next, we have mixed numbers and letters.
  1367. 44:58It may look like 831262149,
  1368. 45:01but that one is actually an L. And so
  1369. 45:04this is just a classic case of bad data.
  1370. 45:06They should all be in the same format
  1371. 45:08with the phone number, but they're not.
  1372. 45:10Some have dashes, some have commas, some
  1373. 45:12don't have anything, and some even have
  1374. 45:13letters. That's very, very messy. Next,
  1375. 45:16we have email address. Now, within this
  1376. 45:18one, they're all somewhat different,
  1377. 45:20right? We all have different email
  1378. 45:21addresses, and again, that's just a
  1379. 45:23standardization, making them all the
  1380. 45:24same issue. But we also have something
  1381. 45:26like a non-printable character. Now,
  1382. 45:29there are specific characters within
  1383. 45:30computer systems that you just shouldn't
  1384. 45:32be putting or really can't put in
  1385. 45:34specific data types. So, if this is a
  1386. 45:36string, that may be a character that you
  1387. 45:38shouldn't have or can't have. That's
  1388. 45:40going to mess up your data.ly in the
  1389. 45:42address section, we have two issues
  1390. 45:43here. We have messy structure and
  1391. 45:45format. So, some are capitalized.
  1392. 45:49So, so some of the data is capitalized
  1393. 45:51versus not capitalized. We also have
  1394. 45:53incomplete data. For example, we have
  1395. 45:55Emily Renzelli Boulevard, but we don't
  1396. 45:57have a number. We don't have a city. We
  1397. 45:59don't have a state. They're just
  1398. 46:00incomplete. And that makes it really
  1399. 46:02difficult to work with that data. Now,
  1400. 46:04here we have something called a data
  1401. 46:05cleaning cycle. And I really like this
  1402. 46:07visualization because it shows that data
  1403. 46:10cleaning is not just a one-time thing.
  1404. 46:12It is something that you have to
  1405. 46:13continuously do. And I have and I have
  1406. 46:16experienced this a lot over my years as
  1407. 46:18a data analyst. Once you clean data
  1408. 46:20isn't necessarily perfectly cleaned. You
  1409. 46:22kind of have to go back and clean it as
  1410. 46:24you go. And it's never really perfect.
  1411. 46:26it's just really usable. This cycle
  1412. 46:28typically starts at the very top. So we
  1413. 46:30have importing data. This is just
  1414. 46:32bringing in data from other systems,
  1415. 46:34usually through some data collection
  1416. 46:35system like a data pipeline that we
  1417. 46:37talked about in the data collection
  1418. 46:39lesson last time. Next we have merging
  1419. 46:41data sets. This is combining multiple
  1420. 46:43data sources into one data set. Next we
  1421. 46:45have rebuilding missing data. This is
  1422. 46:47where you're handling incomplete data or
  1423. 46:49you're actually filling in that missing
  1424. 46:51data. Next we have standardization and
  1425. 46:52normalization. Standardization is where
  1426. 46:54you're making sure that the data follows
  1427. 46:56a consistent format. So all the date
  1428. 46:58formats are the same. For example, if we
  1429. 47:01go back to this one, we can make sure
  1430. 47:02that the address is all standardized.
  1431. 47:05They all have an address, a city, a
  1432. 47:07state, and maybe a zip code if you need.
  1433. 47:09They all have the same data. Next, we
  1434. 47:11have normalization. This is a little bit
  1435. 47:13different because you're adjusting data
  1436. 47:15to a common scale without distorting the
  1437. 47:17data itself. Next, we have dduplication.
  1438. 47:20And this is where you may have
  1439. 47:21duplicates of data in your columns. For
  1440. 47:24example, maybe we have a 100 columns of
  1441. 47:26Alex Freeberg and we don't need 100
  1442. 47:28columns. It's all the exact same data.
  1443. 47:30We would want to remove 99 of those to
  1444. 47:32just keep the one that we actually need.
  1445. 47:34Next, we have what they call
  1446. 47:35verification and enrichment. This is
  1447. 47:37really just data quality. You're going
  1448. 47:38through and you're validating your data,
  1449. 47:40making sure that your data is accurate.
  1450. 47:42Then lastly, you're saving this clean
  1451. 47:44data in the format that you need for
  1452. 47:46your next processes, whether it's
  1453. 47:47analyzing or you're using in some type
  1454. 47:49of product. Now, one thing I want to
  1455. 47:50mention on here is that this cycle is
  1456. 47:53not perfect. In fact, I usually do
  1457. 47:55dduplication earlier on within this
  1458. 47:58cycle, but it really depends on the data
  1459. 48:00itself. Sometimes you're importing,
  1460. 48:02merging, rebuilding, and then going back
  1461. 48:04and getting more data and then
  1462. 48:05importing, merging, and rebuilding. So,
  1463. 48:07this isn't a perfect cycle. This isn't
  1464. 48:09exactly what you should do every time,
  1465. 48:11but these are often the steps that I am
  1466. 48:13taking when I'm cleaning data. Now, data
  1467. 48:15cleaning is very specific to different
  1468. 48:17tools, and I have a lot of different
  1469. 48:19videos on how to exactly clean data with
  1470. 48:21full projects on data cleaning in SQL
  1471. 48:23and Tableau and PowerBI and Python and
  1472. 48:26Excel. And so, if you want to learn
  1473. 48:27hands-on how to actually clean data, go
  1474. 48:30check out those videos cuz they are
  1475. 48:31fantastic to learn how to actually clean
  1476. 48:33data. Today, we are going to be starting
  1477. 48:35our MySQL tutorial series.
  1478. 48:43Now, the entire MySQL series will be
  1479. 48:45broken up in three smaller series. We'll
  1480. 48:47have our beginner, our intermediate, and
  1481. 48:48our advanced. This lesson is the very
  1482. 48:50first lesson in the beginner series
  1483. 48:52where we're going to walk through all of
  1484. 48:53the beginner or the basics of MySQL.
  1485. 48:56Today, we're going to be setting
  1486. 48:57everything up. So, we'll be installing
  1487. 48:58MySQL and then creating our database
  1488. 49:00that we'll use to actually learn MySQL.
  1489. 49:02Now, before we get started, I wanted to
  1490. 49:04let you know that I created three full
  1491. 49:05MySQL courses over on
  1492. 49:07analystbuilder.com. I built a crash
  1493. 49:09course for MySQL for people who are
  1494. 49:10going to be interviewing or taking
  1495. 49:11technical interviews. I also created a
  1496. 49:13full MySQL course that's going to cover
  1497. 49:15everything from the basics all the way
  1498. 49:17to the intermediate level. And then
  1499. 49:18lastly, I created an advanced course
  1500. 49:20that's going to teach you a lot of the
  1501. 49:21more advanced things that an analyst
  1502. 49:22would typically use. Those courses are
  1503. 49:24going to go really in-depth and they're
  1504. 49:25going to have a lot of practice
  1505. 49:26questions along the way and we'll also
  1506. 49:29have full guided projects in there as
  1507. 49:30well. I'll have links in the description
  1508. 49:32to all of those courses if you want to
  1509. 49:33check those out. Now, without further
  1510. 49:35ado, let's jump on my screen and install
  1511. 49:36my SQL and create our database. All
  1512. 49:38right, so let's get started by
  1513. 49:40downloading MySQL. We're going to come
  1514. 49:42right over here to
  1515. 49:43dev.mmysql.com/downs/installer.
  1516. 49:48And I will have that link in the
  1517. 49:49description so you don't have to write
  1518. 49:50all that out, but you should be seeing
  1519. 49:52this page right here. Now, we have to
  1520. 49:54select an operating system. I'm using a
  1521. 49:56Windows machine. And if you aren't, if
  1522. 49:59you're using Linux or Mac or something
  1523. 50:00else, it should populate it for you. But
  1524. 50:03if it doesn't, just select this dropown
  1525. 50:04and select your operating system. Next,
  1526. 50:06we have two different downloads. We can
  1527. 50:08install the MySQL installer community or
  1528. 50:11MySQL installer web community. This one
  1529. 50:13is very small, but then you actually do
  1530. 50:16have to download the installer. It just
  1531. 50:17gets it from the web. This one I'm going
  1532. 50:19to download the actual installer. It's
  1533. 50:21larger, but this is the one I'm going to
  1534. 50:23do. So, I'm going to go ahead and select
  1535. 50:25download. It's going to ask me if I want
  1536. 50:27to log in or create an account, and I
  1537. 50:30don't. I'm going to say no thanks. Just
  1538. 50:31start my download.
  1539. 50:34I'm going to save this in this desktop
  1540. 50:36folder. Doesn't really matter where you
  1541. 50:37save it. We're going to save that. And
  1542. 50:39it's going to download. It should be
  1543. 50:41done in just a few seconds. I'm going to
  1544. 50:43go ahead and click on it. And it's going
  1545. 50:44to open it up when it's finished. And we
  1546. 50:46should get the interface or the UI for
  1547. 50:48the actual installation for MySQL. So,
  1548. 50:51here is the MySQL installer. And first
  1549. 50:54thing we need to do is choose a setup
  1550. 50:56type. Now, we're going to keep the
  1551. 50:57developer default unless you really know
  1552. 51:00what you're doing. And you can select
  1553. 51:02the server only, the client only, full,
  1554. 51:04which is literally everything MySQL has
  1555. 51:06to offer, or custom. So, we're going to
  1556. 51:09keep this developer default, just
  1557. 51:11installing the things that we kind of
  1558. 51:12need. So, let's go ahead and select
  1559. 51:14next. And for whatever reason on my
  1560. 51:16computer, it's saying this path already
  1561. 51:18exists. You probably won't get that, but
  1562. 51:21I'm just going to go ahead and select
  1563. 51:22next. And then I'll select yes. It keeps
  1564. 51:24doing that. I can't explain why, but it
  1565. 51:27keeps doing that for me even though I've
  1566. 51:28deleted it from my computer completely.
  1567. 51:29U but it just remembers it somewhere in
  1568. 51:31its memory. Now the next thing we need
  1569. 51:34is to check requirements. Now I just
  1570. 51:37have this one. It says I need to
  1571. 51:38download this uh Visual Studio. I'm not
  1572. 51:41going to do that, but on your screen you
  1573. 51:42may have multiple multiple requirements.
  1574. 51:45Typically you're looking at something
  1575. 51:47like this Microsoft Visual C++
  1576. 51:50redistributable package. What you need
  1577. 51:52to do is download this. All you have to
  1578. 51:54do is click download. Once you download
  1579. 51:56and install that on your computer and
  1580. 51:58then we go back, all of those should be
  1581. 52:00gone. That's the one that I see the most
  1582. 52:02when I'm actually working with these
  1583. 52:03requirements. I had to install it myself
  1584. 52:05when I got this new laptop. So, go ahead
  1585. 52:08and install that if you need to. But if
  1586. 52:09yours looks like mine, we don't need
  1587. 52:11this Visual Studio for what we're going
  1588. 52:12to do. We're going to go ahead and
  1589. 52:14select next. It is giving us a prompt
  1590. 52:17that we haven't satisfied all the
  1591. 52:18requirements, but that's okay. We're
  1592. 52:19going to go ahead and select yes as
  1593. 52:21well. Now we're ready to install all of
  1594. 52:23these things. These are all things that
  1595. 52:25MySQL wants you to install. The most
  1596. 52:27important are the server and the
  1597. 52:28workbench, but it does not hurt to have
  1598. 52:30all these other things as well. Some of
  1599. 52:32these connectors are also important. So,
  1600. 52:34we're going to go ahead and execute.
  1601. 52:36This will take just a few minutes. I'll
  1602. 52:38skip ahead uh when they're all done, but
  1603. 52:39this should take just a few minutes and
  1604. 52:41then we'll continue on installing my
  1605. 52:43SQL. So, everything just completed and
  1606. 52:46now we're going to select next. And now
  1607. 52:48we need to actually configure our
  1608. 52:49product. Now really the only one that we
  1609. 52:51actually need to configure is the
  1610. 52:53server. The router says we need to
  1611. 52:55configure it and the samples and
  1612. 52:56examples say we need to configure it as
  1613. 52:58well, but really it's just the server.
  1614. 53:00Let's go ahead and select next. Now
  1615. 53:02we're not going to change anything for
  1616. 53:04this type and networking unless you know
  1617. 53:06what you're doing with the port, the X
  1618. 53:07protocol port. Uh we're not going to
  1619. 53:09change any of this. We'll go ahead and
  1620. 53:11select next. Next thing we need to do is
  1621. 53:13select an authentication method. I'm
  1622. 53:15going to be using a password. I'm not
  1623. 53:17going to be using the legacy
  1624. 53:18authentication method. So, I'm just
  1625. 53:20going to go ahead and create a password.
  1626. 53:22Now, [snorts] for you, and I keep
  1627. 53:24getting this error, and I can't explain
  1628. 53:25why right here for you, you should be
  1629. 53:27creating a password at the bottom. It's
  1630. 53:29remembering my password somehow, and I I
  1631. 53:31really can't explain it, but I'm going
  1632. 53:33to create my password or check my
  1633. 53:34password. Uh, this is one that I already
  1634. 53:37created uh before I deleted it off my
  1635. 53:39computer, but it's still there. Um, so
  1636. 53:41it's saying my password is still good,
  1637. 53:43but if you need to, you should be
  1638. 53:45entering a password and then confirming
  1639. 53:46your password and saving it. And then
  1640. 53:48you should also be checking it as well.
  1641. 53:50And then we're going to configure this
  1642. 53:51as a MySQL server as a Windows service.
  1643. 53:53I'm going to keep that checked. Uh, and
  1644. 53:55we're going to start the MySQL server at
  1645. 53:57system startup. I like that
  1646. 53:58automatically being there. I don't want
  1647. 54:00to mess with that. So, I'm going to keep
  1648. 54:01it as it has it. We're going to go ahead
  1649. 54:03and select next. And the last thing we
  1650. 54:05do is just need to execute this. And
  1651. 54:07then everything we put in there is going
  1652. 54:09to actually go. So, let's run this and
  1653. 54:11execute it. And that just finished. So,
  1654. 54:13let's go ahead and select finish. Now,
  1655. 54:15it says configuration complete for the
  1656. 54:17server, but we also need to configure
  1657. 54:18these other two. Let's take a look at
  1658. 54:20these really quickly. We're not going to
  1659. 54:22do anything on this. It even says we
  1660. 54:24really don't need to do this. We just
  1661. 54:25need to click finish and configuration
  1662. 54:28not needed. Next, we'll do samples and
  1663. 54:30examples. And we can input our password.
  1664. 54:34And all this is really going to do is
  1665. 54:36put in some sample databases for us in
  1666. 54:38our database, which if you want, you
  1667. 54:40definitely can do that. Uh, I just
  1668. 54:42connected. That worked. I'm going to hit
  1669. 54:44next and execute. And it's basically
  1670. 54:47just going to put in a database or two,
  1671. 54:49some sample ones for you to look at. And
  1672. 54:51the configuration is complete. You don't
  1673. 54:53have to do that one, but we'll see that
  1674. 54:55in just a second. We're going to select
  1675. 54:57next. And now the installation is
  1676. 54:59completely done. and we can start my SQL
  1677. 55:02workbench after setup and start my SQL
  1678. 55:04shell after setup. Now, I'm not going to
  1679. 55:06do the shell, so I'm going to actually
  1680. 55:07uncheck that and we're going to select
  1681. 55:09finish.
  1682. 55:11Now, my SQL just popped up for us, and
  1683. 55:13this is exactly what you should be
  1684. 55:15seeing. Now, there's a lot of things in
  1685. 55:16my SQL to learn and know how to do.
  1686. 55:19We're not going to be taking a look at
  1687. 55:20all of that stuff today, but in future
  1688. 55:22lessons, we'll walk through a lot of
  1689. 55:24these different things that kind of
  1690. 55:25correlate with different lessons or
  1691. 55:26things that we're working on in my SQL.
  1692. 55:28The first thing that we're going to
  1693. 55:29click on is right over here. This is our
  1694. 55:31local instance. This is local to just
  1695. 55:34our machine. It's not a connection to,
  1696. 55:36you know, some other database on the
  1697. 55:37cloud or anything like that. It's just
  1698. 55:39our local instance. We're going to go
  1699. 55:41ahead and click on this. So, this is
  1700. 55:43what you should be seeing right here.
  1701. 55:44This is where we're going to actually
  1702. 55:45write all of our SQL code. And I'll show
  1703. 55:47you all this in just a second. But this
  1704. 55:49is where we can actually create our
  1705. 55:50database. And our database is going to
  1706. 55:52go right over here on this lefth hand
  1707. 55:53side. This silica one is actually a
  1708. 55:56sample database. It has a bunch of
  1709. 55:58tables and views store procedures
  1710. 56:00functions has all these things in here
  1711. 56:02if you want to go ahead and mess around
  1712. 56:03with that. What we're about to do is
  1713. 56:05create our own database that we're going
  1714. 56:07to be using throughout this entire
  1715. 56:09series both beginner, intermediate, and
  1716. 56:11advanced. We'll use a lot of this and
  1717. 56:13sometimes we'll import some other ones
  1718. 56:15for different use cases, but this will
  1719. 56:17serve for most of what we're trying to
  1720. 56:19do throughout this entire series. Now,
  1721. 56:21what I'm going to do is I'm going to go
  1722. 56:22ahead and I'm going to say open a SQL
  1723. 56:24script file in a new query tab. And
  1724. 56:26right here, it opened up to a folder
  1725. 56:28that I already created, this mysql
  1726. 56:30beginner series folder. Within it, we
  1727. 56:32have this right here, the parks and
  1728. 56:35recreate_b.
  1729. 56:37Now, in order to get this, you just have
  1730. 56:38to go to the GitHub and download this
  1731. 56:40file. That's all you have to do. We're
  1732. 56:42then going to open this file. So, let's
  1733. 56:44click on it. We're going to say open.
  1734. 56:46And what you're now seeing is basically
  1735. 56:48the query editor. This is where you can
  1736. 56:50write your code. Now, we're not
  1737. 56:52importing a database. We're actually
  1738. 56:53creating it by running code. Now,
  1739. 56:56because this is the first lesson in the
  1740. 56:57beginner series, I'm going to assume
  1741. 56:59that you don't know a ton about MySQL.
  1742. 57:01Really, all this is doing is creating
  1743. 57:03the database name and then we're
  1744. 57:05inserting a few tables into that
  1745. 57:08database and then we're inserting data
  1746. 57:10into those tables. So, this is all of
  1747. 57:12our data that will go into these tables
  1748. 57:14that we create. We only have one, two,
  1749. 57:18three different tables that we're going
  1750. 57:19to be using. So, all you have to do to
  1751. 57:21run this is click this lightning button
  1752. 57:23right up here. We're going to go ahead
  1753. 57:25and execute this. If we come down to the
  1754. 57:28bottom and we pull this up, this is our
  1755. 57:30output. This says six rows affected. And
  1756. 57:34we have a bunch of other things like
  1757. 57:35create table, create table, insert,
  1758. 57:37insert, create table, insert into. These
  1759. 57:40things are all working perfectly. So now
  1760. 57:42if we go ahead and click refresh in our
  1761. 57:45schemas with this refresh button right
  1762. 57:47here, this parks and recreation table is
  1763. 57:50populated. If we go under the tables, we
  1764. 57:52see all of these things. So, now that
  1765. 57:54we've actually created our database and
  1766. 57:56our tables, that's really all we were
  1767. 57:58trying to do in this lesson. But I just
  1768. 58:00want to open up a table really quickly,
  1769. 58:02show you what it looks like, show you
  1770. 58:04how we can run code, and then in the
  1771. 58:06next lesson, we'll start actually
  1772. 58:07learning how to query this data. So,
  1773. 58:10let's go up to employee demographics.
  1774. 58:12We're going to rightclick and select
  1775. 58:14rows limit 1000. This is going to open
  1776. 58:16up a new window right up here and it's
  1777. 58:19going to say select everything from this
  1778. 58:22database dot this table employee
  1779. 58:25demographics and it ends with a
  1780. 58:27semicolon. Now right down here we have
  1781. 58:29this output window. This is the actual
  1782. 58:32data that sits in our table. We have
  1783. 58:35columns right here. So employee ID,
  1784. 58:38first name, last name, age, gender, and
  1785. 58:41birth date. And then here are all of our
  1786. 58:43employees on each row. So these are all
  1787. 58:45separate rows. We have Leslie Nope, Tom
  1788. 58:47Havford, and it goes on and on. So this
  1789. 58:49is all of our data. The most important
  1790. 58:51things to know when we're actually
  1791. 58:52working with this, and I'm going to zoom
  1792. 58:54in, is if we hover over this query right
  1793. 58:57here, and we run it, we can select this
  1794. 58:59execute, which is this lightning bolt
  1795. 59:01with this I, we're going to execute
  1796. 59:04this, and it's going to run this because
  1797. 59:05we're highlighted over it. Now, if we
  1798. 59:08have two queries, let's say this one
  1799. 59:10right here, but let's change it to
  1800. 59:12employee salary. We'll do underscore
  1801. 59:16salary. Let's say we want to query this
  1802. 59:18table. So now if we highlight over this
  1803. 59:21and we go up and select the lightning
  1804. 59:22bolt with the I, now we're looking at a
  1805. 59:25different table. But if we select, even
  1806. 59:28if we're hovering over this, if we
  1807. 59:30select this button, we're going to
  1808. 59:32execute everything in this editor
  1809. 59:34window. So let's run this. And now you
  1810. 59:37can see at the bottom we have two
  1811. 59:38outputs, the employee demographics and
  1812. 59:41the employee salary. So this button is
  1813. 59:43going to run everything in this editor
  1814. 59:45window. Whereas if we select this
  1815. 59:47lightning bolt with the I, we're doing
  1816. 59:49everything that's just under where we
  1817. 59:51have the cursor, where we have it
  1818. 59:53highlighted. The very last thing that I
  1819. 59:55want to mention is that right over here,
  1820. 59:56you may have this up and you probably
  1821. 59:59don't want that. We're not going to do
  1822. 1:00:00any SQL editions in this series. You can
  1823. 1:00:03get rid of that by clicking this button
  1824. 1:00:04right here. So, starting in the next
  1825. 1:00:06lesson, we'll have everything ready to
  1826. 1:00:08go and we will start learning the basics
  1827. 1:00:09of my SQL. I hope you're able to follow
  1828. 1:00:12along, get everything set up how we have
  1829. 1:00:14it on this screen. I am super excited
  1830. 1:00:16about this series. I just I love SQL.
  1831. 1:00:18So, I'm really, really, really excited
  1832. 1:00:20to get started on this with you guys. I
  1833. 1:00:22will see you guys in the next lesson.
  1834. 1:00:24[music]
  1835. 1:00:36Hello everybody. In this lesson, we're
  1836. 1:00:38going to be learning about the select
  1837. 1:00:39statement in MySQL. The select statement
  1838. 1:00:42is used to work with columns and specify
  1839. 1:00:44what columns you want to see in your
  1840. 1:00:45output. The first thing that we need to
  1841. 1:00:47do is open up a tab or an editor window.
  1842. 1:00:50So, let's come right up here to the
  1843. 1:00:51left-hand side and we're going to create
  1844. 1:00:53a new tab. And I'm going to zoom in just
  1845. 1:00:56a little. Now, what we need to do is we
  1846. 1:00:59need to select the actual table that
  1847. 1:01:01we're going to be querying off of. If
  1848. 1:01:04you remember from the very first lesson
  1849. 1:01:05when we set everything up, we came over
  1850. 1:01:07here and we rightclicked and did select
  1851. 1:01:10rows limit 1000. We're not going to do
  1852. 1:01:12that. We're going to actually write it
  1853. 1:01:13out. So, what we need to do to select
  1854. 1:01:16that table, the employee demographics
  1855. 1:01:18table, is we need to select
  1856. 1:01:21everything. That's what this star means.
  1857. 1:01:23The star means everything. All tables,
  1858. 1:01:26all rows. Now, we do have a limit on
  1859. 1:01:28here. We have a limit to 1,000 rows. So,
  1860. 1:01:31if we had a table that had 50,000 rows,
  1861. 1:01:33this limiter would be an issue. It would
  1862. 1:01:36still limit it to 1,000 rows. We would
  1863. 1:01:38have to change that to 2,000, 5,000,
  1864. 1:01:41probably all the way up to 50,000 if we
  1865. 1:01:43wanted to view everything. If we had,
  1866. 1:01:45say, a million rows, we would need to
  1867. 1:01:47come up here and say, don't limit, and
  1868. 1:01:49it would give us a million rows. The
  1869. 1:01:51reason they do this is mostly to keep
  1870. 1:01:53the processing time low. If you have a
  1871. 1:01:56million rows, it's going to take a long
  1872. 1:01:57time for the output to actually appear.
  1873. 1:02:00So, let's come right back here. The next
  1874. 1:02:02thing that we need to do is we need to
  1875. 1:02:03say select everything. And now we need
  1876. 1:02:05to say where we're selecting it from.
  1877. 1:02:08So, we're going to come right down here
  1878. 1:02:09and we're going to say from. And now we
  1879. 1:02:12need to specify what table. And we're
  1880. 1:02:14going to say employee
  1881. 1:02:17demographics. And at the end, we need a
  1882. 1:02:20semicolon. Now, why do we need a
  1883. 1:02:22semicolon? This is going to tell my SQL
  1884. 1:02:25that this is the end of this query. So,
  1885. 1:02:28if we write another one down here, which
  1886. 1:02:30we will in just a second, it'll be able
  1887. 1:02:32to distinguish between the two queries.
  1888. 1:02:34We're going to go ahead and we're going
  1889. 1:02:35to run this and we'll just use this
  1890. 1:02:37execute right here instead of this one.
  1891. 1:02:40And there we have our entire table. So,
  1892. 1:02:42we were able to get our table. Now,
  1893. 1:02:44there is one thing that is potentially
  1894. 1:02:46wrong depending on what you're using it
  1895. 1:02:48for. But what we didn't do is we did not
  1896. 1:02:51specify the actual database before it.
  1897. 1:02:54We only specified the table. And this
  1898. 1:02:56works perfectly fine because if you look
  1899. 1:02:59over here on this left-h hand side, we
  1900. 1:03:00have parks and recreation. It's in
  1901. 1:03:03black. It's bold. That means that we're
  1902. 1:03:05hitting off of this database. What's
  1903. 1:03:08going to happen though if we come down
  1904. 1:03:09here to the CIS database and we double
  1905. 1:03:10click on it? Now this database is
  1906. 1:03:13highlighted. So now when we're selecting
  1907. 1:03:16this table, we're trying to select this
  1908. 1:03:18table from the CIS database. Let's go
  1909. 1:03:20ahead and try this.
  1910. 1:03:23If you notice, we have no output. Let's
  1911. 1:03:25come right down here and pull this up.
  1912. 1:03:28It's going to say employee cis.mp
  1913. 1:03:30employee demographics doesn't exist. So
  1914. 1:03:34it's assuming that we're highlighting
  1915. 1:03:36this CIS database. That means we're
  1916. 1:03:38trying to pull from that database. Now
  1917. 1:03:40we can still have this highlighted and
  1918. 1:03:43still select the correct database by
  1919. 1:03:45saying parks_and_recreation
  1920. 1:03:51and let me spell that right dot. So now
  1921. 1:03:54we're selecting everything from parks
  1922. 1:03:56and recreation employee demographics. If
  1923. 1:03:59we run this, we do get the correct
  1924. 1:04:02output. That's just something to
  1925. 1:04:04consider, especially when you're working
  1926. 1:04:06with a lot of databases and a lot of
  1927. 1:04:08tables. It's usually best practice to
  1928. 1:04:11actually put the database in front of
  1929. 1:04:14the table name. Although throughout this
  1930. 1:04:16lesson, we probably won't be doing that
  1931. 1:04:17every time since we're only going to be
  1932. 1:04:19using this parks and recreation
  1933. 1:04:20database. Let's go ahead and double
  1934. 1:04:22click this so we have this highlighted
  1935. 1:04:24again. And let's click all of this.
  1936. 1:04:27Let's copy all of this. We're going to
  1937. 1:04:29come down just a little bit right here.
  1938. 1:04:31Now, so far we've only selected
  1939. 1:04:33everything, but we don't have to do
  1940. 1:04:35that. We can actually just select one
  1941. 1:04:37column if we would like to. For example,
  1942. 1:04:39if we got rid of that star, we say first
  1943. 1:04:42name. We're selecting the first name
  1944. 1:04:45column from this table. If we highlight
  1945. 1:04:48this query and we hit the execute button
  1946. 1:04:51with the I.
  1947. 1:04:54Now, we are only going to return in our
  1948. 1:04:56output all of the first names. And we
  1949. 1:04:58can add a lot more. Let's actually look
  1950. 1:05:00at all these. We can separate multiple
  1951. 1:05:03columns with a comma. So we can do first
  1952. 1:05:05name, last name, and then we could do
  1953. 1:05:09birth date. So now we have three
  1954. 1:05:12separate columns. Let's go ahead and run
  1955. 1:05:14this. And now we have first name, last
  1956. 1:05:17name, and birth date in our output. Now
  1957. 1:05:19the way we just wrote it is all on one
  1958. 1:05:21line. And that's perfectly acceptable
  1959. 1:05:23because my SQL is going to read it the
  1960. 1:05:25exact same as if we did it in a
  1961. 1:05:27different format as long as it's still
  1962. 1:05:29in this order. But sometimes you'll see
  1963. 1:05:32it like this where it's select first
  1964. 1:05:34name, last name, comma, birth date all
  1965. 1:05:37on different rows. Now, there's a lot of
  1966. 1:05:39different use cases for this or reasons
  1967. 1:05:41for this, but it typically can be easier
  1968. 1:05:44to read. Also, if you're doing any type
  1969. 1:05:46of functions or calculations in the
  1970. 1:05:48select statement, it's easier to
  1971. 1:05:50separate those out on its individual
  1972. 1:05:53row. Now, again, we won't always be
  1973. 1:05:54doing this, but it does help sometimes
  1974. 1:05:57if you're doing that. It just makes it
  1975. 1:05:58easier to visualize. For example, if we
  1976. 1:06:01added the age. So, let's add age in
  1977. 1:06:03here. Let's run this. Let's say we were
  1978. 1:06:06doing a calculation where we wanted to
  1979. 1:06:07add, you know, 10 years to their age.
  1980. 1:06:10So, we'll say age and we'll actually
  1981. 1:06:12create a new row for this or new column.
  1982. 1:06:15We'll do age + 10. So, now we can easily
  1983. 1:06:19see that we're doing plus 10 here. And
  1984. 1:06:20this is another thing that you can do in
  1985. 1:06:22the select statement, things like
  1986. 1:06:24calculations. So, if we go up here and
  1987. 1:06:26we run this, we'll now have an age
  1988. 1:06:29column, but we'll also have an age + 10
  1989. 1:06:32column where it just adds 10 to the age.
  1990. 1:06:34And we can at least visualize and really
  1991. 1:06:36easily see this when we're doing these
  1992. 1:06:38calculations. Now, something really
  1993. 1:06:40important to know about any type of
  1994. 1:06:42calculations, any math within my SQL is
  1995. 1:06:45that it follows the rules of PEMDOS.
  1996. 1:06:48Now, PEMDOSS is written like this. It's
  1997. 1:06:50PMDES.
  1998. 1:06:52Now, what I just did right here with
  1999. 1:06:54this pound or this hashtag is actually
  2000. 1:06:56create a comment. So, this code isn't
  2001. 1:06:58going to actually run, but it's just for
  2002. 1:07:00note-taking or seeing things in your
  2003. 1:07:02actual editor window. I'll come back to
  2004. 1:07:05comments in just a second, but just
  2005. 1:07:06wanted to explain what that was. Now,
  2006. 1:07:08what PEMDOS is is the order of
  2007. 1:07:11operations for arithmetic or math within
  2008. 1:07:15my SQL. This stands for parentheses,
  2009. 1:07:18exponent, multiplication, division,
  2010. 1:07:20addition, and subtraction. So this is
  2011. 1:07:22the order that these calculations are
  2012. 1:07:24going to run in the execution engine
  2013. 1:07:27that my SQL has. So if I do age + 10,
  2014. 1:07:31and we'll put that all in parenthesis,
  2015. 1:07:33and then we come over here and we add*
  2016. 1:07:3510. So we're doing plus 10 here and then
  2017. 1:07:37a time 10 here. What's going to actually
  2018. 1:07:40happen is it's going to say age + 10. So
  2019. 1:07:4344 + 10= 54. Then we're multiplying time
  2020. 1:07:4710. The parenthesis executes first
  2021. 1:07:50because it comes first in this order.
  2022. 1:07:52Parenthesis. Multiplication comes next
  2023. 1:07:54because it's this one. And then anything
  2024. 1:07:56else after that if we did, you know,
  2025. 1:07:58plus 10 could run this. And you'll
  2026. 1:08:02notice that it still follows the logic.
  2027. 1:08:0410 was just added at the very end to all
  2028. 1:08:06of these outputs. Now let's go right
  2029. 1:08:08back up here. Let's select everything
  2030. 1:08:09again from this table. Let's pull up
  2031. 1:08:12this table. so we can see it a little
  2032. 1:08:13better. And let's go down because the
  2033. 1:08:17last thing that I want to show you is
  2034. 1:08:19something called distinct. Now, this is
  2035. 1:08:21really, really useful and you use this a
  2036. 1:08:23lot in my SQL. What distinct is going to
  2037. 1:08:26do is it's going to select only the
  2038. 1:08:28unique values within a column. Let's go
  2039. 1:08:31ahead and copy this employee
  2040. 1:08:33demographics. Bring it right down here.
  2041. 1:08:36Let's say select and let's do first
  2042. 1:08:40name. So now we're just selecting the
  2043. 1:08:42first name. Let's come right down here.
  2044. 1:08:48There we go. So now we're selecting just
  2045. 1:08:50the first name from this column. Now
  2046. 1:08:52these are all unique values. So if we
  2047. 1:08:55come right here and we say distinct,
  2048. 1:08:58nothing should happen to this table cuz
  2049. 1:08:59these are all unique values. Let's go
  2050. 1:09:01ahead and run this.
  2051. 1:09:03As you can see, the output looks exactly
  2052. 1:09:05the same. But what if we were do
  2053. 1:09:08something like gender? So let's come
  2054. 1:09:11here. Let's do gender. Let's run this.
  2055. 1:09:14Keeps going down. I don't know why it's
  2056. 1:09:15doing that. Um but now we have male and
  2057. 1:09:18female. Now these are not all unique. We
  2058. 1:09:20have female, female, female, and female.
  2059. 1:09:23And the rest are males. So there's only
  2060. 1:09:25two unique values here. So if we come
  2061. 1:09:27right here and we say distinct gender,
  2062. 1:09:30now there should only be two in the
  2063. 1:09:32output, male and female. Let's go ahead
  2064. 1:09:34and run this.
  2065. 1:09:36So now we get male and female in our
  2066. 1:09:38output. Now this works perfectly in one
  2067. 1:09:41column but what happens if we have two
  2068. 1:09:42columns. So let's do first name, gender.
  2069. 1:09:47Let's go and run this.
  2070. 1:09:49Now the combination of first name and
  2071. 1:09:52gender are no longer unique. Now Leslie
  2072. 1:09:56and female are being grouped together
  2073. 1:09:58and it's taking the distinct between
  2074. 1:10:00both of these columns. So when we're
  2075. 1:10:02only working with gender, it's only
  2076. 1:10:04looking at this one column for both male
  2077. 1:10:06and female. it reduces it down to the
  2078. 1:10:08only two unique values. But because we
  2079. 1:10:11add the first name, all of these values
  2080. 1:10:13are unique. So therefore, the name plus
  2081. 1:10:16the gender combination is always going
  2082. 1:10:18to be unique. The very last thing that I
  2083. 1:10:20want to show you in this lesson doesn't
  2084. 1:10:22actually pertain to the select
  2085. 1:10:23statement, but I want to save this code.
  2086. 1:10:25Let's say we wanted to update this or
  2087. 1:10:27upload this into our GitHub or save this
  2088. 1:10:30and send it to somebody. We can do that.
  2089. 1:10:32We can save it by clicking this save
  2090. 1:10:34button right here. I'm going to go ahead
  2091. 1:10:36and click this. And now we're in our
  2092. 1:10:37MySQL beginner series folder. I'm just
  2093. 1:10:40going to save this. And I can save this
  2094. 1:10:41as anything I want. So I'm going to say
  2095. 1:10:42two dot select statement
  2096. 1:10:46tutorial. So now when I save this,
  2097. 1:10:49you'll notice that the name gets changed
  2098. 1:10:51up here to two select statement
  2099. 1:10:53tutorial. Let's exit out of this. I'm
  2100. 1:10:55going to open up and now I'm going to
  2101. 1:10:57come here to the select statement
  2102. 1:10:58tutorial. I'm going to open it. And now
  2103. 1:11:01I have our code again exactly as we had
  2104. 1:11:04it written before. I just wanted to show
  2105. 1:11:05that to you in case you wanted to save
  2106. 1:11:07your code as you go throughout this
  2107. 1:11:08series because that's usually what I do
  2108. 1:11:10when I'm working with this stuff or
  2109. 1:11:12learning these things. Like to save my
  2110. 1:11:13code as I go along. So with that being
  2111. 1:11:16said, that is the end of the select
  2112. 1:11:18statement. In the next lesson, we're
  2113. 1:11:20going to be learning about the where
  2114. 1:11:21statement where we can actually filter
  2115. 1:11:22our data.
  2116. 1:11:26[music]
  2117. 1:11:36Hello everybody. In this lesson, we're
  2118. 1:11:38going to be taking a look at the wear
  2119. 1:11:39clause. The wear clause is used to help
  2120. 1:11:41filter our records or our rows of data,
  2121. 1:11:44whereas the select statement is used to
  2122. 1:11:46help filter or select our actual
  2123. 1:11:49columns. So, when we're using the wear
  2124. 1:11:51clause, we're only going to return the
  2125. 1:11:52rows that fulfill a specific condition.
  2126. 1:11:55Let's take a look at exactly how this
  2127. 1:11:57works. Let's say we come right up here.
  2128. 1:11:59We're going to say where. And let's go
  2129. 1:12:02down with that one. Let's say where. And
  2130. 1:12:04now we need to specify what column we're
  2131. 1:12:06about to create this condition for. So
  2132. 1:12:08we're going to say first name. So we're
  2133. 1:12:11saying where the first name we'll say is
  2134. 1:12:14equal to and let's do quotes. And let's
  2135. 1:12:16say Leslie. So we're saying the first
  2136. 1:12:19name has to be equal to this value right
  2137. 1:12:22here, which is Leslie for Leslie. Nope.
  2138. 1:12:25If we run this, there's only going to be
  2139. 1:12:28one row that's returned because Leslie
  2140. 1:12:30is the only Leslie in this entire table.
  2141. 1:12:33Now, we just used an equal sign, and
  2142. 1:12:36that's actually called a comparison
  2143. 1:12:37operator. And there's a few other
  2144. 1:12:39comparison operators that you can use.
  2145. 1:12:42Let's take a look at some of these other
  2146. 1:12:43ones. Let's pull this down right down
  2147. 1:12:46here. And let's actually highlight the
  2148. 1:12:49select from, and we're going to run it
  2149. 1:12:51with this one right here. It's going to
  2150. 1:12:53only select everything from the whole
  2151. 1:12:55table. So, we didn't select that wear
  2152. 1:12:57clause. Let's go right down here and
  2153. 1:12:59let's look at this salary field. So, I'm
  2154. 1:13:03going to say where the salary and I'm
  2155. 1:13:05going to do a different comparison
  2156. 1:13:07operator called greater than. So, when
  2157. 1:13:09the salary is greater than 50,000. Now,
  2158. 1:13:13one thing I want to note before we
  2159. 1:13:14actually run this is that right down
  2160. 1:13:16here we have Tom Havford who makes
  2161. 1:13:18exactly 50,000. And I think there's one
  2162. 1:13:21more, Jerry Gurgich, which also makes
  2163. 1:13:24exactly 50,000. If we run this, you'll
  2164. 1:13:28notice that both Tom and Jerry are not
  2165. 1:13:30in this output. But in the salary field,
  2166. 1:13:32everything is greater than 50,000. The
  2167. 1:13:35reason for that is that Tom and Jerry
  2168. 1:13:38made exactly 50,000. What we're saying
  2169. 1:13:41right here is where the salary is only
  2170. 1:13:43greater than. If we want to include Tom
  2171. 1:13:46and Jerry, we have to say greater than
  2172. 1:13:48or equal to. And now we'll select 50,000
  2173. 1:13:51or above. Whereas right here, before
  2174. 1:13:54when we were doing just this, it was
  2175. 1:13:56greater than 50. It didn't include the
  2176. 1:13:5850,000. Let's go ahead and include it
  2177. 1:14:00and run this. And now you'll notice that
  2178. 1:14:03Tom and Jerry were both included because
  2179. 1:14:06they had exactly 50,000 and we said
  2180. 1:14:08greater than or equal to. Now we can do
  2181. 1:14:11the exact same thing but with less than.
  2182. 1:14:14So we have less than 50,000.
  2183. 1:14:17And now we only have two people who make
  2184. 1:14:19less than 50,000. That's April and Andy.
  2185. 1:14:22And if we say less than or equal to, and
  2186. 1:14:25we run that, now we include both Tom and
  2187. 1:14:27Jerry who make exactly 50,000. So it's
  2188. 1:14:30less than or equal to $50,000. Now what
  2189. 1:14:33we're going to do is head on over to a
  2190. 1:14:36different table. We're going to do the
  2191. 1:14:38demographics table.
  2192. 1:14:41Make sure I spell that right. And let's
  2193. 1:14:43add our semicolon. Let's run this. And
  2194. 1:14:46what we want to look at is the gender
  2195. 1:14:49really quick. So we're going to say
  2196. 1:14:51where the gender is equal to, we'll do
  2197. 1:14:55in quotes female. And if we run this, we
  2198. 1:15:00get all the genders that are equal to
  2199. 1:15:02female. But we do have something called
  2200. 1:15:05the not equal to. And it looks like
  2201. 1:15:07this. It's an exclamation point and an
  2202. 1:15:10equal sign. This is going to say where
  2203. 1:15:12the gender is not equal to female. So if
  2204. 1:15:14we run this, you'll notice that the
  2205. 1:15:17gender is all male. Now, now so far
  2206. 1:15:19we've worked with things like integers,
  2207. 1:15:21which are numbers. We've worked with
  2208. 1:15:23characters or strings like names. But
  2209. 1:15:27there's a different type of data type as
  2210. 1:15:28well in here. We have a date column for
  2211. 1:15:31these birth dates. Now, in the wear
  2212. 1:15:33clause, we can also filter on birth
  2213. 1:15:35dates. Let's come over here and we'll
  2214. 1:15:37say birth
  2215. 1:15:39date. Let's say it's greater than and
  2216. 1:15:41within quotes we'll say 1985-01-01.
  2217. 1:15:47This is kind of the standard default
  2218. 1:15:49date format within my SQL which is year,
  2219. 1:15:52month and day. If we go ahead and run
  2220. 1:15:55this, we can also take all the people
  2221. 1:15:57who are greater than or born greater
  2222. 1:15:59than 1985. So all of these dates are
  2223. 1:16:01greater than 1985. Now the next thing
  2224. 1:16:04that I want to take a look at is logical
  2225. 1:16:06operators in the wear clause. So logical
  2226. 1:16:09operators are things like and or and
  2227. 1:16:13not. Now these are called and let's add
  2228. 1:16:16this logical operators. So logical
  2229. 1:16:19operators allow us to have different
  2230. 1:16:22logic. And let's take a look at how this
  2231. 1:16:24works exactly. Let's copy this down
  2232. 1:16:25because we already have this one written
  2233. 1:16:27out. We're saying where the birth date
  2234. 1:16:28is greater than 1985.
  2235. 1:16:31We can also say where the gender is
  2236. 1:16:33equal to male. So we can say and the
  2237. 1:16:37gender is equal and then we'll say male.
  2238. 1:16:40So we're adding a different complexity
  2239. 1:16:42or an additional conditional statement
  2240. 1:16:45within our wear clause. Let's go ahead
  2241. 1:16:47and run this. So now we're only
  2242. 1:16:49selecting birth dates that are greater
  2243. 1:16:51than 1985 and where the gender is equal
  2244. 1:16:54to male. Only the rows that fulfill both
  2245. 1:16:57of those are returned. Now the and says
  2246. 1:17:00both this and this have to be true. But
  2247. 1:17:05we could change this and we could say
  2248. 1:17:07or. What this means is is either this
  2249. 1:17:10one has to be true or this one has to be
  2250. 1:17:13true in order for it to be returned. So
  2251. 1:17:15let's go ahead and run this. You'll
  2252. 1:17:17notice that Jerry Girkitch was born much
  2253. 1:17:20before 1985. But since he has a male
  2254. 1:17:23gender, he is in our output. And we
  2255. 1:17:26could also use the not operator by
  2256. 1:17:28saying or not gender equal to male. So
  2257. 1:17:32now what this is saying is the birthday
  2258. 1:17:34could be greater than 1985 or it could
  2259. 1:17:38not be equal to male which is female. So
  2260. 1:17:40if we look at Leslie nope she was born
  2261. 1:17:43before 1985 but because she is female
  2262. 1:17:46she is in the output. Now like we talked
  2263. 1:17:48about in the last lesson there is
  2264. 1:17:50something called PEMDOS and that
  2265. 1:17:52actually applies to these logical
  2266. 1:17:53operators as well. So, if we run this
  2267. 1:17:56entire table, let's go ahead and run
  2268. 1:17:58this.
  2269. 1:18:00If we're looking at this entire table,
  2270. 1:18:02let's say we want to get someone very,
  2271. 1:18:03very specific. Let's say we're going to
  2272. 1:18:06do uh where the first underscore name is
  2273. 1:18:10equal to Leslie
  2274. 1:18:13and their age has to be equal to 44.
  2275. 1:18:18That's extremely specific. And we can
  2276. 1:18:19actually just do it like this. We don't
  2277. 1:18:21need quotes um for integers. We could
  2278. 1:18:24just do the number if we'd like to. This
  2279. 1:18:26is very specific. This is only one
  2280. 1:18:27person. But if we put this in
  2281. 1:18:29parentheses,
  2282. 1:18:32we can add an or over here. We can say
  2283. 1:18:35or the age is greater than. Let's just
  2284. 1:18:38do 55. Let's go ahead and run this and
  2285. 1:18:40then we'll take a look at it. So within
  2286. 1:18:42these parentheses, we have an and
  2287. 1:18:44operator. What that means is both this
  2288. 1:18:47condition has to be met and this
  2289. 1:18:49condition has to be met. And that's only
  2290. 1:18:50one person. That's Leslie note. But then
  2291. 1:18:52outside of these parenthesis, we have
  2292. 1:18:55another conditional statement or the age
  2293. 1:18:57is greater than 55. So what we're saying
  2294. 1:18:59within these parenthesis is that this is
  2295. 1:19:01an isolated conditional statement.
  2296. 1:19:03Within these parenthesis, if this is
  2297. 1:19:06true, then in our output, it'll be
  2298. 1:19:08returned. But then we have an or
  2299. 1:19:10condition which says or someone with the
  2300. 1:19:12age of greater than 55 can also be in
  2301. 1:19:14the output. So these parentheses can be
  2302. 1:19:16really helpful when you're actually
  2303. 1:19:18using it in the wear clause with these
  2304. 1:19:20and, ors, and nots. Now, I want to take
  2305. 1:19:22a look at just one more thing. And let's
  2306. 1:19:25bring this down here.
  2307. 1:19:28And let's get rid of this entire thing.
  2308. 1:19:33Now, the last thing that we're going to
  2309. 1:19:34take a look at is a like statement. Now,
  2310. 1:19:38the like statement is super unique
  2311. 1:19:40because we can look for specific
  2312. 1:19:42patterns. We're not necessarily looking
  2313. 1:19:44for an exact match. Like here if we said
  2314. 1:19:48where first name is equal to Jerry. If
  2315. 1:19:55we're looking for Jerry it has to be
  2316. 1:19:57exactly Jerry. But if we take this out
  2317. 1:20:00say J and then we run it we get no
  2318. 1:20:03output. It has to be an exact match. But
  2319. 1:20:06here's where the like statement comes in
  2320. 1:20:08because we can actually say like jer and
  2321. 1:20:12we can add two special sequences or
  2322. 1:20:15special characters within our like
  2323. 1:20:18statement. So those special characters
  2324. 1:20:21are the percent sign and the underscore.
  2325. 1:20:26The percent sign means anything and the
  2326. 1:20:28underscore means a specific value. Let's
  2327. 1:20:31see how that actually works. So what
  2328. 1:20:33we're going to do is we're going to say
  2329. 1:20:34like jer percent sign. That's the first
  2330. 1:20:38one in this like statement. What this
  2331. 1:20:40says is the first name is like starting
  2332. 1:20:43with jer but then has anything after it.
  2333. 1:20:47Doesn't matter what it is. As long as it
  2334. 1:20:49has jer at the very beginning it will be
  2335. 1:20:52returned. Let's go ahead and run this.
  2336. 1:20:54Now the only person who starts with jer
  2337. 1:20:56is Jerry. But what if I took the j out
  2338. 1:21:00of here? Now it's saying it starts with
  2339. 1:21:02eer and that's not anybody. What we can
  2340. 1:21:06do is we can add another percent at the
  2341. 1:21:08beginning. This is going to say anything
  2342. 1:21:10comes before anything comes after. All
  2343. 1:21:13we're looking for is e rer somewhere in
  2344. 1:21:16their name. Let's go ahead and run this.
  2345. 1:21:18There still is only one person and
  2346. 1:21:20that's Jerry. Now let's come up here and
  2347. 1:21:23let's get rid of this and let's say
  2348. 1:21:24we're looking for everyone's name who
  2349. 1:21:26starts with a. We can do that really
  2350. 1:21:28easily by saying a percent sign. All
  2351. 1:21:31that says is it starts with a. We don't
  2352. 1:21:33have a percent sign before it, which
  2353. 1:21:35would say this string just has to have
  2354. 1:21:37an a somewhere in it. If we have it like
  2355. 1:21:40this, this means an a has to come at the
  2356. 1:21:42beginning. Let's go and run this. In our
  2357. 1:21:45output, we have April and an Andy. Now,
  2358. 1:21:48let's take a look at the underscore. If
  2359. 1:21:51we get rid of this percent sign and we
  2360. 1:21:54do two underscores one, two, this is
  2361. 1:21:58going to say it starts with an A and
  2362. 1:22:00then it has two characters after it. No
  2363. 1:22:03more, no less. So if we run this, an is
  2364. 1:22:07going to be the only person who's
  2365. 1:22:08returned cuz she has an A and then two
  2366. 1:22:10characters after it. Now if we want
  2367. 1:22:12Andy, we can specify that by doing
  2368. 1:22:15another underscore. That's 1 2 3.
  2369. 1:22:18And now Andy is the only one in our
  2370. 1:22:21output. Now there was also April in
  2371. 1:22:23there, but she had more than three
  2372. 1:22:24characters. But we can actually get her
  2373. 1:22:27in our output by doing a percent sign.
  2374. 1:22:29So we can combine both the underscore
  2375. 1:22:32and the percent sign. And this is going
  2376. 1:22:34to say it starts with an a has 1 2 3
  2377. 1:22:38characters and then it can have anything
  2378. 1:22:41after that. So it just has to have at
  2379. 1:22:43least an A and have one two three
  2380. 1:22:45characters after it. So let's run it.
  2381. 1:22:48Now you can see April comes into here
  2382. 1:22:50because she does have a the P, R, and I
  2383. 1:22:54are the three next characters, but then
  2384. 1:22:56we have a percent sign that allows that
  2385. 1:22:58L to be in the output as well. Now, we
  2386. 1:23:01don't just have to do this with strings
  2387. 1:23:03or text like April and Andy. We could
  2388. 1:23:05also do this with birth dates. For
  2389. 1:23:06example, Andy's birth date is 1989. We
  2390. 1:23:09could say where the birth date is like.
  2391. 1:23:14Let's say we want to look at everyone
  2392. 1:23:16who is 1989
  2393. 1:23:18or born in 1989. Let's go and run this.
  2394. 1:23:21And Andy is the only person born in
  2395. 1:23:231989. But again, we looked at the year
  2396. 1:23:26at the very beginning. So that is how
  2397. 1:23:28the like statement works. It looks for a
  2398. 1:23:31specific sequence within that column
  2399. 1:23:33that you can search for. So it doesn't
  2400. 1:23:35have to be an exact match as long as it
  2401. 1:23:37has that specified sequence that you've
  2402. 1:23:39put in there anywhere within that cell
  2403. 1:23:41or that column. So that is everything
  2404. 1:23:43that we're going to look at for the wear
  2405. 1:23:45clause. In the next lesson, we're going
  2406. 1:23:46to take a look at the group by and the
  2407. 1:23:48order by within my SQL.
  2408. 1:24:02Hello everybody. In this lesson, we're
  2409. 1:24:04going to be taking a look at group by
  2410. 1:24:06and order by in my SQL. Now, when you
  2411. 1:24:08use the group by clause in MySQL, it's
  2412. 1:24:11going to group together rows that have
  2413. 1:24:12the same values in the specified column
  2414. 1:24:15or columns that you're actually grouping
  2415. 1:24:17on. Once you group those rows together,
  2416. 1:24:19you can run something called an
  2417. 1:24:20aggregate function on those rows. Let's
  2418. 1:24:23see how this actually works. Let's go
  2419. 1:24:25ahead and copy this right here. We'll
  2420. 1:24:27bring that down. And let me go back up
  2421. 1:24:30one. Let's go ahead and write gender
  2422. 1:24:33right here. Now, we want to group on
  2423. 1:24:37this gender column. And we're going to
  2424. 1:24:39say group by gender. Let's go ahead and
  2425. 1:24:44run this. We'll see what we get. And so,
  2426. 1:24:46we have male and female. Now, we could
  2427. 1:24:50get the exact same output by saying
  2428. 1:24:52select distinct gender from this table.
  2429. 1:24:55What is group by doing that the gender
  2430. 1:24:58actually isn't doing? Well, it's
  2431. 1:24:59actually rolling up all of these values
  2432. 1:25:02into these rows. So later when we run
  2433. 1:25:05aggregate functions like average, min,
  2434. 1:25:07max, we'll do it based off of these rows
  2435. 1:25:10and all those rows are rolled up into
  2436. 1:25:12these two rows. And we'll see that in a
  2437. 1:25:14little bit. Now, what if I was to come
  2438. 1:25:16up here and in this demographics, we
  2439. 1:25:18have a first name. What would happen if
  2440. 1:25:21I'm selecting the first name, but I'm
  2441. 1:25:23grouping by the gender? Let's go ahead
  2442. 1:25:25and run this.
  2443. 1:25:27If we come right down here, we pull this
  2444. 1:25:29up. You can see that the select list is
  2445. 1:25:32not in group by clause and contains
  2446. 1:25:34non-aggregated columns. What this means
  2447. 1:25:37is that when you are selecting a column,
  2448. 1:25:39if it's not an aggregated column like
  2449. 1:25:41say average of something, if we're not
  2450. 1:25:44using the aggregate functions in the
  2451. 1:25:45select statement, it has to be in the
  2452. 1:25:47group by. These have to match. So this
  2453. 1:25:50gender has to match this group by if
  2454. 1:25:52we're not performing an aggregate
  2455. 1:25:54function on it. Let's go ahead and run
  2456. 1:25:56this. And now it works properly. Now
  2457. 1:26:00let's go back up. Let's run this query
  2458. 1:26:02because I want to select everything
  2459. 1:26:03again. But let's say we wanted to take a
  2460. 1:26:06look at the average ages for gender. So
  2461. 1:26:09what we're going to do is we're
  2462. 1:26:10selecting gender. We're also grouping by
  2463. 1:26:12gender. But what we're going to do is
  2464. 1:26:14add a comma and we'll say the average.
  2465. 1:26:17That's avg. That stands for average. And
  2466. 1:26:19then we're going to put in here age. So
  2467. 1:26:22now this right here is an aggregate
  2468. 1:26:24function. This does not need to go in
  2469. 1:26:26the group by. We're just grouping on the
  2470. 1:26:28gender and then we're performing this
  2471. 1:26:31aggregate function or kind of a
  2472. 1:26:32calculation based off of those grouped
  2473. 1:26:35rows for gender. So let's go ahead and
  2474. 1:26:37run this and take a look at the output.
  2475. 1:26:39So what this is telling me is that for
  2476. 1:26:41the males, all of the male rows that
  2477. 1:26:43were grouped, the average age is 41,
  2478. 1:26:47let's say three, and for female, the
  2479. 1:26:50average age is 38.5.
  2480. 1:26:53So, super quickly, you can tell that the
  2481. 1:26:55average age of females is lower than the
  2482. 1:26:57average age of males. Now, we'll take a
  2483. 1:26:59look at aggregate functions more in just
  2484. 1:27:01a little bit. Let's actually go to a
  2485. 1:27:04different table. Let's come right down
  2486. 1:27:06here. We're going to go to the salary
  2487. 1:27:08table and
  2488. 1:27:11just select everything for now.
  2489. 1:27:14Let's go ahead and run this. Now, what
  2490. 1:27:16we're going to actually be grouping on
  2491. 1:27:18is this occupation right here. Now,
  2492. 1:27:20there's a lot of unique values. It's um
  2493. 1:27:23not as distinct as the gender which only
  2494. 1:27:25had two values. You'll notice we do have
  2495. 1:27:27a few that are the same. We have ones
  2496. 1:27:29like office manager. So when we come up
  2497. 1:27:31here say occupation.
  2498. 1:27:34And of course we need to group by the
  2499. 1:27:36occupation as well. Now let's run this.
  2500. 1:27:39And you'll notice that office manager
  2501. 1:27:41only has one row. Let's say we also want
  2502. 1:27:44to group on the salary. Let's say
  2503. 1:27:46salary. Now we can group on multiple. So
  2504. 1:27:50we're going to say salary like this. So
  2505. 1:27:53we're grouping on the occupation as well
  2506. 1:27:55as the salary. Now let's run this.
  2507. 1:27:59You'll notice that we have two rows for
  2508. 1:28:01office manager. Now this is because this
  2509. 1:28:03salary and this salary for those two
  2510. 1:28:06employees are different. We have 50,000
  2511. 1:28:08and 60,000. For this I just wanted to
  2512. 1:28:11demonstrate that if these had both been
  2513. 1:28:1250,000 there would only be one row.
  2514. 1:28:15Office manager 50,000. But because this
  2515. 1:28:17is a unique value different than 50,000,
  2516. 1:28:20they have their own individual rows
  2517. 1:28:22which we would then perform our
  2518. 1:28:24aggregate calculations on. Let's go and
  2519. 1:28:26get rid of that because we will not be
  2520. 1:28:28using that anymore. I just wanted to
  2521. 1:28:29demonstrate it really quickly. So before
  2522. 1:28:31we were looking at gender and average
  2523. 1:28:33age and we're also grouping on the
  2524. 1:28:35gender. We can perform other aggregate
  2525. 1:28:37functions as well. Let's take a look at
  2526. 1:28:39some of those. We could look at the max
  2527. 1:28:43age as well. The max is going to show us
  2528. 1:28:46the highest value within each of those
  2529. 1:28:48groupings. So we have a male and female.
  2530. 1:28:51The max age for those for the male is 61
  2531. 1:28:54and the highest age for the female is
  2532. 1:28:5646. We can do the exact same thing
  2533. 1:28:58except we can say min or the exact
  2534. 1:29:01opposite thing. We can say the minimum
  2535. 1:29:03age. So this is going to be the lowest
  2536. 1:29:05for both the male and the female. Go and
  2537. 1:29:07run this. Now we have female and male
  2538. 1:29:10and the minimum age is 29 and 34. And
  2539. 1:29:13there is one last one that I want to
  2540. 1:29:15show you which is count. We're going to
  2541. 1:29:17do count. Now count is going to count
  2542. 1:29:20the actual rows within this age column.
  2543. 1:29:24So if we run this, you'll see that we
  2544. 1:29:27have four females for count and we have
  2545. 1:29:29seven males. It's just telling us a
  2546. 1:29:31count of how many values is in this
  2547. 1:29:34column when we're actually grouping on
  2548. 1:29:36the gender. So that's how we can use
  2549. 1:29:38group by to actually roll up and group
  2550. 1:29:42all of these similar values within a
  2551. 1:29:43column or columns and perform our
  2552. 1:29:46aggregate functions on them. Now let's
  2553. 1:29:48come down here and what we're going to
  2554. 1:29:50take a look at is order by. So we're
  2555. 1:29:52going to say order by. Now let's
  2556. 1:29:55actually pull in this demographics table
  2557. 1:30:00right here. We're just going to say
  2558. 1:30:02select everything
  2559. 1:30:05and run this really quickly after we add
  2560. 1:30:07a semicolon. So order by order by is
  2561. 1:30:12going to actually sort the result set in
  2562. 1:30:14either ascending or descending order.
  2563. 1:30:17Let's take a look at how this works. At
  2564. 1:30:19the very end, we could say order by and
  2565. 1:30:23we could order by the first underscore
  2566. 1:30:26name. So, we're going to take this
  2567. 1:30:28column and we're going to order all of
  2568. 1:30:30our rows based off of this one column.
  2569. 1:30:32Let's go ahead and run this. So, it's
  2570. 1:30:34going to do it based off ascending
  2571. 1:30:36order, which means smallest to largest.
  2572. 1:30:38Now, this is a text column or a
  2573. 1:30:40character column. So, we do it A to Z.
  2574. 1:30:43So, Andy and April all the way down to
  2575. 1:30:46Tom. Now, by default, this is in ASC
  2576. 1:30:50order, ascending order. And if we run
  2577. 1:30:52this, it's going to be the exact same
  2578. 1:30:53output. But we can change this to do it
  2579. 1:30:56the opposite, highest to lowest or Z to
  2580. 1:30:58A by doing descending. So now if we run
  2581. 1:31:02this, you'll see that goes Tom all the
  2582. 1:31:04way down to Andy. Now let's take a look
  2583. 1:31:07at ordering on something like gender and
  2584. 1:31:10age because we can do both at the same
  2585. 1:31:12time. So let's order by the gender
  2586. 1:31:14first. Let's go ahead and run this.
  2587. 1:31:18And you'll see that all the females are
  2588. 1:31:20grouped together and then all the males
  2589. 1:31:22are grouped together because that's just
  2590. 1:31:24the order in which it is. But we can do
  2591. 1:31:26an additional column. We can also do it
  2592. 1:31:28based off of the age. Let's go ahead and
  2593. 1:31:30run this.
  2594. 1:31:32So now within the female since that came
  2595. 1:31:35first in our order by, we're ordering by
  2596. 1:31:38the gender and then we're also ordering
  2597. 1:31:40by the age after we've ordered by the
  2598. 1:31:43gender. So now it's 29 all the way up to
  2599. 1:31:4546. Then 34 for males all the way up to
  2600. 1:31:4861. Now we can change this just for the
  2601. 1:31:52age. Let's say we want to do age
  2602. 1:31:54descending. So gender will stay the same
  2603. 1:31:56in ascending order, but now age will be
  2604. 1:31:59in descending order. Let's go ahead and
  2605. 1:32:01run this.
  2606. 1:32:02Now female and male stayed the same, but
  2607. 1:32:04now it starts at the highest down to the
  2608. 1:32:06lowest. Now this is something that I
  2609. 1:32:08would absolutely do in real life except
  2610. 1:32:12sometimes you can make mistakes and
  2611. 1:32:13sometimes you do the wrong column first.
  2612. 1:32:15Let's do age and then we'll do gender.
  2613. 1:32:19Now, if we run this, the gender is not
  2614. 1:32:22going to be used at all. And this is
  2615. 1:32:25because there are no unique values that
  2616. 1:32:27are going to be on the same row. So,
  2617. 1:32:28notice all these values are completely
  2618. 1:32:31unique. So, the gender never is actually
  2619. 1:32:34used to order anything on because if
  2620. 1:32:36there were things like 34, 34, 34, 34,
  2621. 1:32:39these would be ordered based off of the
  2622. 1:32:42gender. But since there's no unique
  2623. 1:32:44fields, this is really pretty useless.
  2624. 1:32:46That's why the order of the order by or
  2625. 1:32:49the columns that you place in the order
  2626. 1:32:51by are actually quite important. Now,
  2627. 1:32:52the last thing that I want to show you,
  2628. 1:32:54and I'll just go back to gender and age,
  2629. 1:32:56is that you don't actually have to use
  2630. 1:32:59the column names. We can use the column
  2631. 1:33:02positions. Now, I will preface this by
  2632. 1:33:04saying I don't recommend doing this, but
  2633. 1:33:07I sometimes do it in shorthand for just
  2634. 1:33:09a quick query. um if I know the column
  2635. 1:33:12position and I don't want to write out
  2636. 1:33:14the whole name. So sometimes I do it
  2637. 1:33:16although it's not best practice but
  2638. 1:33:17let's take a look at it. So gender is
  2639. 1:33:20the 1 2 3 4 5th column. So I'm going to
  2640. 1:33:24replace this with five and age is the 1
  2641. 1:33:272 3 4 column. So these are the positions
  2642. 1:33:31of the fields but not the names of them.
  2643. 1:33:33If we run it, we're going to get the
  2644. 1:33:35exact same output because these
  2645. 1:33:37represent these columns appropriately.
  2646. 1:33:40But again, I just don't recommend it.
  2647. 1:33:44It's kind of a slippery slope that I've
  2648. 1:33:46fallen down myself uh many times. And
  2649. 1:33:48when you get to more advanced SQL and
  2650. 1:33:51you're creating things like store
  2651. 1:33:52procedures and triggers and all these
  2652. 1:33:54things, this can actually cause a lot of
  2653. 1:33:56issues. If you were to add any columns
  2654. 1:33:58or remove any columns, then you'd be
  2655. 1:34:00ordering by the wrong column because
  2656. 1:34:03let's say this last name got removed. We
  2657. 1:34:05didn't want it for some reason. Then the
  2658. 1:34:08gender is 1 2 3 4. Now we're ordering on
  2659. 1:34:12the wrong column and that would be a big
  2660. 1:34:14mistake. So just by best practice, it is
  2661. 1:34:18better to do gender,
  2662. 1:34:21age, but I just wanted to show you that
  2663. 1:34:23in case you want to be like me and kind
  2664. 1:34:25of go down the wrong path. Uh so that is
  2665. 1:34:28everything we're going to take a look at
  2666. 1:34:30with group by and order by. In the next
  2667. 1:34:32lesson, we're going to be taking a look
  2668. 1:34:34at having [music]
  2669. 1:34:34versus where.
  2670. 1:34:48Hello everybody. In this lesson, we're
  2671. 1:34:50going to take a look at the difference
  2672. 1:34:51between having and where. Now, in the
  2673. 1:34:54last lesson, we looked at group by and
  2674. 1:34:56order by. The most obvious thing to do
  2675. 1:34:58would be to come right here and say
  2676. 1:35:00where, and we're going to say this
  2677. 1:35:02column, which is actually named this.
  2678. 1:35:04We'll say where the average age, let's
  2679. 1:35:06say, is greater than 40, which would
  2680. 1:35:09only be the males. So, let's go ahead
  2681. 1:35:11and run this. And as you can see, we're
  2682. 1:35:14not getting any output. Let's bring this
  2683. 1:35:16up and take a look at the error. It says
  2684. 1:35:19invalid use of the group by function.
  2685. 1:35:22What's actually happening is something
  2686. 1:35:24to do with this group by gender right
  2687. 1:35:26here. When we're selecting gender and
  2688. 1:35:28then we're performing an aggregate
  2689. 1:35:30function, this occurs only after the
  2690. 1:35:34group by actually groups those rows
  2691. 1:35:36together. So when we're trying to filter
  2692. 1:35:39based off of this column right here of
  2693. 1:35:41average age, it really hasn't been
  2694. 1:35:42created yet because this group by hasn't
  2695. 1:35:45happened. That's where the having clause
  2696. 1:35:47comes into play. So let's go ahead and
  2697. 1:35:50what we're going to do is we're going to
  2698. 1:35:51get rid of this. We're going to come
  2699. 1:35:53right down here and instead of where
  2700. 1:35:56we're going to say having. Now having
  2701. 1:35:59was specifically created for this exact
  2702. 1:36:02example. It comes right after group by.
  2703. 1:36:05And after group by we can filter based
  2704. 1:36:07off of these aggregate functions. So now
  2705. 1:36:09if we run this, we're going to get an
  2706. 1:36:12output that only has where the average
  2707. 1:36:14age is greater than 40. Now let's take a
  2708. 1:36:18look at just one more example. And I'm
  2709. 1:36:20going to show you how you can use both
  2710. 1:36:21in one query. So instead of
  2711. 1:36:24demographics, let's look at the salary
  2712. 1:36:26table.
  2713. 1:36:28And let's run it.
  2714. 1:36:30Now in this salary table, we have this
  2715. 1:36:33occupation. And remember, we have this
  2716. 1:36:34office manager that happens twice. And
  2717. 1:36:37this is going to be our main example. So
  2718. 1:36:39we're going to say occupation.
  2719. 1:36:41And then we'll say the average salary.
  2720. 1:36:45Now we'll need to come down here and
  2721. 1:36:47we'll say group by. Now we're going to
  2722. 1:36:50say occupation.
  2723. 1:36:52So this should look pretty similar
  2724. 1:36:55because right here we have our office
  2725. 1:36:57manager and one of the office managers
  2726. 1:36:59made 50, one of the office managers made
  2727. 1:37:0260. So the average is 55,000.
  2728. 1:37:04Now I can use the where by saying where.
  2729. 1:37:09Then I'll say occupation
  2730. 1:37:11like and let's see people who are
  2731. 1:37:14managers. So I'll say percent manager
  2732. 1:37:18percent and close that quote. So they're
  2733. 1:37:20like a manager. And then I want to see
  2734. 1:37:23where a manager makes more than let's
  2735. 1:37:25say 75,000. So I won't actually say
  2736. 1:37:28where. I'm going to say having an
  2737. 1:37:30average salary.
  2738. 1:37:33And I need to add a space there. Having
  2739. 1:37:35an average salary greater than let's say
  2740. 1:37:3875,000.
  2741. 1:37:40And let's run this.
  2742. 1:37:42So now I filtered at the row level right
  2743. 1:37:46here in the wear clause. But then down
  2744. 1:37:49here I filtered at the aggregate
  2745. 1:37:51function level. This having is only
  2746. 1:37:54going to work for aggregated functions
  2747. 1:37:57after the group by actually runs. So
  2748. 1:38:00that is the difference between the
  2749. 1:38:01having clause and the wear clause. The
  2750. 1:38:03wear clause you're most likely going to
  2751. 1:38:05use a lot more. But if you do want to
  2752. 1:38:07filter on those aggregated function
  2753. 1:38:09columns, you have to use the having
  2754. 1:38:11clause. I hope that that was really
  2755. 1:38:13helpful. And in the next lesson, we're
  2756. 1:38:15looking at our very last lesson in our
  2757. 1:38:17beginner series. We're going to look at
  2758. 1:38:19limit and aliasing.
  2759. 1:38:28>> [music]
  2760. 1:38:33>> Hello everybody. In this lesson, we're
  2761. 1:38:35going to be taking a look at limit and
  2762. 1:38:37aliasing. Limit is just going to specify
  2763. 1:38:40how many rows you want in your output.
  2764. 1:38:42If we take this table for example, if we
  2765. 1:38:44come right here and we say limit, let's
  2766. 1:38:47do three. If we run this, it's only
  2767. 1:38:49going to take the top three that we
  2768. 1:38:52have. Let's go and run this. As you can
  2769. 1:38:54see, we have employee 1, three, and
  2770. 1:38:56four, Leslie, Tom, and April. Now, this
  2771. 1:38:59seems super straightforward, really,
  2772. 1:39:00really easy, but it can be combined with
  2773. 1:39:03order by to actually be really powerful.
  2774. 1:39:06For example, let's say we wanted to take
  2775. 1:39:08the three oldest employees. All we'd
  2776. 1:39:11have to do is come right under here. We
  2777. 1:39:14say order by, and we'll order by the age
  2778. 1:39:17in descending order. So we're going to
  2779. 1:39:20order on age descending and then it's
  2780. 1:39:22going to take the top three. So if we
  2781. 1:39:24run this and very quickly we have the
  2782. 1:39:26top three oldest people in this table.
  2783. 1:39:28Now there is one additional parameter
  2784. 1:39:30that we can use in limit and all we have
  2785. 1:39:33to do to access it is have a comma here.
  2786. 1:39:36Now what this is going to do and I'll
  2787. 1:39:37put a one here. What this is going to do
  2788. 1:39:39is it's now going to say we're going to
  2789. 1:39:41start at position three and then we're
  2790. 1:39:44going to go one row after it. Now, I
  2791. 1:39:47actually want to take one of these
  2792. 1:39:49people. So, let's start at position two
  2793. 1:39:51and select the next one after it, which
  2794. 1:39:53should be Leslie. Nope. So, we're going
  2795. 1:39:55to start at position two, and we're
  2796. 1:39:57going to select the one right after it.
  2797. 1:39:59So, we're going to start at position
  2798. 1:40:00two, and then one means we're taking the
  2799. 1:40:03next one row. Let's go ahead and run
  2800. 1:40:05this. And as you can see, we got Leslie
  2801. 1:40:08nope in our output. Now, let's come
  2802. 1:40:10right down here. We are going to now
  2803. 1:40:12look at
  2804. 1:40:14aliasing. Now, aliasing is just a way to
  2805. 1:40:18change the name of the column for the
  2806. 1:40:21most part. And it can also be used in
  2807. 1:40:23joins, but we're going to take a look at
  2808. 1:40:25joins or aliasing joins in the
  2809. 1:40:27intermediate series. In a previous
  2810. 1:40:29lesson, we looked at a group by that
  2811. 1:40:31looked like this. We selected gender,
  2812. 1:40:33then we said from I believe it was
  2813. 1:40:36employee
  2814. 1:40:38demographics. Then we said group by
  2815. 1:40:42gender. And we also had the average and
  2816. 1:40:46I think it was age. There we go. And
  2817. 1:40:49we'll add our semicolon. Let's go ahead
  2818. 1:40:51and run this. In our output, we have
  2819. 1:40:53gender as our gender column, the same as
  2820. 1:40:55the column name. But then average age is
  2821. 1:40:58average age. And so if we want to
  2822. 1:41:01actually do something like a having
  2823. 1:41:03where we say having the average age,
  2824. 1:41:07let's say greater than 40 like we had
  2825. 1:41:10it. we have to actually use this
  2826. 1:41:12aggregate function in our having clause
  2827. 1:41:14and we don't want to always have to do
  2828. 1:41:16that. We can actually change the name of
  2829. 1:41:18this column and subsequently use it
  2830. 1:41:20throughout our query with that alias
  2831. 1:41:22name. So I'm going to say as and that's
  2832. 1:41:25the keyword to actually change it. We'll
  2833. 1:41:27say as and we'll do average
  2834. 1:41:30age. So now we've changed this name to
  2835. 1:41:34average age and we can come down here to
  2836. 1:41:36having and say having the average age
  2837. 1:41:39greater than 40. And when we run this it
  2838. 1:41:42works perfectly. And you'll notice that
  2839. 1:41:43the name of the column was actually
  2840. 1:41:45changed. Now this as isn't actually 100%
  2841. 1:41:49needed. It's kind of implied. Even if we
  2842. 1:41:51get rid of it, it's implied there's like
  2843. 1:41:53this as in there somewhere. Um but we
  2844. 1:41:56don't have to have it. If we took it out
  2845. 1:41:58and ran it like this, it would still
  2846. 1:42:00work exactly the same. So that is how we
  2847. 1:42:03can use limit and aliasing in SQL. And
  2848. 1:42:06congratulations, this is the end of the
  2849. 1:42:08beginner series in my SQL. In the
  2850. 1:42:11intermediate series, we're going to take
  2851. 1:42:12a look at things like joins, unions,
  2852. 1:42:15case statements, subqueries, and window
  2853. 1:42:17functions.
  2854. 1:42:30Hello everybody. In this lesson, we're
  2855. 1:42:32going to be taking a look at joins.
  2856. 1:42:34Joins allow you to combine two tables or
  2857. 1:42:36more together if they have a common
  2858. 1:42:39column. That doesn't mean the column
  2859. 1:42:41name has to be the exact same, but at
  2860. 1:42:43least the data within it are similar
  2861. 1:42:45that you can use. There are several
  2862. 1:42:47joins that we're going to look at today
  2863. 1:42:49like inner joins, outer joins, and self
  2864. 1:42:51joins. These are the two tables that
  2865. 1:42:53we'll be working with the most
  2866. 1:42:54throughout this lesson. We have the
  2867. 1:42:56employee demographics table as well as
  2868. 1:42:58the employee salary table. Now, within
  2869. 1:43:00the employee demographics table, we do
  2870. 1:43:02have this employee ID column. And if we
  2871. 1:43:05look at the employee salary, we also
  2872. 1:43:06have the employee ID column. So, in this
  2873. 1:43:09instance, the column name is actually
  2874. 1:43:10the exact same. And of course, the data
  2875. 1:43:12inside of it is also very similar. So
  2876. 1:43:15let's start by writing out an inner
  2877. 1:43:17join. This is probably one of the most
  2878. 1:43:18common joins, one of the most simple
  2879. 1:43:20joins as well. An inner join is going to
  2880. 1:43:23return rows that are the same in both
  2881. 1:43:26columns from both tables. So let's see
  2882. 1:43:28how we can actually write out this join.
  2883. 1:43:30Let's come right down here and let's
  2884. 1:43:32copy this. This will be the first table
  2885. 1:43:34that we start with. And then we'll join
  2886. 1:43:36the salary table onto this demographics
  2887. 1:43:38table. So what we need to do is we need
  2888. 1:43:41to come right here and we need to say
  2889. 1:43:43join. Now by default join represents an
  2890. 1:43:48inner join although we can write inner
  2891. 1:43:50join here to make it more explicit
  2892. 1:43:52explicitly writing out inner join. Then
  2893. 1:43:55we're going to come up here and we're
  2894. 1:43:57going to say employee salary. So we're
  2895. 1:44:00selecting everything from the employee
  2896. 1:44:02demographics and we're doing an injoin
  2897. 1:44:04on the employee salary. Now we have to
  2898. 1:44:07tell my SQL exactly what columns we're
  2899. 1:44:10supposed to be joining on. I'm going to
  2900. 1:44:12hit enter and I'm going to hit tab. Now,
  2901. 1:44:14you don't have to hit tab. It just looks
  2902. 1:44:16more codelike and it's easier to read.
  2903. 1:44:19And that's how I've done it for other
  2904. 1:44:20programming languages as well. So,
  2905. 1:44:22that's how I'm going to show you how to
  2906. 1:44:24do it. What we need to do is say on.
  2907. 1:44:26Now, this keyword is going to allow us
  2908. 1:44:28to say we're joining the demographics
  2909. 1:44:30table to the salary table based on these
  2910. 1:44:33two columns. So, from the demographics
  2911. 1:44:35table, we're doing the employee ID is
  2912. 1:44:38equal to and then in the salary table,
  2913. 1:44:41it's also the employee ID. Let's do
  2914. 1:44:43employee now and you spell it right.
  2915. 1:44:46Employee ID.
  2916. 1:44:49Now, if we try to run this and let's do
  2917. 1:44:51this, we're going to get an error. And
  2918. 1:44:54let's bring this up. It's going to say
  2919. 1:44:55column employee ID on the in clause is
  2920. 1:44:58ambiguous. Now, what does it mean
  2921. 1:45:00ambiguous? That means that it doesn't
  2922. 1:45:03know what table this employee ID is
  2923. 1:45:05from. Is it from the employee
  2924. 1:45:07demographics table? Is it from the
  2925. 1:45:08employee salary table? We don't know
  2926. 1:45:10because it's ambiguous. Now what we can
  2927. 1:45:13do is we can specify it by saying
  2928. 1:45:15employee demographics
  2929. 1:45:17dot employee ID and then employee salary
  2930. 1:45:21do employee ID. Now if we run this
  2931. 1:45:26we're going to get the output that we're
  2932. 1:45:27looking for. And let's take a look at
  2933. 1:45:29this real quick. Let me bring this up.
  2934. 1:45:32So we're pulling everything from the
  2935. 1:45:34employee demographics that's right here
  2936. 1:45:36all the way through the birth date. Then
  2937. 1:45:38we're pulling the employee salary table.
  2938. 1:45:40That's the employee ID all the way.
  2939. 1:45:43Let's scroll over through the department
  2940. 1:45:45ID. So, we're basically pulling in all
  2941. 1:45:47of the rows or all the columns from both
  2942. 1:45:49tables, but we're not pulling in all of
  2943. 1:45:51the rows. Remember, an interjoin is only
  2944. 1:45:54going to bring over the rows that have
  2945. 1:45:56the same values in both columns that
  2946. 1:45:58we're tying on. So, in this employee ID,
  2947. 1:46:00we're missing number two. Are we missing
  2948. 1:46:04any other ones? No, we're only missing
  2949. 1:46:06number two. Let's go back up and I'm
  2950. 1:46:09going to run both of these tables and
  2951. 1:46:10we're going to take a look. So, let's
  2952. 1:46:13run this.
  2953. 1:46:14So, you'll notice in the employee salary
  2954. 1:46:16table, we have a number two right here
  2955. 1:46:19and that's Ron Swanson. But in the
  2956. 1:46:21employee demographics table, we don't
  2957. 1:46:24have that. I believe that Ron Swanson
  2958. 1:46:27did this that Leslie Nope would not know
  2959. 1:46:29when his birth date was because he
  2960. 1:46:31didn't want to bring that information. I
  2961. 1:46:32think that makes the most sense.
  2962. 1:46:34Although Ron was not willing to give a
  2963. 1:46:37comment on that. Now, if we run this
  2964. 1:46:39again, you'll notice that two is not in
  2965. 1:46:42there. Since two is not in the employee
  2966. 1:46:45demographics table, the employee ID 2 is
  2967. 1:46:47not going to be populated or brought
  2968. 1:46:49over into this output from the employee
  2969. 1:46:52salary table. Now, really quickly, this
  2970. 1:46:54is honestly uh giving me some anxiety
  2971. 1:46:56because this is so incredibly long.
  2972. 1:46:58Something that I mentioned in the
  2973. 1:47:00beginner's series is that you can use
  2974. 1:47:01something called aliasing when using
  2975. 1:47:03joins and it's really helpful. This is
  2976. 1:47:05what I mean. So right here we have
  2977. 1:47:07employee demographics. We're going to
  2978. 1:47:08call this DEM. You can also do as DEM.
  2979. 1:47:13You can do as SAL. These are just short
  2980. 1:47:16names for demographics and short name
  2981. 1:47:18for salary. And we can replace these and
  2982. 1:47:21say DEM.mp employee ID and SA.mployee
  2983. 1:47:26ID. Oh, that looks so much better. Now,
  2984. 1:47:28we're going to run this and it'll be the
  2985. 1:47:30exact same output, but now we're using
  2986. 1:47:32these aliases, which just makes it so
  2987. 1:47:34much easier to read. Now, one last thing
  2988. 1:47:37that I want to show you while we're just
  2989. 1:47:38looking at the inner join is selecting
  2990. 1:47:41the actual columns. Let's say we wanted
  2991. 1:47:43to select the employee ID
  2992. 1:47:46and we wanted to select age and then we
  2993. 1:47:49wanted to select their occupation.
  2994. 1:47:52If we try to run this, we're going to
  2995. 1:47:54get an error and it's going to be almost
  2996. 1:47:56the exact same error that we got before,
  2997. 1:47:58which is column employee ID in field
  2998. 1:48:00list is ambiguous. So in our field list,
  2999. 1:48:04which is right up here in the select
  3000. 1:48:05statement, we have this employee ID. It
  3001. 1:48:08does not know which employee ID to pull
  3002. 1:48:10from, whether it's the demographics or
  3003. 1:48:12the salary. So we have to tell it which
  3004. 1:48:14one to pull from. So let's pull it from
  3005. 1:48:16the demographics by saying DM.PMP
  3006. 1:48:18employee ID. Now when we run this, we're
  3007. 1:48:21able to get information from both tables
  3008. 1:48:24in our output without having all of the
  3009. 1:48:26information. And if there are columns
  3010. 1:48:29that are similar in both tables, we have
  3011. 1:48:32to denote that by using this alias or
  3012. 1:48:35the table name. All right, so that is
  3013. 1:48:37inner joins. Now, let's move down here.
  3014. 1:48:40I'm going to copy this and we're going
  3015. 1:48:41to come right down here and we're going
  3016. 1:48:43to look at outer joins next. And let's
  3017. 1:48:46put that right here. Now for outer joins
  3018. 1:48:48we have a left join and we have a right
  3019. 1:48:51join or a left outer and a right outer
  3020. 1:48:53join. A left join is going to take
  3021. 1:48:55everything from the left table even if
  3022. 1:48:57there's no match in the join and then it
  3023. 1:48:59will only return the matches from the
  3024. 1:49:01right table. The exact opposite is true
  3025. 1:49:04for a right join. Let's see how this
  3026. 1:49:06actually works. Let's start by changing
  3027. 1:49:08this to a left join or a left outer
  3028. 1:49:12join. They're both the same and you can
  3029. 1:49:13use them uh similarly. I'm just going to
  3030. 1:49:16say left join and we're joining it on
  3031. 1:49:18the exact same things and I'm going to
  3032. 1:49:20take everything because I think that'll
  3033. 1:49:21be easier to visualize and I'm going to
  3034. 1:49:23run this. Now you may notice that this
  3035. 1:49:25looks exactly the same and that's for a
  3036. 1:49:28very good reason. It's because in the
  3037. 1:49:31left table which is the employee
  3038. 1:49:33demographics table the from statement
  3039. 1:49:35that's our left table and then the join
  3040. 1:49:38where we're actually joining on that's
  3041. 1:49:40our right table. So this is our right
  3042. 1:49:41table. So since we're doing a left, it's
  3043. 1:49:43taking everything from the employee
  3044. 1:49:45demographics. Now remember, the employee
  3045. 1:49:48demographics didn't have Ron Swanson. It
  3046. 1:49:51had no information. So everything in the
  3047. 1:49:53right table had a match. Let's change
  3048. 1:49:56this to a right join. And what this is
  3049. 1:50:00going to do, and I want to make it all
  3050. 1:50:01cap, make it all the same. What this is
  3051. 1:50:03going to do is it's going to take
  3052. 1:50:05everything from the employee salary
  3053. 1:50:07table, but if there is not a match in
  3054. 1:50:10the employee demographics, it just will
  3055. 1:50:12have nulls. Let's go ahead and run this.
  3056. 1:50:15So now it looks a little bit different.
  3057. 1:50:17Now we're taking everything from the
  3058. 1:50:19employee salary. So we're taking Ron
  3059. 1:50:21Swanson, but if there is not a match, it
  3060. 1:50:24will still populate that row, but it'll
  3061. 1:50:27have all nulls in it. Then any of the
  3062. 1:50:29information that is overlapping or the
  3063. 1:50:31same, it will bring over. So employee ID
  3064. 1:50:33is matched to employee ID 1. Then we'll
  3065. 1:50:36bring all that information over from the
  3066. 1:50:38left table. And that's essentially what
  3067. 1:50:39a left and a right join is. With a left
  3068. 1:50:42table, you're taking everything from the
  3069. 1:50:43left table and then matches from the
  3070. 1:50:45right table. If you do a right join,
  3071. 1:50:47you're taking everything from the right
  3072. 1:50:49table, but only matches on the left
  3073. 1:50:50table. And again, it populates it with
  3074. 1:50:53nulls. Now, let's go down and look at
  3075. 1:50:55our last type of join that we're going
  3076. 1:50:56to look at. And this is a self, let me
  3077. 1:51:00spell that right, a self join. Now what
  3078. 1:51:02is a self join? It is a join where you
  3079. 1:51:04tie the table to itself. Now why would
  3080. 1:51:07you want to do this? Let's take a look
  3081. 1:51:09at a very serious use case. Let's do
  3082. 1:51:12select everything. Let's do this from uh
  3083. 1:51:16employee
  3084. 1:51:18salary and let's run this. Now, let's
  3085. 1:51:21say it's December 1st and the employee
  3086. 1:51:23and Rex department decided to do a
  3087. 1:51:25secret Santa and they wanted to assign
  3088. 1:51:29based off of their employee ID the
  3089. 1:51:31person who they're going to have as a
  3090. 1:51:33secret Santa. We can help orchestrate
  3091. 1:51:35this very easily using my SQL. Well,
  3092. 1:51:38very easily is subjective, I guess, but
  3093. 1:51:40let's take a look at how we can do this.
  3094. 1:51:42So, just like any other join, the first
  3095. 1:51:44thing we're going to do is select
  3096. 1:51:45everything from employee salary and then
  3097. 1:51:47say join. And then we're going to say
  3098. 1:51:50employee salary again. So we're tying it
  3099. 1:51:52to itself. Now when we come down here
  3100. 1:51:55and let me do this. When we come down
  3101. 1:51:57here and we say on, we have to specify
  3102. 1:52:01which table we're pulling from. Are we
  3103. 1:52:03pulling from the left table which is
  3104. 1:52:05like the first table we're pulling from?
  3105. 1:52:06Are we pulling from when we're joining
  3106. 1:52:08on the right table? We need to be able
  3107. 1:52:10to distinguish these two tables because
  3108. 1:52:11they are the same. So, I'm going to say
  3109. 1:52:14EMP1 and I'm going to say EMP2 just to
  3110. 1:52:18say this is employee table one and
  3111. 1:52:20employee table 2. So, we're going to tie
  3112. 1:52:22them based off the employee ID because
  3113. 1:52:24we know those will be the exact same
  3114. 1:52:25because we're pulling from the same
  3115. 1:52:27table. So, we'll do emp1
  3116. 1:52:30employee.
  3117. 1:52:32And just so you know, if it populates
  3118. 1:52:34like this, you can hit tab and it'll
  3119. 1:52:36auto uh finish that for you. and
  3120. 1:52:38emporid.
  3121. 1:52:43Now, if we run this, let's do this. The
  3122. 1:52:47output that we're going to get is
  3123. 1:52:48literally just a one forone match. It's
  3124. 1:52:51all the columns and all the rows because
  3125. 1:52:52they all match exactly. But now what
  3126. 1:52:55we're going to do is we're going to
  3127. 1:52:56assign an employee ID to the next
  3128. 1:52:58employee ID and that will be their
  3129. 1:52:59secret Santa. So, just keep it really
  3130. 1:53:01simple. The next highest person with an
  3131. 1:53:04employee ID, that is their secret Santa.
  3132. 1:53:06So let's do an employee ID + one is
  3133. 1:53:11equal to employee 2 employee ID. So
  3134. 1:53:14we're adding one over here and we're
  3135. 1:53:16saying that's equal to this employee ID
  3136. 1:53:18over here. Let's run this.
  3137. 1:53:21So now you can see Leslie Nope is now
  3138. 1:53:25going to be assigned to Ron Swanson who
  3139. 1:53:27has an ID of two. Ron Swanson is going
  3140. 1:53:30to be assigned to Tom Havford which I'm
  3141. 1:53:32sure he's really happy about. and so on
  3142. 1:53:34and so forth. Now, let's bring this down
  3143. 1:53:37here. And what we're going to do is try
  3144. 1:53:40to simplify this and simplify this
  3145. 1:53:42output a little bit because this is a
  3146. 1:53:43little bit chaotic down here. So, we're
  3147. 1:53:45going to specify what columns we want in
  3148. 1:53:47our output. What we're going to want is
  3149. 1:53:49the employee ID, first name, last name,
  3150. 1:53:52and then employee ID, first name, last
  3151. 1:53:54name of the person who they got for
  3152. 1:53:56Secret Santa. So, we're going to start
  3153. 1:53:58with emp1.mp
  3154. 1:54:01employee
  3155. 1:54:03employee
  3156. 1:54:04id and we can call this we'll just say
  3157. 1:54:07as emp
  3158. 1:54:10Santa then we'll do a comma and we'll
  3159. 1:54:12come down now I need to spell employee
  3160. 1:54:16right so we have our employee ID and now
  3161. 1:54:18we need our first name and last name now
  3162. 1:54:20remember Leslie nope is going to be the
  3163. 1:54:22secret Santa for Ron Swanson I don't
  3164. 1:54:24know if I made that clear but that's I
  3165. 1:54:26guess how it works so now we need to do
  3166. 1:54:29uh emp1 one dot and we'll do first_ame
  3167. 1:54:34and we'll do as we do as first_ame
  3168. 1:54:39Santa. We can do a comma. We'll do the
  3169. 1:54:42exact same thing except for the last
  3170. 1:54:45name. So last_ame
  3171. 1:54:50last name Santa. Now all we have to do
  3172. 1:54:54is do a copy all this bring it down here
  3173. 1:54:57and change this to two. They're pulling
  3174. 1:54:59from the second table.
  3175. 1:55:01And it'll look just like this. And get
  3176. 1:55:03rid of this comma. And this is done.
  3177. 1:55:06Let's run it.
  3178. 1:55:08And let's bring this up. So we have
  3179. 1:55:10employee Santa, first name Santa,
  3180. 1:55:13Leslie, last name Santa. Nope. Then
  3181. 1:55:16employee Santa. And we actually need to
  3182. 1:55:18change these names. That is one thing we
  3183. 1:55:20need to do. We'll just change it to
  3184. 1:55:22employee name, first name,
  3185. 1:55:26employee, and last name employee.
  3186. 1:55:32And now when we run this, we have our
  3187. 1:55:33Santa. And then we just have the
  3188. 1:55:35employee who this person is going to be
  3189. 1:55:37the Santa for. Now, this is kind of a
  3190. 1:55:39silly way to look at it, but in essence,
  3191. 1:55:41this is exactly how a self join works.
  3192. 1:55:43Now the very very very last thing I
  3193. 1:55:46promise you the last thing that I want
  3194. 1:55:47to show you is how we can join multiple
  3195. 1:55:50tables together. So we're going to say
  3196. 1:55:51joining multiple you spell that right
  3197. 1:55:55multiple
  3198. 1:55:57tables together. Now not just one table
  3199. 1:56:00together to another table. I'm talking
  3200. 1:56:02about one table to another table to
  3201. 1:56:04another table. So let's go all the way
  3202. 1:56:06back up. We're going to take this right
  3203. 1:56:09here and bring it all the way down. And
  3204. 1:56:12what we're now going to do is we're
  3205. 1:56:14going to tie in this table right here,
  3206. 1:56:16the parks department. Let's actually
  3207. 1:56:18look at this table and let's select
  3208. 1:56:21everything real quick and let's run
  3209. 1:56:23this. Now, let's go down here and we're
  3210. 1:56:26going to say select everything. We'll do
  3211. 1:56:28this from
  3212. 1:56:30park
  3213. 1:56:32departments and let's run this. Now,
  3214. 1:56:34this is something called a reference
  3215. 1:56:36table. This is not a table that most
  3216. 1:56:39likely you'll ever add a bunch of
  3217. 1:56:42information to. It's there to reference
  3218. 1:56:44that we have these department names.
  3219. 1:56:46Tables like the salary table or employee
  3220. 1:56:48demographics table are going to change
  3221. 1:56:50pretty often as people get raises or as
  3222. 1:56:52they get older with their age. Those are
  3223. 1:56:54going to be updated fairly often.
  3224. 1:56:56Whereas this parks department table is
  3225. 1:56:58just there for reference. Now, if we
  3226. 1:57:00look down here in the columns, we have a
  3227. 1:57:02department ID. Then we have a department
  3228. 1:57:04name. So, we have the ID and the name of
  3229. 1:57:07that ID. If we run our join and we
  3230. 1:57:10scroll all the way to the right, you'll
  3231. 1:57:13notice we have a DPT ID. This stands for
  3232. 1:57:16department ID that's in the salary
  3233. 1:57:18table. So, what we want to do is join
  3234. 1:57:21this department ID to the department ID
  3235. 1:57:24from the parks and wreck. So, what we
  3236. 1:57:25can do is we're going to say inner join.
  3237. 1:57:29And now we're going to join. Let's
  3238. 1:57:31scroll down just a hair. There we go.
  3239. 1:57:34Now, we're going to take this and do it
  3240. 1:57:36off this. So, we're going to call this
  3241. 1:57:38PD for short and we're going to say
  3242. 1:57:41we're joining it on. Now, we cannot join
  3243. 1:57:44this parks department to the employee
  3244. 1:57:46demographics table. Why is that? Well,
  3245. 1:57:49the employee demographics table only has
  3246. 1:57:51employee ID all the way through birth
  3247. 1:57:53date. There's no common column that we
  3248. 1:57:56can tie to this parks department. The
  3249. 1:57:58only table that has a common column is
  3250. 1:58:01this department ID in this salary table.
  3251. 1:58:04So what we need to do is actually take
  3252. 1:58:05S. So we'll say SA dot and then we're
  3253. 1:58:09going to say DP and we'll say department
  3254. 1:58:12ID is equal to the PD dot and we need to
  3255. 1:58:16take the department ID. Now notice these
  3256. 1:58:19are not the exact same name. They are a
  3257. 1:58:21little bit different but they have the
  3258. 1:58:23same values. One thing I forgot to
  3259. 1:58:25mention is that in this parks department
  3260. 1:58:27there's no repeating. That's why it's a
  3261. 1:58:29reference. Whereas in the salary, the
  3262. 1:58:30department ID repeats several times
  3263. 1:58:32because multiple people are in the same
  3264. 1:58:34department. So this reference table also
  3265. 1:58:36usually does not have duplicates. Uh
  3266. 1:58:38just one other thing to note, but we
  3267. 1:58:40have now tied it successfully. Let's try
  3268. 1:58:42to run this.
  3269. 1:58:45And if we come down here, go all the way
  3270. 1:58:47to the right. We now have the department
  3271. 1:58:49ID 11111 and the department ID and
  3272. 1:58:52department name. Parks and recreation,
  3273. 1:58:54healthcare, public works, finance,
  3274. 1:58:56public works, and parks and recreation.
  3275. 1:58:58So this worked perfectly. So this is how
  3276. 1:59:00you can tie multiple tables together. If
  3277. 1:59:03you have common columns between them,
  3278. 1:59:05even though employee demographics has no
  3279. 1:59:08column that's related to the parks
  3280. 1:59:09department table, we can still tie them
  3281. 1:59:11together based through this employee
  3282. 1:59:14salary because employee demographics can
  3283. 1:59:16tie to employee salary. Employee salary
  3284. 1:59:18can tie to the parks department. And
  3285. 1:59:20that really is the majority of what you
  3286. 1:59:22need to know in order to use joins.
  3287. 1:59:24Well, now in the next lesson, we're
  3288. 1:59:25going to be taking a look at something
  3289. 1:59:26called a union.
  3290. 1:59:40Hello everybody. In this lesson, we're
  3291. 1:59:42going to be taking a look at unions in
  3292. 1:59:43MySQL. A union allows you to combine
  3293. 1:59:46rows together, not like columns like we
  3294. 1:59:48were doing before with joins where one
  3295. 1:59:50column is next to the other. A union
  3296. 1:59:53allows you to combine the rows of data
  3297. 1:59:55from separate tables or from the same
  3298. 1:59:57table. It's up to you. But you do that
  3299. 1:59:59by taking one select statement and using
  3300. 2:00:02a union to combine it with another
  3301. 2:00:04select statement. Let's see how this
  3302. 2:00:06actually looks. So what we're going to
  3303. 2:00:08do is right after this select statement,
  3304. 2:00:10we're going to come here and say union.
  3305. 2:00:12Then we're going to go right below the
  3306. 2:00:14union and we're going to do another
  3307. 2:00:16select statement. So we're going to copy
  3308. 2:00:18this, place it right here. But instead
  3309. 2:00:21of the demographics table, just for
  3310. 2:00:22example, we'll do the salary table. Now,
  3311. 2:00:25if we look at the demographics table,
  3312. 2:00:27let's say we want to take age and
  3313. 2:00:31gender. And let's go and take a look
  3314. 2:00:33really quickly at the salary table. And
  3315. 2:00:37let's say we want to take first name and
  3316. 2:00:40last name. So, we'll do first_ame
  3317. 2:00:43and last_ame.
  3318. 2:00:45Now, let's go ahead and run this and see
  3319. 2:00:47what it looks like. And let's pull this
  3320. 2:00:49up. So, as you can see, we have age and
  3321. 2:00:52gender. That's from the very first
  3322. 2:00:53select statement. And that's also the
  3323. 2:00:55column names. But then we have all of
  3324. 2:00:57the data for the age and gender. And
  3325. 2:00:59then below, if we move this over a
  3326. 2:01:02little bit, we have the last name and
  3327. 2:01:05first name from the employee salary
  3328. 2:01:07table. It's just down here. Now, what I
  3329. 2:01:10just demonstrated is that this doesn't
  3330. 2:01:12always work for everything. You can't
  3331. 2:01:14just combine random data together
  3332. 2:01:16because this is bad data. We shouldn't
  3333. 2:01:18have age and gender mixed with first
  3334. 2:01:20name and last name. Really, when you're
  3335. 2:01:22using this, you need to keep the data
  3336. 2:01:24the same. So, for us, we should take the
  3337. 2:01:27first I'll actually just copy this. The
  3338. 2:01:29first and last name from the employee
  3339. 2:01:31demographics as well. And let's run
  3340. 2:01:33this. And now we have all the names from
  3341. 2:01:36all of the tables. Now, you may be
  3342. 2:01:39thinking, where did all the other data
  3343. 2:01:40go? Before we had a lot of rows, but now
  3344. 2:01:43we only have a unique row for each one.
  3345. 2:01:46Well, by default, this is actually a
  3346. 2:01:49union distinct. And if you remember,
  3347. 2:01:52distinct is only going to take unique
  3348. 2:01:53values. So when we're doing this, union
  3349. 2:01:56is going to remove all the duplicates.
  3350. 2:01:58And the first name and last name from
  3351. 2:02:00salary overlaps a lot with the employee
  3352. 2:02:03demographics table. So when we ran this,
  3353. 2:02:06the only one that's actually somewhat
  3354. 2:02:08unique to one table is that in the
  3355. 2:02:09employee salary table, we have Ron
  3356. 2:02:11Swanson, whereas we don't have that in
  3357. 2:02:13the employee demographics. Now, if we
  3358. 2:02:16wanted to show all of them without the
  3359. 2:02:18distinct, there is something called a
  3360. 2:02:20union all. If we run this
  3361. 2:02:24now, we're going to get all of the
  3362. 2:02:25results without removing any of the
  3363. 2:02:27duplicates. So, if we scroll down, we're
  3364. 2:02:29going to have duplicates in here, but
  3365. 2:02:32we're just showing all of the results
  3366. 2:02:33from this table and from this table. Now
  3367. 2:02:36that we know how to actually use a
  3368. 2:02:37union, let's look at a use case. So,
  3369. 2:02:40let's go right down here and let's copy
  3370. 2:02:43this. Why not?
  3371. 2:02:45and let's put it right down here. Now,
  3372. 2:02:48let's say in the employee demographics,
  3373. 2:02:50we wanted to take the first name and
  3374. 2:02:52last name where the age is greater than
  3375. 2:02:5750. And let's run this. So, there's only
  3376. 2:03:00one person, but let's label them. Let's
  3377. 2:03:04add a label. We're going to say, comma,
  3378. 2:03:06old. So, this person is old. And if we
  3379. 2:03:10run this, it says first name, last name,
  3380. 2:03:12and old. And we can even call this as
  3381. 2:03:16label. And if we run this, the label is
  3382. 2:03:19old. So Jerry Giritch, he's the only old
  3383. 2:03:21person in this demographics table. Now,
  3384. 2:03:24why are we doing this? Well, the parks
  3385. 2:03:26department is trying to cut their budget
  3386. 2:03:28a little bit. They want to identify
  3387. 2:03:30older employees that they can push out.
  3388. 2:03:32And they also want to identify high paid
  3389. 2:03:35employees who they can reduce their pay
  3390. 2:03:36or push them out to save money. So, we
  3391. 2:03:39just identified someone who's older who
  3392. 2:03:40are going to want to try to push out.
  3393. 2:03:42But let's in the same output find people
  3394. 2:03:45who are also highly paid. So now we can
  3395. 2:03:48come down here. We can say union and
  3396. 2:03:51let's do this like this. I need to spell
  3397. 2:03:53this right. All right. Union and let's
  3398. 2:03:56take this. We're not going to be using
  3399. 2:03:58[clears throat] this exact same query,
  3400. 2:04:00but we actually need to pull from the
  3401. 2:04:01salary table. So the employee salary. So
  3402. 2:04:04we also want the first name and last
  3403. 2:04:06name. But let's say where their salary
  3404. 2:04:10is greater than let's say 70,000 cuz
  3405. 2:04:13that's a lot of money. If you're making
  3406. 2:04:14more than 70 uh for sure the parks
  3407. 2:04:16department is going to try to get rid of
  3408. 2:04:17you. But for the label we're going to
  3409. 2:04:20change it to a highly paid employee.
  3410. 2:04:25Now let's go ahead and run this. So now
  3411. 2:04:28we have Leslie Nope and Chris Trager.
  3412. 2:04:31They're both labeled as highly paid
  3413. 2:04:33employees. Now 50 I think is just a
  3414. 2:04:36little too low. Um if I'm being
  3415. 2:04:38completely honest, I think we need to
  3416. 2:04:39change this and we should do a union and
  3417. 2:04:43then add another select statement. Let's
  3418. 2:04:46bring this down. I think the 50 is too
  3419. 2:04:49low. Let's change it to 40.
  3420. 2:04:52And let's add one more thing. Let's say
  3421. 2:04:56and
  3422. 2:04:58the gender is equal to male.
  3423. 2:05:02And then we'll go down here and say
  3424. 2:05:04where the gender is equal to female
  3425. 2:05:07because we want to separate this out. So
  3426. 2:05:09we want to know who's the old man. Oh,
  3427. 2:05:12that's actually old lady. This is the
  3428. 2:05:14female one. And for up here where it's
  3429. 2:05:16male, we'll say old man. So we have
  3430. 2:05:20three different select statements using
  3431. 2:05:22two separate unions. We're selecting the
  3432. 2:05:24first name and the last name in all of
  3433. 2:05:26them, keeping the data consistent. And
  3434. 2:05:28then in our third column, we're labeling
  3435. 2:05:30it either old man, old lady, or highly
  3436. 2:05:33paid employee. Let's go ahead and run
  3437. 2:05:35this. And let's look at our output. Now,
  3438. 2:05:39you may notice something really quickly
  3439. 2:05:42that Chris Trager and Leslie Nope are an
  3440. 2:05:44old man and an old lady. And Leslie Nope
  3441. 2:05:47and Chris Trager are both highly paid
  3442. 2:05:49employees. So, these people meet
  3443. 2:05:51multiple criteria. Yeah. So, let's
  3444. 2:05:53actually order by and then we'll do
  3445. 2:05:55first_ame,
  3446. 2:05:57last name because we want to order by
  3447. 2:06:00these to see. So, let's run.
  3448. 2:06:03And now we can easily see that Chris
  3449. 2:06:05Trager is both of these. Donna is just
  3450. 2:06:08an old lady. Jerry's just an old man.
  3451. 2:06:10And Leslie is both an old lady and a
  3452. 2:06:12highly paid employee. So, now we can
  3453. 2:06:15send this to whoever we need to send it
  3454. 2:06:16to to make sure that these people get
  3455. 2:06:18looked at first so that our job is still
  3456. 2:06:21secure. The job market is tough these
  3457. 2:06:22days. You got to do what you got to do.
  3458. 2:06:24So that is how we use union. And let's
  3459. 2:06:28just take one more look at it. There we
  3460. 2:06:30go. So this is how we can use unions.
  3461. 2:06:33It's kind of a real use case. I've done
  3462. 2:06:34something very similar to this in my
  3463. 2:06:36real job, but you know, this is just an
  3464. 2:06:39example of how you can have multiple
  3465. 2:06:41select statements all combined or
  3466. 2:06:44combining the rows using a union. In the
  3467. 2:06:46next lesson, we're going to be taking a
  3468. 2:06:48look at case statements.
  3469. 2:06:53>> [music]
  3470. 2:07:01>> Hello everybody. In this lesson, we're
  3471. 2:07:03going to be taking a look at string
  3472. 2:07:05functions. Now, string functions are
  3473. 2:07:07built-in functions within MySQL that
  3474. 2:07:09will help us use strings and work with
  3475. 2:07:11strings differently. Now, we're going to
  3476. 2:07:12look at a ton of different ones. They
  3477. 2:07:14all have different use cases, but I'll
  3478. 2:07:16try to walk through some of those as we
  3479. 2:07:18go along. But we'll look at a lot of
  3480. 2:07:20different string functions in this
  3481. 2:07:21lesson. We'll start off with one that's
  3482. 2:07:23really simple. This one is called
  3483. 2:07:24length. So, if we select and then we say
  3484. 2:07:28length and let's say we put in and I
  3485. 2:07:32don't know why it's popping up like
  3486. 2:07:33that. Let's say we put in something like
  3487. 2:07:35sky or skyfall or really anything. If we
  3488. 2:07:39run this, it's going to give us the
  3489. 2:07:41length of how long this string is. So,
  3490. 2:07:44if I come down here and we say select
  3491. 2:07:47everything from employee
  3492. 2:07:51demographics
  3493. 2:07:53and let's add a semicolon here. Let's
  3494. 2:07:55run this one right down. Now, what we
  3495. 2:07:58can do is we can look at how long each
  3496. 2:08:01person's name is. What we can do is just
  3497. 2:08:04take the first name, but then we'll also
  3498. 2:08:07do the length of the first underscore
  3499. 2:08:11name. So if we run this now, we get
  3500. 2:08:14Leslie, Tom, Jerry, Donna, and it gives
  3501. 2:08:16us the length of their name. If we
  3502. 2:08:19wanted to, we could even order by this.
  3503. 2:08:20So we could do order by, and we could
  3504. 2:08:23just do two for now. And we can order by
  3505. 2:08:26the length from the shortest name all
  3506. 2:08:28the way to the longest name. Now, one
  3507. 2:08:30use case that I've used length for in my
  3508. 2:08:32actual job was when I was working with
  3509. 2:08:34phone numbers. I wanted to make sure
  3510. 2:08:36that they were exactly 10 characters
  3511. 2:08:38long. Otherwise, something went wrong
  3512. 2:08:40somewhere in the data cleaning process.
  3513. 2:08:42So, I would go and look at the length
  3514. 2:08:44and I would make sure they're all 10.
  3515. 2:08:45And if any were above 10, I would go and
  3516. 2:08:47specifically look at those and try to
  3517. 2:08:48clean those and fix those up. Now, let's
  3518. 2:08:50go on to the next one. And these next
  3519. 2:08:52ones are pretty simple ones. At least I
  3520. 2:08:54think they're fairly simple. We're going
  3521. 2:08:56to look at upper first. And it's doing
  3522. 2:08:58the same thing as the other one. We'll
  3523. 2:09:00do upper. And let's say we're going to
  3524. 2:09:02do sky. If we select upper sky, it's
  3525. 2:09:06going to give us an all uppercase. Or we
  3526. 2:09:09can copy this and we can do lower. So
  3527. 2:09:13now let me add semicolons otherwise it's
  3528. 2:09:15going to drive me crazy. Uh let's try
  3529. 2:09:18this lower. Now it's going to do all
  3530. 2:09:21lower even if I make it all capital. So
  3531. 2:09:24if I say all capital sky, it's going to
  3532. 2:09:26make it all lower. So if we come back
  3533. 2:09:28up, let's copy this
  3534. 2:09:31and instead of doing the length now
  3535. 2:09:33we'll do upper.
  3536. 2:09:36Let's go ahead and select this. So we
  3537. 2:09:38have Leslie and then we have the upper
  3538. 2:09:40first name. So upper allcase Leslie. Now
  3539. 2:09:43this is actually really good. This is
  3540. 2:09:45really helpful especially with
  3541. 2:09:46standardization is what I found a great
  3542. 2:09:48use case for it because sometimes it'll
  3543. 2:09:50be all capital tom and sometimes I'll
  3544. 2:09:53put it in as T lowercase OM. uh and just
  3545. 2:09:56making them all uppercase or all
  3546. 2:09:57lowercase can help correct those really
  3547. 2:10:00simple standardization issues within a
  3548. 2:10:02single column. The next one that we're
  3549. 2:10:03going to look at is trim. Now there's
  3550. 2:10:06multiple trims. We have trim, left trim,
  3551. 2:10:08and right trim. Trim is basically going
  3552. 2:10:11to take the white space on the front or
  3553. 2:10:13the end and get rid of it, which is
  3554. 2:10:15really really helpful. So what we're
  3555. 2:10:16going to do is we're going to come right
  3556. 2:10:18here and say select and we'll start off
  3557. 2:10:20with trim. And let me add a semicolon
  3558. 2:10:23every time. So then we'll do trim. And
  3559. 2:10:26for our actual string, we'll do
  3560. 2:10:30something a little bit odd. We'll do
  3561. 2:10:31some spaces. And then we'll do sky. And
  3562. 2:10:34then we'll add some spaces. Let's run
  3563. 2:10:36this and add our semicolon. That's going
  3564. 2:10:38to be the end of me in this lesson. I
  3565. 2:10:40was just adding semicolons. Now it fixes
  3566. 2:10:43it completely. Now, what if we don't add
  3567. 2:10:45sky at all? We'll [snorts] just keep it
  3568. 2:10:47like this. Well, you can see that
  3569. 2:10:49there's spaces before and there's spaces
  3570. 2:10:51after. But that's what trim does. trims
  3571. 2:10:54gets rid of the leading and the trailing
  3572. 2:10:57white spaces. Now, if we come up here
  3573. 2:10:59and we just do the left trim, it's only
  3574. 2:11:02going to remove from the left hand side.
  3575. 2:11:05So, we're only getting rid of the
  3576. 2:11:06left-hand side white spaces. This right
  3577. 2:11:09hand side, as you can see, is really
  3578. 2:11:10long. It's still there. And if we do RT
  3579. 2:11:14trim, we go ahead and run this one. It
  3580. 2:11:16gets rid of the white space on this
  3581. 2:11:18side, but it doesn't get rid of the left
  3582. 2:11:20space on this side. Now, let's keep
  3583. 2:11:22going. We have a lot to cover still.
  3584. 2:11:24We're going to move on to what I think
  3585. 2:11:25is probably my most favorite string
  3586. 2:11:27function if I'm allowed to have a
  3587. 2:11:28favorite string function and that's
  3588. 2:11:30substring. But I'm going to kind of work
  3589. 2:11:33us into substring a little bit by
  3590. 2:11:35looking at two smaller functions which
  3591. 2:11:37is left and right. So let's select
  3592. 2:11:40everything and we'll do that from the
  3593. 2:11:43employee demographics again. Let's add
  3594. 2:11:44our semicolon. Now I'm going to run
  3595. 2:11:47this. Now I want to get the first name
  3596. 2:11:50and I'm going to do left of the first
  3597. 2:11:54underscore name just like this. Now when
  3598. 2:11:57you're using this is actually going to
  3599. 2:11:59be an error. Let's see if I highlight
  3600. 2:12:00over this if it'll tell me what the
  3601. 2:12:02error is. It says the parenthesis is not
  3602. 2:12:04a valid position. They're expecting
  3603. 2:12:06something else. And basically what
  3604. 2:12:08they're telling us is that this is not
  3605. 2:12:10how it should be written. We're looking
  3606. 2:12:12for a different value. That different
  3607. 2:12:14value is actually a number. We're going
  3608. 2:12:16to do comma and let's do four. That's
  3609. 2:12:18what it was looking for. It didn't want
  3610. 2:12:20this at the end. It needed this comma
  3611. 2:12:22four. And what we're actually specifying
  3612. 2:12:24is how many characters from the left
  3613. 2:12:26hand side do we want to select. So we're
  3614. 2:12:29selecting the first name and we're going
  3615. 2:12:31from the left four characters. Let's go
  3616. 2:12:33ahead and run this. And so we have
  3617. 2:12:35Leslie, Tom, April all the way down. You
  3618. 2:12:38can see that there's only four
  3619. 2:12:39characters in each one. So, someone like
  3620. 2:12:41Chris, the S is no longer going to be
  3621. 2:12:44there because we're only looking at the
  3622. 2:12:45first four characters. Now, we can do
  3623. 2:12:47the exact same thing. And let's actually
  3624. 2:12:49copy this uh down here. So, we'll come
  3625. 2:12:52we'll go like this. Try to make this a
  3626. 2:12:54little more professional and we'll do
  3627. 2:12:57right. So, now we'll do right. If we do
  3628. 2:13:00the right four, it's going to go from
  3629. 2:13:02the right hand side of the string and go
  3630. 2:13:05left four. So, we're looking at the far
  3631. 2:13:08four for most right characters. Now,
  3632. 2:13:10this can be useful in certain instances,
  3633. 2:13:13but if I'm being honest, I don't use
  3634. 2:13:15these that much. For the most part, I'm
  3635. 2:13:18pretty addicted to using substrings. I
  3636. 2:13:20love substrings. I think they're
  3637. 2:13:21fantastic. And let's look at substrings
  3638. 2:13:25like this. So, a substring is going to
  3639. 2:13:27allow us to do a few different things.
  3640. 2:13:30Let's do first_ame.
  3641. 2:13:32The second thing that we put within this
  3642. 2:13:34function is the position that we want to
  3643. 2:13:36start at. So let's say we want to start
  3644. 2:13:38at the third position. And then we
  3645. 2:13:41specify how many characters we want to
  3646. 2:13:43go. So with this we specified four, but
  3647. 2:13:46let's just do two. So now we're going to
  3648. 2:13:49the third position and we're going over
  3649. 2:13:51to the right two characters. Let's go
  3650. 2:13:53ahead and run this. So with Leslie we
  3651. 2:13:56get SL. So we go 1 2 and three. We start
  3652. 2:14:00at the third position and then we take
  3653. 2:14:02two characters, the S and the L. I have
  3654. 2:14:05found this one to be extremely extremely
  3655. 2:14:08useful. Let's take this for example.
  3656. 2:14:10Let's do comma. Let's do birth
  3657. 2:14:13date. And let's run this. I'm keeping
  3658. 2:14:16everything in here. Although it might be
  3659. 2:14:18a bit much, but let's say we have this
  3660. 2:14:19birthday. And this middle column is the
  3661. 2:14:22month. And we're running some, you know,
  3662. 2:14:24query. We want to find the month that
  3663. 2:14:26everyone is born. So we can do that very
  3664. 2:14:29easily using substring and we wouldn't
  3665. 2:14:32have been able to do this very easily
  3666. 2:14:34using left or right. So now we're going
  3667. 2:14:36to take this birth date and we're going
  3668. 2:14:38to use the substring and we want to
  3669. 2:14:39select these middle characters. So what
  3670. 2:14:41we need to do since it's all
  3671. 2:14:42standardized we do 1 2 3 4 5 6. We start
  3672. 2:14:46at position six and we want to select
  3673. 2:14:49one and two. Let's go ahead and run
  3674. 2:14:52this.
  3675. 2:14:53And now we've pulled out all of the
  3676. 2:14:55months. So we can say as birth_mon
  3677. 2:15:00month and now we could save that put it
  3678. 2:15:03into a temp table add it as a new column
  3679. 2:15:05in our table whatever we want to do. Uh
  3680. 2:15:07but now we have this information that we
  3681. 2:15:09desperately desperately wanted to know.
  3682. 2:15:11So that is left right and substring.
  3683. 2:15:13Again substring is it's fantastic. Now
  3684. 2:15:15let's keep going. The next thing that
  3685. 2:15:17we're going to take a look at is
  3686. 2:15:18replace. Now replace will replace
  3687. 2:15:21specific characters with a different
  3688. 2:15:23character that you want. So, let's
  3689. 2:15:26actually copy all this right here
  3690. 2:15:28because I don't want to keep writing
  3691. 2:15:29this out. And we'll say select
  3692. 2:15:32everything.
  3693. 2:15:33Now, what we're going to do is we're
  3694. 2:15:35going to take the first underscore name
  3695. 2:15:37and then we're going to say replace. And
  3696. 2:15:40then we'll also do the first underscore
  3697. 2:15:42name, but we can specify what we want to
  3698. 2:15:44replace and then what we want to replace
  3699. 2:15:46it with. So, we have two more parameters
  3700. 2:15:48that we need to put in this function. So
  3701. 2:15:51let's say A and let's replace it with a
  3702. 2:15:54Z. Let's just see what that does. Let's
  3703. 2:15:57go ahead and run this. And so now when
  3704. 2:16:00we see the letter A and we are
  3705. 2:16:01specifying a lowercase A like mark that
  3706. 2:16:05is replaced with a Z. So that's really
  3707. 2:16:07all replace does. It specifies what you
  3708. 2:16:09want to replace and then what you're
  3709. 2:16:10going to replace it with. Now let's take
  3710. 2:16:12a look at the next one and we're going
  3711. 2:16:13to take a look at a function called
  3712. 2:16:15locate. So, if I say select and let's do
  3713. 2:16:19locate. I'm going to give it a string.
  3714. 2:16:22I'll say Alexander. That's my name. And
  3715. 2:16:24I'm going to specify what I'm looking
  3716. 2:16:26for. So, let's close this parenthesis.
  3717. 2:16:28The string that we're actually looking
  3718. 2:16:29for comes first. So, what we're going to
  3719. 2:16:31do is I'm looking for the letter X in my
  3720. 2:16:34name. So, we'll do X and Alexander.
  3721. 2:16:37Let's go ahead and run this. And it
  3722. 2:16:39tells us that it is in position four.
  3723. 2:16:41So, we have one, two, three, and four.
  3724. 2:16:44That's where our position is. That's
  3725. 2:16:46where it locates that sequence that
  3726. 2:16:47we're looking for. Now, if we pull this
  3727. 2:16:50down here,
  3728. 2:16:52place this right here, and we'll change
  3729. 2:16:54this locate. Now, let's say we're still
  3730. 2:16:57looking at the first name, but we want
  3731. 2:16:59to locate people that have an a
  3732. 2:17:02like this in their name. Let's go ahead
  3733. 2:17:05and run this. And we get zeros for
  3734. 2:17:08everybody except for an andy. So, this
  3735. 2:17:12might be something where we put it into
  3736. 2:17:13a CTE or a temp table. Then we can
  3737. 2:17:15filter down based off of these results
  3738. 2:17:17to where it only equals one. Now the
  3739. 2:17:20last one that we're going to take a look
  3740. 2:17:21at and let's go right here. We're going
  3741. 2:17:23to do first name last underscore name.
  3742. 2:17:26Now this one is super super useful
  3743. 2:17:29because what we can do is have a
  3744. 2:17:31concatenation
  3745. 2:17:33of multiple columns. So let's go down
  3746. 2:17:36right here. So we have first name and
  3747. 2:17:38last name. But if we come down and we
  3748. 2:17:40say concat, we can then combine these
  3749. 2:17:43columns into one single column. So we'll
  3750. 2:17:46do concat. It'll do first underscore
  3751. 2:17:49name and then comma last underscore
  3752. 2:17:52name. And if we run this, it's going to
  3753. 2:17:55be Leslie and nope combined into Leslie
  3754. 2:17:58nope. Now this doesn't look perfect,
  3755. 2:18:00right? We don't want it to look like
  3756. 2:18:01that. All we have to do is come in here
  3757. 2:18:03and we could do a little space. So we'll
  3758. 2:18:06add a space in there. And if we run that
  3759. 2:18:08now we have Leslie and nope. And we
  3760. 2:18:10could call this as full_name.
  3761. 2:18:15And this is something that I've done a
  3762. 2:18:17million times in my real job where
  3763. 2:18:19there's multiple columns. We want to
  3764. 2:18:21create one column out of it or take two
  3765. 2:18:23columns and create one column. Happens
  3766. 2:18:25all the time. So this concat is really
  3767. 2:18:27really helpful to combine those columns
  3768. 2:18:29really quickly. So that is all we're
  3769. 2:18:31going to take a look at in this string
  3770. 2:18:32functions lesson. In my full course you
  3771. 2:18:34can find in the description below. I
  3772. 2:18:35also have lessons on numeric functions,
  3773. 2:18:37date and time functions, converting
  3774. 2:18:39different data types, all in [music] the
  3775. 2:18:41functions module.
  3776. 2:18:52[music]
  3777. 2:18:54Hello everybody. In this lesson, we're
  3778. 2:18:56going to be taking a look at case
  3779. 2:18:58statements in MySQL. A case statement
  3780. 2:19:00allows you to add logic in your select
  3781. 2:19:02statement. Sort of like an if else
  3782. 2:19:04statement in almost all other
  3783. 2:19:05programming languages or even things
  3784. 2:19:07like Excel. Let's see how this actually
  3785. 2:19:09works. So let's bring this down and
  3786. 2:19:12let's take this employee demographics
  3787. 2:19:14table and let's take the first name and
  3788. 2:19:17let's take the last name and let's add a
  3789. 2:19:21case statement.
  3790. 2:19:23How we need to do this is we have to say
  3791. 2:19:25case. So that's going to signify that
  3792. 2:19:27we're starting a case statement. And
  3793. 2:19:29then I'm going to go over here and say
  3794. 2:19:31tab. So this is where our logic comes
  3795. 2:19:33into play. So I'm going to say when the
  3796. 2:19:36age let's say is less than or equal to
  3797. 2:19:4030 then so I'm saying if the age is less
  3798. 2:19:44than or equal to 30 then what's going to
  3799. 2:19:46happen? We'll just keep it really simple
  3800. 2:19:48for now. We'll just say that this person
  3801. 2:19:50is young. And then if we want to end the
  3802. 2:19:53case statement, we'll come down here and
  3803. 2:19:55say end. So this is a complete case
  3804. 2:19:58statement. Let's go ahead and run it.
  3805. 2:20:01And let's take a look at the output. So
  3806. 2:20:03we have the first name, we have the last
  3807. 2:20:05name, and then we have this case
  3808. 2:20:07statement right here. And if their age
  3809. 2:20:09is less than or equal to 30, they're
  3810. 2:20:10young. Let's actually add the age right
  3811. 2:20:13here just so we can visually see that as
  3812. 2:20:15well. So we have the age. So this person
  3813. 2:20:18is the only person who's under or equal
  3814. 2:20:20to the age of 30. That's April. So, she
  3815. 2:20:23has a label of young. The great thing
  3816. 2:20:26about case statements is you can add
  3817. 2:20:28multiple when statements. So, we can
  3818. 2:20:29come down here and say when. And then we
  3819. 2:20:32can do something like when age and maybe
  3820. 2:20:34we'll say between. So, I don't know if
  3821. 2:20:37in previous lessons we've looked at
  3822. 2:20:38between, but between just says between
  3823. 2:20:40this number and this number. So, we'll
  3824. 2:20:42say between 31 and 50. If they're
  3825. 2:20:46between 31 and 50, well, good night. uh
  3826. 2:20:50that person is old. So, we're going to
  3827. 2:20:52have it just like this. We're going to
  3828. 2:20:54run it.
  3829. 2:20:56And now we have a lot of people who are
  3830. 2:20:59old. These are all people between the
  3831. 2:21:01ages of 31 and 50. But we still have
  3832. 2:21:04more people outside of the age of 50 or
  3833. 2:21:06older than 50. So, we could do when the
  3834. 2:21:10age and now we can say greater than or
  3835. 2:21:13equal to 50. and we're gonna say then
  3836. 2:21:17and then we're gonna say on death's
  3837. 2:21:20door. Uh because good night if you're
  3838. 2:21:22over 50, my parents are gonna love me
  3839. 2:21:24for this one. So let's go ahead and run
  3840. 2:21:26this. And then if we look at this, we
  3841. 2:21:29have on death store right there. Now
  3842. 2:21:31this is huge. This is massive. So let's
  3843. 2:21:33actually name this and we'll just say as
  3844. 2:21:36at the end of end, so right after end,
  3845. 2:21:38we'll say as age uh bracket and let's
  3846. 2:21:42run this.
  3847. 2:21:44And this looks a lot better. So now we
  3848. 2:21:47have this age bracket just signifying
  3849. 2:21:49kind of where people are at. And most
  3850. 2:21:51people are quite old. Poor Jerry. Uh you
  3851. 2:21:54know, can't catch a break that guy. Now
  3852. 2:21:56let's go down and let's take a look at a
  3853. 2:21:58different table. So let's select
  3854. 2:22:00everything. We'll do from employee
  3855. 2:22:04salary.
  3856. 2:22:05Now that we have our employee salary
  3857. 2:22:07table, here is the scenario that we are
  3858. 2:22:09given. The Pawne Council sent out a memo
  3859. 2:22:12of their bonus and pay increase for end
  3860. 2:22:14of year and we need to follow it and
  3861. 2:22:16determine people's end ofear salary or
  3862. 2:22:18the salary going into the new year and
  3863. 2:22:20if they got a bonus how much was it. So
  3864. 2:22:23the first thing we need to do is we need
  3865. 2:22:25to get the pay increase and bonus and
  3866. 2:22:29their pay increases look like this. So,
  3867. 2:22:31if they made less than 50,000, then that
  3868. 2:22:35equals a 5% raise. Very generous. And if
  3869. 2:22:38they made greater than 50,000, that
  3870. 2:22:42equals a 7% raise. Very, very generous.
  3871. 2:22:45Lastly, if they work in the finance
  3872. 2:22:48department, that equals a 10% bonus.
  3873. 2:22:52Just cash that goes into their bank
  3874. 2:22:54account. Very, very generous, but only
  3875. 2:22:56the finance department gets it. So,
  3876. 2:22:58these are the guidelines that the Pawne
  3877. 2:22:59Council sent out and it is our job to
  3878. 2:23:02determine and figure out those pay
  3879. 2:23:04increases as well as the bonuses. So,
  3880. 2:23:06let's come right down here. We're going
  3881. 2:23:08to have our salary employee. I actually
  3882. 2:23:10want to be able to see these. Let me
  3883. 2:23:12pull this up just a touch. There we go.
  3884. 2:23:15So, we want to be able to write this
  3885. 2:23:17out. So, first thing we should do is
  3886. 2:23:18just select the columns that we need.
  3887. 2:23:20First name, last name, probably salary
  3888. 2:23:23as well. And now what we can do is
  3889. 2:23:26determine this first one which is if
  3890. 2:23:28they make less than 50,000 they get a 5%
  3891. 2:23:31raise. So let's say case and I'll also
  3892. 2:23:35add uh end in here and we're going to
  3893. 2:23:38say when their salary is less than
  3894. 2:23:4250,000
  3895. 2:23:43what's going to happen then we say then
  3896. 2:23:47salary. So, we're taking their initial
  3897. 2:23:48salary and we're saying plus then we're
  3898. 2:23:51going to do salary times 0.05.
  3899. 2:23:56And if we run this
  3900. 2:23:59should work. Let's pull this up really
  3901. 2:24:01quickly. So, April Lgate, she made under
  3902. 2:24:0450,000. So, she got a raise and her new
  3903. 2:24:07salary is 26,250.
  3904. 2:24:10We could actually call that. We'll say
  3905. 2:24:12uh as a actually let's do new salary
  3906. 2:24:17because that's their new salary. And
  3907. 2:24:19let's run this. So the new salary is
  3908. 2:24:2226,250.
  3909. 2:24:24Andy Dwire is now making 21,000. Now
  3910. 2:24:27this calculation you can do it different
  3911. 2:24:29ways. We could do it exactly like this
  3912. 2:24:30or we could just do times 1.05.
  3913. 2:24:34Should be the exact same thing. Uh just
  3914. 2:24:36however you would like to write it out.
  3915. 2:24:38it's just you know adding it
  3916. 2:24:40[clears throat] or multiplying it by
  3917. 2:24:41this. So let's take this and now we're
  3918. 2:24:45going to say when it is greater than
  3919. 2:24:4850,000 so let's say greater than 50,000
  3920. 2:24:51they get a 1.07.
  3921. 2:24:54So this is the 7% increase. This is a 5%
  3922. 2:24:56increase. This is a 7% increase. And
  3923. 2:24:59let's run this
  3924. 2:25:02and let's put this up here.
  3925. 2:25:05So now if they made greater so 50,000
  3926. 2:25:08that's 75,000 they got a 7% increase.
  3927. 2:25:11Now unfortunately we did not make the
  3928. 2:25:13rules the Pawnie Council did and the
  3929. 2:25:17people who made exactly 50,000
  3930. 2:25:19unfortunately were not part of those
  3931. 2:25:21brackets. Uh and that just wasn't up to
  3932. 2:25:23us. We couldn't control that. So
  3933. 2:25:25unfortunately Tom Havford and Jerry
  3934. 2:25:28Gurggic just didn't get races this year.
  3935. 2:25:30And that's not our fault. Okay. That's
  3936. 2:25:32not our fault. Now, the next thing that
  3937. 2:25:35we need to do is determine the bonuses.
  3938. 2:25:38Now, let's come right back up here
  3939. 2:25:40really quickly and let's just copy this
  3940. 2:25:43because what we need to determine is
  3941. 2:25:47how we know that somebody is in the
  3942. 2:25:50finance department because if they're in
  3943. 2:25:52the finance department, that means they
  3944. 2:25:53get a 10% bonus. That's really
  3945. 2:25:55important.
  3946. 2:25:57Now, it's not in the employee
  3947. 2:25:59demographics. We don't have anything
  3948. 2:26:00about the department. But if we look in
  3949. 2:26:03the salary and we run this, we do have
  3950. 2:26:06the department ID. Now, let's open up
  3951. 2:26:11and let's pull this up right here. We'll
  3952. 2:26:13look at the parks department. And in the
  3953. 2:26:18parks department, here we go. The
  3954. 2:26:20finance is department ID of six. So if
  3955. 2:26:24we're looking at the salary,
  3956. 2:26:26there's only one person who's in uh
  3957. 2:26:29department ID equal to six. So what we
  3958. 2:26:32can do is another case statement. We can
  3959. 2:26:35say comma we'll do case and end
  3960. 2:26:40and we'll do another one. We're going to
  3961. 2:26:42say when
  3962. 2:26:44dep
  3963. 2:26:46so when the department ID is equal to
  3964. 2:26:49six, then we're going to give them a
  3965. 2:26:52bonus. So, we're going to say salary
  3966. 2:26:54times.10
  3967. 2:26:57and we'll call this as bonus. Let's go
  3968. 2:27:01ahead and run this
  3969. 2:27:03and let's pull it up. So, he gets a
  3970. 2:27:06$7,000 bonus this year. That's Ben Wyatt
  3971. 2:27:09uh because he was part of the finance
  3972. 2:27:11department that just did uh an
  3973. 2:27:12exceptional job this year apparently
  3974. 2:27:14according to the Ponyie Council. So,
  3975. 2:27:17that is how case statements work.
  3976. 2:27:19They're really powerful, really useful.
  3977. 2:27:21I honestly use them quite often and
  3978. 2:27:23they're just a way to really add some
  3979. 2:27:25logic and some, you know, labeling or
  3980. 2:27:28even do calculations like we did right
  3981. 2:27:30here with the salary. In the next
  3982. 2:27:32lesson, we're going to be taking a look
  3983. 2:27:33at sub queries in MySQL.
  3984. 2:27:47Hello everybody. In this lesson, we're
  3985. 2:27:49going to be taking a look at sub queries
  3986. 2:27:51in MySQL. Now, subquery is basically
  3987. 2:27:54just a query within another query. We
  3988. 2:27:57can do this in a few different ways, and
  3989. 2:27:59I'm going to try to show you a lot of
  3990. 2:28:00the different variations within this
  3991. 2:28:02lesson. The first way that we're going
  3992. 2:28:03to use a subquery is in the wear clause.
  3993. 2:28:06Then, we'll take a look at the select
  3994. 2:28:08and the from clause. Also, let's take
  3995. 2:28:09this demographics table that we have
  3996. 2:28:11down here. What if we only wanted to
  3997. 2:28:13select the employees who worked in the
  3998. 2:28:16actual parks and recck department? Well,
  3999. 2:28:18we could do that if we had a few joins.
  4000. 2:28:21We have this salary table and one
  4001. 2:28:24actually represents that they work for
  4002. 2:28:26the parks and wreck. If we come over
  4003. 2:28:28here and we open this up, we can see
  4004. 2:28:30that parks and wreck is the department
  4005. 2:28:32ID of one. So, we do have that option.
  4006. 2:28:35We could just join these two tables
  4007. 2:28:36together. But sometimes we don't want to
  4008. 2:28:39do that and we'll use a subquery. Let's
  4009. 2:28:41see how it works in the wear clause. So,
  4010. 2:28:44let's go ahead and get rid of this. So
  4011. 2:28:45what we're going to do is we're going to
  4012. 2:28:47say select everything from employee
  4013. 2:28:49demographics where and now we want to
  4014. 2:28:52pull because this is the salary table.
  4015. 2:28:54We want to pull employee IDs where the
  4016. 2:28:57department ID is equal to one. But
  4017. 2:28:59remember we're querying off of this
  4018. 2:29:02table. So let's actually pull this up.
  4019. 2:29:05This is what we're working with. So we
  4020. 2:29:07want to say where the employee
  4021. 2:29:10ID that's referencing this column in the
  4022. 2:29:13demographics table is in what we're
  4023. 2:29:16going to do is we're going to do a
  4024. 2:29:18parentheses here and we can even come
  4025. 2:29:20down and put a parenthesis down here. So
  4026. 2:29:22what we're going to do now is write our
  4027. 2:29:24query which is our sub query and this is
  4028. 2:29:26our outer query. So now we're going to
  4029. 2:29:28write an entirely other query within
  4030. 2:29:31this. So, we'll say select. And now
  4031. 2:29:33we're going to say employee
  4032. 2:29:35id. And let's just bring this over. I
  4033. 2:29:38usually have it something like this. And
  4034. 2:29:41I'm going to try to bring this down a
  4035. 2:29:43little bit. So, select everything. And
  4036. 2:29:45then we'll do from and then instead of
  4037. 2:29:48employee demographics,
  4038. 2:29:50we'll do employee salary.
  4039. 2:29:54And let's just format this a little
  4040. 2:29:55better. So, select the employee ID from
  4041. 2:29:58employee salary. And remember we wanted
  4042. 2:30:00to do where the department ID is equal
  4043. 2:30:03to one. Now let's bring this back up.
  4044. 2:30:07And this is what the query is going to
  4045. 2:30:09look like. Now just by itself, let's run
  4046. 2:30:12this subquery or this inner query. When
  4047. 2:30:15we run this, it's going to create this
  4048. 2:30:17list of just employee IDs where the
  4049. 2:30:20department ID is equal to one. So when
  4050. 2:30:22we say where the employee ID from the
  4051. 2:30:25employee demographics table is in, it's
  4052. 2:30:28going to try to match those employee IDs
  4053. 2:30:31to this list of employee IDs. So just
  4054. 2:30:34remember 1 2 3 4 5 6 and 12. Let's go
  4055. 2:30:37ahead and run this entire query.
  4056. 2:30:40Now we have 1 3 4 5 6 12. If you
  4057. 2:30:44remember from previous lessons, the two
  4058. 2:30:47is Ron Swanson and he's only in the
  4059. 2:30:49salary table. So since we're doing just
  4060. 2:30:52the employee demographics table, he's
  4061. 2:30:54not in here. So what we're doing is
  4062. 2:30:55we're selecting everything from the
  4063. 2:30:57employee demographics where the employee
  4064. 2:30:59ID in this table matches or is in the
  4065. 2:31:04select employee ID from the salary table
  4066. 2:31:07where the department ID is equal to one.
  4067. 2:31:09In essence, this is what a subquery is.
  4068. 2:31:12It's a query within a query. Now, what
  4069. 2:31:14would happen if we have the employee ID,
  4070. 2:31:16but we also wanted to say the department
  4071. 2:31:18ID because we just wanted to view this.
  4072. 2:31:20Let's go ahead and try to run this.
  4073. 2:31:23We are going to get no output and we're
  4074. 2:31:25going to get an error that says operand
  4075. 2:31:27should contain one column. The operand
  4076. 2:31:30referring to this entire thing right
  4077. 2:31:32here cuz this is an operator. So, this
  4078. 2:31:35is our operand and we're returning two
  4079. 2:31:37columns in here which is saying we
  4080. 2:31:39cannot do. We have to only have one. So
  4081. 2:31:43now if we run this, it works perfectly
  4082. 2:31:46well. And let's bring that down. Now we
  4083. 2:31:48can also use the subquery in a select
  4084. 2:31:51statement. So let's take a look at that.
  4085. 2:31:53Next, let's go down here and let's say
  4086. 2:31:56we want to do select everything from
  4087. 2:31:59employee salary. And let me spell that
  4088. 2:32:03right.
  4089. 2:32:04Let's say we want to look at all the
  4090. 2:32:06salaries just like how we have it now.
  4091. 2:32:08But in a column next to it, we also want
  4092. 2:32:10to compare it to the average salary for
  4093. 2:32:13everyone. So we'll be able to see, you
  4094. 2:32:15know, whether somebody's salary is above
  4095. 2:32:16average or below average. So what we
  4096. 2:32:19would try to do potentially is do
  4097. 2:32:22something like uh first name salary and
  4098. 2:32:26average salary. And we try to run this.
  4099. 2:32:30And of course, we're going to get an
  4100. 2:32:31error. It's going to basically tell us
  4101. 2:32:33that we need to group by if we're doing
  4102. 2:32:35this. So, let's go back down and let's
  4103. 2:32:38actually add that group by.
  4104. 2:32:41And we'll say group by first name and
  4105. 2:32:43salary.
  4106. 2:32:45And we'll look at this output.
  4107. 2:32:48And this is not looking good at all.
  4108. 2:32:50It's just looking at the average salary
  4109. 2:32:52for each unique row, which is Leslie
  4110. 2:32:5575,000. So, the average is 75,000. This
  4111. 2:32:58is not what we're looking for. This is
  4112. 2:32:59not what we want. Here's what we really
  4113. 2:33:02do want. we want to just take the
  4114. 2:33:04average salary of this entire column
  4115. 2:33:07regardless of group by or anything else.
  4116. 2:33:09So let's get rid of this and let's see
  4117. 2:33:10how we can do that. So let's come right
  4118. 2:33:13down here. We're going to say select
  4119. 2:33:17select the average salary and then we're
  4120. 2:33:19going to say from add our parenthesis
  4121. 2:33:22because this is our subquery from the
  4122. 2:33:25employee salary table just like that.
  4123. 2:33:28Now if we run this we should get the
  4124. 2:33:30exact output we're looking for. So the
  4125. 2:33:33average salary is 57,250
  4126. 2:33:38and we have our salary right here. So we
  4127. 2:33:40can compare really quickly just like
  4128. 2:33:42that. Now we can also use a subquery in
  4129. 2:33:45the from statement. So let's go down
  4130. 2:33:48here and let's say select everything
  4131. 2:33:51from employee_demographics.
  4132. 2:33:55Let's have it autocomplete for me. So we
  4133. 2:33:57have the employee demographics table.
  4134. 2:33:59Now let's create a group by based off
  4135. 2:34:01the gender column and add some
  4136. 2:34:02aggregated functions and I'm going to
  4137. 2:34:04show you how you can use this as a
  4138. 2:34:06subquery. So let's go up here say gender
  4139. 2:34:10and then we'll let's go ahead and add
  4140. 2:34:12our group by. So we'll say group by
  4141. 2:34:14gender as well. Now let's add a few
  4142. 2:34:16things. We'll do average we'll do
  4143. 2:34:18average age and then we can do let's
  4144. 2:34:21just do all of them based off the age.
  4145. 2:34:23We'll just do age,
  4146. 2:34:26min of age, and count
  4147. 2:34:31of age.
  4148. 2:34:33When I try to write fast, it doesn't
  4149. 2:34:35always go right. So, we have this. Let's
  4150. 2:34:37run this. And this is what our output is
  4151. 2:34:40going to look like. Now, what if we
  4152. 2:34:41wanted to get the average of the oldest
  4153. 2:34:44age or the average of the smallest ages
  4154. 2:34:47or, you know, see what the average count
  4155. 2:34:49is for males and females? Well, we can't
  4156. 2:34:52do that given this table. But let's do
  4157. 2:34:56something right here. Select everything.
  4158. 2:34:58And then we're going to say from and in
  4159. 2:35:01our from statement, we're going to have
  4160. 2:35:03a parenthesis. We're going to paste our
  4161. 2:35:05select statement and then close the
  4162. 2:35:07parenthesis. So, we're going to select
  4163. 2:35:09everything from this output that is
  4164. 2:35:13right down here. So if we run just this,
  4165. 2:35:17we're going to get an error and forgot
  4166. 2:35:19this was going to happen. But every
  4167. 2:35:20drive table must have its own alias. So
  4168. 2:35:23you have to name a table. I forgot it
  4169. 2:35:25does that. All we have to do to fix this
  4170. 2:35:27is just name it. So we'll say as and
  4171. 2:35:29we'll say aggregated table. We'll just
  4172. 2:35:32call it aggregated table. So let's run
  4173. 2:35:34this. And we get the exact same output.
  4174. 2:35:37But here's the neat thing is we can now
  4175. 2:35:40select we can do gender. And these are
  4176. 2:35:43actually the column names now. So I can
  4177. 2:35:45do the average of this column right
  4178. 2:35:49here. But I can't do it just like this
  4179. 2:35:53because it's going to give us an error.
  4180. 2:35:55And I'll show you why in just a second.
  4181. 2:35:57Says unknown column age in field list.
  4182. 2:36:00So what it's saying is is we're trying
  4183. 2:36:02to perform an aggregated function on the
  4184. 2:36:05aggregation of an age column, but we
  4185. 2:36:08don't have an age column in our table
  4186. 2:36:11right here. Let me run this again. We
  4187. 2:36:14have a column named this exact thing. So
  4188. 2:36:17what we actually need to do is do this
  4189. 2:36:19back tick and back tick. This is the
  4190. 2:36:21actual name of the column. It's not an
  4191. 2:36:23aggregation anymore. The back tick on my
  4192. 2:36:26laptop is right above the tab on the far
  4193. 2:36:28left hand side. Um right under the
  4194. 2:36:30escape. That's where mine is. Uh so
  4195. 2:36:32these back ticks, it's not a quote like
  4196. 2:36:35this. It's a back tick. So you just need
  4197. 2:36:37to find that on your keyboard. But now
  4198. 2:36:39if we run this, it looks like we
  4199. 2:36:41encountered another error. Says in
  4200. 2:36:43aggregated query without group by.
  4201. 2:36:45That's right. Now we need a group by. So
  4202. 2:36:48now we need a group by gender.
  4203. 2:36:51Sometimes you got to figure this out on
  4204. 2:36:52the fly and it should work. There we go.
  4205. 2:36:57So now we can perform aggregations on
  4206. 2:37:00this table. Now, this doesn't actually
  4207. 2:37:02work perfect because we're still
  4208. 2:37:04grouping by the female male. But let's
  4209. 2:37:06get rid of this for a second. And we'll
  4210. 2:37:08get rid of this group by entirely. And
  4211. 2:37:10if we run this, we're now looking at the
  4212. 2:37:13averages of this column right here, max
  4213. 2:37:16age. Now, when you're doing something
  4214. 2:37:18like this, it's actually really smart to
  4215. 2:37:21rename these. We'll say as average age.
  4216. 2:37:25We'll say as max age. And it makes it so
  4217. 2:37:28much easier. you don't have to do these
  4218. 2:37:30back ticks anymore. Um, and as min age
  4219. 2:37:34and so on and so forth and I would
  4220. 2:37:36probably format this better and stuff
  4221. 2:37:38like that. Well, we don't have to go
  4222. 2:37:39through everything, right? I'm just kind
  4223. 2:37:41of giving you an example.
  4224. 2:37:43But then when we're using this table,
  4225. 2:37:46these columns are actually named this.
  4226. 2:37:49So I don't have to do these back ticks
  4227. 2:37:50anymore. I can just take this whole
  4228. 2:37:53thing. Oops. Get rid of that back tick.
  4229. 2:37:56Now I can just take this column because
  4230. 2:37:58this is the column name. So let's go
  4231. 2:38:00ahead and run this and it's still going
  4232. 2:38:02to work perfectly. So this one's pretty
  4233. 2:38:04cool because you're basically creating
  4234. 2:38:06this kind of like a temp table. Um
  4235. 2:38:08you're just creating your own little
  4236. 2:38:10output. Then you can query off of it and
  4237. 2:38:12you can do you know more advanced
  4238. 2:38:14calculations this way. It's actually
  4239. 2:38:15really useful. But there are better ways
  4240. 2:38:18to do something like this uh like a CTE
  4241. 2:38:21or a temp table that we'll look at in
  4242. 2:38:23the advanced series. But this is at
  4243. 2:38:25least how you can do it and you can
  4244. 2:38:27actually try it out using subqueries. So
  4245. 2:38:29that is all we're going to look at today
  4246. 2:38:31for sub queries. In the next lesson,
  4247. 2:38:33we're going to take a look [music] at
  4248. 2:38:34window functions.
  4249. 2:38:47Hello everybody. In this lesson, we're
  4250. 2:38:49going to be taking a look at window
  4251. 2:38:51functions. Now, window functions are
  4252. 2:38:53really powerful and are somewhat like a
  4253. 2:38:55group by, except they don't roll
  4254. 2:38:57everything up into one row when
  4255. 2:38:59grouping. Window functions allow us to
  4256. 2:39:01look at a partition or a group, but they
  4257. 2:39:04each keep their own unique rows in the
  4258. 2:39:06output. We're also going to look at
  4259. 2:39:07things like row numbers, rank, and dense
  4260. 2:39:09rank at the end of this lesson. So,
  4261. 2:39:11before we jump into writing a window
  4262. 2:39:13function and seeing how the syntax
  4263. 2:39:15works, let's actually write out a group
  4264. 2:39:17by, and then we'll compare the two when
  4265. 2:39:19we actually do write the window
  4266. 2:39:20function. Let's say we want to take this
  4267. 2:39:21demographics table and we want to take
  4268. 2:39:23this gender and compare it to the actual
  4269. 2:39:25salaries. So what we actually need to do
  4270. 2:39:28is we need to say join and we're going
  4271. 2:39:31to join on the employee salary. Let's go
  4272. 2:39:34like this.
  4273. 2:39:36Get rid of all of this and we'll do
  4274. 2:39:38salary and we're going to say on and
  4275. 2:39:42let's do dm and sal for the aliases.
  4276. 2:39:46We'll say dm.mp employee id is equal to
  4277. 2:39:51sal employee id. Now we're going to come
  4278. 2:39:54up here and we're going to say gender
  4279. 2:39:57comma and we want to look at the average
  4280. 2:39:59salary. And we need to get rid of this
  4281. 2:40:01right here and we need to come down to
  4282. 2:40:03the bottom and say group by gender. Now
  4283. 2:40:07let's go ahead and run this query. See
  4284. 2:40:10if it works. And it did. So we have our
  4285. 2:40:12gender and we have our average salary
  4286. 2:40:15from our salary table. And we can rename
  4287. 2:40:18this as average and we'll do average
  4288. 2:40:22salary. Just like that. So this is how
  4289. 2:40:25group by works. It rolls everything up
  4290. 2:40:28into one row. Now let's try doing
  4291. 2:40:31something pretty similar except we're
  4292. 2:40:34going to use a window function. Let's
  4293. 2:40:36come right down here and let's paste
  4294. 2:40:38this and let's start writing out our
  4295. 2:40:40window function. Now we don't have to
  4296. 2:40:41use the group by. We're going to go
  4297. 2:40:43ahead and get rid of that. And right
  4298. 2:40:45here for gender, we can keep that the
  4299. 2:40:47exact same. All we're really going to
  4300. 2:40:50change is this part right here. We're
  4301. 2:40:52going to say average salary. And that is
  4302. 2:40:55part of creating a window function.
  4303. 2:40:58Typically with a straightforward window
  4304. 2:40:59function, all we have to put is over
  4305. 2:41:02with a closed parenthesis. This is going
  4306. 2:41:04to say we're looking at the average
  4307. 2:41:06salary over and normally in here you'll
  4308. 2:41:09specify something and we'll get to that
  4309. 2:41:10in a little bit, but we're just going to
  4310. 2:41:11look at an average salary over
  4311. 2:41:13everything. So let's go ahead and run
  4312. 2:41:16this output. So this is going to look a
  4313. 2:41:18little bit different, right? So the male
  4314. 2:41:20and female all have their own individual
  4315. 2:41:24rows, which is not the same as group by.
  4316. 2:41:26And this average salary is looking at
  4317. 2:41:28the average salary of everybody. We're
  4318. 2:41:31not breaking it out by the gender like
  4319. 2:41:34we did up here. Here we rolled it up.
  4320. 2:41:37Now we're looking at the average salary
  4321. 2:41:39for the entire column. Now what we can
  4322. 2:41:42do is actually partition by. Now
  4323. 2:41:44partition by is going to separate it out
  4324. 2:41:46kind of like grouping it. So let's say
  4325. 2:41:48partition
  4326. 2:41:50partition by and we'll say gender. So
  4327. 2:41:53just like when we did the group by, the
  4328. 2:41:55group by rolled everything up into one
  4329. 2:41:57row. This is not going to roll
  4330. 2:41:59everything up, but it is going to
  4331. 2:42:00perform this calculation based off of
  4332. 2:42:03the different genders, the unique values
  4333. 2:42:05in this column. Let's go ahead and run
  4334. 2:42:07this.
  4335. 2:42:09And if you'll notice, the female is
  4336. 2:42:1153,750,
  4337. 2:42:13the male 57,428.
  4338. 2:42:16Now, let's go and compare these. I'm
  4339. 2:42:17going to run this and this query. Let's
  4340. 2:42:20run this.
  4341. 2:42:21So if we look at our group by, it's the
  4342. 2:42:24exact same numbers except we have it on
  4343. 2:42:28their own individual rows. Now, why
  4344. 2:42:30would we want this? Well, let's say we
  4345. 2:42:33want additional information. So let's
  4346. 2:42:35just look at this one for now. So in
  4347. 2:42:38this one, let's say we wanted to add
  4348. 2:42:39additional things like the first name.
  4349. 2:42:42So we'll do demirst_ame.
  4350. 2:42:46We can do last or dem.last_ame.
  4351. 2:42:50So, we can add other information and it
  4352. 2:42:53doesn't affect this column at all
  4353. 2:42:56because we're using a window function.
  4354. 2:42:58If we try to add these exact things, and
  4355. 2:43:00I'm going to go up here and do it. If we
  4356. 2:43:02try to add these exact things to this,
  4357. 2:43:05let's see if um yeah, that works. And
  4358. 2:43:08then we also have to group by this.
  4359. 2:43:12If we run this query now, it's going to
  4360. 2:43:14be completely different because we're
  4361. 2:43:17using a group by. We're grouping by the
  4362. 2:43:19first name, the last name, and the
  4363. 2:43:21gender. We're breaking everything out
  4364. 2:43:23based off of the unique values in these
  4365. 2:43:25columns. Whereas down here,
  4366. 2:43:29it's completely independent
  4367. 2:43:32of what's going on in these other
  4368. 2:43:33columns. All we're doing is we're doing
  4369. 2:43:35a window function just based off of that
  4370. 2:43:38column. So, I think that's pretty
  4371. 2:43:40amazing. And there's a lot of additional
  4372. 2:43:43functionality that we can do with these
  4373. 2:43:45window functions. And we're going to
  4374. 2:43:47take a look at a lot of those things in
  4375. 2:43:48just a little bit. Let's try another
  4376. 2:43:50example really quickly. Let's literally
  4377. 2:43:52just copy this, paste it down here. And
  4378. 2:43:55all we're going to do is we're going to
  4379. 2:43:56change this to sum.
  4380. 2:43:59So now instead of the average salary,
  4381. 2:44:02we're looking at the sum of salaries and
  4382. 2:44:05we're still partitioning by the gender.
  4383. 2:44:07Let's go ahead and run this and let's
  4384. 2:44:09pull this up.
  4385. 2:44:11So, all the men together make $42,000.
  4386. 2:44:16All the females make $215,000.
  4387. 2:44:20Now, what we're about to do is something
  4388. 2:44:22called a rolling total. If you've never
  4389. 2:44:25heard of a rolling total, a rolling
  4390. 2:44:26total is super cool and can be done
  4391. 2:44:29within my SQL. A rolling total is going
  4392. 2:44:32to start at a specific value and add on
  4393. 2:44:34values from subsequent rows based off of
  4394. 2:44:37your partition. So, all we have to do is
  4395. 2:44:39add an order by. And we're going to
  4396. 2:44:42order by let's say the employee
  4397. 2:44:44ID. Let's go ahead and take a look at
  4398. 2:44:46this. And it looks like the employee ID
  4399. 2:44:49is ambiguous. I had a feeling. So, I
  4400. 2:44:52just need to say uh dem employee ID.
  4401. 2:44:56Let's try this one. So, now we have
  4402. 2:44:59something called a rolling total. I'm
  4403. 2:45:00going to actually name it as
  4404. 2:45:02rolling_total
  4405. 2:45:05because this is super cool. that window
  4406. 2:45:08functions can do this and this is
  4407. 2:45:10something that a lot of people in like
  4408. 2:45:12finance do. I did it myself when I
  4409. 2:45:14worked in healthcare and it partitions
  4410. 2:45:17based off the female and you can't see
  4411. 2:45:19the employee ID but there's an employee
  4412. 2:45:20ID that we're kind of ordering on in the
  4413. 2:45:22background. Now what it's doing is it's
  4414. 2:45:24starting with Leslie nope and she made
  4415. 2:45:2675,000 then the next person April she
  4416. 2:45:29made 25,000 which equals 100. And just
  4417. 2:45:32to actually see this better, I'm going
  4418. 2:45:34to add salary.
  4419. 2:45:36And so Leslie Nome had 75,000. Then
  4420. 2:45:40we're adding this 25,000 to the 75 and
  4421. 2:45:42we get 100. Then we're adding the 60,000
  4422. 2:45:46to 160,000. Then we're adding 55,000 to
  4423. 2:45:49215,000. So we're adding every single
  4424. 2:45:53time we're adding this salary to the
  4425. 2:45:56already existing total all the way up to
  4426. 2:45:59our grand total, which was 215,000. The
  4427. 2:46:02exact same thing happens with the males.
  4428. 2:46:04So, we start with 50,000, then we add
  4429. 2:46:0650, then we add 90, then we add 70, all
  4430. 2:46:09the way up to 42,000. Now, you can do
  4431. 2:46:11this in a lot of different
  4432. 2:46:12configurations on a lot of different
  4433. 2:46:14columns, but in essence, this is exactly
  4434. 2:46:17what a rolling total is. That's how it
  4435. 2:46:19works. And we were able to partition
  4436. 2:46:21based off of this column. We don't have
  4437. 2:46:23to use partition by. We could do this
  4438. 2:46:25completely regardless of the partition,
  4439. 2:46:27but I thought it was interesting to at
  4440. 2:46:29least break it out by female versus
  4441. 2:46:32male. So, now that we know how to use a
  4442. 2:46:34window function, let's look at some
  4443. 2:46:36special things that you can really only
  4444. 2:46:38do with window functions or window like
  4445. 2:46:41functions. So, we're going to bring this
  4446. 2:46:42down and what we're going to do is get
  4447. 2:46:44rid of this entire thing and we're going
  4448. 2:46:47to look at something called row number
  4449. 2:46:49and we're going to look at rank and then
  4450. 2:46:50we'll look at dense rank. So let's look
  4451. 2:46:52at row number. And this is just like an
  4452. 2:46:57aggregate function like we're doing the
  4453. 2:46:59average age or average salary or
  4454. 2:47:01something like that. This is what we're
  4455. 2:47:02doing. We're doing a row number. Now
  4456. 2:47:04we're going to do this over and we'll
  4457. 2:47:06just do everything for right now. So
  4458. 2:47:08let's go ahead and run this and just see
  4459. 2:47:10what it looks like. Let's bring it up.
  4460. 2:47:13And what we're doing is we're saying,
  4461. 2:47:15okay, we have first name, last name,
  4462. 2:47:17gender, salary. That's all great. But
  4463. 2:47:18then we get to row number. and we're
  4464. 2:47:20doing a row number based off of
  4465. 2:47:22everything. It doesn't matter what it
  4466. 2:47:24is. So, we're starting at one, which is
  4467. 2:47:26the very first row, and we go all the
  4468. 2:47:28way down to the bottom, just like an
  4469. 2:47:30employee ID. So, let's actually add
  4470. 2:47:32that. Let's do dm
  4471. 2:47:34employee id just like this.
  4472. 2:47:38So, we have this 1 2 3 4 5 6 7 8 9 10
  4473. 2:47:4111. Now, if you remember on this table,
  4474. 2:47:44we are missing Ron Swanson. So, it kind
  4475. 2:47:47of skips that, but it's basically like
  4476. 2:47:48an employee ID. We're kind of giving it
  4477. 2:47:50its own unique value. And these row
  4478. 2:47:53numbers are not going to repeat itself
  4479. 2:47:55if you do it like this. Now, they can
  4480. 2:47:58repeat themselves if we do a partition.
  4481. 2:48:00And let's do a partition on the gender
  4482. 2:48:02again because we know how to do that
  4483. 2:48:03one. We'll do partition
  4484. 2:48:06by, let me spell that right, partition
  4485. 2:48:08by the gender. Now, we're going to add a
  4486. 2:48:10row number based off the gender, but
  4487. 2:48:12again, it's broken out or partitioned by
  4488. 2:48:15gender. Let's look at this.
  4489. 2:48:18Now it goes for the females 1 2 3 4.
  4490. 2:48:22Then for the males it restarts 1 2 3 4 5
  4491. 2:48:266 7. Now this is just in a random order
  4492. 2:48:29based off how the you know data was
  4493. 2:48:30stored in the table itself. Now what if
  4494. 2:48:33we wanted to kind of rank these based
  4495. 2:48:35off of the highest salary first down to
  4496. 2:48:37the lowest salary? You nailed it. We
  4497. 2:48:40just add an order by. So we'll order by
  4498. 2:48:43salary. And if we want to do it from
  4499. 2:48:44highest to lowest, giving the highest
  4500. 2:48:47salary, the number one, and the lowest
  4501. 2:48:49salary, you know, later down, we'll do
  4502. 2:48:51descending.
  4503. 2:48:52And let's run this. And you'll see that
  4504. 2:48:55for female, we're still partitioning by
  4505. 2:48:57gender. For female, the highest salary
  4506. 2:48:59is one. Next is two, three, and then
  4507. 2:49:01four. Then for males, the highest salary
  4508. 2:49:04is one, all the way down to seven. So
  4509. 2:49:06that's what row number does. just gives
  4510. 2:49:08a row number based off of whatever
  4511. 2:49:10you're partitioning by or ordering by in
  4512. 2:49:13your window function. Now, let's go over
  4513. 2:49:15here and add a comma. And we're going to
  4514. 2:49:17add and let's go down just a hair. Let's
  4515. 2:49:22add rank. So, I want to do rank and
  4516. 2:49:25we'll do our parenthesis. Now, rank is
  4517. 2:49:27going to give it more of an official
  4518. 2:49:29rank. And let's see how this works. So,
  4519. 2:49:32we'll do rank and we'll do over
  4520. 2:49:34partition by salary descended. The exact
  4521. 2:49:36same thing.
  4522. 2:49:39And while we're here, I'm going to
  4523. 2:49:41rename these. I'm going to say as
  4524. 2:49:43as row_num
  4525. 2:49:46and we'll call this one uh rank num. So
  4526. 2:49:51let's go ahead and run this. And it
  4527. 2:49:54looks very very very similar except for
  4528. 2:49:57one small thing. This right here. So
  4529. 2:49:59when we're using the row number,
  4530. 2:50:01whatever we are partitioning by, it's
  4531. 2:50:03not going to have duplicate rows within
  4532. 2:50:04that partition. It just won't. So even
  4533. 2:50:06if there's 50,000 right here, it's just
  4534. 2:50:09going to automatically assign it based
  4535. 2:50:10off of something that it's running in
  4536. 2:50:12the background, whether it's the order
  4537. 2:50:13of how the data is stored in the table
  4538. 2:50:15or some other order by that you are
  4539. 2:50:17using on the table. Now rank is a little
  4540. 2:50:20bit different because rank is going to
  4541. 2:50:22take it just like it did the ronum
  4542. 2:50:24except when it encounters a duplicate
  4543. 2:50:26based off of the order by which is the
  4544. 2:50:29salary, it's going to assign it the same
  4545. 2:50:32number. So this is five and five. What's
  4546. 2:50:35unique about rank is that the next
  4547. 2:50:37number is not going to be the next
  4548. 2:50:38number numerically. It's going to be the
  4549. 2:50:40next number positionally. So this is 1 2
  4550. 2:50:443 4 five. This is kind of like a six.
  4551. 2:50:47And then it goes to seven. So it skips
  4552. 2:50:50number six. Now there's another one.
  4553. 2:50:53Let's copy this rank. There's another
  4554. 2:50:55type of rank called dense rank. And
  4555. 2:50:58we'll do dense rank. So, we'll do dense
  4556. 2:51:04rank. And let's run this.
  4557. 2:51:07And let's pull this up.
  4558. 2:51:09There we go. Now, dense rank is ever so
  4559. 2:51:13slightly different than rank in the fact
  4560. 2:51:14that when it gets down to duplicates,
  4561. 2:51:17it's still going to duplicate them. So,
  4562. 2:51:18it's going to have a five and a five,
  4563. 2:51:20but it's going to give the next number
  4564. 2:51:23numerically, not positionally. That is
  4565. 2:51:25the only real difference between rank
  4566. 2:51:27and dense rank. And again, row number is
  4567. 2:51:30just not going to have duplicates. It's
  4568. 2:51:32going to give it its own unique within
  4569. 2:51:33that partition. So, I know I just threw
  4570. 2:51:35a lot at you, but that's row number,
  4571. 2:51:37rank, and dense rank in a nutshell. And
  4572. 2:51:40you can review this, mess around with
  4573. 2:51:41it, all of these things, because, you
  4574. 2:51:43know, these are actually really, really
  4575. 2:51:44useful. So, that's all we're going to
  4576. 2:51:46take a look at in this window functions
  4577. 2:51:47lesson. I hope all of that made sense. I
  4578. 2:51:49hope you kind of got an understanding of
  4579. 2:51:51how it can work and how powerful these
  4580. 2:51:52window functions can be. And this is
  4581. 2:51:54actually the last lesson in the
  4582. 2:51:55intermediate MySQL series. Thank you
  4583. 2:51:57guys so much for watching. I really
  4584. 2:51:59appreciate it. If you like this video,
  4585. 2:52:01be sure to like and subscribe and
  4586. 2:52:02[music] I'll see you in the next video.
  4587. 2:52:10[music]
  4588. 2:52:16Hello everybody and welcome to the first
  4589. 2:52:17lesson in the advanced MySQL tutorial
  4590. 2:52:20series. Today we are going to be looking
  4591. 2:52:21at CTE. Now CTE stand for common table
  4592. 2:52:25expression. They're going to allow you
  4593. 2:52:27to define a subquery block that you can
  4594. 2:52:29then reference within the main query.
  4595. 2:52:32Now, that may not make perfect sense,
  4596. 2:52:34but we've looked at subqueries in the
  4597. 2:52:35past or in previous lessons in the
  4598. 2:52:37intermediate series. So, you kind of
  4599. 2:52:38understand that it's kind of like a
  4600. 2:52:40query within a query, except we're going
  4601. 2:52:42to name this subquery block, and it'll
  4602. 2:52:44be a little bit more standardized, a
  4603. 2:52:46little bit better formatted than
  4604. 2:52:48actually using a subquery. Let's take a
  4605. 2:52:50look at the basics of writing a CTE.
  4606. 2:52:53Let's pull this down really quickly. And
  4607. 2:52:55all we're going to do is we want to
  4608. 2:52:58create this as a CTE. So we'll say with
  4609. 2:53:01and that is our keyword to define our
  4610. 2:53:04CTE. So we're going to say with name our
  4611. 2:53:06CTE and we'll just call it CTE and we'll
  4612. 2:53:09do underscore example. And then we're
  4613. 2:53:12going to say as. So this is how we
  4614. 2:53:14define it. And now we need to actually
  4615. 2:53:16put it in parenthesis. Now you can do
  4616. 2:53:18this in several different ways. I'm
  4617. 2:53:20going to do it kind of like this just to
  4618. 2:53:23really emphasize that this is within the
  4619. 2:53:26CTE. Now, CTE are unique because you can
  4620. 2:53:29only use the CTE immediately after you
  4621. 2:53:32create it. So, if we come right down
  4622. 2:53:34here and we come right below it, we'll
  4623. 2:53:37say select everything and we're going to
  4624. 2:53:40say from CTE example. So, we'll say from
  4625. 2:53:44CTE example. And let's bring this back
  4626. 2:53:47up. Now, if we run this, we're going to
  4627. 2:53:49get the exact same output. Now, this
  4628. 2:53:52should seem pretty familiar, almost like
  4629. 2:53:54we're using a subquery. And within our
  4630. 2:53:58subquery, we have this right here. We're
  4631. 2:54:00kind of building our own little table.
  4632. 2:54:02And then we can query off of it down
  4633. 2:54:04below. So, we can come down here and
  4634. 2:54:06let's actually change the names in here.
  4635. 2:54:08We're going to say average
  4636. 2:54:11cell. And we'll change all of these real
  4637. 2:54:14quick just because don't uh I don't like
  4638. 2:54:18having to actually put the, you know, uh
  4639. 2:54:20the tick marks. I don't like doing that.
  4640. 2:54:22So here we're going to say max, then
  4641. 2:54:25we'll say min,
  4642. 2:54:28and then we'll say count. And let's go
  4643. 2:54:31ahead and run this again. And so now we
  4644. 2:54:33have these different names. And when we
  4645. 2:54:35come right here, we can say select, and
  4646. 2:54:38then we'll just do something really
  4647. 2:54:39simple. Let's do the average of average
  4648. 2:54:43cell. So the average salary and let's
  4649. 2:54:47run this. And so this is the average
  4650. 2:54:49between both the males and the females.
  4651. 2:54:52Kind of the purpose of these CTE is to
  4652. 2:54:54be able to perform more advanced
  4653. 2:54:56calculations. Something that you can't
  4654. 2:54:58easily do or can't do at all within just
  4655. 2:55:01one query. Another reason to use a CTE
  4656. 2:55:04is just the readability. You can
  4657. 2:55:06absolutely write this using a subquery.
  4658. 2:55:08And let's do that really quickly. And
  4659. 2:55:10it's just going to be a little bit
  4660. 2:55:11tougher to read and look at. So let's
  4661. 2:55:14come right up here. We're going to say
  4662. 2:55:18from and we'll do right here. We'll say
  4663. 2:55:21select everything. We'll do select
  4664. 2:55:24average cell
  4665. 2:55:26from here. And we're going to need to
  4666. 2:55:27name this. So we'll say um do example
  4667. 2:55:32subquery.
  4668. 2:55:34We'll get rid of this. And then we just
  4669. 2:55:36need to get rid of this. And we can run
  4670. 2:55:39this query. And we get the exact same
  4671. 2:55:41output. Now, if I formatted this exactly
  4672. 2:55:44the same, just like this, and the names
  4673. 2:55:47down there. If we look at this, the
  4674. 2:55:49syntax is just a little bit more
  4675. 2:55:50difficult to read. We're selecting the
  4676. 2:55:52average of average sal from, and then we
  4677. 2:55:54have our subquery right here, and then
  4678. 2:55:56we're naming it at the bottom. If we
  4679. 2:55:59scroll up and compare this, this one
  4680. 2:56:01just looks a lot better. Now, when
  4681. 2:56:04you're writing in my SQL, sometimes it
  4682. 2:56:05doesn't matter if it looks pretty or
  4683. 2:56:07not, as long as it gets the job done.
  4684. 2:56:09That is true, especially if you're just
  4685. 2:56:10going to be using it yourself. But in a
  4686. 2:56:12more professional environment, when
  4687. 2:56:14you're using this in your actual job,
  4688. 2:56:16they're going to be people who've been
  4689. 2:56:17using this for 10, 20 years, and they're
  4690. 2:56:19going to expect you to write it well.
  4691. 2:56:21They don't want it to be really messy.
  4692. 2:56:22They aren't most likely going to want it
  4693. 2:56:24to be written like this. I've been using
  4694. 2:56:26it for quite a long time and I much
  4695. 2:56:28prefer CTE over subqueries just visually
  4696. 2:56:31and it makes it a lot quicker to
  4697. 2:56:33actually read through. So that is just
  4698. 2:56:35one of the reasons although you get the
  4699. 2:56:37exact same output. Now there is some
  4700. 2:56:39additional functionality within CTE as
  4701. 2:56:41well. Now one thing that I mentioned
  4702. 2:56:43just a second ago is that when you build
  4703. 2:56:45a CTE you can only use it immediately
  4704. 2:56:48after. You can't use it right below it.
  4705. 2:56:50So, let's go ahead and let's copy this
  4706. 2:56:52query and we're going to bring it right
  4707. 2:56:54here. If we try to run this and let's do
  4708. 2:56:57this. We're going to get an error and
  4709. 2:57:00let's pull this up. It says table parks
  4710. 2:57:03andrec.ct
  4711. 2:57:04example doesn't exist. So, we're looking
  4712. 2:57:07for a table called CTE example in our
  4713. 2:57:11database, but it's not there. Now, the
  4714. 2:57:13reason this happens is because you're
  4715. 2:57:15creating a CTE. You're not creating a
  4716. 2:57:17permanent object like a temp table,
  4717. 2:57:19which we'll look at in the next lesson.
  4718. 2:57:21And you're not creating a real table and
  4719. 2:57:23you're not creating a view. You're
  4720. 2:57:24really not creating anything. It's just
  4721. 2:57:26a common table expression to create this
  4722. 2:57:29table right here. This basically almost
  4723. 2:57:31like a temporary table almost, but then
  4724. 2:57:35you're just using it to query off of it.
  4725. 2:57:37You're not saving it. You're not storing
  4726. 2:57:39it in memory. You're not really doing
  4727. 2:57:41anything with it. It's just like writing
  4728. 2:57:42a regular query. So this is why you can
  4729. 2:57:45only write it immediately after creating
  4730. 2:57:47the CTE. You can't write it down below
  4731. 2:57:49and reuse it because it's just like
  4732. 2:57:51calling a query that you wrote before.
  4733. 2:57:53It just isn't going to work. Now the
  4734. 2:57:55next thing that I want to take a look at
  4735. 2:57:57and let's copy this down here. Next
  4736. 2:58:00thing I want to take a look at is that
  4737. 2:58:01you can actually create multiple CTE
  4738. 2:58:05within just one. And so if we wanted to
  4739. 2:58:07do a more complex query or joining more
  4740. 2:58:10complex queries together, we can do that
  4741. 2:58:12all within one CTE. So let's come right
  4742. 2:58:15here. Let's get rid of all of this.
  4743. 2:58:19And we're going to say uh from the
  4744. 2:58:22demographics table, we're going to say
  4745. 2:58:24where birth date and let's just do as
  4746. 2:58:28larger than 1985-1.
  4747. 2:58:32So we have one query and we'll take just
  4748. 2:58:36a few columns from this table. So we'll
  4749. 2:58:39take let's say the employer or employee
  4750. 2:58:42ID. We'll take the gender and the birth
  4751. 2:58:46underscore date. So this is one query
  4752. 2:58:49and we're filtering just based off of
  4753. 2:58:51this birth date. Now when we create
  4754. 2:58:53this, this is the CTE example, but we
  4755. 2:58:57can have a comma here. We can come down
  4756. 2:58:59below and then we can say ct
  4757. 2:59:03example 2 and I need to combine that. So
  4758. 2:59:06two and then we can say as and then we
  4759. 2:59:09have another query. So then right here
  4760. 2:59:12we could say select everything. We'll
  4761. 2:59:15change that in a second from employee
  4762. 2:59:18say salary
  4763. 2:59:19and in the salary we'll just do a simple
  4764. 2:59:22one. We'll do where salary is greater
  4765. 2:59:25than 50,000.
  4766. 2:59:28And we'll actually just take the
  4767. 2:59:31employee id and the salary. Now if I
  4768. 2:59:36come right down here, I can say select
  4769. 2:59:38everything from CTE example which is and
  4770. 2:59:40let me scroll up so we can see
  4771. 2:59:41everything.
  4772. 2:59:43That's our original. Our CT example is
  4773. 2:59:45this first query right here. Then we're
  4774. 2:59:48creating our second one right here. And
  4775. 2:59:51we can join basically on these two
  4776. 2:59:54common table expressions. So now we can
  4777. 2:59:56say join and then we'll do CTE example
  4778. 3:00:022. I need to change that X
  4779. 3:00:05and then we'll say on then
  4780. 3:00:08[clears throat] we're just going to do
  4781. 3:00:09TT example
  4782. 3:00:12employee ID is equal to TTample2
  4783. 3:00:17employee
  4784. 3:00:19ID and not an equal sign but a dot.
  4785. 3:00:22There we go. Now, if we run this, it
  4786. 3:00:25should work and we can pull this down
  4787. 3:00:27and look at our output. Now, this is
  4788. 3:00:29just an example. This isn't a real use
  4789. 3:00:31case because, of course, we could just
  4790. 3:00:33join these two tables together normally,
  4791. 3:00:36but you can imagine you have a much more
  4792. 3:00:37complex query or you're doing a lot of
  4793. 3:00:40functionality within this table and you
  4794. 3:00:42just want a certain subsection of this
  4795. 3:00:44table and you're wanting to combine
  4796. 3:00:46those. This is how you can do that with
  4797. 3:00:48a CTE. So now we have all of our
  4798. 3:00:51information right here. And that can be
  4799. 3:00:53extremely extremely helpful. Now, one
  4800. 3:00:55last thing that I want to show you.
  4801. 3:00:56We're going to go all the way back up
  4802. 3:00:58really quickly right here. Let's run
  4803. 3:01:01this one one more time and let's
  4804. 3:01:04actually take everything
  4805. 3:01:07and let's run this. So here we have our
  4806. 3:01:11gender, average salary, max salary,
  4807. 3:01:13men's salary, and count salary. The last
  4808. 3:01:15thing that I want to show you, and this
  4809. 3:01:17is more of something that's just
  4810. 3:01:18somewhat helpful, you don't have to
  4811. 3:01:20actually do it in your main query, is
  4812. 3:01:22before we went in here and we changed
  4813. 3:01:24all the column names by doing an alias
  4814. 3:01:27by saying as and then saying the average
  4815. 3:01:29salary. And the as is just implied here.
  4816. 3:01:32But we're changing this via an alias. We
  4817. 3:01:34don't have to do this. In fact, we could
  4818. 3:01:36come right here and we could do a
  4819. 3:01:38parenthesis. We could call it gender.
  4820. 3:01:41We'd call it average salary, max salary,
  4821. 3:01:47miners
  4822. 3:01:49salary, and let's do countd
  4823. 3:01:54salary. So now, if we were to run this,
  4824. 3:01:56let's change this up. We'll do capital
  4825. 3:01:58on this one. If we wanted to run it like
  4826. 3:02:00this, when we run this, it'll change all
  4827. 3:02:02of those names to what we have it right
  4828. 3:02:04here. So this will be the default. This
  4829. 3:02:07will overwrite the column names that you
  4830. 3:02:09have in your actual CTE expression or
  4831. 3:02:12the query that you have within your CTE.
  4832. 3:02:14So, that is all we're going to take a
  4833. 3:02:15look at in this lesson on CTE. These are
  4834. 3:02:18very, very helpful, definitely help with
  4835. 3:02:20more complex queries, and they're just
  4836. 3:02:22really easy to read and understand,
  4837. 3:02:24which is why I personally use them a
  4838. 3:02:26lot. In the next lesson, we're going to
  4839. 3:02:28be taking a look at temp tables, and
  4840. 3:02:30we'll also compare temp tables to CTE,
  4841. 3:02:32and we'll [music] take a look at the
  4842. 3:02:33difference.
  4843. 3:02:46Hello everybody. In this lesson, we're
  4844. 3:02:48going to be taking a look at temporary
  4845. 3:02:50tables. Now, temporary tables are tables
  4846. 3:02:53that are only visible to the session
  4847. 3:02:55that they're created in. So, if I create
  4848. 3:02:57a temp table right now and I exit out of
  4849. 3:03:00my SQL and I come back in, it's not
  4850. 3:03:02going to be there anymore. And we'll
  4851. 3:03:03look at that in just a little bit. Now,
  4852. 3:03:05temporary tables can be used for a lot
  4853. 3:03:06of things, but how I've mostly used
  4854. 3:03:08them, especially as a data analyst, is
  4855. 3:03:10for storing intermediate results for
  4856. 3:03:12complex queries, somewhat like a CTE,
  4857. 3:03:15but also for using it to manipulate data
  4858. 3:03:18before I insert it into a more permanent
  4859. 3:03:20table. So, let's take a look at how we
  4860. 3:03:22can create a temp table. There's two
  4861. 3:03:24ways that you can do it. I'll show you
  4862. 3:03:25the first way, which I don't think is as
  4863. 3:03:27popular, and then I'll show you the
  4864. 3:03:28second way, which is how I typically use
  4865. 3:03:30it the most. Now, the first way to
  4866. 3:03:32create a temp table is to create a
  4867. 3:03:36temporary
  4868. 3:03:38table. I need to sound it out like that.
  4869. 3:03:39It's the only way I can spell. So, we're
  4870. 3:03:41going to do temp table. So, this is our
  4871. 3:03:43name. Now, if we just took this out and
  4872. 3:03:46we created a table, this would create a
  4873. 3:03:48table in our parks and recreation
  4874. 3:03:50database. But we don't want that. We
  4875. 3:03:53want to create a temporary table that
  4876. 3:03:55just lives inside of our memory or the
  4877. 3:03:57memory within our computer. Now, we're
  4878. 3:03:59going to create this temporary table
  4879. 3:04:01much like we would a regular table. And
  4880. 3:04:03we're going to need to name the columns
  4881. 3:04:05as well as the data types. So, let's do
  4882. 3:04:07first name. And our data type can be
  4883. 3:04:10varchar. Let's say 50. And we'll do a
  4884. 3:04:13comma. Then we'll do last name. We're
  4885. 3:04:16going to keep this really simple. We'll
  4886. 3:04:17do varchchar 50 again. And then for our
  4887. 3:04:21last one, we'll do favorite
  4888. 3:04:24movie. And for this one, it needs to be
  4889. 3:04:26longer. So we'll do varchchar let's say
  4890. 3:04:28100. Now let's get rid of this and let's
  4891. 3:04:31actually run this after we do our
  4892. 3:04:32semicolon. Let's actually run this and
  4893. 3:04:36nothing's going to happen. Let's click
  4894. 3:04:37refresh. Nothing's going to happen. At
  4895. 3:04:38least you can't see it happening. Let's
  4896. 3:04:41pull this up. And you can see that
  4897. 3:04:43create temporary table says zero row is
  4898. 3:04:46affected, but it was created. Now in
  4899. 3:04:48order to actually see it, we can do
  4900. 3:04:50select everything. And we'll do this
  4901. 3:04:53from our temp table. And we'll add a
  4902. 3:04:56semicolon. And then we run this. And we
  4903. 3:04:59have this empty table right here. Now,
  4904. 3:05:02what's really great about these temp
  4905. 3:05:03tables is then you can insert data into
  4906. 3:05:06it. And it basically is like a real
  4907. 3:05:08table except it just lives in memory and
  4908. 3:05:11they go away after a while. But you can
  4909. 3:05:13reuse this temp table over and over and
  4910. 3:05:16over again. Now, let's insert some data
  4911. 3:05:18into here and then we'll take a look at
  4912. 3:05:20this again. So, let's come right down
  4913. 3:05:21here. Let's insert data. We'll do insert
  4914. 3:05:24into and we want to insert that into the
  4915. 3:05:26temp table. And we're just going to say
  4916. 3:05:28values. Now, we just say values. I'll
  4917. 3:05:30use myself for this one. We'll do uh
  4918. 3:05:32Alex Freeberg. And what's my favorite
  4919. 3:05:36movie? Give me a comma. That'll be Lord
  4920. 3:05:39of uh I think it's like that. Lord of
  4921. 3:05:41the Rings, the Two Towers.
  4922. 3:05:46Uh it's probably my favorite movie of
  4923. 3:05:47all time. Now, let's go ahead and insert
  4924. 3:05:49this data.
  4925. 3:05:51And let's pull this down here. And let's
  4926. 3:05:53run it all the way down here after we
  4927. 3:05:56add our semicolon. And when we run this,
  4928. 3:05:59you'll notice that now we have data in
  4929. 3:06:01here. So now we can use this table much
  4930. 3:06:03like any real table. So that's the first
  4931. 3:06:06way to create a temp table. Not my
  4932. 3:06:08personal favorite way, although there
  4933. 3:06:10have been some use cases where I've done
  4934. 3:06:12it like that. I'm going to show you the
  4935. 3:06:13way that I typically do it. And for
  4936. 3:06:16this, let's select everything from the
  4937. 3:06:19employee
  4938. 3:06:20salary table. Let's run this. Now, let's
  4939. 3:06:24say I just wanted a subsection of this
  4940. 3:06:26data to sit in this temp table where the
  4941. 3:06:29salary is greater than let's say 50,000.
  4942. 3:06:32I could easily easily do this. I'm going
  4943. 3:06:33to say create temporary table and let's
  4944. 3:06:38do this one as salary over
  4945. 3:06:4150k. Now, one thing about naming either
  4946. 3:06:45temp tables or CTEs or sub queries or
  4947. 3:06:47any of these things where you need to
  4948. 3:06:48name something, I try to typically name
  4949. 3:06:50it something that actually makes sense.
  4950. 3:06:53So, the salary over 50k is something I
  4951. 3:06:55would actually name it in my real work.
  4952. 3:06:58I wouldn't normally name it something
  4953. 3:06:59like tempt table. The reason for that is
  4954. 3:07:02because when you're in a work
  4955. 3:07:03environment and you have lots of temp
  4956. 3:07:05tables, you're creating really advanced
  4957. 3:07:06store procedures, really advanced
  4958. 3:07:08queries, you have hundreds or even
  4959. 3:07:10thousands of tables and different
  4960. 3:07:11databases, it gets really complex. So
  4961. 3:07:14naming conventions are actually pretty
  4962. 3:07:16important or they become more important
  4963. 3:07:18uh the more you get entrenched in this
  4964. 3:07:19stuff. So just something to think about.
  4965. 3:07:22Now we're creating this temp table. Now,
  4966. 3:07:23we don't have to really insert data into
  4967. 3:07:26it more than we're just going to select
  4968. 3:07:28data from an already existing table. So,
  4969. 3:07:31I'm going to say select everything from
  4970. 3:07:35I'm going to say employee salary
  4971. 3:07:38and we're just going to say where the
  4972. 3:07:40salary is greater than 50,000. Now, I
  4973. 3:07:44want uh Tom and Jerry, I want them to be
  4974. 3:07:47included as well. So, I'll actually say
  4975. 3:07:49greater than or equal to. So now we're
  4976. 3:07:52creating a temporary table based off of
  4977. 3:07:54an already existing table and we're just
  4978. 3:07:56selecting data into this temporary
  4979. 3:07:59table. So when we run this now we can
  4980. 3:08:03select the salary over 50k and let's run
  4981. 3:08:08this and it works perfectly. Now the
  4982. 3:08:12great thing about tempt tables is they
  4983. 3:08:13last as long as you are within that
  4984. 3:08:15session. Meaning if I copy this query,
  4985. 3:08:18let's go to a new window and let's paste
  4986. 3:08:21this in here and let's zoom in a little
  4987. 3:08:24bit and let's run this. It still works
  4988. 3:08:27even in a new window. But if I'm to exit
  4989. 3:08:30out and come back in, then it is no
  4990. 3:08:33longer going to be working. Now, let's
  4991. 3:08:35exit out of this. Let's come back in and
  4992. 3:08:36we'll see if these temp tables still
  4993. 3:08:38work. Let's go ahead and exit out. Oh
  4994. 3:08:40jeez, I'm embarrassed. All right, let's
  4995. 3:08:42go to my SQL.
  4996. 3:08:45Let's come over here to the local
  4997. 3:08:46instance. So now it pulls right back up.
  4998. 3:08:49Zoom in once again on both these and
  4999. 3:08:51let's try to pull up our salary over 50k
  5000. 3:08:54temporary table. Let's run this. And
  5001. 3:08:57we're not getting an output. Let's go
  5002. 3:09:00back. It's going to say error code. The
  5003. 3:09:02table salary over 50k does not exist. So
  5004. 3:09:05it only lasted as long as we were within
  5005. 3:09:08this session. So that is how we create
  5006. 3:09:11our temp tables and that's how we use
  5007. 3:09:13our temp tables. Now in the last lesson
  5008. 3:09:15we had looked at CTE. CTE and tempt
  5009. 3:09:18tables both have their own use cases
  5010. 3:09:20within my SQL. For temp tables this is
  5011. 3:09:22usually for the more advanced things. So
  5012. 3:09:25I'm usually using these in store
  5013. 3:09:26procedures when I'm really manipulating
  5014. 3:09:29data and I'm doing a lot more complex
  5015. 3:09:31queries overall and oftent times I'll
  5016. 3:09:33use multiple temp tables and I'm joining
  5017. 3:09:35them together and I'm just doing a lot
  5018. 3:09:36of more advanced stuff. With CTE, it's
  5019. 3:09:39typically more simple things because you
  5020. 3:09:41can't make as advanced CTE or as complex
  5021. 3:09:44CTE. So with those, I'm usually keeping
  5022. 3:09:47it to just one level of transformation.
  5023. 3:09:49I have my base CTE or my base subquery
  5024. 3:09:52or query, however you want to call that,
  5025. 3:09:54and I'm changing it or doing one level
  5026. 3:09:57of advanced thing on top of that query.
  5027. 3:10:00That's what a CT is really great for.
  5028. 3:10:02Temp tables, you can just get a lot more
  5029. 3:10:04advanced with it. They also last within
  5030. 3:10:05the session. And if I'm using it
  5031. 3:10:07multiple times throughout something like
  5032. 3:10:09a store procedure, then it makes so much
  5033. 3:10:12sense to use a temporary table. So this
  5034. 3:10:14has been our lesson on temporary tables.
  5035. 3:10:16In the next lesson, we're going to be
  5036. 3:10:18taking a look at string functions.
  5037. 3:10:20[music]
  5038. 3:10:32Hello everybody. In this lesson, we're
  5039. 3:10:34going to be taking a look at stored
  5040. 3:10:35procedures. Store procedures are a way
  5041. 3:10:37to save your SQL code that you can reuse
  5042. 3:10:39over and over again. When you save it,
  5043. 3:10:42you can call that stored procedure, and
  5044. 3:10:43it's going to execute all the code that
  5045. 3:10:45you wrote within your store procedure.
  5046. 3:10:47It's really helpful for storing complex
  5047. 3:10:50queries, simplifying repetitive code,
  5048. 3:10:52and just enhancing performance overall.
  5049. 3:10:54So, let's take a look at how we can
  5050. 3:10:55create a stored procedure. Now, we're
  5051. 3:10:57going to start by just creating a really
  5052. 3:10:58simple query. We'll make it a little bit
  5053. 3:11:00more advanced as we go along and take a
  5054. 3:11:02look at the different things within
  5055. 3:11:04store procedures that you can do. Now,
  5056. 3:11:06let's change this query. Let's say where
  5057. 3:11:09the salary is greater than let's do
  5058. 3:11:1250,000. Let's actually do greater than
  5059. 3:11:14or equal to 50,000. We want to include
  5060. 3:11:17Tom uh and Jerry as well. So, let's go
  5061. 3:11:19ahead and run this. Now, what we want to
  5062. 3:11:21do is save this really complex code
  5063. 3:11:24within a store procedure. Let's come
  5064. 3:11:26right down here and we can create a
  5065. 3:11:29super super super simple store procedure
  5066. 3:11:32by just saying create procedure
  5067. 3:11:36and pasting that. Now we just have to
  5068. 3:11:38name it. So we have create procedure and
  5069. 3:11:40we'll call this large
  5070. 3:11:43salaries and then we do a closed
  5071. 3:11:46parenthesis. Now this is as simple as it
  5072. 3:11:49can possibly be. It does not get any
  5073. 3:11:51simpler than this. So let's go ahead and
  5074. 3:11:52run this. And if we go down, we pull
  5075. 3:11:56this up, you can see that it says create
  5076. 3:11:58procedure, zero rows affected. So it
  5077. 3:12:00looks like it worked. And if we come
  5078. 3:12:02over here to this refresh button, you
  5079. 3:12:04should see now that under store
  5080. 3:12:06procedures, it drops down and we have
  5081. 3:12:08our large salaries. That's exactly what
  5082. 3:12:10should have happened. We wanted to save
  5083. 3:12:12that into our parks and recreation. Now,
  5084. 3:12:14if you wanted to be careful, you could
  5085. 3:12:16say use parks
  5086. 3:12:20recreation. This is not a bad idea, but
  5087. 3:12:23you don't have to. But you can specify
  5088. 3:12:25what database within your actual editor
  5089. 3:12:27window. Sometimes that is helpful. But
  5090. 3:12:30now we've created it. Now let's see how
  5091. 3:12:32we can call it. All we have to do is say
  5092. 3:12:34call. We're going to copy this entire
  5093. 3:12:37thing including the parenthesis.
  5094. 3:12:39And let's end it with that's right, a
  5095. 3:12:43semicolon. Let's go ahead and run this.
  5096. 3:12:45And as you can see, it worked because we
  5097. 3:12:47got the exact output. So we actually
  5098. 3:12:49called this store procedure and this
  5099. 3:12:52code ran. So it's just a select
  5100. 3:12:54statement. So it worked perfectly. Now
  5101. 3:12:56you can also come over here to large
  5102. 3:12:58salaries and there's this little tiny
  5103. 3:13:00little button here that looks like a
  5104. 3:13:01lightning bolt. And if you click it,
  5105. 3:13:03it's going to open up a different window
  5106. 3:13:05and we'll say call parks and
  5107. 3:13:07recreation.large salaries. So you can do
  5108. 3:13:10it that way as well, but uh we're not
  5109. 3:13:12going to be doing it that way. Now what
  5110. 3:13:13we've written right here is not best
  5111. 3:13:16practice by any means. And I'm going to
  5112. 3:13:18copy this down here because there's a
  5113. 3:13:21lot of different things that you need to
  5114. 3:13:22take into account when you're creating a
  5115. 3:13:24store procedure. For example, this right
  5116. 3:13:27here is most likely not what you're
  5117. 3:13:29going to be putting into a store
  5118. 3:13:30procedure. This is super super simple.
  5119. 3:13:32Typically, you'll be having multiple
  5120. 3:13:34queries. And let's see what happens if I
  5121. 3:13:37try to put another query in here. And
  5122. 3:13:39let's get rid of this. So, we're going
  5123. 3:13:41to select everything where the salary is
  5124. 3:13:43greater than 50,000. Then we'll select
  5125. 3:13:45everything where it's greater than
  5126. 3:13:4610,000 which is everybody. Let's call
  5127. 3:13:48this large salaries 2. So we have two
  5128. 3:13:51different statements in here and we want
  5129. 3:13:53them all to be under this large salaries
  5130. 3:13:55too. Let's select everything and let's
  5131. 3:13:58run this and we're getting an output
  5132. 3:14:01which is already not a good sign but we
  5133. 3:14:03created the store procedure and then we
  5134. 3:14:06selected everything. So what's actually
  5135. 3:14:09happening here? Pull this back down.
  5136. 3:14:12What's happening is is this is creating
  5137. 3:14:14the store procedure and this is just
  5138. 3:14:16some other you know random query. But
  5139. 3:14:19that's not what we want. What we want is
  5140. 3:14:21everything or both of these queries
  5141. 3:14:23within one store procedure. The best
  5142. 3:14:25practice is to use something called a
  5143. 3:14:27delimiter. Now this right here is a
  5144. 3:14:29delimiter. The semicolon. So the
  5145. 3:14:32semicolon separates our queries from one
  5146. 3:14:34another. It tells my SQL hey you know
  5147. 3:14:36this is a different query. Don't be
  5148. 3:14:38mixing these and cause errors. You know,
  5149. 3:14:41that's essentially what a delimiter
  5150. 3:14:42does. Now, we can change the delimiter
  5151. 3:14:45by coming up here and saying delimiter,
  5152. 3:14:48and we can change it to almost anything
  5153. 3:14:50we want. Now, in my actual job, I've
  5154. 3:14:52seen it done many different ways. I've
  5155. 3:14:54seen these forward slashes. I've also
  5156. 3:14:56seen dollar signs. This is probably the
  5157. 3:14:58one that I've seen the most when I
  5158. 3:14:59worked with data engineers, data
  5159. 3:15:01scientists, database developers. You
  5160. 3:15:03This one I see a lot. And then you'll
  5161. 3:15:05come into the code and you'll say begin.
  5162. 3:15:09And let's go over here and let's tab all
  5163. 3:15:12of this. And then we'll say end. Now
  5164. 3:15:15when we end, we're going to end it with
  5165. 3:15:18this dollar sign. So here's what's
  5166. 3:15:20happening. We're changing the delimiter
  5167. 3:15:21right here to dollar sign. We're
  5168. 3:15:23creating our store procedure and within
  5169. 3:15:25it, we are keeping all of this. So all
  5170. 3:15:29of this code is going to go into this
  5171. 3:15:31one stored procedure. Then at the end,
  5172. 3:15:34we are saying this is the end right here
  5173. 3:15:37of this stored procedure. These
  5174. 3:15:39semicolons no longer are the delimiter
  5175. 3:15:42that's telling us when it is the end of
  5176. 3:15:44the store procedure. That's what the
  5177. 3:15:45delimiter does. Now, it is best practice
  5178. 3:15:47at the end to change it back, right? Uh
  5179. 3:15:50let me spell it right because if you
  5180. 3:15:52don't, then you're going to have to
  5181. 3:15:54start using uh these dollar signs for
  5182. 3:15:56everything. And how do you spell
  5183. 3:15:58delimiter? Oh man, there we go. Now,
  5184. 3:16:01we've changed it back to a semicolon
  5185. 3:16:04afterwards. So, then we can go and write
  5186. 3:16:05other queries and it'll um act
  5187. 3:16:07appropriately. Uh, let's go down. So,
  5188. 3:16:10this is getting closer to best practice.
  5189. 3:16:14Let's go ahead and run this entire
  5190. 3:16:16thing.
  5191. 3:16:17And if we pull this up, we're not
  5192. 3:16:19getting an output. That's a good sign.
  5193. 3:16:20If we pull this up, it's saying we
  5194. 3:16:22already created number two. Change that
  5195. 3:16:25to three. My apologies. Let's go down
  5196. 3:16:27here.
  5197. 3:16:29Now, we've created the store procedure
  5198. 3:16:31three. Now, let's go over here. We're
  5199. 3:16:33going to rightclick on this. We're going
  5200. 3:16:36to say alter stored procedure. And now
  5201. 3:16:39you can see that we have both of these
  5202. 3:16:41queries within this stored procedure.
  5203. 3:16:44Let's get rid of this. And we're going
  5204. 3:16:45to go and call this. So let's copy this
  5205. 3:16:49large salaries three.
  5206. 3:16:51Bring this all the way down.
  5207. 3:16:54And let's say call
  5208. 3:16:58that store procedure. If we run it,
  5209. 3:17:00you'll notice we get two outputs. We
  5210. 3:17:03have six and seven. This result six is
  5211. 3:17:06where it's greater than 50,000 or 50,000
  5212. 3:17:09uh or greater. This one is where it's
  5213. 3:17:11greater than 10,000 which is essentially
  5214. 3:17:13the entire table. Now, so far we've done
  5215. 3:17:15everything just by writing it all out.
  5216. 3:17:17And that's fantastic. But you can also
  5217. 3:17:20come over here to store procedures. You
  5218. 3:17:22can rightclick and say create stored
  5219. 3:17:24procedure. Now let's actually copy this.
  5220. 3:17:28We're just going to create the exact
  5221. 3:17:29same thing. We'll create store
  5222. 3:17:30procedure. And we can just paste this in
  5223. 3:17:33here. And let's go ahead and do that.
  5224. 3:17:35There we go. And sure, we'll call it new
  5225. 3:17:38procedure. Why not? And if we say apply,
  5226. 3:17:42you'll notice that it generates this
  5227. 3:17:44script right here. And we can apply it
  5228. 3:17:46and we can create it. We will in just a
  5229. 3:17:48second, but let's take a look at it. So,
  5230. 3:17:50we're going to use parks and recreation.
  5231. 3:17:52That's what I was mentioning before.
  5232. 3:17:54We're then going to say drop procedure
  5233. 3:17:56if exists. Now, this is something that I
  5234. 3:17:59was going to show you later, but I'll
  5235. 3:18:00just show it to you now. Sometimes it is
  5236. 3:18:02really beneficial to write something
  5237. 3:18:04like this before you create it in case
  5238. 3:18:06you've already created a store procedure
  5239. 3:18:08with that name that you're wanting to
  5240. 3:18:10replace. So it's checking if it's there
  5241. 3:18:12and if that new procedure is already
  5242. 3:18:14there, it's just going to drop it. Then
  5243. 3:18:16it comes down and let me see if I can
  5244. 3:18:17zoom in on this. And then it's going to
  5245. 3:18:20create our delimter which it uses dollar
  5246. 3:18:22signs. So my SQL is even, you know,
  5247. 3:18:23validating what I was saying earlier.
  5248. 3:18:25We're going to use parks and recreation
  5249. 3:18:27again. And now again we have to use
  5250. 3:18:29instead of a semicolon we're using
  5251. 3:18:30dollar signs. Then we're creating the
  5252. 3:18:33procedure which is new procedure we're
  5253. 3:18:35saying begin and then it's even changing
  5254. 3:18:38the delimter back. So basically
  5255. 3:18:40everything that I said this is kind of
  5256. 3:18:42doing it for you automatically. Now when
  5257. 3:18:44I click apply it went ahead and executed
  5258. 3:18:47that SQL statement and our new one is
  5259. 3:18:50ready. So, we can go ahead and alter
  5260. 3:18:52that store procedure, and it looks
  5261. 3:18:54exactly the same as this one out here,
  5262. 3:18:58which was uh large salaries number
  5263. 3:19:01three. So, it looks exactly the same.
  5264. 3:19:03Now, let's go ahead and get rid of this.
  5265. 3:19:05Get rid of this, and let's go down
  5266. 3:19:08below. The next thing I want to take a
  5267. 3:19:10look at is something called a parameter.
  5268. 3:19:13Now, before I actually get into this,
  5269. 3:19:14I'm going to copy all this down here
  5270. 3:19:16because I don't want to rewrite all of
  5271. 3:19:17it, uh, if I'm being honest. So let's
  5272. 3:19:20paste this in here. Now parameters are
  5273. 3:19:22variables that are passed as an input
  5274. 3:19:25into a store procedure in the allow the
  5275. 3:19:27store procedure to accept an input value
  5276. 3:19:30and place it into your code. Let's take
  5277. 3:19:32a look at what that actually means. Now
  5278. 3:19:34before I do anything, I'm just going to
  5279. 3:19:35change this to uh number four so I don't
  5280. 3:19:38forget. So let's get rid of all of this.
  5281. 3:19:42We're going to keep it somewhat simple
  5282. 3:19:43because we're looking at something new.
  5283. 3:19:45Now, when I say we're passing through a
  5284. 3:19:46parameter, I'm talking about when we're
  5285. 3:19:48calling it. So, let's say we've already
  5286. 3:19:51created this one. I'm not going to, you
  5287. 3:19:52know, run this yet, but let's say we've
  5288. 3:19:54created it. Let's say I want to pass in
  5289. 3:19:56an employee ID. I want to pass in a
  5290. 3:19:58specific person and I want to retrieve
  5291. 3:20:00their salary. I know their employee IDs.
  5292. 3:20:03I just want it to pull up their salary
  5293. 3:20:05for us. So, what we're going to do is
  5294. 3:20:07we'll get rid of this. And when we're
  5295. 3:20:09calling it, put this down. When we're
  5296. 3:20:11calling it, I'm going to pass through a
  5297. 3:20:12value like one. That's Leslie. Nope. And
  5298. 3:20:15then I want the salary to be the output.
  5299. 3:20:18So I'm going to select the salary. So
  5300. 3:20:20we're selecting salary from the employee
  5301. 3:20:23salary. But how do we know that this one
  5302. 3:20:26is the person we're looking for? Well,
  5303. 3:20:28when we're actually creating this
  5304. 3:20:29parameter, we create it right in here.
  5305. 3:20:32That's what tells the store procedure to
  5306. 3:20:34accept an input value when we're calling
  5307. 3:20:37it down below. We're going to call this
  5308. 3:20:39employee
  5309. 3:20:41ID. Now, after we call it, after we name
  5310. 3:20:44our parameter, we need to then give it a
  5311. 3:20:47data type. So, I'll call this an
  5312. 3:20:48integer. So, we're telling the store
  5313. 3:20:50procedure, when somebody calls this
  5314. 3:20:51store procedure, they have to pass
  5315. 3:20:53through an integer. It can't be a string
  5316. 3:20:56or it can't be a date. It has to be an
  5317. 3:20:58integer. Now what we're going to go do
  5318. 3:21:00is right down here we'll say where the
  5319. 3:21:04employee ID that's from this column in
  5320. 3:21:07the actual table we'll say is equal to
  5321. 3:21:10the employee
  5322. 3:21:12ID which is our parameter right here.
  5323. 3:21:15Now you may be thinking that's really
  5324. 3:21:17confusing. They're named the exact same
  5325. 3:21:18thing. Can I change it? The answer is
  5326. 3:21:21yes. I actually encourage it. So there
  5327. 3:21:22are some naming conventions that are out
  5328. 3:21:24there that I think are helpful ones that
  5329. 3:21:25I personally use. Um, but remember this
  5330. 3:21:28is just kind of a variable parameter
  5331. 3:21:30name. You can kind of call it whatever
  5332. 3:21:31you want. So if I wanted to say Huggy
  5333. 3:21:34Muffin, I could. Uh, and this could be
  5334. 3:21:37Huggy Muffin. So let's try it with Huggy
  5335. 3:21:39Muffin. I just came up with that off the
  5336. 3:21:41top of my head, so don't judge me. Um,
  5337. 3:21:43but we're going to create the store
  5338. 3:21:44procedure. And then when we call it
  5339. 3:21:46later, we want it to return the salary
  5340. 3:21:49where the employee ID right here is
  5341. 3:21:52equal to whatever was passed through
  5342. 3:21:55that parameter, that input parameter.
  5343. 3:21:57We're going to keep it as one. So it
  5344. 3:21:58should return 75,000. Let's go ahead.
  5345. 3:22:01We're going to create this. And now
  5346. 3:22:03let's go right down here and we're going
  5347. 3:22:05to run it. And we can see that that is
  5348. 3:22:07the salary and it worked perfectly. Now
  5349. 3:22:10like I was saying, that is not what I
  5350. 3:22:11would actually name it. Uh there are
  5351. 3:22:13some naming conventions like underscore
  5352. 3:22:16param at the end. So you kind of want to
  5353. 3:22:18keep it at least I recommend you try to
  5354. 3:22:21keep it similar to what you're actually
  5355. 3:22:23looking for. And you can either end it
  5356. 3:22:25in underscore param or there's another
  5357. 3:22:27way that you can do it which is come
  5358. 3:22:28right over here and do p underscore. And
  5359. 3:22:31these are just ways that you can tell
  5360. 3:22:33the code or you can just be able to
  5361. 3:22:35visually see the difference in the code.
  5362. 3:22:36So this is just what I recommend. Then
  5363. 3:22:39you put it right down here. you say
  5364. 3:22:41where the employee ID is equal to P
  5365. 3:22:43employee ID saying this is the parameter
  5366. 3:22:46that's being passed through and put into
  5367. 3:22:48our actual query. So that is all we're
  5368. 3:22:50going to take a look at in this lesson.
  5369. 3:22:52In the next lesson, we're going to be
  5370. 3:22:54taking a look at triggers [music] and
  5371. 3:22:55events.
  5372. 3:23:08Hello everybody. In this lesson, we're
  5373. 3:23:10going to be taking a look at triggers
  5374. 3:23:12and events. A trigger is a block of code
  5375. 3:23:14that executes automatically when an
  5376. 3:23:16event takes place on a specific table.
  5377. 3:23:19For example, let's take a look at these
  5378. 3:23:20two tables. Now, when a new employee is
  5379. 3:23:22hired, they're put into this table with
  5380. 3:23:25their salary information and everything,
  5381. 3:23:26but sometimes people forget or don't add
  5382. 3:23:30their information like uh you know who
  5383. 3:23:33right here. Uh they're not put into this
  5384. 3:23:35demographics table. And we want to
  5385. 3:23:37change that because we want to have
  5386. 3:23:38everybody in here. So when somebody is
  5387. 3:23:41put into this salary table, we want it
  5388. 3:23:43to automatically update with the
  5389. 3:23:45employee ID, first name, and last name
  5390. 3:23:48into this table right here for the
  5391. 3:23:50employee ID, first name, and last name.
  5392. 3:23:52So we're going to write a trigger when
  5393. 3:23:54data is updated into the salary, it's
  5394. 3:23:57going to also update the employee
  5395. 3:23:58demographics for us. Now, let's go right
  5396. 3:24:00down here and we're going to take a look
  5397. 3:24:03at how we can do that. Now, if you
  5398. 3:24:04watched the last lesson on store
  5399. 3:24:06procedures, we'll do a lot of the same
  5400. 3:24:08writing style or same formatting for
  5401. 3:24:11triggers and events. So, we're going to
  5402. 3:24:12start with is the delimter. We're just
  5403. 3:24:14going to do that right off the bat
  5404. 3:24:15before we get into anything. And we're
  5405. 3:24:16going to change that to the double
  5406. 3:24:18dollar sign. Now, the delimiter again in
  5407. 3:24:21case we have multiple lines of code,
  5408. 3:24:22which we're going to have. If we have
  5409. 3:24:24multiple lines of code when we're
  5410. 3:24:25creating this trigger, this delimter is
  5411. 3:24:28going to help us have multiple queries
  5412. 3:24:30within our create trigger statement. So
  5413. 3:24:33this is really important. We'll just
  5414. 3:24:34start out by doing that. Now let's
  5415. 3:24:36create our trigger. And we do need to
  5416. 3:24:40name this. So we'll say employee_insert.
  5417. 3:24:45And we'll just call it like that. Did I
  5418. 3:24:47spell that right? Yeah. Employee insert.
  5419. 3:24:49So we have our create trigger. We've
  5420. 3:24:52named it. Now we need to specify what
  5421. 3:24:54event needs to take place in order for
  5422. 3:24:57this to be triggered. So we're going to
  5423. 3:24:59say after an insert and I need to spell
  5424. 3:25:03insert right after an insert on and
  5425. 3:25:05we'll do the employee
  5426. 3:25:08salary table. So after we insert onto
  5427. 3:25:11the employee salary table down below
  5428. 3:25:13we're going to write what's actually
  5429. 3:25:14going to happen. Now we're writing after
  5430. 3:25:16because we're doing it where when new
  5431. 3:25:18information is put on the salary table
  5432. 3:25:20it's automatically updated into the
  5433. 3:25:22demographics table. But you could also
  5434. 3:25:25do before which means if data is deleted
  5435. 3:25:28from the employee salary table something
  5436. 3:25:30could happen but we're not doing any
  5437. 3:25:32deleting or any updating we're doing
  5438. 3:25:35insertion. So we're going to say after
  5439. 3:25:38an insert on now the next part that we
  5440. 3:25:40need to write is for each row. Now this
  5441. 3:25:43for each row means that the trigger is
  5442. 3:25:46going to get activated for each row that
  5443. 3:25:48is inserted. So, if we had an insert
  5444. 3:25:51statement that inserted four different
  5445. 3:25:52people who were just hired, that means
  5446. 3:25:54this trigger is going to be activated
  5447. 3:25:56four times. Now, some SQL databases like
  5448. 3:25:59Microsoft SQL Server have things like
  5449. 3:26:01batch triggers or table level triggers
  5450. 3:26:03that'll only trigger once for all four
  5451. 3:26:06of them. And in my opinion, those are
  5452. 3:26:08really, really nice. Uh, I've used
  5453. 3:26:10those. I like them. The way that my SQL
  5454. 3:26:12has it right here is not the most
  5455. 3:26:13optimal way to do it, unfortunately. but
  5456. 3:26:15we don't have access to the batch level
  5457. 3:26:17or the table level triggers at this
  5458. 3:26:19time. So this is really just the setup
  5459. 3:26:21for what we're about to write. So after
  5460. 3:26:23it's inserted on the employee salary
  5461. 3:26:25table for each row, what is going to
  5462. 3:26:28happen? We're going to go down here and
  5463. 3:26:29we're going to say begin and we'll have
  5464. 3:26:32end. Now the code that we're going to
  5465. 3:26:34write here is what's going to happen
  5466. 3:26:36after this event takes place. So what
  5467. 3:26:40we're going to do is we want to take
  5468. 3:26:42from this table. Let's bring this back
  5469. 3:26:44up real quick. When we insert a new
  5470. 3:26:47person, we want to take the employee ID,
  5471. 3:26:50the first name, and the last name and
  5472. 3:26:52automatically put it into the
  5473. 3:26:54demographics table. So, we want to say
  5474. 3:26:58insert and let me do tab insert into
  5475. 3:27:02we're going to insert into the employee
  5476. 3:27:06demographics
  5477. 3:27:08table. And we're not taking everything.
  5478. 3:27:10So, let's actually specify what columns
  5479. 3:27:12we're doing. We're doing employee id
  5480. 3:27:14first name and then the last underscore
  5481. 3:27:20name. Now we need to specify what the
  5482. 3:27:22values are. Now from the employee salary
  5483. 3:27:25table we're taking employee ID, first
  5484. 3:27:27name and last name. But we don't want to
  5485. 3:27:29take all of them, right? We don't want
  5486. 3:27:31to take every single employee ID, every
  5487. 3:27:33single first name, every single last
  5488. 3:27:34name. We only want to take the new
  5489. 3:27:36values that were just inserted. Well,
  5490. 3:27:39lucky for us, there is something that we
  5491. 3:27:41have for this. So, let's do values, new
  5492. 3:27:44parenthesy. We have something called
  5493. 3:27:45new. Now, new is going to say we're only
  5494. 3:27:48taking the new rows that were inserted.
  5495. 3:27:50There's also an old like this where it
  5496. 3:27:54takes rows that were deleted or updated,
  5497. 3:27:56but of course, for us, we're going to be
  5498. 3:27:58using new. So, we'll say new employee
  5499. 3:28:01ID, new_ame,
  5500. 3:28:05and then new.ast_ame. last underscore
  5501. 3:28:08name and we'll close that. Then we'll
  5502. 3:28:10come down here and we'll do our
  5503. 3:28:14delimiter and we'll change this as well.
  5504. 3:28:16We'll say delimiter back to a semicolon.
  5505. 3:28:20Now, we're getting this error because we
  5506. 3:28:22need this right here. So, let's recap
  5507. 3:28:25what we've created, then we'll actually
  5508. 3:28:26create it and try it out. So, we're
  5509. 3:28:29creating our trigger called employee
  5510. 3:28:31insert. After a row is inserted into the
  5511. 3:28:35employee salary table, for each row,
  5512. 3:28:38here's what's going to happen. We are
  5513. 3:28:39going to insert into the employee
  5514. 3:28:41demographics table the employee ID, the
  5515. 3:28:43first name, and the last name. Those are
  5516. 3:28:45the columns that we're going to insert
  5517. 3:28:46into. Then we're taking the values new.
  5518. 3:28:50ID, new name, and new.ast name. Now,
  5519. 3:28:54MySQL understands that when we say new,
  5520. 3:28:56we're talking about the event that takes
  5521. 3:28:58place. So, this is the data that's being
  5522. 3:29:00inserted. It just knows that. So, let's
  5523. 3:29:02go ahead and create it. We're going to
  5524. 3:29:04run this. And it should work. Let's pull
  5525. 3:29:06this up. Says create trigger. So, that
  5526. 3:29:08worked. Now, the thing about triggers,
  5527. 3:29:11uh, that's unfortunate, it does doesn't
  5528. 3:29:13have its own little section under here,
  5529. 3:29:15right? But it does have under the
  5530. 3:29:18employee salary. Let's go right here.
  5531. 3:29:21And then under the triggers. So, we can
  5532. 3:29:23find it, which is great. So, we have
  5533. 3:29:26this employee insert. If we rightclick,
  5534. 3:29:29we can't really do anything with it.
  5535. 3:29:30That's the unfortunate thing. We can't
  5536. 3:29:32alter it. We can't change it. We can't
  5537. 3:29:34drop it. We can't do anything. Um,
  5538. 3:29:35that's the unfortunate part. But let's
  5539. 3:29:37actually test it. So now we're going to
  5540. 3:29:39say insert into and we're going to
  5541. 3:29:41insert into this employee salary. That's
  5542. 3:29:44how we're going to trigger it. So insert
  5543. 3:29:45into the employee salary. And then we'll
  5544. 3:29:48do employee ID. These are all the
  5545. 3:29:51columns. The first underscore name, last
  5546. 3:29:54underscore name, occupation.
  5547. 3:29:57Uh, bear with me for a second. Then we
  5548. 3:29:59have salary and then department ID. So
  5549. 3:30:03this is what we're inserting into. Now
  5550. 3:30:05we have to do our values. Now this
  5551. 3:30:06should be shorter hopefully. We'll do
  5552. 3:30:0913. We'll call him uh Jean Ralph.
  5553. 3:30:14There we go. Last name is Sapperstein.
  5554. 3:30:19Just like that. And not actually just
  5555. 3:30:21like that. That's not spelled right. So
  5556. 3:30:23we have Sapperstein. His occupation is
  5557. 3:30:26entertainment
  5558. 3:30:28720 CEO. How much is he making? Uh let's
  5559. 3:30:32say a million. Is that a million? A
  5560. 3:30:35million. He's making a million dollars.
  5561. 3:30:37And he's really not part of any uh
  5562. 3:30:39department. So we're just going to have
  5563. 3:30:40null. So what we're about to do is we're
  5564. 3:30:43only inserting on the employee salary
  5565. 3:30:45table, but we're putting all the values
  5566. 3:30:47that we need into the appropriate
  5567. 3:30:49places. Let's add a semicolon. Let's go
  5568. 3:30:52ahead and run this. Make sure it worked.
  5569. 3:30:56And it says insert into and then one row
  5570. 3:30:59affected. Now let's come back up. Let's
  5571. 3:31:02look at our salary table first and get
  5572. 3:31:05rid of this.
  5573. 3:31:07If we pull this up, you can see Jean
  5574. 3:31:09Ralph Sapperstein. He was added. Let's
  5575. 3:31:13go over to the demographics is the
  5576. 3:31:14moment of truth. Let's see if it worked.
  5577. 3:31:18And as you can see, it worked perfectly.
  5578. 3:31:20We have Jean Ralph Sapperstein. Now,
  5579. 3:31:22they do need to come back and fill in
  5580. 3:31:23this information, but it's already in
  5581. 3:31:26here kind of queuing them up saying,
  5582. 3:31:27"Hey, we need this person's age, gender,
  5583. 3:31:29birth date, all that other information."
  5584. 3:31:31So, that is how we can create a trigger
  5585. 3:31:34based off of a specific table and then
  5586. 3:31:37when it happens, it just automatically
  5587. 3:31:40does it for us. We don't have to really
  5588. 3:31:41think about it. We just know that we've
  5589. 3:31:43created a trigger and we can actually go
  5590. 3:31:44and insert data on that table and that
  5591. 3:31:46trigger is going to work. it's going to
  5592. 3:31:48do what it's supposed to do. And that's
  5593. 3:31:50really, really helpful in the real world
  5594. 3:31:52when you're working with a ton of
  5595. 3:31:53tables. A ton of things need to be
  5596. 3:31:55automatically done and you don't want to
  5597. 3:31:57have to manually do this. So, having
  5598. 3:31:59these triggers can save you a ton of
  5599. 3:32:01time. Now, let's scroll down and we're
  5600. 3:32:03going to take a look at
  5601. 3:32:05events. Now, event is kind of similar to
  5602. 3:32:07a trigger. A trigger happens when an
  5603. 3:32:09event takes place, whereas an event
  5604. 3:32:12takes place when it's scheduled. So,
  5605. 3:32:14this is more of a scheduled automator
  5606. 3:32:17rather than a trigger that happens when
  5607. 3:32:18an event takes place. These can be
  5608. 3:32:20fantastic for a lot of things like when
  5609. 3:32:22you're importing data. You can pull data
  5610. 3:32:24from a specific file path on a schedule.
  5611. 3:32:27You can build reports that are exported
  5612. 3:32:28to a file on a schedule. You can do it
  5613. 3:32:31daily, weekly, monthly, yearly, really
  5614. 3:32:33whatever you'd like. It's just super
  5615. 3:32:35helpful for automation in general. Now,
  5616. 3:32:37let's say the Pawne Council comes up
  5617. 3:32:39with some new legislation. They need to
  5618. 3:32:42save some money, especially in the parks
  5619. 3:32:43and recck department. We're just
  5620. 3:32:44spending too much or they're spending
  5621. 3:32:46too much. And what they want to do is
  5622. 3:32:48retire people who are over the age of 60
  5623. 3:32:50immediately and give them lifetime pay.
  5624. 3:32:54So what we want to do is create an event
  5625. 3:32:57that checks it, let's say every month or
  5626. 3:32:59every day. And then if they're over a
  5627. 3:33:02specific age, we are then going to
  5628. 3:33:04delete them from the table and they will
  5629. 3:33:06be retired. This is a fake example, so
  5630. 3:33:09you know, go with it. So, what we're
  5631. 3:33:10going to do is come right down here.
  5632. 3:33:12We'll select everything from employee
  5633. 3:33:15demographics
  5634. 3:33:17and let's run this and let's pull this
  5635. 3:33:20up. So, let's say if they are over the
  5636. 3:33:22age of 60, which unfortunately is Jerry
  5637. 3:33:25Gurgage, like I don't make the rules,
  5638. 3:33:27but if they're over the age of 60, they
  5639. 3:33:29are going to be automatically retired.
  5640. 3:33:32So, let's come right over here. We're
  5641. 3:33:35going to say create event and we'll call
  5642. 3:33:38this the delete
  5643. 3:33:40and delete
  5644. 3:33:43retirees. Now before when we were
  5645. 3:33:46creating the trigger, we were saying
  5646. 3:33:47based off of a specific event, but here
  5647. 3:33:49we're going to schedule it. We're going
  5648. 3:33:51to say on schedule and then we're going
  5649. 3:33:54to say every and we could do one month.
  5650. 3:33:57Maybe we'll look every single month. But
  5651. 3:33:59here we'll do let's do every 30 seconds.
  5652. 3:34:03every 30 second. Now, we're going to go
  5653. 3:34:05down. We'll say do. And this is going to
  5654. 3:34:07say here's what needs to happen every 30
  5655. 3:34:10seconds. So, we'll say begin and end.
  5656. 3:34:14Now, what's going to happen every 30
  5657. 3:34:16seconds is we're just going to start
  5658. 3:34:17with a select statement. And I'll just
  5659. 3:34:19copy this. Actually, we'll start with a
  5660. 3:34:21select statement, but then we'll update
  5661. 3:34:22it to a delete statement. But we'll come
  5662. 3:34:25right here. We'll say where the age is
  5663. 3:34:29greater than or equal to 60. So, if we
  5664. 3:34:32just run this query right here,
  5665. 3:34:36that's only one person. That's Jerry
  5666. 3:34:37Gurgg. Now, if we want to write this
  5667. 3:34:39correctly, we'll do the delimiter.
  5668. 3:34:42We'll have the dollar signs. We'll have
  5669. 3:34:45the dollar sign right down here as well.
  5670. 3:34:47And we'll say delimiter back to a
  5671. 3:34:50semicolon. Now, every 30 seconds, we
  5672. 3:34:53don't want to select people who are that
  5673. 3:34:54age. We want to delete. So, let's go
  5674. 3:34:57right here. We're going to change this
  5675. 3:34:58because now we know it should be
  5676. 3:34:59deleting the right person. and we're
  5677. 3:35:01going to go ahead and create this event.
  5678. 3:35:04Let's go ahead and run this.
  5679. 3:35:06And let's make sure it was created
  5680. 3:35:08properly.
  5681. 3:35:10It looks like create event zero is
  5682. 3:35:12affected. This should be working. Let's
  5683. 3:35:14go back up to the demographics table and
  5684. 3:35:16let's run this.
  5685. 3:35:19And let's pull this down and pull this
  5686. 3:35:22up. And as you can see, unfortunately,
  5687. 3:35:25Jerry Gurgich is no more. Um, you know,
  5688. 3:35:28he's just too old. and the Pony Council,
  5689. 3:35:30they recognized that. And so it wasn't
  5690. 3:35:32my rule. That was unfortunately Ponyie
  5691. 3:35:34Council's rule. Now, really quickly, if
  5692. 3:35:36that did not work, let's say you
  5693. 3:35:38couldn't create your event at all. Let's
  5694. 3:35:41go down here. I'm going to show
  5695. 3:35:43variables
  5696. 3:35:44and we'll run it just like this.
  5697. 3:35:48Um, I'm going to show you how you may
  5698. 3:35:50need to fix this. So, we can say where
  5699. 3:35:53variables is like, and then we'll say,
  5700. 3:35:56uh, event. do it just like this. So, I
  5701. 3:36:00have a ventuler where the value is on.
  5702. 3:36:03If yours is off, which sometimes that
  5703. 3:36:05can happen, you're just going to update
  5704. 3:36:07this to on. Now, another issue could
  5705. 3:36:10have happened, and I just want to
  5706. 3:36:11explore this for just one second. You
  5707. 3:36:12may not have permissions to delete
  5708. 3:36:14things. If you do not come right up
  5709. 3:36:16here, let's try to figure this out
  5710. 3:36:18together. It's actually edit
  5711. 3:36:19preferences,
  5712. 3:36:21and I want to say it's right here into
  5713. 3:36:23the SQL editor at the very bottom. Yep.
  5714. 3:36:26So, save updates rejects updates and
  5715. 3:36:29deletes with no restrictions. This needs
  5716. 3:36:31to be unchecked. So, go to preferences,
  5717. 3:36:33go to the SQL editor down at the bottom,
  5718. 3:36:35uncclick this if that didn't work. Now,
  5719. 3:36:38if everything worked perfectly, you
  5720. 3:36:39don't need to change a thing. But if it
  5721. 3:36:41didn't, I just wanted to work through,
  5722. 3:36:42you know, some uh troubleshooting that
  5723. 3:36:44you may just have to Google or chat GBT
  5724. 3:36:47or something to try to figure out. So,
  5725. 3:36:49that is how we can create an event in my
  5726. 3:36:51SQL to run on a schedule. Now, typically
  5727. 3:36:53you wouldn't do it on every 30 seconds.
  5728. 3:36:56you would do something like every 1
  5729. 3:36:57month or every 1 year or you know a
  5730. 3:37:00longer time frame but you get the
  5731. 3:37:02picture of what we're trying to do. So
  5732. 3:37:04that is how we create triggers and
  5733. 3:37:05events and this is also the end of the
  5734. 3:37:08advanced my SQL series. If you made it
  5735. 3:37:11this far absolutely fantastic work in
  5736. 3:37:13the next two lessons those are going to
  5737. 3:37:14be our projects that we're going to work
  5738. 3:37:16on for this series. We'll have a data
  5739. 3:37:18cleaning project and we'll have an
  5740. 3:37:19exploratory data analysis project. Both
  5741. 3:37:22of those are going to include a ton of
  5742. 3:37:24things that we've looked at in this
  5743. 3:37:25series and even some new things that we
  5744. 3:37:27didn't look at in the actual lessons
  5745. 3:37:28themselves. So, thank you guys for
  5746. 3:37:30watching. I hope you enjoyed this entire
  5747. 3:37:32series. If you did, be sure to leave a
  5748. 3:37:34like and a subscribe below. I will see
  5749. 3:37:36you in those projects.
  5750. 3:37:41[music]
  5751. 3:37:50Hello everybody and welcome to the very
  5752. 3:37:52first project in the MySQL series. Today
  5753. 3:37:55we're going to be focusing on data
  5754. 3:37:56cleaning. Now if you don't know what
  5755. 3:37:58data cleaning is, it's basically where
  5756. 3:38:00you get it in a more usable format. So
  5757. 3:38:02you fix a lot of the issues in the raw
  5758. 3:38:04data that when you start creating
  5759. 3:38:06visualizations or start using it in your
  5760. 3:38:08products that the data is actually
  5761. 3:38:10useful and there aren't a lot of issues
  5762. 3:38:11with it. So that's really what data
  5763. 3:38:13cleaning is. Now, what we're about to do
  5764. 3:38:14is create a database. We're going to
  5765. 3:38:16import a data set. This is a real data
  5766. 3:38:18set. And what we're going to do is we're
  5767. 3:38:20going to clean the data. So, I'm going
  5768. 3:38:21to show you and walk you through all the
  5769. 3:38:23steps in order to clean the data. The
  5770. 3:38:25data set that we're going to be working
  5771. 3:38:26with will be in the GitHub. So, you can
  5772. 3:38:27just go and download that. I'll have a
  5773. 3:38:29link somewhere in the description. But,
  5774. 3:38:31let's get started. First thing we're
  5775. 3:38:33going to do is create a new database.
  5776. 3:38:34So, we'll go right over here to create a
  5777. 3:38:36new schema. And we're just going to call
  5778. 3:38:38this one. We'll do this is world
  5779. 3:38:42layoffs. So, if you can't tell already,
  5780. 3:38:45uh, we're going to do world layoffs. Uh,
  5781. 3:38:46that's the data set that we're going to
  5782. 3:38:47be doing. We'll just click apply. And
  5783. 3:38:50that creates our world layoffs right
  5784. 3:38:52here. Now, we're going to go into here.
  5785. 3:38:54There are no tables. We're going to
  5786. 3:38:56right click on tables and go to table
  5787. 3:38:58data import wizard. Now, we haven't done
  5788. 3:39:00this yet uh in this series. We haven't
  5789. 3:39:02imported any data, but that's what we're
  5790. 3:39:04doing here. We're going to show you how
  5791. 3:39:06to import data. So, we'll go ahead and
  5792. 3:39:08click browse. And as you can see right
  5793. 3:39:10here, we have this layoffs data set.
  5794. 3:39:12Let's open this up and we're going to
  5795. 3:39:15click next and we're going to create a
  5796. 3:39:18new table. There's no existing table in
  5797. 3:39:20this database. You can drop it if it
  5798. 3:39:22exists uh if you'd like to. It doesn't
  5799. 3:39:23matter. This is new. We're going to go
  5800. 3:39:25ahead and select next. Now, right here
  5801. 3:39:27is where you configure import settings.
  5802. 3:39:29Now, MySQL is going to automatically
  5803. 3:39:31assign a data type based off of the data
  5804. 3:39:33in these columns. So, we'll take a look
  5805. 3:39:35at the data later. Now, there is one
  5806. 3:39:38thing that you can take a look at real
  5807. 3:39:39quick. We have this date column. Now, in
  5808. 3:39:42here, it assigned it as a text. That's
  5809. 3:39:44because the format. We are going to
  5810. 3:39:46import this as the raw data. We're not
  5811. 3:39:48going to try to change anything in the
  5812. 3:39:50import settings. We're just going to
  5813. 3:39:51assume this is how the data was in the
  5814. 3:39:53table. So, we're not going to change
  5815. 3:39:54anything. Although, this may be
  5816. 3:39:57something that you would want to change
  5817. 3:39:58to something like a date time and go and
  5818. 3:40:01fix that. But, we're going to import
  5819. 3:40:03this as the raw data. Let's go ahead and
  5820. 3:40:05select next. We're going to import it.
  5821. 3:40:08We just select next. Now, this could
  5822. 3:40:09take a little bit. Uh, so while this is
  5823. 3:40:11importing, I'm just going to skip ahead.
  5824. 3:40:13This should take just a few minutes to
  5825. 3:40:14import. All right, this just finished.
  5826. 3:40:16Let's select next. And we imported 2,361
  5827. 3:40:20records. Let's go ahead and select
  5828. 3:40:22finish. We can get rid of this. And
  5829. 3:40:26let's refresh this. Perfect. We have our
  5830. 3:40:29layoffs table. So, we'll select
  5831. 3:40:31everything. And I'm going to go and
  5832. 3:40:33double click on the world layoffs
  5833. 3:40:35because I don't want to write out the
  5834. 3:40:36whole thing every time. So we're going
  5835. 3:40:37to say from layoffs and let's see what
  5836. 3:40:41we get. So let's take a look at the data
  5837. 3:40:44that we're going to be working with in
  5838. 3:40:46this data cleaning project. So this data
  5839. 3:40:48set is layoffs from around the world
  5840. 3:40:50starting I think 2021. And we'll take a
  5841. 3:40:52look at that in this date column later.
  5842. 3:40:54But it has the company. So it has the
  5843. 3:40:56company that did the layoffs. It has the
  5844. 3:40:58location of where they are, what
  5845. 3:41:00industry they are part of, how many they
  5846. 3:41:02laid off, the percentage that they laid
  5847. 3:41:04off. So the percentage of their company,
  5848. 3:41:06the date, the stage, which refers to the
  5849. 3:41:09stage that the company is in, whether
  5850. 3:41:10it's a series B, post IPO, uh they don't
  5851. 3:41:13know. Then there's the country, and then
  5852. 3:41:15we have funds raised millions. So we
  5853. 3:41:18have a lot of information here. And in
  5854. 3:41:21the next project, we're going to be
  5855. 3:41:22doing exploratory data analysis. So
  5856. 3:41:24we're cleaning all of this data and then
  5857. 3:41:27in the next lesson, we're going to
  5858. 3:41:28actually dive into it and try to find
  5859. 3:41:30trends and patterns and all these other
  5860. 3:41:32things. So what we are going to do is
  5861. 3:41:34we're going to go through multiple
  5862. 3:41:36steps. Step number one is we are going
  5863. 3:41:39to try to remove duplicates if there are
  5864. 3:41:42any. That is the first thing I typically
  5865. 3:41:44do especially if I know this data
  5866. 3:41:46shouldn't have any duplicates or it'd be
  5867. 3:41:48you know repetitive or unnecessary to
  5868. 3:41:50have duplicates. The second thing is
  5869. 3:41:52going to be to standardize
  5870. 3:41:55the data.
  5871. 3:41:56That just means that if there are issues
  5872. 3:41:58with the data with spellings or things
  5873. 3:42:00like that, we just want to standardize
  5874. 3:42:02it to where it's all the same as it
  5875. 3:42:03should be. Number three is we'll look at
  5876. 3:42:06the null values or blank values. And
  5877. 3:42:10there's a lot of null values in here.
  5878. 3:42:12There's even a blank value right here.
  5879. 3:42:14And we're going to see if we can
  5880. 3:42:16populate that if we can. And there are
  5881. 3:42:18times where you should, there are times
  5882. 3:42:20where you shouldn't. I'll kind of walk
  5883. 3:42:21through that as well. And lastly, we
  5884. 3:42:24want to remove any columns and rows that
  5885. 3:42:27aren't necessary. And there's a few
  5886. 3:42:28different ways to do that. Uh, this one
  5887. 3:42:30is a little bit, you know, um, let me
  5888. 3:42:33write this actually real quick. Remove
  5889. 3:42:34any columns. So, I'm just going to say
  5890. 3:42:36there are instances where you can do
  5891. 3:42:38this. There are instances where you
  5892. 3:42:39shouldn't do this. When you're working
  5893. 3:42:41with massive data sets and you have a
  5894. 3:42:43column that's, you know, completely
  5895. 3:42:44irrelevant, completely blank, you don't
  5896. 3:42:46have any ETL process that is required
  5897. 3:42:48for it. Um, you can get rid of it. it
  5898. 3:42:51can save you time when you're querying
  5899. 3:42:52your data. Now, with that being said, uh
  5900. 3:42:55and we'll talk about this later, in the
  5901. 3:42:57real workplace, oftent times you have
  5902. 3:42:59processes that automatically import data
  5903. 3:43:01from different data sources. If you
  5904. 3:43:02remove a column from the raw data set,
  5905. 3:43:05that's a big big problem. So, what we're
  5906. 3:43:08going to do is something I would
  5907. 3:43:10actually do in my real work, which is I
  5908. 3:43:12would create some type of staging or raw
  5909. 3:43:14data set. Let's say this one's our raw
  5910. 3:43:16one. And we could have even called this
  5911. 3:43:18layoffs raw. We're going to create
  5912. 3:43:21another one. We're going to create a
  5913. 3:43:22table. So, we'll say create table. And
  5914. 3:43:25let's call this one layoffs_staging.
  5915. 3:43:29And we literally just want to copy all
  5916. 3:43:31of the data from the raw table into the
  5917. 3:43:35staging table. So, we can do that really
  5918. 3:43:37quickly by just saying like layoffs.
  5919. 3:43:42And if we run this and we refresh,
  5920. 3:43:45you'll see we have the staging database.
  5921. 3:43:48And let's copy this.
  5922. 3:43:51Here we go. We'll do layoffs_staging.
  5923. 3:43:56And so now we have all of the columns.
  5924. 3:43:58And all we have to do is insert the
  5925. 3:44:00data. So we're just going to say insert.
  5926. 3:44:03Then we're going to say layoffs staging
  5927. 3:44:06right here. And we'll select everything
  5928. 3:44:10from
  5929. 3:44:12layoffs.
  5930. 3:44:14And let's run this. And if we select the
  5931. 3:44:17table, we now have all the data over. So
  5932. 3:44:20super super easy. And now we have these
  5933. 3:44:23two different tables. Now again, why do
  5934. 3:44:24we do this is because we're about to
  5935. 3:44:26change the staging database a lot. If we
  5936. 3:44:29make some type of mistake, we want to
  5937. 3:44:31have the raw data available. This does
  5938. 3:44:34happen. This is something that you do in
  5939. 3:44:36the real workplace because you're not
  5940. 3:44:37going to work on the raw data. It just
  5941. 3:44:39you shouldn't do it. It's not best
  5942. 3:44:40practice. So I'm going to show you what
  5943. 3:44:42I would actually do in my, you know,
  5944. 3:44:43like a real job. So, that's what we're
  5945. 3:44:46going to do now. We're only going to be
  5946. 3:44:47working off the staging database, and we
  5947. 3:44:49can copy this and make different
  5948. 3:44:51databases for different things. Um, as
  5949. 3:44:53long as we have our raw data, we can
  5950. 3:44:55really do anything we want going
  5951. 3:44:56forward. Uh, and that's what we're going
  5952. 3:44:58to do. So, the number one thing we're
  5953. 3:45:01going to look at is to make sure that we
  5954. 3:45:03are removing duplicates. We want to make
  5955. 3:45:05sure we don't have any duplicate data in
  5956. 3:45:06here, and if so, we're going to get rid
  5957. 3:45:07of it. Now, really quickly, if you did
  5958. 3:45:09my Microsoft SQL Server project, we did
  5959. 3:45:12something very similar, but we had an
  5960. 3:45:14extra column over here that gave the
  5961. 3:45:16unique row ID, which made it really easy
  5962. 3:45:19to remove the duplicates. Here, there is
  5963. 3:45:23no identifying factor that's going to be
  5964. 3:45:25easy for that. So, I'm just going to
  5965. 3:45:26tell you up front, removing these
  5966. 3:45:27duplicates is not going to be easy, but
  5967. 3:45:29we'll walk through it every step of the
  5968. 3:45:31way. So, what we can do is try and do
  5969. 3:45:33something like a row number and we'll
  5970. 3:45:35match it against all of these columns
  5971. 3:45:37and then we'll see if there are any
  5972. 3:45:39duplicates. Now, I'm just we're starting
  5973. 3:45:41off strong. Okay, we're jumping into
  5974. 3:45:43kind of some of the more advanced
  5975. 3:45:44things. It does get actually easier as
  5976. 3:45:46we go, but this is the actual order that
  5977. 3:45:48I follow. So, uh I'm going to keep it.
  5978. 3:45:50So, let's try to identify duplicates.
  5979. 3:45:53So, let's copy this.
  5980. 3:45:56Let's pull this down. Do underscore
  5981. 3:45:58staging.
  5982. 3:46:00There we go. Now, what we can do is we
  5983. 3:46:02can do row number and we'll do that
  5984. 3:46:04partition by basically we could do every
  5985. 3:46:07single one of these columns. That's kind
  5986. 3:46:09of what we're doing. So, what we can do
  5987. 3:46:12is we can say everything. Then we can do
  5988. 3:46:14a comma and we'll say row number and be
  5989. 3:46:19just like this. And we're going to do
  5990. 3:46:21this over and we want to partition by
  5991. 3:46:24all of these columns essentially. We
  5992. 3:46:27could just do a few for now to see if we
  5993. 3:46:29get any hits and then we can look at
  5994. 3:46:30that. But they're going to be multiple
  5995. 3:46:32companies that have layoffs in the same
  5996. 3:46:34location and industry. Although their
  5997. 3:46:36total laid off would probably be
  5998. 3:46:37different. The date would probably be
  5999. 3:46:38different. So if we do something like uh
  6000. 3:46:41company, let's do industry. We will do
  6001. 3:46:46total_laid
  6002. 3:46:49off,
  6003. 3:46:50percentage
  6004. 3:46:52laid off. And then let's do date. Now
  6005. 3:46:56I'm doing date with the back ticks
  6006. 3:46:58because date is a keyword in my SQL. So
  6007. 3:47:02if we do it like this, it just really
  6008. 3:47:04makes it easy. So we're going to
  6009. 3:47:06partition by all of these things. So
  6010. 3:47:08let's do partition by and let's bring
  6011. 3:47:12this down real quick. So I'm just going
  6012. 3:47:14to say over partition by and we're going
  6013. 3:47:16to call this as row_num.
  6014. 3:47:20Now let's try running this. Let's see if
  6015. 3:47:22it works really quickly. It's important.
  6016. 3:47:25And over here you can see that we have
  6017. 3:47:28our row number. Now these mostly are
  6018. 3:47:30unique and these all look unique. I'm
  6019. 3:47:32not going to scroll through all of them,
  6020. 3:47:33but we want to be able to filter on
  6021. 3:47:35this. So we can filter where the row
  6022. 3:47:36number is greater than two. If it has
  6023. 3:47:38two or above, that means there's
  6024. 3:47:39duplicates. That means there's an issue.
  6025. 3:47:42So let's go ahead and we're going to
  6026. 3:47:44take this. We'll put it into either a uh
  6027. 3:47:47subquery or a CTE. I'll create a CTE for
  6028. 3:47:49this uh because it's really easy. So
  6029. 3:47:51we'll say four or not four, we'll say
  6030. 3:47:54width and then we'll do uh duplicate_ct
  6031. 3:47:59as then we'll just do our parenthesis.
  6032. 3:48:02We'll paste this in here and get rid of
  6033. 3:48:04that right there. And now we're going to
  6034. 3:48:06say
  6035. 3:48:08select everything from this duplicate
  6036. 3:48:12CTE. Then we'll say where row num is
  6037. 3:48:16greater than one. Let's run this and add
  6038. 3:48:19a semicolon. Let's run this. And you can
  6039. 3:48:22see that these ones have duplicates. So
  6040. 3:48:25these are our duplicates actually. And
  6041. 3:48:28we want to get rid of these exact rows.
  6042. 3:48:30Now just to confirm that these are uh
  6043. 3:48:32the duplicates, let's look at this one.
  6044. 3:48:35I've never heard of this company. Um but
  6045. 3:48:37we'll take it really quick
  6046. 3:48:40and let's select we'll say
  6047. 3:48:44where company is equal to. We'll call
  6048. 3:48:48this ODA. So, let's run this.
  6049. 3:48:53And it looks like these
  6050. 3:48:55No, no, no, no. These aren't duplicates.
  6051. 3:48:58That's a good thing we checked. Okay,
  6052. 3:49:00because it looks like um these aren't
  6053. 3:49:03the exact same. Although they're very,
  6054. 3:49:05very close, these technically are not
  6055. 3:49:07duplicates. So, I'm glad we checked
  6056. 3:49:09this. We need to do this partition by
  6057. 3:49:11over every single column. That's what
  6058. 3:49:13I'm realizing. So, we'll do company,
  6059. 3:49:16location. I'm glad I'm genuinely glad
  6060. 3:49:18we're, you know, it's good to make
  6061. 3:49:20mistakes um and figure things out as you
  6062. 3:49:22go. It really is important. So, company,
  6063. 3:49:24location, industry, total laid off,
  6064. 3:49:26percentage laid off, date, then we'll do
  6065. 3:49:29stage,
  6066. 3:49:30and then we'll do country, and then
  6067. 3:49:34funds
  6068. 3:49:36raised
  6069. 3:49:38millions. So, we're changing the CTE to
  6070. 3:49:41partition over everything. So, now let's
  6071. 3:49:43run this. Okay, ODA is not in there.
  6072. 3:49:46That's the only one we checked. Um, but
  6073. 3:49:48let's look at Casper. I know this. These
  6074. 3:49:50are the um Aren't these the mattress
  6075. 3:49:52people? Didn't know they had layoffs.
  6076. 3:49:54Poor guys. Um, all right. Let's take a
  6077. 3:49:55look. It looks like this row and this
  6078. 3:50:00row are duplicates. These are our
  6079. 3:50:02duplicates. So, we are going to want to
  6080. 3:50:04remove only one of those. We don't want
  6081. 3:50:07to remove all of those. So, um, just
  6082. 3:50:11looking at this one example, it looks
  6083. 3:50:12like this, uh, query is working well. So
  6084. 3:50:15here's our duplicates. Now we need to
  6085. 3:50:17identify these exact rows. We don't want
  6086. 3:50:20to delete both of them. When we looked
  6087. 3:50:22at Casper, there's the real one that we
  6088. 3:50:24want to keep. Then there's a duplicate
  6089. 3:50:25that we want to remove. We don't want to
  6090. 3:50:27remove both. That would be bad. Now in
  6091. 3:50:29my SQL, it's a little bit trickier to
  6092. 3:50:31remove things than it is in something
  6093. 3:50:33like Microsoft SQL Server, Postgrace
  6094. 3:50:35SQL. Um they have different ways that
  6095. 3:50:37they can delete rows. For example, in
  6096. 3:50:39Microsoft SQL Server, we could literally
  6097. 3:50:41identify these row numbers in the CTE
  6098. 3:50:43and delete them from it and it would
  6099. 3:50:45delete it from the actual table. We
  6100. 3:50:46can't do that in my SQL. And I'll show
  6101. 3:50:49you uh let's actually copy this.
  6102. 3:50:54We'll go like this and we'll say uh
  6103. 3:50:57let's say we want to delete these. We'll
  6104. 3:50:59say delete from we're deleting this from
  6105. 3:51:02where the row number is uh greater than
  6106. 3:51:04one. What am I writing right here?
  6107. 3:51:06Delete. There we go. So delete from this
  6108. 3:51:08duplicate CTE where the row number is
  6109. 3:51:10greater than one. That's all these
  6110. 3:51:11duplicates. We want to remove them.
  6111. 3:51:13Let's try to do this. Let's run it.
  6112. 3:51:16Let's go down. If we look at the bottom,
  6113. 3:51:18it says the target table duplicate CTE
  6114. 3:51:21of the delete is not updatable. So you
  6115. 3:51:23cannot update a CTE. A delete statement
  6116. 3:51:27is like an update statement. Um
  6117. 3:51:29essentially. So what we are going to do
  6118. 3:51:31is we're going to do something a little
  6119. 3:51:33bit different because this is how I
  6120. 3:51:34would love to do it. That makes it super
  6121. 3:51:36super easy to remove duplicates. But
  6122. 3:51:38that is not always the way that things
  6123. 3:51:40happen in the real world. I think what
  6124. 3:51:42we should do is take this right here and
  6125. 3:51:44let's run this. We should take this
  6126. 3:51:46right here and put this into let's say a
  6127. 3:51:48staging two database and then we can
  6128. 3:51:51delete it because we can filter on
  6129. 3:51:53[clears throat] these row nums and we
  6130. 3:51:54can delete those which are equal to two.
  6131. 3:51:56So it's essentially like you know
  6132. 3:51:59creating some type of table and then uh
  6133. 3:52:01just deleting the actual column. So
  6134. 3:52:03we're that's exactly what we're going to
  6135. 3:52:05do. So it's essentially just creating
  6136. 3:52:06another table that has this extra row
  6137. 3:52:08then deleting it where that row is equal
  6138. 3:52:11to two. So you know somewhat fairly
  6139. 3:52:13straightforward but um let's try it and
  6140. 3:52:17let's see what happens. So we're going
  6141. 3:52:19to come down here and do is create our
  6142. 3:52:22table. Uh let's try doing that with
  6143. 3:52:24here. Let's uh let's copy to clipboard a
  6144. 3:52:29create statement. Let's see if this
  6145. 3:52:30works. Perfect. That's exactly what I
  6146. 3:52:33wanted. Now, all we're going to do is
  6147. 3:52:36say we're creating the table layoff
  6148. 3:52:38staging 2. Now, this is a create table
  6149. 3:52:41statement and we're naming the columns
  6150. 3:52:43and then we're also assigning the data
  6151. 3:52:45type. So, we have all these things, but
  6152. 3:52:48we want one more. Let's do a comma and
  6153. 3:52:51we want to add row_num.
  6154. 3:52:54And I need to underscore num. And that
  6155. 3:52:56should be an integer data type. So, we
  6156. 3:52:59just keep it just like this. Let's go
  6157. 3:53:02ahead and copy this and let's run it.
  6158. 3:53:07See if it worked. Bring this up. Looks
  6159. 3:53:10like it worked properly.
  6160. 3:53:12Uh, and let's say
  6161. 3:53:15let's go back up.
  6162. 3:53:18I want to rewrite things that I don't
  6163. 3:53:20have to.
  6164. 3:53:22Let's run this. So, now we have this
  6165. 3:53:24empty table. So, we want to insert
  6166. 3:53:27this information right here. So, we're
  6167. 3:53:30going to insert into. So, we'll insert
  6168. 3:53:33into
  6169. 3:53:34and then we'll do this right here. So,
  6170. 3:53:36insert into staging two. Now, let's try
  6171. 3:53:39to run this. See if it works. And let's
  6172. 3:53:42run it. And let's select that table. And
  6173. 3:53:46now we have it. So, let's pull this back
  6174. 3:53:47up and I'll walk through what we just
  6175. 3:53:49did because I know I'm going quick, but
  6176. 3:53:50we have so much to cover um in this
  6177. 3:53:52lesson. So we just inserted basically a
  6178. 3:53:56copy of all these columns but in this
  6179. 3:53:59new table we added one more the row num.
  6180. 3:54:01So now we can filter and we can say
  6181. 3:54:04where I need to spell that right where
  6182. 3:54:07row num is equal to two or we should
  6183. 3:54:10should say greater than one because some
  6184. 3:54:12might have multiple duplicates. And
  6185. 3:54:14there you go. Here are our duplicates.
  6186. 3:54:16Now we're going to delete these. So all
  6187. 3:54:18we have to do is come right back down.
  6188. 3:54:21Where'd I go? Copy this. Come right back
  6189. 3:54:24down here and we're just going to say
  6190. 3:54:26delete from. We just did a select
  6191. 3:54:29statement. I always recommend doing that
  6192. 3:54:30to identify what you're deleting. Then
  6193. 3:54:32you change it to delete. And now if we
  6194. 3:54:35run this
  6195. 3:54:37go. And I'm actually going to keep this.
  6196. 3:54:39Um let me see. There we go. And let's
  6197. 3:54:42run it again. And now they're gone. And
  6198. 3:54:45if we say um just the whole table.
  6199. 3:54:50This looks wonderful. Now, this row num
  6200. 3:54:52is going to be a column at the end that
  6201. 3:54:53we probably don't need anymore, right?
  6202. 3:54:55It's a redundant column. It adds up
  6203. 3:54:57extra space in memory and storage and
  6204. 3:54:59all these other things and processing
  6205. 3:55:00times. We're just going to get rid of
  6206. 3:55:01it. Uh that'll be at the very end, I'm
  6207. 3:55:03sure. So, it looks like we are good to
  6208. 3:55:07go. That's how we remove duplicates.
  6209. 3:55:08Now, um there are different
  6210. 3:55:10[clears throat] ways to do it when you
  6211. 3:55:12have different columns. Like if you have
  6212. 3:55:13a unique column over here, makes it so
  6213. 3:55:16much easier. So, so so so much easier.
  6214. 3:55:18But we didn't have that. So we had to
  6215. 3:55:19kind of do a workaround. Uh welcome to
  6216. 3:55:21the real world. Now let's look at
  6217. 3:55:23standardizing
  6218. 3:55:26data. So standardizing data is finding
  6219. 3:55:29issues in your data and then fixing it.
  6220. 3:55:32So I'm already noticing right here. It
  6221. 3:55:35looks like we have a space at the
  6222. 3:55:36beginning. Uh we could easily just do a
  6223. 3:55:38trim on this column. Um and let's I'm I
  6224. 3:55:42don't even think I was um I did this
  6225. 3:55:44when I wrote out all the the scripts for
  6226. 3:55:46this. Let's just do from this table. Why
  6227. 3:55:49am I writing it all out again? We
  6228. 3:55:50actually want to select the company and
  6229. 3:55:53then the or actually we'll just do
  6230. 3:55:55distinct company. Distinct
  6231. 3:55:58company. Let's run this.
  6232. 3:56:02And
  6233. 3:56:04if we do a trim around this, let's run
  6234. 3:56:09this again.
  6235. 3:56:11And that looks better. So, if we do uh
  6236. 3:56:13company
  6237. 3:56:15company, comma, and then we'll just do
  6238. 3:56:17the trim. I don't want to
  6239. 3:56:20we don't need to do distinct right now.
  6240. 3:56:21We'll do the company. This just looks
  6241. 3:56:23better. So, we're going to update that.
  6242. 3:56:25Uh it's super easy. Now, if you ran into
  6243. 3:56:28an issue just a second ago, uh I may
  6244. 3:56:31need to help you change that. So, if you
  6245. 3:56:33couldn't update or delete those things
  6246. 3:56:35earlier, I should have told you this
  6247. 3:56:36earlier. I apologize. All you need to go
  6248. 3:56:39is to edit. You just need to go to edit,
  6249. 3:56:41go to preferences at the very bottom, go
  6250. 3:56:43to SQL editor, go all the way down to
  6251. 3:56:45the bottom, and right here we have safe
  6252. 3:56:48updates on. If you have this selected,
  6253. 3:56:50that means you can't update anything.
  6254. 3:56:51That's a problem. So, what you need to
  6255. 3:56:53do is select this uh or unselect it like
  6256. 3:56:56I have it and save it. You may have to
  6257. 3:56:59even restart your MySQL potentially uh
  6258. 3:57:01in order for the changes to take effect,
  6259. 3:57:03but then you should be able to update
  6260. 3:57:05that. Now, all we're going to do is
  6261. 3:57:07update this table.
  6262. 3:57:10and we're going to set. And now we need
  6263. 3:57:12to come back here and we'll say we're
  6264. 3:57:14going to set the company equal to trim.
  6265. 3:57:18Now, if you don't know what trim is or
  6266. 3:57:20you haven't taken that lesson, trim just
  6267. 3:57:22takes off the white space off the end.
  6268. 3:57:24So, it took the white space out of here
  6269. 3:57:26or off the right hand side as well. So,
  6270. 3:57:28we're going to update this and let's do
  6271. 3:57:30a semicolon. A semicolon. Let's run
  6272. 3:57:33this. Let's select this again. And it
  6273. 3:57:36was updated properly. So, we're already
  6274. 3:57:38off to a great start. Now, the next
  6275. 3:57:41thing that I want to take a look at is
  6276. 3:57:43the actual industry. So, let's go back.
  6277. 3:57:47Let's copy this
  6278. 3:57:50and let's take a look at the industry.
  6279. 3:57:52So, we'll do industry and we'll run it.
  6280. 3:57:55Now, if you look in here, there's a ton
  6281. 3:57:58of different industries. Um, and there's
  6282. 3:58:01marketing and marketing. Oh, because I
  6283. 3:58:03haven't done distinct.
  6284. 3:58:05Uh, please ignore me. Let's do distinct.
  6285. 3:58:08And there's a ton of different
  6286. 3:58:09industries in here. Transportation,
  6287. 3:58:11healthcare, consumer, uh there's a blank
  6288. 3:58:14one, which we'll take a look at.
  6289. 3:58:16Aerospace. There's a lot of really
  6290. 3:58:18unique ones. Let's actually order this.
  6291. 3:58:19We'll do order by uh and let's just do
  6292. 3:58:23one, which is the first column. We're
  6293. 3:58:24just ordering our own stuff. So, we have
  6294. 3:58:26null. We have blank. That's a problem.
  6295. 3:58:28We'll take a look at that later.
  6296. 3:58:31Uh but this is an issue. Crypto,
  6297. 3:58:32cryptocurrency, and cryptocurrency.
  6298. 3:58:34These are all the same thing. These
  6299. 3:58:35should all be uh on or labeled the exact
  6300. 3:58:39same thing. The reason we need to change
  6301. 3:58:41this is because when we start doing uh
  6302. 3:58:43the exploratory data analysis
  6303. 3:58:45visualizing it, these would all be their
  6304. 3:58:48own rows, their own unique thing, which
  6305. 3:58:50we don't want. We want them all to be
  6306. 3:58:52grouped together so we can accurately
  6307. 3:58:54look at the data. Let's take a look at
  6308. 3:58:56any other ones. Fintech and finance,
  6309. 3:58:59that could be the same thing. I'm not
  6310. 3:59:01100% sure. I'm not a fintech person. Um,
  6311. 3:59:05I think for now the only one that I'm
  6312. 3:59:07confident in changing is this one right
  6313. 3:59:10here, which is cryptocurrency. So, let's
  6314. 3:59:13go ahead and update that. So, all we
  6315. 3:59:15have to do and we need to actually let's
  6316. 3:59:17select really quickly where it's like
  6317. 3:59:20crypto. So we'll say uh where industry
  6318. 3:59:23and we want to select everything
  6319. 3:59:27where the industry
  6320. 3:59:29is like and we'll just do crypto. They
  6321. 3:59:34all start with crypto, right? Yeah. So
  6322. 3:59:35we'll do crypto just like this and let's
  6323. 3:59:38run this and let's just take a look. Lot
  6324. 3:59:43of layoffs in the crypto industry. Good
  6325. 3:59:45night. All right. Let's find where it's
  6326. 3:59:46cryptocurrency. Okay. So, even this one,
  6327. 3:59:49it's crypto. And I know Gemini crypto.
  6328. 3:59:51Crypto. And then it says cryptocurrency.
  6329. 3:59:53So, these should be all crypto. You see
  6330. 3:59:56how 95% of them are crypto. So, we're
  6331. 3:59:58going to update these other ones. Oh,
  6332. 4:00:01this one is C R Y PT. Is that how you
  6333. 4:00:03spell crypto? Jeez, I don't know
  6334. 4:00:05anything. All right. So, we want to
  6335. 4:00:06update all of them to be crypto. So,
  6336. 4:00:09what we're going to do is we're going to
  6337. 4:00:11say update
  6338. 4:00:14layoffs industry 2. We want to set the
  6339. 4:00:18industry equal to crypto
  6340. 4:00:22just like this where and we can do it a
  6341. 4:00:26few different ways. We can say industry.
  6342. 4:00:28We I think we can do like let's try this
  6343. 4:00:30real quick. I I some of this stuff I
  6344. 4:00:32don't have planned out. I'm just kind of
  6345. 4:00:33going with it as we go. Um which I like
  6346. 4:00:35better. You know, we kind of we work
  6347. 4:00:37together on this. We figure these things
  6348. 4:00:39out together. That's what I like. Um
  6349. 4:00:41then we'll do like crypto just like
  6350. 4:00:43this. Exactly like we had it up here.
  6351. 4:00:45So, if it's like crypto, it should be
  6352. 4:00:47crypto. Let's try this. Let's see if it
  6353. 4:00:50ran because it may not have. I can't
  6354. 4:00:52remember. Yeah, it worked. Okay, so it
  6355. 4:00:54updated uh three rows and that looks
  6356. 4:00:57correct. Now, let's go back up and let's
  6357. 4:01:02run this. And as we scroll down, they
  6358. 4:01:05are all the exact same. Beautiful,
  6359. 4:01:07beautiful, beautiful. So if we do uh
  6360. 4:01:10distinct industry again, let's get rid
  6361. 4:01:14of this.
  6362. 4:01:16If we run this query and we scroll down,
  6363. 4:01:19crypto is its own thing. Beautiful.
  6364. 4:01:23And it looks great. We can look at those
  6365. 4:01:26later on how we can update those. Um but
  6366. 4:01:29let's keep going. Let's look at our
  6367. 4:01:32whole table again. And these blanks and
  6368. 4:01:34these nulls are actually an issue. We do
  6369. 4:01:36need to deal with them. But I I my
  6370. 4:01:38instinct is telling me go fix it. Um but
  6371. 4:01:41my you know tutorial side is saying okay
  6372. 4:01:43stick with uh the tutorial the order
  6373. 4:01:46that we agreed on. Um so let's go take a
  6374. 4:01:49look. So we've looked at company, we've
  6375. 4:01:51looked at industry. Um let's just real
  6376. 4:01:53quick look at uh distinct
  6377. 4:01:56uh location. Now it's good to look at
  6378. 4:02:00most of these things, right? There could
  6379. 4:02:01be small tiny issues that you just never
  6380. 4:02:04saw. Um, and we're just going to order
  6381. 4:02:07by
  6382. 4:02:08order by one. Just do a real quick just
  6383. 4:02:12a scan to see if we find any issues.
  6384. 4:02:17Um, that could be an issue, but that
  6385. 4:02:19could just be another language if I'm
  6386. 4:02:21being honest. I don't know. I'm as I'm
  6387. 4:02:23just scrolling through here because I
  6388. 4:02:25want to make sure because this is not
  6389. 4:02:26something I had in my uh pre-written
  6390. 4:02:28script. This looks pretty good to me.
  6391. 4:02:31Um, let's do everything. We'll run this
  6392. 4:02:35and now let's look at country. So we'll
  6393. 4:02:38do distinct country and let's run this
  6394. 4:02:43and let's scroll down
  6395. 4:02:47again. This is sometimes just what I
  6396. 4:02:50actually do. All right, we got an issue
  6397. 4:02:52right here. Super common. Somebody put a
  6398. 4:02:54period at the end. Some dingus. Uh and
  6399. 4:02:57we're not going to judge that person. I
  6400. 4:02:58don't know who it was or who ruined this
  6401. 4:03:00data set, but um yeah, that's a problem.
  6402. 4:03:03So, we're going to need to just update
  6403. 4:03:04that. It looks pretty simple. Um, but
  6404. 4:03:07I'll just say where country is equal to
  6405. 4:03:10or let's say like and then I'll say like
  6406. 4:03:14United States.
  6407. 4:03:17There we go. And oops. I'm going to say
  6408. 4:03:20select everything. So, I just want to
  6409. 4:03:21see
  6410. 4:03:23um where it's at. Oh jeez, there's too
  6411. 4:03:26many.
  6412. 4:03:28Let me see if I can spot it.
  6413. 4:03:31I can't spot it. It looks like they're
  6414. 4:03:32supposed to be United States, not United
  6415. 4:03:34States dot. That's the issue. Um, we can
  6416. 4:03:37easily easily fix this. And we can
  6417. 4:03:40probably Let's do um really quickly,
  6418. 4:03:45let's do select, oops, select distinct,
  6419. 4:03:49and then we'll do country, comma, and
  6420. 4:03:52then we'll do a trim because we want to
  6421. 4:03:55get rid of that um that one. We'll do
  6422. 4:03:59country. Now, just doing the trim won't
  6423. 4:04:02fix it. Let's go to the bottom. So, that
  6424. 4:04:04doing the trim doesn't fix it. But
  6425. 4:04:06here's what you can do. It's a little
  6426. 4:04:08trick of the trade here. We're going to
  6427. 4:04:09do something called trailing, which
  6428. 4:04:11means coming at the end. So, what's
  6429. 4:04:13trailing? The period from country. Let's
  6430. 4:04:17try running this. Scroll to the bottom.
  6431. 4:04:20And it fixed it. So, this is a little um
  6432. 4:04:23a little advanced little tidbit for the
  6433. 4:04:26trim here. We can do trailing from the
  6434. 4:04:28country and we're looking for something
  6435. 4:04:30that's not a whites space. We're
  6436. 4:04:32specifying we're looking for a period.
  6437. 4:04:33So now what we can do is we can say
  6438. 4:04:35update. We can set the country do update
  6439. 4:04:39um this table and we'll oops and we'll
  6440. 4:04:44set what am I doing? What's going on
  6441. 4:04:46here? We'll set the country equal to and
  6442. 4:04:50we'll do it just like this. But we're
  6443. 4:04:51only going to do it for a country,
  6444. 4:04:53right? Uh so we'll say is equal to trim
  6445. 4:04:57and we'll say where country is equal to
  6446. 4:05:01or actually let's say like
  6447. 4:05:04and let me see if I have this. I don't.
  6448. 4:05:08Let's
  6449. 4:05:10let's just say like United States like
  6450. 4:05:11we had before.
  6451. 4:05:14Just like this. So let's go ahead and
  6452. 4:05:16update this after I put my semicolon in.
  6453. 4:05:18Let's run this. And let's run this
  6454. 4:05:21again.
  6455. 4:05:22It shouldn't need to fix it anymore.
  6456. 4:05:24It's just one row. That's perfect.
  6457. 4:05:26That's exactly what we wanted. Now, one
  6458. 4:05:29thing that's really important, uh, and
  6459. 4:05:31this is, you know, this is a
  6460. 4:05:32longitudinal,
  6461. 4:05:34it's not the right word at all. Give me
  6462. 4:05:36a second. I can't I can't speak and
  6463. 4:05:38write at the same time. So, sometimes I
  6464. 4:05:39just say, uh, dumb things. Um, uh, if we
  6465. 4:05:43want to do not longitudinal, but, um,
  6466. 4:05:46time series, that's the word I'm looking
  6467. 4:05:48for. If we're trying to do time series
  6468. 4:05:50um exploratory data analysis, time
  6469. 4:05:52series visualizations later on, this
  6470. 4:05:55needs to be changed. Right now it's text
  6471. 4:05:57and we can look at that by going right.
  6472. 4:05:59Actually, let's refresh this. We're not
  6473. 4:06:02looking at staging. We're looking at
  6474. 4:06:03staging two. If we look at the columns
  6475. 4:06:05and we come down here to date, it is a
  6476. 4:06:08text column. That's not good. If we're
  6477. 4:06:10trying to do uh time series stuff, we
  6478. 4:06:13want to change this to a date column.
  6479. 4:06:15Now, how can we do that? Let's take a
  6480. 4:06:17look. So, let's do date and let's not
  6481. 4:06:20actually do it like that. Let's do date
  6482. 4:06:21backslash. So, we're just going to look
  6483. 4:06:23at the date. Now, let's change this
  6484. 4:06:27because we want to format it how we want
  6485. 4:06:29to format it with it, which is month,
  6486. 4:06:31day, year. So, how can we do this? Well,
  6487. 4:06:34there's something that's very, very
  6488. 4:06:36helpful, works perfectly in this
  6489. 4:06:38situation, and is exactly what we're
  6490. 4:06:39going to do. It's called string to date.
  6491. 4:06:41So we're going to do string underscore
  6492. 4:06:43there it is right there undersc_2
  6493. 4:06:46date. It literally helps us go from a
  6494. 4:06:49string which is a text that's the data
  6495. 4:06:51type to a date. So it's perfect. Now all
  6496. 4:06:54we need to do is pass through two
  6497. 4:06:55parameters. We have to pass through the
  6498. 4:06:57column which is the date column and then
  6499. 4:06:59what format we want it in. Now if you
  6500. 4:07:02haven't done date formats before I'm
  6501. 4:07:03going to kind of walk you through it
  6502. 4:07:04while we're looking at it. Um in order
  6503. 4:07:07to format this properly you use a
  6504. 4:07:09percent sign. This is going to be a
  6505. 4:07:10formatting for a month. A lowercase M. A
  6506. 4:07:14capital M is something completely
  6507. 4:07:15different. I believe it's spelled out. I
  6508. 4:07:17need to I we can look at that in a
  6509. 4:07:18second if we want to actually. And then
  6510. 4:07:20we can do this right here. And then
  6511. 4:07:22we'll do another one. So we're
  6512. 4:07:23formatting it in the way that we want
  6513. 4:07:25it, but also converting it to an actual
  6514. 4:07:29uh date column. So now we want month and
  6515. 4:07:31then we want day lowercase day. We'll do
  6516. 4:07:34a forward slash and then another percent
  6517. 4:07:36sign and then a capital Y which stands
  6518. 4:07:38for I believe the four um four number
  6519. 4:07:42long year. Uh I have a let's just um
  6520. 4:07:45let's look at this real quick. So it
  6521. 4:07:47worked perfect. So we're it's taking in
  6522. 4:07:49this format that it's in right over here
  6523. 4:07:52and converting it into the date format.
  6524. 4:07:55So this is the standard date format that
  6525. 4:07:57you're going to find in my SQL. Now
  6526. 4:07:59let's see what happens really quickly
  6527. 4:08:00just for fun. Uh, let's see if we do
  6528. 4:08:02capital M. Uh, it looks like that's not
  6529. 4:08:05going to work at all. Uh, let's do
  6530. 4:08:07lowercase Y and um
  6531. 4:08:11just formatted it to 2020. I think it
  6532. 4:08:14took the first two numbers it looks
  6533. 4:08:16like. I don't know why it's doing that
  6534. 4:08:18if I'm being honest. Um, but if we keep
  6535. 4:08:21it with the capital Y as we should, this
  6536. 4:08:24looks perfect. This looks exactly like
  6537. 4:08:27what we're trying to do. So, you can
  6538. 4:08:28mess around with it. It depends on the
  6539. 4:08:30how the data is formatted in your
  6540. 4:08:32original column when it converts it to
  6541. 4:08:34the string to date. And there's a lot of
  6542. 4:08:36different stuff. You should just look up
  6543. 4:08:37um date formatting in my SQL. Really
  6544. 4:08:39interesting stuff. So, we're going to
  6545. 4:08:40update this date column to this, which
  6546. 4:08:43is our new date column. Let's go ahead
  6547. 4:08:45and do that. We're going to say update.
  6548. 4:08:48You guys should be getting used to this
  6549. 4:08:49by now. That's the whole point is
  6550. 4:08:50getting used to doing these things. So,
  6551. 4:08:52we're going to set date equal to and
  6552. 4:08:57then we're going to put in this right
  6553. 4:08:58here, the string to date. Go ahead and
  6554. 4:09:00do this. And let's run it.
  6555. 4:09:04Make sure it worked. 2355
  6556. 4:09:07rows. It looked like it did every single
  6557. 4:09:09one. Uh, but let's go ahead and get rid
  6558. 4:09:12of this
  6559. 4:09:14and let's run it.
  6560. 4:09:16And it looks like it worked perfectly.
  6561. 4:09:18Now, there were some nles. It looks like
  6562. 4:09:22and that'll be something we have to look
  6563. 4:09:23at later when we talk about nulls. But
  6564. 4:09:26um overall I believe this looks proper.
  6565. 4:09:30Now if we refresh this, let's refresh.
  6566. 4:09:33Let's come down to the date. You'll
  6567. 4:09:34notice it is still a text. It's date.
  6568. 4:09:38It's called text, but now it's in the
  6569. 4:09:39date format. Now that's really
  6570. 4:09:41important. And maybe I should have done
  6571. 4:09:43that earlier if I'm being honest. Um
  6572. 4:09:45tried to convert it to a date column. It
  6573. 4:09:46wouldn't work. It would give us an
  6574. 4:09:48error. Um you just have to trust me on
  6575. 4:09:49that one. But now we can do it where we
  6576. 4:09:52can change it to a date column. So let's
  6577. 4:09:55do alter table. Now only do this, never
  6578. 4:10:00ever do this on your raw table. Only do
  6579. 4:10:02this on things like a staging table
  6580. 4:10:03because we're about to completely change
  6581. 4:10:05the data type of the actual table. So we
  6582. 4:10:08want to change the layoff staging too.
  6583. 4:10:10And then we're going to come down here
  6584. 4:10:11and we're going to say modify column.
  6585. 4:10:14And what column are we modifying? It's
  6586. 4:10:17this date column.
  6587. 4:10:19There we go. And we want to change it to
  6588. 4:10:21what data type? A date. And am I
  6589. 4:10:24spelling this right? Yeah. I just need a
  6590. 4:10:26semicolon here. Whenever I see an error,
  6591. 4:10:28I always you got to just look for the
  6592. 4:10:30semicolons. So, let's go and run this.
  6593. 4:10:33And let's refresh. See if it worked. And
  6594. 4:10:35the date was changed to a date, which is
  6595. 4:10:38perfect. That's all we wanted to do. Uh
  6596. 4:10:40just to make sure we were doing what uh
  6597. 4:10:43or we'll set ourselves up later in the
  6598. 4:10:45future really well. Let's look at our
  6599. 4:10:48table.
  6600. 4:10:50All right, this is very good. So, we
  6601. 4:10:54fixed a few uh just issues with the
  6602. 4:10:57company. I believe something with the
  6603. 4:10:59industry or the cryptocurrency. We
  6604. 4:11:01changed the country. Um I'm just going
  6605. 4:11:03to go ahead and tell you right now, this
  6606. 4:11:05one uh we're not going to look at until
  6607. 4:11:07we look at the um nullles and whatnot in
  6608. 4:11:10just a second. So, we're not looking at
  6609. 4:11:11that one yet. And then uh we have this
  6610. 4:11:13extra column that we've done. So we've
  6611. 4:11:15done a lot so far, but the next thing in
  6612. 4:11:18the process, step one was remove
  6613. 4:11:19duplicates. Step two was
  6614. 4:11:20standardization. Step three is working
  6615. 4:11:22with null and blank values. Now this is
  6616. 4:11:25going to happen. You're going to have
  6617. 4:11:27nles and you're going to have uh blank
  6618. 4:11:30values in here. I it's somewhere um it's
  6619. 4:11:33just going to happen. And so we need to
  6620. 4:11:35think about what we're going to do with
  6621. 4:11:36that information. Whether we want to
  6622. 4:11:38make them all nulls, make them all
  6623. 4:11:39blanks, try to populate that data. Let's
  6624. 4:11:42see what we're going to do. So let's
  6625. 4:11:45start off with the total laid off. We'll
  6626. 4:11:48just do uh where total_laid
  6627. 4:11:53off is null. So in order to look at the
  6628. 4:11:56null, we say is null. Let's try equal to
  6629. 4:12:00null. It's not going to give it to us.
  6630. 4:12:02We have to say where it is null. So we
  6631. 4:12:05have these values. These are completely
  6632. 4:12:08null. Uh there's quite a few of them.
  6633. 4:12:10But remember this is also useful
  6634. 4:12:13information. But if they have two nulls,
  6635. 4:12:16uh that probably is pretty useless to
  6636. 4:12:19us. Um that's something I think we'll
  6637. 4:12:21take a look at in a little bit.
  6638. 4:12:22Actually, we'll say we and we may save
  6639. 4:12:25this query. Percentage
  6640. 4:12:28uh laid off is null. So if they're both
  6641. 4:12:32null like these, these are all I believe
  6642. 4:12:36fairly useless to us. These might be
  6643. 4:12:38ones that we remove. So let's actually
  6644. 4:12:40look at this. Um in step four we look at
  6645. 4:12:43removing rows and columns. But one thing
  6646. 4:12:46we should take a look at I remember this
  6647. 4:12:48industry.
  6648. 4:12:50Let's do uh industry
  6649. 4:12:53do distinct.
  6650. 4:12:55This industry had some missing values
  6651. 4:12:59and let's take a look at that. Okay. So
  6652. 4:13:02we have a missing value and we have a
  6653. 4:13:04null here. So let's look at this query
  6654. 4:13:09and let's say where
  6655. 4:13:12industry is null or
  6656. 4:13:17do industry
  6657. 4:13:18is equal to a blank like this. We'll
  6658. 4:13:22select everything. Let's run this. All
  6659. 4:13:26right. So it looks like there are a few
  6660. 4:13:30that are blank. Now, what we can try to
  6661. 4:13:32do is see if any of these have one
  6662. 4:13:34that's populated. Let's take Airbnb for
  6663. 4:13:36example. Let's search for this really
  6664. 4:13:38quickly. And this is 100% um you know,
  6665. 4:13:42it's just helpful. It's really really
  6666. 4:13:43helpful to be able to populate data that
  6667. 4:13:46is populatable. Is that a word? Um let's
  6668. 4:13:49try it. So, we'll say uh select
  6669. 4:13:52everything. I just wanted to do where
  6670. 4:13:56spell that right where company is equal
  6671. 4:13:58to and let's do Airbnb.
  6672. 4:14:03There we go. Let's run this.
  6673. 4:14:07And it looks like we have this one right
  6674. 4:14:08here. So, for example, um these whether
  6675. 4:14:12they have them or not, we're going to
  6676. 4:14:14try to populate these. If this Bs or
  6677. 4:14:17Carvana or Jewel had multiple layoffs,
  6678. 4:14:20these ones should if these ones aren't
  6679. 4:14:22blank. If they have one that's not
  6680. 4:14:23blank, we should be able to populate it.
  6681. 4:14:25For example, um not the one I was trying
  6682. 4:14:27to do. If we look at Airbnb, this one
  6683. 4:14:30has travel. So, we know this is the
  6684. 4:14:32travel industry. So, we can populate
  6685. 4:14:34this with travel. Again, we want this
  6686. 4:14:36data to be uh the same. So, if we're
  6687. 4:14:39trying to look at, you know, what
  6688. 4:14:41industries were impacted the most, this
  6689. 4:14:43row isn't going to be affected or this
  6690. 4:14:45row won't be in our output because it's
  6691. 4:14:46blank. We want that to be traveled to
  6692. 4:14:49represent the data properly. So, we want
  6693. 4:14:50to update it. So, if this one has
  6694. 4:14:52travel, we should be able to update this
  6695. 4:14:54row with this travel right here. So,
  6696. 4:14:58let's see how we can write this. And let
  6697. 4:15:00me give myself some rows right here. All
  6698. 4:15:03right. Now, what we're going to need to
  6699. 4:15:04do is try to do a join here. So, let's
  6700. 4:15:09try running out in a select statement
  6701. 4:15:10and then we'll just change it to an
  6702. 4:15:11update if it works. So, we're going to
  6703. 4:15:14select everything and we're going to do
  6704. 4:15:16this from staging two. from staging two
  6705. 4:15:20and we'll call this ST2
  6706. 4:15:23and then we'll join on itself because
  6707. 4:15:26what we're going to do is we're going to
  6708. 4:15:27check in this table does it have one
  6709. 4:15:29that is blank and not blank. If so
  6710. 4:15:32update it with the non-blank one that's
  6711. 4:15:35essentially uh in layman terms what
  6712. 4:15:37we're trying to write but writing it out
  6713. 4:15:38could be a little bit more difficult.
  6714. 4:15:40Um, so we're going to join on itself and
  6715. 4:15:44we'll call this let's actually call this
  6716. 4:15:45table one. T1 and T2 because they're the
  6717. 4:15:48exact same table. Uh, and we'll do this
  6718. 4:15:51on and we're going to say T1
  6719. 4:15:55company is equal to T2 company. So the
  6720. 4:16:00company has to be the same. That's
  6721. 4:16:02important. And we probably should do the
  6722. 4:16:04location is the same as well. Now we'll
  6723. 4:16:07do and T1.loation location is equal to
  6724. 4:16:12T2.loation. I'm imagining, you know,
  6725. 4:16:15there's another Airbnb in like South
  6726. 4:16:18America somewhere that's called Airbnb,
  6727. 4:16:20but you know, I'm just imagining a
  6728. 4:16:22scenario, right, where we have to think
  6729. 4:16:23about different use cases rather than
  6730. 4:16:24just large companies. So, those other
  6731. 4:16:27ones, they may have ones that are in
  6732. 4:16:29different locations. We don't want those
  6733. 4:16:31um we don't want to change them if
  6734. 4:16:32they're not the same. So, these are the
  6735. 4:16:34same. Now what we want to find is we're
  6736. 4:16:37going to say oops we want to say where
  6737. 4:16:40then we'll do t1.industry
  6738. 4:16:44is null and then we want to check that
  6739. 4:16:47t2.industry is not null. We'll say and
  6740. 4:16:51t2.industry
  6741. 4:16:55is not null. And let's just run this.
  6742. 4:16:58Let's see if we get anything. So let's
  6743. 4:17:00think this through because we got
  6744. 4:17:01nothing in our output. We're selecting
  6745. 4:17:04everything. We're joining on the company
  6746. 4:17:07and the company um and the location
  6747. 4:17:09where T1 industry is null and T2
  6748. 4:17:12industry is not null. Let's just get rid
  6749. 4:17:14of this for a second. I just want to see
  6750. 4:17:15if this changes anything. It doesn't.
  6751. 4:17:17And it's possible actually that instead
  6752. 4:17:20of doing is null, we could do or
  6753. 4:17:24and this I'm glad we're walking through
  6754. 4:17:26this. We can do or
  6755. 4:17:28is equal to blank. And let's try running
  6756. 4:17:31this. There we go.
  6757. 4:17:34Okay, so it looks like there's Jewel,
  6758. 4:17:38Carvana, and Airbnb. These ones all have
  6759. 4:17:41industries um where it's null or blank
  6760. 4:17:44and an industry is not null. So that's
  6761. 4:17:47really good. Now, if we scroll over, see
  6762. 4:17:49the industry here. This is our T1. This
  6763. 4:17:51is our first table. If we scroll over, I
  6764. 4:17:53bet we'll see the T2 industry where it's
  6765. 4:17:55not null. Let's scroll over. And here's
  6766. 4:17:59our industry. We have travel,
  6767. 4:18:00transportation, and consumer. So, this
  6768. 4:18:04worked exactly as we had hoped. I can
  6769. 4:18:06even um pull this up here just to show
  6770. 4:18:09kind of show you a little bit easier
  6771. 4:18:11what that's doing. And we'll do
  6772. 4:18:12T2.industry.
  6773. 4:18:14This is kind of like what we're trying
  6774. 4:18:15to do. So, if it's blank, this one is
  6775. 4:18:19going to be populated into here if there
  6776. 4:18:21is one that is not blank. So, that's
  6777. 4:18:23essentially what we're going to do.
  6778. 4:18:24Let's write the update statement and
  6779. 4:18:26we're going to see if it works. This we
  6780. 4:18:28have to translate this to an update
  6781. 4:18:30statement. So we'll do update and we're
  6782. 4:18:32going to update uh this right here. So
  6783. 4:18:35we'll say update T1 and then we'll do
  6784. 4:18:38the join
  6785. 4:18:40right there. And now we have to do a set
  6786. 4:18:42statement. So we'll set uh the
  6787. 4:18:44T1.industry
  6788. 4:18:47equal to and I'll just copy this
  6789. 4:18:50T2.industry. I just don't like I don't
  6790. 4:18:52like writing things out. Um then we say
  6791. 4:18:54where. So we do this
  6792. 4:18:58just like that.
  6793. 4:19:01and let's add a semicolon.
  6794. 4:19:03Okay, let's confirm. So, we're updating
  6795. 4:19:05this table T1. We're joining on T2 where
  6796. 4:19:08the company is the exact same. We're
  6797. 4:19:11setting T1 industry equal to T2
  6798. 4:19:13industry. So, the T1 should be the blank
  6799. 4:19:15one. So, where the T1 industry is null
  6800. 4:19:17or blank and T2 industry is not null.
  6801. 4:19:22Let's go ahead and run this semicolon.
  6802. 4:19:26See if there were about three updated.
  6803. 4:19:28Yep. Rematch zero rows affected though.
  6804. 4:19:32Let's go take a look. We have to let's
  6805. 4:19:36run this query. Looks like those are
  6806. 4:19:38still null. Let's run this. Uh, that one
  6807. 4:19:41is still blank. Now, let me think here.
  6808. 4:19:43I'm I'm trying to think of why this
  6809. 4:19:44didn't work. And I want to walk you
  6810. 4:19:47through my thought process.
  6811. 4:19:49It is possible that because these are
  6812. 4:19:52blanks and not nulls that it's not
  6813. 4:19:55working. I and I will say that is
  6814. 4:19:56something I typically do where I set
  6815. 4:19:59these blanks to nulls first. So let's
  6816. 4:20:03actually try that and see if that
  6817. 4:20:06changes anything. I'm just going to
  6818. 4:20:08update uh this. I'm going to say set the
  6819. 4:20:14industry
  6820. 4:20:16equal to null. We'll say where industry
  6821. 4:20:21is equal to blanks. So, we're just
  6822. 4:20:24changing it to null where it's blank.
  6823. 4:20:26Let's try this.
  6824. 4:20:29And let's go back down here to our
  6825. 4:20:30select statement.
  6826. 4:20:32So, these are all nulls. Okay. I think I
  6827. 4:20:36think this is now going to work because
  6828. 4:20:38now you can see on this side it's going
  6829. 4:20:40to it there's only one option for it to
  6830. 4:20:42populate it. Before there were those um
  6831. 4:20:45blanks which I think was causing the
  6832. 4:20:46issue. Um, let's get rid of this part
  6833. 4:20:51because now we have no nulls.
  6834. 4:20:53And now let's try running this. We're
  6835. 4:20:56workshopping this on the fly, guys. Uh,
  6836. 4:20:58let's see. Three rows affected. Heyo.
  6837. 4:21:01All right. Let's go see if it worked.
  6838. 4:21:03Um, let's run this query. And we have
  6839. 4:21:06none. That's perfect. Let's look at
  6840. 4:21:07Airbnb.
  6841. 4:21:11All right. All right. Ran into some
  6842. 4:21:12issues, but we worked through it. We
  6843. 4:21:14figured out the issue and now it's
  6844. 4:21:16working properly. And we can even come
  6845. 4:21:18back up here to select everything. And
  6846. 4:21:21it looks like Bailey's is the only one
  6847. 4:21:23that still has a null. Let's look up
  6848. 4:21:25Bailey's real quick and we'll say our
  6849. 4:21:28company is like uh Bailey.
  6850. 4:21:33Let's run this. Yeah. And there's only
  6851. 4:21:36one. So there wasn't another row. All
  6852. 4:21:38these other ones like Carvana and um I
  6853. 4:21:41can't remember where the other Jewel and
  6854. 4:21:43Airbnb, those ones had an extra row.
  6855. 4:21:45They did multiple layoffs. This one only
  6856. 4:21:47did one layoff. So, we don't have
  6857. 4:21:49another populated row where it's not
  6858. 4:21:51null to actually populate the null row.
  6859. 4:21:54That's really all that happened. Uh
  6860. 4:21:56that's why that worked that way. So, I'm
  6861. 4:21:58really happy that worked. Awesome job,
  6862. 4:22:00guys. Uh I was starting to question
  6863. 4:22:02myself. Do I even know how to use my
  6864. 4:22:05SQL? I mean, I was really starting to
  6865. 4:22:06question my abilities here.
  6866. 4:22:08um take a look. Uh I think that is all
  6867. 4:22:12we're going to do for populating null
  6868. 4:22:15values. Now, here's why. Things like
  6869. 4:22:18total laid off, percentage laid off, um
  6870. 4:22:21funds raised, how are we going to
  6871. 4:22:23populate that with the data that we have
  6872. 4:22:25here? I don't believe we can. Now, we
  6873. 4:22:28might be able to populate Oops. We might
  6874. 4:22:31be able to populate some of this if we
  6875. 4:22:33had the um company total like if we had
  6876. 4:22:36the original total before laid off
  6877. 4:22:38because then we could do calculations
  6878. 4:22:40like um oh these companies went
  6879. 4:22:42completely out of business. That's not
  6880. 4:22:44good. At 1% that means 100% was laid
  6881. 4:22:46off. Um [clears throat] but if we had
  6882. 4:22:49you know the total they had 50 employees
  6883. 4:22:52and 100% were laid off. We could
  6884. 4:22:53populate the total laid off. Whoops. Did
  6885. 4:22:56it again. We could populate the total
  6886. 4:22:58laid off by saying if this is 50 100%
  6887. 4:23:01was laid off that's 50 people were laid
  6888. 4:23:03off. We don't have that data so we can't
  6889. 4:23:05go and populate it I don't believe funds
  6890. 4:23:08raised we might be able to scrape some
  6891. 4:23:10data from the web and populate this but
  6892. 4:23:12that's a totally different thing um not
  6893. 4:23:15part of this project. So I think the
  6894. 4:23:17data cleaning for the null values and
  6895. 4:23:19blank values I think that's going to be
  6896. 4:23:21done. Um, it's possible that the stage
  6897. 4:23:24could be the same and if you want to go
  6898. 4:23:25check, you can, but we're going to keep
  6899. 4:23:27chugging along because we want to remove
  6900. 4:23:29columns and rows that we need to. Now,
  6901. 4:23:32if you remember, we were looking at this
  6902. 4:23:33before. Did I save that uh query? Let's
  6903. 4:23:36go look. Here we go.
  6904. 4:23:39Bring this down to the bottom.
  6905. 4:23:42All right, these rows. Let's let's
  6906. 4:23:46really take a look at these um and think
  6907. 4:23:47about if this is going to be help to us.
  6908. 4:23:49Um what we are trying to do with this
  6909. 4:23:53data in the near future is we're not
  6910. 4:23:55just trying to identify a company or a
  6911. 4:23:57location that had layoffs and maybe we
  6912. 4:23:59are maybe that maybe we are trying to do
  6913. 4:24:01that but these have no layoffs and no
  6914. 4:24:04percentage laid off. So in my opinion I
  6915. 4:24:07don't know if these laid off any at all.
  6916. 4:24:10Um I believe that we can get rid of
  6917. 4:24:13these. Now deleting data is a very
  6918. 4:24:17interesting thing to do. You have to be
  6919. 4:24:19confident. Am I 100% confident? No, not
  6920. 4:24:21really. But I'm confident enough to know
  6921. 4:24:23that what we're about to look at in the
  6922. 4:24:25next one, we're going to be using these
  6923. 4:24:26total laid off a lot, percentage laid
  6924. 4:24:28off a lot when we're looking at um you
  6925. 4:24:31know, actually querying the data and
  6926. 4:24:33doing some exploratory data analysis.
  6927. 4:24:35So, we're going to use these a lot. I
  6928. 4:24:36don't think uh these I'm not even sure
  6929. 4:24:40if these are accurate. I'm not even sure
  6930. 4:24:42if they actually did have a layoff. It's
  6931. 4:24:44saying they did, but it doesn't show if
  6932. 4:24:46they laid off any. So, um, can we delete
  6933. 4:24:49this? Yes. Should we delete this? It's
  6934. 4:24:52iffy. Uh, I'm not 100% if I'm being
  6935. 4:24:54completely honest. And there's a lot of
  6936. 4:24:56rows like that. This is This could be
  6937. 4:24:58like 100 or so. Really not. I mean, I
  6938. 4:25:01could run a query and run it, but I
  6939. 4:25:02don't want to. I don't It's not a big
  6940. 4:25:03deal. The point being, I don't think we
  6941. 4:25:06need this information. So, we're going
  6942. 4:25:07to get rid of it if nothing else just to
  6943. 4:25:10show that you can do it. So, now we'll
  6944. 4:25:12say uh delete. And then we'll do from
  6945. 4:25:15here. There we go. So now we're going to
  6946. 4:25:18delete these rows. Let's try to select
  6947. 4:25:20them again. And they are gone. So we
  6948. 4:25:22deleted the ones where the total laid
  6949. 4:25:23off was blank and the percentage laid
  6950. 4:25:25off was blank. We just I can't trust
  6951. 4:25:26that data. I really can't. Um and let's
  6952. 4:25:30go back down.
  6953. 4:25:32Come right here.
  6954. 4:25:35Semicolon. So I sometimes I have to walk
  6955. 4:25:37myself through these things. Um all
  6956. 4:25:40right. this row num. I mean, come on. We
  6957. 4:25:44don't need that anymore. Let's get rid
  6958. 4:25:46of it. Um, so what we can do now, it's a
  6959. 4:25:49little bit different syntax. We want to
  6960. 4:25:51drop a column from this table. So, we
  6961. 4:25:54have to do the alter table again. So,
  6962. 4:25:56we're going to alter table layoff
  6963. 4:25:59staging two. And then we're going to say
  6964. 4:26:02drop column and row_num.
  6965. 4:26:07If we run this
  6966. 4:26:09then we run the table again should be
  6967. 4:26:12gone and it is. So this is it. This is
  6968. 4:26:16our finalized clean data. Now in the
  6969. 4:26:19next project we're going to be doing
  6970. 4:26:21exploratory data analysis on this
  6971. 4:26:23cleaned data. We're going to finding
  6972. 4:26:25trends and patterns and running complex
  6973. 4:26:27queries. It's going to be phenomenal.
  6974. 4:26:29I'm super excited about it and I love
  6975. 4:26:30this data cleaning one. Um I made some
  6976. 4:26:33mistakes. I'll be the first one to
  6977. 4:26:34admit. But cleaning data is not always a
  6978. 4:26:37straightforward thing. Um, you know, you
  6979. 4:26:39have to you kind of mess around with it,
  6980. 4:26:41figure it out. Uh, and and you know,
  6981. 4:26:44that's what we did. Uh, whoa, took a
  6982. 4:26:47while. So, just to recap, we removed
  6983. 4:26:50duplicates, we standardized the data, we
  6984. 4:26:53looked at the null values or blank
  6985. 4:26:54values, and we removed any columns
  6986. 4:26:58or rows. So, we did a lot. Um, and if
  6987. 4:27:00you go back and you actually scroll
  6988. 4:27:02through here and look at some of this
  6989. 4:27:03code that we wrote, uh, it's not super
  6990. 4:27:06beginner stuff. So, if you're following
  6991. 4:27:08along with these things and you are
  6992. 4:27:10getting this project, this is a
  6993. 4:27:11fantastic project to put on your
  6994. 4:27:13portfolio. I myself would put this
  6995. 4:27:15project on my portfolio because it's a
  6996. 4:27:17very, very relevant thing. So, I hope
  6997. 4:27:19this was helpful. I'm just going to keep
  6998. 4:27:21scrolling while I talk, but I hope this
  6999. 4:27:22was helpful. I hope you learned
  7000. 4:27:23something. We did a we did a lot of
  7001. 4:27:25different things that we didn't even do
  7002. 4:27:26in the lessons, which I like doing
  7003. 4:27:28because you can't cover every single
  7004. 4:27:30aspect of my SQL in lessons, right?
  7005. 4:27:32Sometimes you just got to get in there,
  7006. 4:27:34get into the nitty-gritty, clean some
  7007. 4:27:36data, and you'll find uh or discover new
  7008. 4:27:38things, try new things. Um, and now
  7009. 4:27:42we're getting to the bottom. And awesome
  7010. 4:27:44work, awesome, awesome, awesome work.
  7011. 4:27:46Uh, this is an A1 project. I think this
  7012. 4:27:50should be in everyone's uh portfolio. If
  7013. 4:27:52I don't see it in your portfolio and you
  7014. 4:27:54know you send it to me, I'm going to say
  7015. 4:27:56it's the garbage portfolio. So, this is
  7016. 4:27:58a good one. So, with that being said,
  7017. 4:28:01thank you guys so much for watching. I
  7018. 4:28:02If you made it all the way to the end,
  7019. 4:28:04you're still listening to me. Awesome
  7020. 4:28:05work. Really awesome work. For real. I
  7021. 4:28:09you know, you're just following along
  7022. 4:28:10with the tutorial. That's what it feels
  7023. 4:28:11like. But by the end of this, I I just
  7024. 4:28:14know you're learning a ton and you're
  7025. 4:28:16you're trying new things and you're
  7026. 4:28:18really pushing yourself beyond just
  7027. 4:28:20simple tutorials. So trust me when I say
  7028. 4:28:23this is not easy. Not everyone was able
  7029. 4:28:25to make it to the end. So great work
  7030. 4:28:26getting here. So I will uh see you guys
  7031. 4:28:29in the next project when we actually
  7032. 4:28:31explore this data. We'll walk through a
  7033. 4:28:33lot of different ways to do that. So
  7034. 4:28:35thank you again for watching. If you
  7035. 4:28:37like this, be sure to like and subscribe
  7036. 4:28:39below. I put out tons of content about
  7037. 4:28:41all this stuff and I absolutely love it.
  7038. 4:28:43It is definitely one of my passions in
  7039. 4:28:44life. So go ahead and do that and I will
  7040. 4:28:47see you in the next video.
  7041. 4:29:00Hello everybody. In this project, we're
  7042. 4:29:02going to be focusing on exploratory data
  7043. 4:29:04analysis. Now in the first project we
  7044. 4:29:06worked with this exact data set and we
  7045. 4:29:08cleaned up the entire thing and that was
  7046. 4:29:10a really good project and it set us up
  7047. 4:29:12to explore the data and with all that
  7048. 4:29:15clean data we'll be able to look at our
  7049. 4:29:17data much better and find better
  7050. 4:29:19insights while we are using it. Now
  7051. 4:29:20normally when you start the EDA process
  7052. 4:29:22or the exploratory data analysis process
  7053. 4:29:24you have some idea of what you're
  7054. 4:29:26looking for sometimes not always and
  7055. 4:29:29sometimes when you're exploring the data
  7056. 4:29:31you also find issues with the data that
  7057. 4:29:32you then have to clean. So even though I
  7058. 4:29:35did a data cleaning video and then an
  7059. 4:29:37exploratory data analysis video and
  7060. 4:29:38they're kind of separate projects,
  7061. 4:29:40sometimes those coincide together where
  7062. 4:29:43you're exploring it and cleaning it at
  7063. 4:29:44the same time. Now what we're going to
  7064. 4:29:46be doing here with this data set, we're
  7065. 4:29:48just going to be kind of exploring it. I
  7066. 4:29:50don't have any agenda. I don't have any,
  7067. 4:29:53you know, one thing that I want to look
  7068. 4:29:54at. I just kind of want to look at
  7069. 4:29:56everything and we'll kind of discover
  7070. 4:29:58and go uh about things as we are
  7071. 4:30:01learning and looking at this data set.
  7072. 4:30:02We will however start off really simple
  7073. 4:30:05with kind of the basics, work a little
  7074. 4:30:06bit more towards the tougher stuff and
  7075. 4:30:08then at the end we'll have some more
  7076. 4:30:09advanced things that I think will be
  7077. 4:30:11really fun. So with that being said,
  7078. 4:30:13let's start off with kind of more easier
  7079. 4:30:15things. We'll kind of just ease our way
  7080. 4:30:17into exploring this data set. Let's pull
  7081. 4:30:20this down and let's copy this right down
  7082. 4:30:22here. Now we're going to be working with
  7083. 4:30:25this total laid off and percentage laid
  7084. 4:30:27off or most likely this total laid off
  7085. 4:30:29quite a bit. The percentage laid off
  7086. 4:30:31isn't super helpful because we don't
  7087. 4:30:33know how large the company is. We don't
  7088. 4:30:35have another column here that says
  7089. 4:30:37here's how many total employees they
  7090. 4:30:38had. And then okay, they had a
  7091. 4:30:40percentage laid off. You know, we won't
  7092. 4:30:43work as much with this one, but we'll
  7093. 4:30:44work quite a bit with this total laid
  7094. 4:30:46off. Let's look real quick. We could
  7095. 4:30:48look at something like the max uh total.
  7096. 4:30:52And I need to use a parenthesis max
  7097. 4:30:54total laid off. And let's look at this.
  7098. 4:30:59So on one day there was somebody out
  7099. 4:31:02there who had the max total laid off of
  7100. 4:31:0512,000 people. That's a lot of people to
  7101. 4:31:08lay off in one, you know, one go. That's
  7102. 4:31:11a lot. Let's also take a look at the max
  7103. 4:31:15and I think it was percentage laid off.
  7104. 4:31:20Let's run this. And it looks like one.
  7105. 4:31:22Now one represents 100. That means 100%
  7106. 4:31:26of the company was laid off. Um, and
  7107. 4:31:29that's, you know, that's not great. Uh,
  7108. 4:31:31that just means an entire company went
  7109. 4:31:32under essentially. We can actually take
  7110. 4:31:34a look at that because I'm interested to
  7111. 4:31:36see, you know, if there's any companies
  7112. 4:31:37I recognize or can see, um, where, let
  7113. 4:31:42me come right down here where the
  7114. 4:31:45percentage laid off is equal to one.
  7115. 4:31:49Let's go ahead and look at this and
  7116. 4:31:52let's take a look. So, we have this
  7117. 4:31:55ahead. I'm just going to go through here
  7118. 4:31:56and see if I recognize any of these. Uh,
  7119. 4:32:00some in the crypto space. BlockFi. I
  7120. 4:32:03feel like I recognize that one. I don't
  7121. 4:32:05know. Uh, let's keep going. Deliveroo.
  7122. 4:32:09It's not good. They left like let go of
  7123. 4:32:11120 people. Uh, I'm just curious. I
  7124. 4:32:13mean, I'm I'm just kind of scrolling
  7125. 4:32:14through here trying to see if I
  7126. 4:32:15recognize any. These are companies that
  7127. 4:32:17like completely went under or or lost
  7128. 4:32:20all their employees. Volt Bank.
  7129. 4:32:24Interesting. just interesting to me.
  7130. 4:32:25We're going to be taking a look at a lot
  7131. 4:32:27of stuff. Um, but these are companies
  7132. 4:32:28that completely went under and that's,
  7133. 4:32:31you know, unfortunate. We can also order
  7134. 4:32:33by uh total_laid
  7135. 4:32:36off in that's not how you spell it. In
  7136. 4:32:39descending, we'll see which company went
  7137. 4:32:41under had the largest. So, this one had
  7138. 4:32:442000. Construction company had 2400
  7139. 4:32:46people they went um under. Doesn't say
  7140. 4:32:49what stage they were at, but that's in
  7141. 4:32:50the United States. We can also take a
  7142. 4:32:52look at and there's another column over
  7143. 4:32:53here called funds raised in millions.
  7144. 4:32:56Let's look at that one. So I want to see
  7145. 4:32:58um these are companies that had a lot of
  7146. 4:33:01funding or potentially a ton of funding.
  7147. 4:33:05Uh let's go over. So this is like $2.4
  7148. 4:33:08billion I believe. Like I think this is
  7149. 4:33:10like a ton of money. Um Quibby I believe
  7150. 4:33:14I know this company uh in BlockFi. I I
  7151. 4:33:16thought I had heard of them. I'm pretty
  7152. 4:33:17sure I know who that is. So, Whibby is
  7153. 4:33:19one that I'm definitely familiar with.
  7154. 4:33:21It was like a short form uh media
  7155. 4:33:24company. Yeah. Yeah. And then there's
  7156. 4:33:26British Volt, which looks like an
  7157. 4:33:28electric company that went under. So,
  7158. 4:33:29you know, some big companies that went
  7159. 4:33:31under um in 2023, 2020, 2022. So, that's
  7160. 4:33:36interesting. So, we have a lot of
  7161. 4:33:37companies here and we're just looking at
  7162. 4:33:39um that had total laid off. But, let's
  7163. 4:33:42take a look. Let's let's use group by
  7164. 4:33:45real quick. I want to look at the
  7165. 4:33:46company and I also want to look at the
  7166. 4:33:49sum of the total laid off. And for that
  7167. 4:33:54we need to use a group by the company
  7168. 4:33:57and let's just start with this and I'm
  7169. 4:33:59sure we'll use an order by in a second.
  7170. 4:34:01Yeah, let's order by
  7171. 4:34:04order by let's just do two for now in
  7172. 4:34:07descending
  7173. 4:34:09and two stands for one two this is the
  7174. 4:34:12total it off. So, uh, for the total for
  7175. 4:34:15this table, and we don't know how far go
  7176. 4:34:17back it goes. We haven't checked that
  7177. 4:34:18yet. We'll check that in a second, but
  7178. 4:34:20for this table, you should recognize a
  7179. 4:34:23lot of these companies. So, I think it
  7180. 4:34:25starts in like 2020 until like sometime
  7181. 4:34:28in 2023, but this is Amazon let go of
  7182. 4:34:311,800 people, Google 12,000. I'm
  7183. 4:34:33guessing that's at one time because that
  7184. 4:34:35was the max that we looked at earlier.
  7185. 4:34:37Uh this is Facebook or Meta, Salesforce,
  7186. 4:34:40Microsoft, Phillips, Uber, Dell, Cisco,
  7187. 4:34:43Pelaton. I mean these are a ton of big
  7188. 4:34:45companies. Arvana, they let go of
  7189. 4:34:48thousands and thousands and thousands of
  7190. 4:34:49people. Twitter, that's not surprising,
  7191. 4:34:52uh given what's the change of things.
  7192. 4:34:54Groupon, um ton of ton of people or a
  7193. 4:34:57ton of companies and that's a lot of
  7194. 4:34:58people that have been let go. Now, let's
  7195. 4:35:00really quickly uh before we keep going,
  7196. 4:35:02I want to look at our date ranges real
  7197. 4:35:04quick. So, let's select everything. Um,
  7198. 4:35:07whoops. We'll do from there. And how do
  7199. 4:35:10we want to do this? Let's do minimum of
  7200. 4:35:12date. And let me do it like this. Date.
  7201. 4:35:17And then we'll do uh the max as well
  7202. 4:35:19because I want to look at the date range
  7203. 4:35:21that we have here.
  7204. 4:35:23Let's run this.
  7205. 4:35:25It looks like it starts in 2020 of 311.
  7206. 4:35:28So right when like I believe the
  7207. 4:35:29pandemic started or the uh COVID 19
  7208. 4:35:32started. I want to say that's like right
  7209. 4:35:34when it hit at least us in the United
  7210. 4:35:35States. Then this is almost exactly
  7211. 4:35:37three years later. So early 2023. So
  7212. 4:35:41just in those three years, you know,
  7213. 4:35:44here's some of what we're looking at.
  7214. 4:35:46These companies have let go of quite a
  7215. 4:35:47few people or had layoffs. We could also
  7216. 4:35:49take this exact thing. Oops. What did I
  7217. 4:35:53do here? Copy this again. We can also
  7218. 4:35:56take this exact thing and look at quite
  7219. 4:35:57a few other things. There was um the
  7220. 4:36:00industry. So we can look at industry
  7221. 4:36:02like what industry got hit the most
  7222. 4:36:04during this time or had the most
  7223. 4:36:06layoffs. Um all we're looking at right
  7224. 4:36:08now is total laid off. We can also look
  7225. 4:36:10at um percentage in a little bit but
  7226. 4:36:13looks like consumer got hit really hard,
  7227. 4:36:15retail really hard. That makes a lot of
  7228. 4:36:17sense with shops closing down because
  7229. 4:36:19people couldn't come in for the corona
  7230. 4:36:21virus. Now we're just making
  7231. 4:36:22assumptions, right? Um but you know
  7232. 4:36:25during that time it was mostly COVID
  7233. 4:36:27that impacted a lot of stuff. Then we
  7234. 4:36:29have transportation, finance,
  7235. 4:36:30healthcare, food, real estate. Um, yeah,
  7236. 4:36:34there's a lot a lot of people. Let's
  7237. 4:36:35look at the lowest ones. Manufacturing,
  7238. 4:36:38fintech, aerospace, energy, legal. So,
  7239. 4:36:42low numbers on those, high numbers on
  7240. 4:36:45these. So, really, really interesting.
  7241. 4:36:47Uh, let's go back up. Just want to look
  7242. 4:36:50at our whole table really quickly. See
  7243. 4:36:51what we got while we're looking at this
  7244. 4:36:54stuff. And let's run this. Now we looked
  7245. 4:36:57at the company, looked at the industry.
  7246. 4:36:59I would really be interested to look at
  7247. 4:37:00the country as well. Which countries at
  7248. 4:37:03least from this data set and we can copy
  7249. 4:37:05or we can go right here country because
  7250. 4:37:09I believe that United States had the
  7251. 4:37:12most. Holy mackerel, they had by far the
  7252. 4:37:17most. Uh then India, this is 256,000
  7253. 4:37:21people um lost their jobs. We'll look I
  7254. 4:37:24think we'll look at the dates in a
  7255. 4:37:25little while like at kind of like time
  7256. 4:37:27series like how many per year per month
  7257. 4:37:29per day or whatever we want to look at
  7258. 4:37:32but goodness gracious uh that's a lot of
  7259. 4:37:34people within just three years in the
  7260. 4:37:35United States India Netherlands Sweden
  7261. 4:37:38Brazil Germany uh United Kingdom then it
  7262. 4:37:40goes down and down and down but these
  7263. 4:37:42are just reported um from this data set
  7264. 4:37:45that I I had gotten. So really really
  7265. 4:37:48interesting. Good night. the United
  7266. 4:37:50States had much more than than most for
  7267. 4:37:53sure. Um, let's actually look at that
  7268. 4:37:55date real quick or we can look at it by
  7269. 4:37:57year. Um, so we have this date and if we
  7270. 4:38:01do it like this and we can
  7271. 4:38:06do by date real quick. So this is going
  7272. 4:38:08to do it by individual date. And let's
  7273. 4:38:11order by let's do one. So this is the
  7274. 4:38:14most recent date. So it's literally by
  7275. 4:38:16date that's reported. Um, we don't want
  7276. 4:38:19that. Let's do it by the year. So, 2020,
  7277. 4:38:222021, 2022, 2023. We can do that fairly
  7278. 4:38:26easily. We'll use this year function.
  7279. 4:38:30And we'll group by
  7280. 4:38:33the year as well.
  7281. 4:38:36Let's try running this. There we go. It
  7282. 4:38:39looks like in 2020, 80,000 people. 2021
  7283. 4:38:43uh 16,000.
  7284. 4:38:45160,000. in 2022. This looks like the
  7285. 4:38:48worst year. And then it's only we only
  7286. 4:38:50have three months of data in 2023.
  7287. 4:38:53There's 125,000. Holy smokes. So in
  7288. 4:38:562023, it looks like we're ramping up
  7289. 4:38:58because I'm recording this in 2023,
  7290. 4:39:00about a month after this data set that
  7291. 4:39:02we got this data set. There's 125,000
  7292. 4:39:05people um around the world, you know,
  7293. 4:39:07but just in those first three months. So
  7294. 4:39:10this is going to be a lot higher than
  7295. 4:39:12even 2022. That's pretty wild. Um very
  7296. 4:39:16very interesting
  7297. 4:39:19one other one one while we're looking at
  7298. 4:39:20group by um there's there was a column
  7299. 4:39:24and you can go back and look at it if
  7300. 4:39:25you'd like but it's called stage and
  7301. 4:39:27this shows the stage of the company and
  7302. 4:39:30if we run this and we're all just
  7303. 4:39:31looking at total but if you look at the
  7304. 4:39:34um stage of the company this is like the
  7305. 4:39:37different series that they're in A B C D
  7306. 4:39:40A I believe is like a series A funding
  7307. 4:39:42that's like a super super starting oh
  7308. 4:39:44This is like a seed phase. Then there's
  7309. 4:39:46series A and then it goes up up up up
  7310. 4:39:48until usually they go um like they do
  7311. 4:39:51IPO or they get acquired or something.
  7312. 4:39:53Now if we go up here and we do two
  7313. 4:39:55descending I want to see which one had
  7314. 4:39:56the most. So this is post IPO. This is
  7315. 4:39:58the Amazon, the Googles of the world,
  7316. 4:40:00the large large companies that are post
  7317. 4:40:03IPO or initial public offering. Then
  7318. 4:40:05there's unknown. We don't know which
  7319. 4:40:07that is. Um a lot of you know layoffs
  7320. 4:40:09from acquisitions CD B all the way down.
  7321. 4:40:14So, it looks like um most of it's coming
  7322. 4:40:16from, you know, these ones right here.
  7323. 4:40:19Really, really interesting. Let's go
  7324. 4:40:21look at percentages. I'm just going to
  7325. 4:40:22literally crying to say literally. I'm
  7326. 4:40:25going to literally copy these. Um and
  7327. 4:40:29with percentages, I don't think uh let
  7328. 4:40:33me look at percentage. I don't think the
  7329. 4:40:34sum is going to be a good indicator. I
  7330. 4:40:36don't know if this is a good one to even
  7331. 4:40:37look at because and then we're looking
  7332. 4:40:40at company right now because percentages
  7333. 4:40:42refer to a percent of the company,
  7334. 4:40:45right? So, we don't have hard numbers
  7335. 4:40:48because we don't know how large these
  7336. 4:40:49companies are. So, now that we're
  7337. 4:40:51actually looking at this, this
  7338. 4:40:52percentage laid off isn't super
  7339. 4:40:54relevant. Um, really the one that's kind
  7340. 4:40:56of more, you know, has better this is a
  7341. 4:40:59better use for what we're looking at is
  7342. 4:41:01this total laid off because again, we
  7343. 4:41:02don't know these sums. We could we could
  7344. 4:41:04look at like the average, right? Um but
  7345. 4:41:07again, that just doesn't help us that
  7346. 4:41:09much. I don't think um I think we're
  7347. 4:41:14going to really dive into that too much
  7348. 4:41:17is my uh is my feeling. Now, one thing
  7349. 4:41:21that I would be really interested in is
  7350. 4:41:24to kind of look at the progression of
  7351. 4:41:26layoff, right? Uh you could call this a
  7352. 4:41:29rolling sum. So, start at the very
  7353. 4:41:31earliest of layoffs and do a rolling sum
  7354. 4:41:33until the very end of these layoffs. Um,
  7355. 4:41:36and let's go to the bottom. This is
  7356. 4:41:37where it's going to start getting a
  7357. 4:41:39little tougher. Um, and there's, you
  7358. 4:41:42know, we're just doing a little bit of
  7359. 4:41:43exploratory data analysis. You know, do
  7360. 4:41:45digging into this a little bit. You can
  7361. 4:41:47go and dig into this as much as you'd
  7362. 4:41:50like. You don't have to just do what I'm
  7363. 4:41:51doing, but I'm just trying to show you
  7364. 4:41:52some stuff. Now, let's try to do rolling
  7365. 4:41:54total of layoffs. Um, we could do that
  7366. 4:41:57on the day, although I feel like that's
  7367. 4:42:00going to be way too many rows. Let's do
  7368. 4:42:02it based off the month. So, right here
  7369. 4:42:04in this month. Now, let's see if we do
  7370. 4:42:07just the month. Let's do something. I'll
  7371. 4:42:09show you the month. And that's going to
  7372. 4:42:10be an issue. And I'll in my head I
  7373. 4:42:12already know. But let's look at it. We
  7374. 4:42:15could do something like select um from
  7375. 4:42:18and let's get this.
  7376. 4:42:22There we go.
  7377. 4:42:24So, if we do um we'll do substring. Let
  7378. 4:42:27me add a semicolon. Let's do substring.
  7379. 4:42:31And we want to pull out this month right
  7380. 4:42:34here. So, we'll go one, two, three,
  7381. 4:42:36four, five, six. So, start at position
  7382. 4:42:39six. Um, and this is of course in the
  7383. 4:42:42date column. We'll start at position six
  7384. 4:42:44and then we'll take two. Let's just run
  7385. 4:42:46this really quickly. And there's our
  7386. 4:42:49month. So, this we can do this as month,
  7387. 4:42:52right?
  7388. 4:42:54um or like this.
  7389. 4:42:57Is that correct? Yeah. So, as month. So,
  7390. 4:43:00this is our month that we're doing it.
  7391. 4:43:01Now, if we group on this and we do like
  7392. 4:43:04something like a sum of total uh laid
  7393. 4:43:08off, I think that's the column. And then
  7394. 4:43:10we do a group by on this month. So, it'
  7395. 4:43:13be like this right here.
  7396. 4:43:17We'll do
  7397. 4:43:19group by
  7398. 4:43:22this. Let's try running this. We should
  7399. 4:43:25be able to do month as well. Let's try
  7400. 4:43:27this real quick as well because I don't
  7401. 4:43:29want to have this if I don't have to run
  7402. 4:43:32it. Perfect. So the months right here
  7403. 4:43:35don't show us the year. So if we're
  7404. 4:43:37trying to get a rolling to total of just
  7405. 4:43:39the month, it's actually would work fine
  7406. 4:43:42when we actually implement the the
  7407. 4:43:44rolling total use um you know a window
  7408. 4:43:46function. But the issue with this is
  7409. 4:43:48it's just going to show us month. So
  7410. 4:43:49this is 2020. This is January of 2020,
  7411. 4:43:532021, 2022, 2023, any other years we
  7412. 4:43:56have it. This is not a great rolling
  7413. 4:43:58total. What if we did one all the way to
  7414. 4:44:02I want to say it's seven, six, seven.
  7415. 4:44:04Let's try this. Now, this is going to
  7416. 4:44:07give us a much better Let's order this.
  7417. 4:44:09Order by one.
  7418. 4:44:12This is just our first column. So, now
  7419. 4:44:14uh well, we should do it where it's not.
  7420. 4:44:16Give me a second. I'm I'm I'm figuring
  7421. 4:44:18this out as we go. We'll do where uh the
  7422. 4:44:21month write that where the month is not
  7423. 4:44:25null. I'm just going to get rid of that
  7424. 4:44:27one.
  7425. 4:44:34And of course, uh that doesn't work
  7426. 4:44:37because we're looking at the substring.
  7427. 4:44:38So, let's try doing this.
  7428. 4:44:42There we go. Um it just wasn't reading
  7429. 4:44:44in that month that I was trying to use.
  7430. 4:44:46Let's go down. Now, here's what we're
  7431. 4:44:48going to do is we want to take it from
  7432. 4:44:50the very first month and we're grouping
  7433. 4:44:52everything. So, these are all the
  7434. 4:44:54layoffs from 2020 of 03. So, that's
  7435. 4:44:57March of 2020. Then we have April, May,
  7436. 4:44:59and these are the layoffs. So, this is
  7437. 4:45:01really good. This is exactly what I was
  7438. 4:45:03imagining in my head. So, we want this.
  7439. 4:45:06This is just, you know, 12 months in a
  7440. 4:45:08year, and we go all the way to the
  7441. 4:45:09bottom. And I want to do a rolling sum
  7442. 4:45:12of this. So, let's see how we can do
  7443. 4:45:14that. And we'll use this logic in a
  7444. 4:45:16little bit. Let's copy this
  7445. 4:45:19and let's do select everything. We'll do
  7446. 4:45:22right here. Now, what we actually want
  7447. 4:45:24to do now that I'm thinking about it is
  7448. 4:45:25we want to take this data and we want to
  7449. 4:45:28do the rolling sum based off this exact
  7450. 4:45:30thing. So, we actually need to take uh
  7451. 4:45:33this. Let's get rid of this. And we'll
  7452. 4:45:36do it with a CTE. So we'll say width and
  7453. 4:45:39we'll do rolling_total
  7454. 4:45:43that we'll say as and then we'll put
  7455. 4:45:46this in here just like that. So with
  7456. 4:45:50rolling total as now we're going to say
  7457. 4:45:53select and we'll just do from here. Now
  7458. 4:45:56what we need to do is we need to select
  7459. 4:45:58the month. So let's go ahead and select
  7460. 4:46:00that month and we'll take it just like
  7461. 4:46:02this. So we'll select the month and we
  7462. 4:46:04need to do a rolling total. All we have
  7463. 4:46:05to do for that is the sum of which
  7464. 4:46:08column we're doing. Let's actually
  7465. 4:46:10change this real quick. Um we're going
  7466. 4:46:12to call this as
  7467. 4:46:15um total
  7468. 4:46:18off. I'm just going to keep it simple.
  7469. 4:46:21So the sum of total off. So now we're
  7470. 4:46:24doing that, but we want to do it over.
  7471. 4:46:26And all we need to add into here is an
  7472. 4:46:28order by. We're not going to partition
  7473. 4:46:29by anything because in here we already
  7474. 4:46:32did a group by. So it's, you know, kind
  7475. 4:46:34of like partitioning it. We just need to
  7476. 4:46:36say order by and we just need to order
  7477. 4:46:38by the month, I believe. So let's try
  7478. 4:46:41that.
  7479. 4:46:44And let's run it. Let's do that. And we
  7480. 4:46:47actually need to since we're doing um
  7481. 4:46:50this, we need this at the end. And we
  7482. 4:46:52can rename this if we'd like. So we can
  7483. 4:46:54do this as rolling total all lowercase.
  7484. 4:46:58Let's try running this and let's see
  7485. 4:47:01what we get.
  7486. 4:47:05Okay. And this looks correct. So,
  7487. 4:47:08starting in 2020 of 03, we had 9,000
  7488. 4:47:11layoffs. Then the next total we added
  7489. 4:47:14onto here. Now, this visually isn't the
  7490. 4:47:17best. I would like the month right here
  7491. 4:47:20as well. So, let me actually add um let
  7492. 4:47:24me create its own row. Put a comma here.
  7493. 4:47:28Then right here, I want to keep this
  7494. 4:47:31total off so we can visually see better.
  7495. 4:47:35Much better. Okay, so we have the month
  7496. 4:47:38and as it goes down, we're having more
  7497. 4:47:41laid off. Now, this is our rolling
  7498. 4:47:43total. Here's essentially how this
  7499. 4:47:45works. It starts with 9,628.
  7500. 4:47:48Then it adds on the next month, which is
  7501. 4:47:5026,000, which equals 36,000. Then it
  7502. 4:47:53adds on the next month, and we get 62.
  7503. 4:47:56adds on the next month 69, right? It
  7504. 4:47:58keeps going all the way down. This just
  7505. 4:48:00shows each month how many were laid off
  7506. 4:48:03and this shows a monthby-month
  7507. 4:48:05progression all the way down to the
  7508. 4:48:06bottom. So, let's keep let's just, you
  7509. 4:48:08know, take a look. In 2020 of 03, we had
  7510. 4:48:109,000. By the end of 2020, we had about
  7511. 4:48:1481,000 or so. Then, at the beginning,
  7512. 4:48:17right here all the way down to 2021. By
  7513. 4:48:21the end of 2021, we only had 96,000. So
  7514. 4:48:242021 was a good year. It looks like um
  7515. 4:48:27comparatively we had 90 80 well let me
  7516. 4:48:30see 91,000 people let go and here we
  7517. 4:48:34only have 96,000 let go. So that's what
  7518. 4:48:37uh 81 that's only like 15,000 people.
  7519. 4:48:40That's like nothing um comparatively.
  7520. 4:48:42Then in 2022
  7521. 4:48:44uh things start ramping up dramatically.
  7522. 4:48:47It looks like we have um 12,000 people,
  7523. 4:48:5017,000, 16,000, and they're adding up.
  7524. 4:48:53It's going from 97 all the way up to
  7525. 4:48:56good night right before the holidays in
  7526. 4:48:592022 of this past year. I mean, we had
  7527. 4:49:03uh 247,000 people. So, that's like uh
  7528. 4:49:0613ome,000. My math my math's really bad.
  7529. 4:49:09It's like 150,000.
  7530. 4:49:11And then we only have Oh, we have even
  7531. 4:49:13more here actually. And then we only
  7532. 4:49:15have the first three months of 2023. So
  7533. 4:49:18these months right here were really
  7534. 4:49:22devastating. It's just around the world.
  7535. 4:49:24Now, we can also break this out
  7536. 4:49:26potentially
  7537. 4:49:27by country. So we can see how many per
  7538. 4:49:30country, but this is just around the
  7539. 4:49:31world. That's a lot of people losing
  7540. 4:49:33their jobs all the way up to 383,000.
  7541. 4:49:35So, in this range, 383,000
  7542. 4:49:38from March of 2023 all the way back to
  7543. 4:49:41March of 2020 lost their jobs. And this
  7544. 4:49:44is just reported. I'm sure there was uh
  7545. 4:49:46you know, much more than that, but this
  7546. 4:49:47is that like tech companies, larger
  7547. 4:49:50companies that have like series A
  7548. 4:49:52funding, IPOs, etc. Um, but a lot of
  7549. 4:49:54small businesses went out of business.
  7550. 4:49:56Um, so we don't we don't have that
  7551. 4:49:58information in this data set. So I think
  7552. 4:49:59that's what we're going to do next is
  7553. 4:50:01kind of look at the company maybe
  7554. 4:50:03because I'm always interested in the
  7555. 4:50:04company and actually earlier let's not
  7556. 4:50:07do that one earlier we're looking at the
  7557. 4:50:09company the sum of totally loft let's um
  7558. 4:50:13let's bring this down let's run that
  7559. 4:50:15because that that's what rolling total
  7560. 4:50:17is by the way rolling totals are great
  7561. 4:50:19really good for visualizations as well
  7562. 4:50:22um let's see yeah so I want to take a
  7563. 4:50:24look at these companies but I want to
  7564. 4:50:26see how much they were laying off per
  7565. 4:50:28year. So, instead of just looking at it
  7566. 4:50:30as a total, we'll break it out by the
  7567. 4:50:32year. Now, I'm just going to warn you,
  7568. 4:50:34this probably going to this most likely
  7569. 4:50:36will be our last one in the in the
  7570. 4:50:37lesson. This is going to be probably our
  7571. 4:50:38hardest one yet. Um potentially. We'll
  7572. 4:50:41see. Maybe the other one was earlier. Uh
  7573. 4:50:44was harder earlier.
  7574. 4:50:46Now, let's use this kind of as um a
  7575. 4:50:51starting point. But what we're going to
  7576. 4:50:53need to do is we want to take the
  7577. 4:50:54company, but I also want the date. So I
  7578. 4:50:56need to do a comma then date. So we need
  7579. 4:51:00our date here and I'm going to do that.
  7580. 4:51:03I need to group by the date as well. So
  7581. 4:51:05we'll do date and let's run this. All
  7582. 4:51:08right. Now this is just doing the, you
  7583. 4:51:11know, company and the exact date. We
  7584. 4:51:13don't want to do that. Let's actually do
  7585. 4:51:14the year. Let's just look at the year. I
  7586. 4:51:16think that'll be plenty. You could also
  7587. 4:51:18do the exact same thing as we did above
  7588. 4:51:19with the substring. Um although I think
  7589. 4:51:21that's going to get a little messier. um
  7590. 4:51:24stuff, you know, just a thought. Let's
  7591. 4:51:27run this. Okay, so now we're looking at
  7592. 4:51:30just the year. We're grouping by year
  7593. 4:51:32and let's order by uh let's say the
  7594. 4:51:35company. And we'll do that in sending.
  7595. 4:51:39There we go. And let's run this. So now
  7596. 4:51:41we have it open. Let's see who, you
  7597. 4:51:43know, you can see people who made
  7598. 4:51:44multiple layoffs. This is in 2020, they
  7599. 4:51:46let go of 200. And then in 2023, they
  7600. 4:51:49let go of 155. This is a company I've
  7601. 4:51:52never heard of. So this is already
  7602. 4:51:53looking really good. Now let's say we
  7603. 4:51:56wanted to use this and what we want to
  7604. 4:51:58do is we want to rank which years they
  7605. 4:52:02laid off the most employees. Now this is
  7606. 4:52:04just a small uh sample. We'll look at
  7607. 4:52:06more in just a little bit. We can
  7608. 4:52:07actually look at um let's just do three
  7609. 4:52:11uh three descending just like this
  7610. 4:52:15should be large companies. So, you know,
  7611. 4:52:17some of these companies like Microsoft,
  7612. 4:52:20even Amazon right here and Amazon right
  7613. 4:52:22there, they let go of multiple or
  7614. 4:52:24thousands of people in different years.
  7615. 4:52:26So, I want to rank those. I want to say,
  7616. 4:52:29you know, the highest one uh based off
  7617. 4:52:31of the laid off should be ranked number
  7618. 4:52:34one. That's the year that they laid off
  7619. 4:52:35the most people. So, let's go ahead and
  7620. 4:52:38try to do that. Thing we need to do is
  7621. 4:52:40uh do a CTE. We'll start with that. Let
  7622. 4:52:43me um me add some more things down here
  7623. 4:52:47so we're good to go. So let's do we'll
  7624. 4:52:51do with let's do uh company. So this is
  7625. 4:52:54going to be the company year_year.
  7626. 4:52:57We'll do it as and that's what this is
  7627. 4:53:00going to be. This is our company year.
  7628. 4:53:02And we can do select everything from
  7629. 4:53:05company year. It's going to be the exact
  7630. 4:53:07query that we're looking at. Let's go
  7631. 4:53:10ahead and run this. Okay. So this is
  7632. 4:53:12good. Now I do want to change these
  7633. 4:53:14columns and I can do that right here.
  7634. 4:53:16We'll do company
  7635. 4:53:18um let's call this years and then we'll
  7636. 4:53:21do I can do total laid off again. So
  7637. 4:53:24total_laid
  7638. 4:53:26off just the sum right total laid off
  7639. 4:53:29per year. So let's go ahead and run this
  7640. 4:53:31now. There we go. We have company years
  7641. 4:53:34and total laid off. So this looks much
  7642. 4:53:37better. And what we're going to do is
  7643. 4:53:38select everything, but we want to
  7644. 4:53:41partition it uh probably based off this
  7645. 4:53:43years right here. And then we want to
  7646. 4:53:46rank it based off how many they laid off
  7647. 4:53:48in that year. So we'll get to see who
  7648. 4:53:50laid off the most people per year. Cuz
  7649. 4:53:53some companies like Amazon, they let
  7650. 4:53:55they let off multiple people per year,
  7651. 4:53:57but was at the highest per year. That's
  7652. 4:53:58kind of what we're going to look at. Um
  7653. 4:54:00so we'll do dense_rank
  7654. 4:54:03and we're going to do that over. Now,
  7655. 4:54:05we're going to partition by, oops,
  7656. 4:54:08that's not how you spell partition.
  7657. 4:54:09Partition by. We want to partition by
  7658. 4:54:11the years. So, all of the 2021 layoffs
  7659. 4:54:14will be in the same partition. All the
  7660. 4:54:162022 will be in the same partition. And
  7661. 4:54:18we'll do years. And we want to also
  7662. 4:54:21order by the total laid off. Now, we
  7663. 4:54:24want to do that in descending. So, we'll
  7664. 4:54:26do total laid off descending. And then
  7665. 4:54:29we want to um add this dense rank to it.
  7666. 4:54:32So, let's try it. Let's run this. Good
  7667. 4:54:36night. That's a a big one. So, let's
  7668. 4:54:40take a look. So, in 2021,
  7669. 4:54:44it looks like um or 2020, it looks like
  7670. 4:54:47Uber had the highest. Now, we want to
  7671. 4:54:49take out these nulls. So, let's do um
  7672. 4:54:52where years,
  7673. 4:54:56let's say, is not null. And let's run
  7674. 4:54:59that. There we go. So in 2020 and that's
  7675. 4:55:02what we're partitioning on first. It
  7676. 4:55:03looks like this is one two three. These
  7677. 4:55:05are the top ones. Um and let's order by
  7678. 4:55:10and let's do the let's order by the
  7679. 4:55:12rank. Um first let's call this as
  7680. 4:55:17bring it down. What do we want to call
  7681. 4:55:20this?
  7682. 4:55:22We'll call this as ranking. There we go.
  7683. 4:55:26So order by ranking
  7684. 4:55:30ascending.
  7685. 4:55:33There we go. Now we have our ranking. So
  7686. 4:55:36in 2020, this is the biggest one of
  7687. 4:55:39layoffs. 2021, this was the biggest
  7688. 4:55:42layoff. I guess we'll have to take a
  7689. 4:55:44look in Meta. In 2022, they had the
  7690. 4:55:46biggest layoff. And Google had the
  7691. 4:55:47biggest layoff total for 2023. So, this
  7692. 4:55:51looks correct,
  7693. 4:55:53but I kind of want to filter on this
  7694. 4:55:55ranking to be able to only filter maybe
  7695. 4:55:58the top like five um companies per year.
  7696. 4:56:02And I think we can do that. Let's
  7697. 4:56:06actually get rid of this. I think what
  7698. 4:56:08we should do is we should add this as
  7699. 4:56:10another CTE and query off of that. So
  7700. 4:56:13now we'll call this company_year_rank.
  7701. 4:56:18So now we have the year rank as
  7702. 4:56:21we'll have our query oops have our
  7703. 4:56:24query.
  7704. 4:56:26So now this is our company year rank. So
  7705. 4:56:28now if we do select everything from
  7706. 4:56:31company year rank
  7707. 4:56:34this we run it. Okay. So now we have our
  7708. 4:56:38rankings. Let's come down. Now we have
  7709. 4:56:41our rankings but I just want to filter
  7710. 4:56:43it based off of that ranking. We'll say
  7711. 4:56:45uh where ranking is greater than or
  7712. 4:56:48equal to let's say five. We'll look at
  7713. 4:56:50the top five rankings. Let's run this.
  7714. 4:56:54And I said greater than I wanted uh less
  7715. 4:56:56than. Run that.
  7716. 4:56:59That's looking good. Okay. So, really
  7717. 4:57:02quickly, we have in 2020
  7718. 4:57:05we had these are the top five people who
  7719. 4:57:07laid people off. Uber, Booking.com,
  7720. 4:57:10Groupon, Swiggy, Airbnb. In 2021, the
  7721. 4:57:13largest layoff was Bite Dance, which I
  7722. 4:57:16think is Tik Tok, right? Uh Catera,
  7723. 4:57:18Zillow,
  7724. 4:57:20uh yeah, these are the top five. So 2021
  7725. 4:57:22and or 2022 and 2023 were definitely the
  7726. 4:57:25largest as well. We have Meta 11,000
  7727. 4:57:28people, Amazon, Cisco, Pelaton,
  7728. 4:57:31and Carvana, as well as Phillips. They
  7729. 4:57:33tied. That's why we have the dense
  7730. 4:57:35ranking because some of these will be
  7731. 4:57:36ties. Then we have Google
  7732. 4:57:39uh in 2023 all the way down to Dell.
  7733. 4:57:42These are all ones I know. Microsoft,
  7734. 4:57:44Ericson, Amazon, Salesforce, and Dell.
  7735. 4:57:47So, this is really, really interesting
  7736. 4:57:49just looking at a year-by-year snapshot,
  7737. 4:57:52right? These are the total laid off for
  7738. 4:57:54each company. And we could even go back
  7739. 4:57:56and change this for like industry or,
  7740. 4:57:59you know, really whatever we want to
  7741. 4:58:01change this to. This is just an
  7742. 4:58:02interesting query in general to look at,
  7743. 4:58:05you know, per year. here. And we could
  7744. 4:58:06go back and change for month or lots of
  7745. 4:58:09stuff we can change in here, but this is
  7746. 4:58:10really interesting to me. Um, it just
  7747. 4:58:13looks like a lot of the large tech
  7748. 4:58:14companies had some took some big L's,
  7749. 4:58:17took some big hits. Um, let's recap this
  7750. 4:58:20query really quickly in case, you know,
  7751. 4:58:21it's tough to follow. But we created
  7752. 4:58:24this query up here and we're looking at
  7753. 4:58:26the company by the year and how many
  7754. 4:58:29people they let off. Then right over
  7755. 4:58:32here we said with the company year we
  7756. 4:58:35changed these columns. This is our CTE.
  7757. 4:58:37So we created our first CTE.
  7758. 4:58:40Then we went and we gave it a rank and
  7759. 4:58:43we wanted to you know filter on that
  7760. 4:58:45rank. So we did this rank as another CT.
  7761. 4:58:48We just did a comma had a second CTE and
  7762. 4:58:51we hit off the first CT the company year
  7763. 4:58:54which is right here. So we hit off our
  7764. 4:58:57first CTE to make this second CTE. And
  7765. 4:58:59then finally we um queried off of the
  7766. 4:59:02final CTE. Definitely not an easy query
  7767. 4:59:05to kind of think through and walk
  7768. 4:59:06through, but I hope you know you're able
  7769. 4:59:07to follow um because you know that's a a
  7770. 4:59:10really good query. This is something
  7771. 4:59:11I've definitely done in my real job when
  7772. 4:59:14I was working with a lot of healthcare
  7773. 4:59:16data. This is a lot of stuff that I
  7774. 4:59:18would do. And so this is a you know
  7775. 4:59:20pretty good um pretty good query to know
  7776. 4:59:23how to do. But with that being said uh
  7777. 4:59:25we are done with this lesson. I hope
  7778. 4:59:27this wasn't too short. I don't know how
  7779. 4:59:28long I ran, but um you know, we looked
  7780. 4:59:30at a lot of different stuff. Let's go
  7781. 4:59:32back to the top again. We were just
  7782. 4:59:34exploring the data. We looked at lay it
  7783. 4:59:36off a lot. Um looked a lot at the
  7784. 4:59:39company, uh when these dates actually
  7785. 4:59:42started for these layoffs in this data
  7786. 4:59:44set. We looked at the country, the
  7787. 4:59:46actual year of layoff. Uh then we went
  7788. 4:59:48to a little bit more difficult things.
  7789. 4:59:51We looked at it per month. So per month,
  7790. 4:59:54how many layoffs they had, and then we
  7791. 4:59:56did a rolling total. This one was a
  7792. 4:59:58pretty good one using that substring.
  7793. 5:00:00Um, I love substrings, man. They're
  7794. 5:00:02awesome or lady. They're awesome. Uh,
  7795. 5:00:05and then we came down here and we did
  7796. 5:00:07the one we just did with multiple CTEs
  7797. 5:00:09in the company. I think it was a a
  7798. 5:00:11really really good solid project. Um,
  7799. 5:00:14combine that with that data cleaning
  7800. 5:00:15project and man, you got a just a really
  7801. 5:00:17good start with some MySQL projects and
  7802. 5:00:19this one can be expanded upon. Don't
  7803. 5:00:21stop where I stopped. Right? Let me go
  7804. 5:00:23back to the top. Don't stop where I
  7805. 5:00:25stopped. Right? This data set has so
  7806. 5:00:29much data in it. You can do a lot of
  7807. 5:00:31different things. And even if you want
  7808. 5:00:34to, you could go and find these
  7809. 5:00:36companies right over here and you could
  7810. 5:00:39try to uh get their total uh total
  7811. 5:00:42company that they had and you could use
  7812. 5:00:45this column a lot more. That'd be really
  7813. 5:00:47interesting with some calculations
  7814. 5:00:48there. So with that being said, that is
  7815. 5:00:50the end of our exploratory data analysis
  7816. 5:00:52project. I hope you enjoyed it. I hope
  7817. 5:00:54you learned something both in the data
  7818. 5:00:56cleaning project and in this exploratory
  7819. 5:00:58data analysis project. That's what this
  7820. 5:00:59is all about and getting the confidence
  7821. 5:01:02and gaining the experience to create
  7822. 5:01:04these projects and add those to your
  7823. 5:01:06portfolios. Speaking of which, if you
  7824. 5:01:08haven't already, check out my video on
  7825. 5:01:10how to create a free portfolio website
  7826. 5:01:13uh using GitHub. Awesome. I highly
  7827. 5:01:15recommend it. You can add these to your
  7828. 5:01:17portfolio. So, with that being said,
  7829. 5:01:19thank you so much for watching. I really
  7830. 5:01:21appreciate it. If you like this video,
  7831. 5:01:22if you learned anything at all, be sure
  7832. 5:01:24to like and subscribe below. Check out
  7833. 5:01:25my channel for tons of other videos just
  7834. 5:01:27like this one and more. I will see you
  7835. 5:01:30in the next video.
  7836. 5:01:44What's going on everybody? Today we are
  7837. 5:01:45starting our Excel tutorial series.
  7838. 5:01:50>> [music]
  7839. 5:01:53>> Now, there are so many things that you
  7840. 5:01:55can do in Excel. So, I don't know how
  7841. 5:01:56long the series is going to be. It could
  7842. 5:01:58be 15 or even 20 videos. But what I do
  7843. 5:02:00know is that I'm going to be covering
  7844. 5:02:02just about every single thing that I've
  7845. 5:02:03used since I became a data analyst. And
  7846. 5:02:05I want to show you how to do it. Uh so,
  7847. 5:02:07it won't just be the more concrete
  7848. 5:02:09things. Um you know, like pivot tables,
  7849. 5:02:11charts, VLOOKUPs, things like that.
  7850. 5:02:13It'll also be some of the more nuanced
  7851. 5:02:14things like how to deal with missing
  7852. 5:02:16data or how to deal with dirty data and
  7853. 5:02:18how to clean that up within Excel. And
  7854. 5:02:20so those are things that you may not be
  7855. 5:02:22able to do, you know, if somebody wasn't
  7856. 5:02:24showing you how to do it. And so that's
  7857. 5:02:25what I'm going to try to help you
  7858. 5:02:27because I know that that is something
  7859. 5:02:28that you will need to do or learn how to
  7860. 5:02:30do in Excel. Without further ado, let's
  7861. 5:02:32jump on my screen and get started with
  7862. 5:02:33our very first Excel tutorial. All
  7863. 5:02:34right, so I'm going to go ahead and get
  7864. 5:02:35rid of myself. We are going to be
  7865. 5:02:36looking at something absolutely pivotal
  7866. 5:02:39in your data analytics career, and that
  7867. 5:02:41is pivot tables. Uh, and I think that's
  7868. 5:02:43really appropriate. It is probably one
  7869. 5:02:45of the most commonly used things I think
  7870. 5:02:48that data analysts use to convey
  7871. 5:02:50information in Excel. It's super easy to
  7872. 5:02:52group things together to display
  7873. 5:02:53information in a very easily
  7874. 5:02:56understandable way, especially for
  7875. 5:02:58people who are not data analysts, right?
  7876. 5:03:00I use this a lot for other managers or
  7877. 5:03:02for higherups um, who don't want to get
  7878. 5:03:05into SQL or or, you know, aren't super
  7879. 5:03:07techsavvy in like Python or Tableau.
  7880. 5:03:09They just want it in in Excel. And so I
  7881. 5:03:12use it all the time for that reason. And
  7882. 5:03:14so we're going to be using this data set
  7883. 5:03:15right here, bike store sales in Europe.
  7884. 5:03:17I will include this link in the
  7885. 5:03:18description. Um we're not going to look
  7886. 5:03:20at the columns just yet. We're going to
  7887. 5:03:21download it. Um I've already downloaded
  7888. 5:03:23it a few times, [clears throat] but we
  7889. 5:03:25are going to go to
  7890. 5:03:28um our downloads. We're going to open it
  7891. 5:03:30up and we're going to open up this sales
  7892. 5:03:33right here. And give it a second.
  7893. 5:03:38All right. Perfect. And so here's what
  7894. 5:03:39it looks like, at least on my screen.
  7895. 5:03:41I'm going to spread it out just a little
  7896. 5:03:44bit. Um, and really quickly, let's take
  7897. 5:03:47a very quick glance at this. So we have
  7898. 5:03:50a date, a day, a month, a year. So some
  7899. 5:03:53um some date information.
  7900. 5:03:56Um, then we have some customer age
  7901. 5:03:59information. So how old was the
  7902. 5:04:00customer? Again, this is bike sales. So
  7903. 5:04:03what did um, you know, what did they
  7904. 5:04:05buy? And then we have some demographic
  7905. 5:04:07information. So this is their age group.
  7906. 5:04:09We have uh the gender, the country,
  7907. 5:04:12state, uh the product category, the
  7908. 5:04:16subcategory, the actual product that was
  7909. 5:04:17purchased, and then we have things like
  7910. 5:04:20um you know how much these things cost,
  7911. 5:04:22the quantity that was that was ordered.
  7912. 5:04:25So we have order quant quantity, unit
  7913. 5:04:27cost, unit price. Then we have the
  7914. 5:04:29profit cost and revenue. all things that
  7915. 5:04:32we almost everything in here we can in
  7916. 5:04:36some way put into a pivot table. Now,
  7917. 5:04:37I'm not going to go through every single
  7918. 5:04:39variation of that, but we are going to
  7919. 5:04:41be um looking at a lot of this um
  7920. 5:04:44revenue over here because I think it's
  7921. 5:04:46it's pretty easy to show the value of a
  7922. 5:04:48pivot table with especially with um you
  7923. 5:04:50know currency or money. So, what we're
  7924. 5:04:54going to do to get started is we're
  7925. 5:04:56going to go up to insert and we're going
  7926. 5:04:58to click on insert and then we're going
  7927. 5:05:00to click on pivot table. Now, really
  7928. 5:05:02quick, there is a recommended pivot
  7929. 5:05:03tables and if you click on that, what
  7930. 5:05:05will come up is some recommendations
  7931. 5:05:07that Excel gives based on the data that
  7932. 5:05:09you have. Um, and it can kind of give
  7933. 5:05:12you some ideas of of what you can do
  7934. 5:05:15with pivot tables. It's going to
  7935. 5:05:16generate it for you. We're not going to
  7936. 5:05:18do that. We're going to build our own.
  7937. 5:05:21Uh but let's click on pivot table and
  7938. 5:05:24it's going to auto select basically
  7939. 5:05:26everything and that's fantastic. Um but
  7940. 5:05:29what if it doesn't come like that I I
  7941. 5:05:31just erased that. If it doesn't come
  7942. 5:05:32like that you can click right here. You
  7943. 5:05:34can click excuse [clears throat] me you
  7944. 5:05:36can click control shift and then the
  7945. 5:05:38right arrow and then the down arrow and
  7946. 5:05:40that is going to select all of our data.
  7947. 5:05:43Um and you have right here a new
  7948. 5:05:44worksheet or an existing worksheet.
  7949. 5:05:46We're going to create a new worksheet.
  7950. 5:05:48just tends to get too clogged up if we
  7951. 5:05:50put it on the same worksheet that
  7952. 5:05:51already has a lot of data in it. So,
  7953. 5:05:54right over here are pivot table fields,
  7954. 5:05:57and these are all of our columns that we
  7955. 5:05:59just looked at. And we're going to be
  7956. 5:06:01able to select those and kind of drag
  7957. 5:06:02and drop. Now, if you just took the
  7958. 5:06:04Tableau um tutorial series that I just
  7959. 5:06:07finished doing last week, then this is
  7960. 5:06:10going to be pretty familiar. um you're
  7961. 5:06:12going to start seeing a little bit of um
  7962. 5:06:15hopefully some patterns about how the
  7963. 5:06:18data is kind of displayed. And so we
  7964. 5:06:19have our filters down here. We have
  7965. 5:06:21columns, rows, values.
  7966. 5:06:24All of these things uh we will be using
  7967. 5:06:27I'll show you how to use today as well
  7968. 5:06:28as some additional things. Um one thing
  7969. 5:06:32that we want to start with uh for this
  7970. 5:06:34demonstration is we're going to be
  7971. 5:06:35looking at kind of the um these bottom
  7972. 5:06:38ones right here, profit, cost, and
  7973. 5:06:40revenue. And we're going to be doing
  7974. 5:06:42that per country uh per country and
  7975. 5:06:44state and we'll kind of do some drill
  7976. 5:06:46downs. Um and I'll show you how those
  7977. 5:06:48work. So for just to start out, we're
  7978. 5:06:50going to take the country right here and
  7979. 5:06:53you'll see it populate right over here.
  7980. 5:06:54In fact, um let me zoom in maybe once.
  7981. 5:06:58Uh yeah, that should be fine. I don't
  7982. 5:07:00know if I want I might zoom in again in
  7983. 5:07:02just a little bit. Um so we have our
  7984. 5:07:04country and and it's just like this.
  7985. 5:07:06Very very simple. Oops. Um now I'm going
  7986. 5:07:09to include the state. Now, I'm going to
  7987. 5:07:10drag this um all the way and I'm going
  7988. 5:07:13to put it under. You can put it above or
  7989. 5:07:14you can put it below. I'm going to put
  7990. 5:07:16it below. Uh it definitely makes the
  7991. 5:07:18most sense there. Now, when you do that,
  7992. 5:07:21it it um kind of populates it in an
  7993. 5:07:25expanded way, but you can collapse this
  7994. 5:07:28very easily. We're going to go right
  7995. 5:07:29here. We're going to rightclick. We're
  7996. 5:07:31going to go go down to expand and
  7997. 5:07:33collapse, and we're going to collapse
  7998. 5:07:34the entire field. And so now here are
  7999. 5:07:37all of our um all of our countries as
  8000. 5:07:40they were before, but now each of them
  8001. 5:07:41has this plus sign to the left. And if
  8002. 5:07:43you click on it now, we can go and we
  8003. 5:07:45see this state that we that we added to
  8004. 5:07:47these rows. And what this is going to do
  8005. 5:07:50is it kind of is like a rollup or it's
  8006. 5:07:51like a grouping. Um and so if you you
  8007. 5:07:54know have taken the SQL um tutorial
  8008. 5:07:57series and you've done uh things with
  8009. 5:07:59group by, this is very similar to that.
  8010. 5:08:01Um, and if you've done the uh Tableau
  8011. 5:08:05tutorial series, it's kind of like a
  8012. 5:08:06drill down. It's [clears throat] very,
  8013. 5:08:08very similar. So, you can drill into the
  8014. 5:08:10information. So, we um can put some
  8015. 5:08:13values in here. Uh, and what we're what
  8016. 5:08:16that's going to do is that's going to
  8017. 5:08:18kind of create some some context to what
  8018. 5:08:21this what we're grouping by. So, just
  8019. 5:08:24for um visual purposes, let's add this
  8020. 5:08:27revenue. So this is the revenue that is
  8021. 5:08:30bike uh bike sales revenue, right?
  8022. 5:08:32That's what we're looking at. So this is
  8023. 5:08:34the sum of the revenue for these bike
  8024. 5:08:39sales per country. Now if we drop down
  8025. 5:08:41right here, we can see that in Australia
  8026. 5:08:45uh New South Wales had uh 92, what is
  8027. 5:08:48that? 9,23,495.
  8028. 5:08:52Queensland had 5 million, you know,
  8029. 5:08:55etc., etc. So now we can break it down.
  8030. 5:08:57we can't it's we don't just have to look
  8031. 5:08:59at Australia. We can now drill down even
  8032. 5:09:01further to the actual state is what
  8033. 5:09:04they're calling it. Um the actual state
  8034. 5:09:07within Australia and so it's super super
  8035. 5:09:09useful and you can do that for every
  8036. 5:09:10single one. And so we can look at
  8037. 5:09:13Canada, we can look at France and we can
  8038. 5:09:15really drill down into uh the revenue
  8039. 5:09:17for each of these countries as well as
  8040. 5:09:20the states within them. Now over here,
  8041. 5:09:23this is not the most uh pretty. Um it
  8042. 5:09:26just says sum of revenue and then it has
  8043. 5:09:28some numbers. Not not the most pretty
  8044. 5:09:30thing I've ever seen. Um really quick,
  8045. 5:09:33we can go like we can um kind of
  8046. 5:09:35highlight over these and we can go back
  8047. 5:09:37to home. You can do it in a couple
  8048. 5:09:38different ways. We can go to home and
  8049. 5:09:40we'll type currency. Now it has these
  8050. 5:09:42two. Z00 zeros at the end. You can get
  8051. 5:09:45rid of those really easily by going like
  8052. 5:09:47that. Um already this looks quite a bit
  8053. 5:09:50better just visually. um especially if
  8054. 5:09:51you're looking at it in uh you know
  8055. 5:09:54dollars, you can change the currency um
  8056. 5:09:56to different currencies if you want to
  8057. 5:09:59do that. Now, we don't just have to do
  8058. 5:10:03uh the sum of revenue. We can do a lot
  8059. 5:10:05of different things. So, let's go to the
  8060. 5:10:07value field settings. So, we can
  8061. 5:10:10customize this name. So, we can do um
  8062. 5:10:14revenue. Oops, be good if I could spell
  8063. 5:10:17revenue per country.
  8064. 5:10:20Um, that's fine. That, you know, it's
  8065. 5:10:22just a placeholder to try to show you.
  8066. 5:10:24But we don't have to just do that. Um,
  8067. 5:10:26you know, we could do the count, the
  8068. 5:10:28average, the max, the min. We can do
  8069. 5:10:30just about anything we want. Um, but
  8070. 5:10:33let's keep it the sum right now. Um, and
  8071. 5:10:38if we want to, we can show this value as
  8072. 5:10:41different things. So, we percentage the
  8073. 5:10:44percentage of column total, percentage
  8074. 5:10:45of row total. Let's do really quick just
  8075. 5:10:48for demonstration purposes the
  8076. 5:10:49percentage of grand total. So when we do
  8077. 5:10:53that we can see that the United States
  8078. 5:10:55the per revenue per country United
  8079. 5:10:58States has 32%. Just between these um
  8080. 5:11:02you know these countries and Australia
  8081. 5:11:04has the next one. So you know it might
  8082. 5:11:07be kind of hard to glance at this really
  8083. 5:11:09quickly to know who has the highest. Um,
  8084. 5:11:12but what we can do is we can go right
  8085. 5:11:14here and we can go to sort and we can do
  8086. 5:11:16largest to smallest. And there we have
  8087. 5:11:19the United States on top. Now, when you
  8088. 5:11:21do it right here, it's not sorted
  8089. 5:11:24largest uh to smallest. You'd have to go
  8090. 5:11:26and again click sort and do largest to
  8091. 5:11:29smallest. And so now we can see that
  8092. 5:11:30California has the has the um, you know,
  8093. 5:11:33biggest percentage. They're pulling in
  8094. 5:11:3520% of that 32% of revenue.
  8095. 5:11:39So, I'm just going to click control-z a
  8096. 5:11:41few times and get us back to where we
  8097. 5:11:44just were. Um, and what I want to do is
  8098. 5:11:47I want to show you a few different
  8099. 5:11:49things uh pretty quickly. So, we want to
  8100. 5:11:52pull in this profit and this cost. Uh,
  8101. 5:11:54and so I'm going to pull in this cost
  8102. 5:11:56next. And then I'm going to pull in this
  8103. 5:11:59profit. Again, uh, I'm going to change
  8104. 5:12:03the currency on this.
  8105. 5:12:06And I'm not going to change the names um
  8106. 5:12:07right now, but you absolutely can do
  8107. 5:12:11that. Now, the revenue is the how much
  8108. 5:12:14is actually being sold. So, you know,
  8109. 5:12:16for the United States, it was 27
  8110. 5:12:19million. Now, the cost is how much did
  8111. 5:12:22it cost to manufacture or or store um or
  8112. 5:12:26distribute all of these products. So,
  8113. 5:12:28that was 16 million. And the profit is
  8114. 5:12:30actually how much money is being made at
  8115. 5:12:33the end of the day after um you know all
  8116. 5:12:36their costs after all their employee
  8117. 5:12:37costs after everything they're still
  8118. 5:12:39making the United States is still making
  8119. 5:12:41$11 million.
  8120. 5:12:43Now you might look at this and you might
  8121. 5:12:45say well you know I can kind of glance
  8122. 5:12:47at it and say know that this profit is
  8123. 5:12:49correct based off these two numbers. Um
  8124. 5:12:52but we can do a calculated field. Um,
  8125. 5:12:55and if you remember what calculated
  8126. 5:12:57fields are, that's something from
  8127. 5:12:58Tableau. Very uh basically the exact
  8128. 5:13:01same thing. And so we can create an
  8129. 5:13:03additional column right here that is a
  8130. 5:13:05calculated field that can add and
  8131. 5:13:06subtract these things to make sure that
  8132. 5:13:08our numbers are adding up correctly. So
  8133. 5:13:11let's do that really quickly. Uh let's
  8134. 5:13:13go to pivot table analyze. We're going
  8135. 5:13:16to go over to fields, items, and sets
  8136. 5:13:19and go to calculated field. Now we can
  8137. 5:13:21name this anything. Um, and I'm just
  8138. 5:13:24going to for demo purposes, I'm going to
  8139. 5:13:26say, um, oops, calculated
  8140. 5:13:30field demo. Uh, I'm sure yours will be
  8141. 5:13:34different. Now, um, if you want to, you
  8142. 5:13:37can go in here and this is the formula.
  8143. 5:13:38It's almost like, um, you know, we
  8144. 5:13:40haven't looked at formulas. This is our
  8145. 5:13:42first tutorial. But, you know, when we
  8146. 5:13:43look at formulas, it's basically the
  8147. 5:13:45same thing as writing an if inside of a
  8148. 5:13:47cell, but here it gives us kind of this
  8149. 5:13:50um open text to do how we uh do what we
  8150. 5:13:53want with it. Now, what we're going to
  8151. 5:13:55do is we're going to do revenue. I'm
  8152. 5:13:58going to insert that. I'm going to get
  8153. 5:14:00rid of this. I'm going to do revenue.
  8154. 5:14:04And so, that's the the the very large
  8155. 5:14:06number. And then we're going to
  8156. 5:14:08subtract.
  8157. 5:14:09And we're going to subtract our cost.
  8158. 5:14:12We're going to insert that. And let's do
  8159. 5:14:15this. And click okay. So this is our
  8160. 5:14:18calculated field demo column that we
  8161. 5:14:21just created. And as you can see, it
  8162. 5:14:23matches our uh sum of profit column
  8163. 5:14:25exactly. And that's exactly what we want
  8164. 5:14:27to see. We want to kind of check to make
  8165. 5:14:29sure that this revenue and cost uh
  8166. 5:14:32fields are generating the correct
  8167. 5:14:34profit. And sometimes those are off. And
  8168. 5:14:36so it's really good to kind of check
  8169. 5:14:37those and have that additional column.
  8170. 5:14:39Um you probably wouldn't have this if
  8171. 5:14:41you were um you know going to submit
  8172. 5:14:43this to somebody. Uh just so you know
  8173. 5:14:46now that this is an actual column. You
  8174. 5:14:48can't go here and do something like cut
  8175. 5:14:50or and paste it over here. You know
  8176. 5:14:53that's not it won't let you do that.
  8177. 5:14:55What it is is now an actual um column.
  8178. 5:14:58And so we can go and remove that and we
  8179. 5:15:00can add it back at any moment. So, if we
  8180. 5:15:02want to go back and add that um oops,
  8181. 5:15:05add that down here, we can do that
  8182. 5:15:07because we've created that column. It's
  8183. 5:15:09now permanently there unless we go and
  8184. 5:15:11delete all of that data. Uh and so we
  8185. 5:15:14can just click this check mark and it
  8186. 5:15:16will get rid of it for us. All right.
  8187. 5:15:17Now, the last thing that we have not
  8188. 5:15:19used down here is the filters. Now, the
  8189. 5:15:22filters is exactly what it sounds like.
  8190. 5:15:24It's going to allow you to filter on
  8191. 5:15:26certain things. Um, but probably not
  8192. 5:15:29things that you already have included in
  8193. 5:15:31your pivot table. So, if you add
  8194. 5:15:33something like the country down here,
  8195. 5:15:36um, it's going to kind of expand
  8196. 5:15:38everything and then if you then go and
  8197. 5:15:40filter on it, it kind of breaks it down.
  8198. 5:15:44That's really not what the filter is
  8199. 5:15:46kind of used for or meant for. Um, for
  8200. 5:15:49example, right up here we have uh
  8201. 5:15:52customer gender. Okay, so let's take the
  8202. 5:15:54customer gender and we'll put it in this
  8203. 5:15:55filters. Now we can see all of the
  8204. 5:15:58revenue, all of the cost, all the
  8205. 5:16:01profit, and we can do that based off of
  8206. 5:16:03the gender. So we can filter by a
  8207. 5:16:05gender, not really having to change
  8208. 5:16:07anything about our pivot table. And so
  8209. 5:16:09at a super quick glance, we can see that
  8210. 5:16:12uh the males are the the profit from the
  8211. 5:16:15males is 16.487 487 million and the
  8212. 5:16:19profit from the females is 15.733
  8213. 5:16:23million. So at a super uh basic level at
  8214. 5:16:25a really quick glance we can see that
  8215. 5:16:27the men or the males are you know
  8216. 5:16:30spending a little bit more than the
  8217. 5:16:32females by about about $700,000.
  8218. 5:16:35Now let's go ahead and create one more
  8219. 5:16:37pivot table. Uh we are going to create a
  8220. 5:16:39pivot table right over here. Let's go
  8221. 5:16:41back to the sales
  8222. 5:16:43right here again. control shift right
  8223. 5:16:46down. It's going to select all of our
  8224. 5:16:48data and we're click okay. So, one thing
  8225. 5:16:53that we're going to look at is we're
  8226. 5:16:54going to use some of this date
  8227. 5:16:56information right here. So, let's select
  8228. 5:16:58our country just like we did before. Um,
  8229. 5:17:01and what we want to do is see, you know,
  8230. 5:17:03what year were we performing our best?
  8231. 5:17:06when were we doing our absolute best uh
  8232. 5:17:08with oops let me go back
  8233. 5:17:13uh with our sales. So I'm going to
  8234. 5:17:15select the year and put that in our
  8235. 5:17:17columns. And so now we have 2011 through
  8236. 5:17:212016 and we want to look at our revenue.
  8237. 5:17:25So let's put our revenue right down
  8238. 5:17:26here. And now we have all of our
  8239. 5:17:29revenue. Now let's again make this into
  8240. 5:17:32a currency.
  8241. 5:17:35Just like that. And super quickly now,
  8242. 5:17:38we can get a really quick glance at how
  8243. 5:17:40Australia was doing each year. And we
  8244. 5:17:43can see that there was a huge uptick in
  8245. 5:17:45uh 2013 and a huge uptick in 2015. That
  8246. 5:17:49didn't happen for every single country.
  8247. 5:17:51Uh did go up uh for most countries, very
  8248. 5:17:54slightly for some, but we can see on a
  8249. 5:17:57large scale from um year to year what
  8250. 5:18:01that's like. And so within just a few
  8251. 5:18:03minutes, we're able to create some
  8252. 5:18:04really useful pivot tables that anybody
  8253. 5:18:06could look at and understand. And that's
  8254. 5:18:08really the biggest use of these pivot
  8255. 5:18:10tables is that you can kind of group
  8256. 5:18:12these things together, show some uh
  8257. 5:18:14information, data at at kind of a broad
  8258. 5:18:16larger scale and make it to where
  8259. 5:18:19anybody who's looking at it can
  8260. 5:18:20understand it. That is why pivot tables
  8261. 5:18:22are so useful. And so I hope that this
  8262. 5:18:24video was helpful. I hope that I was
  8263. 5:18:26able to walk through it and help you
  8264. 5:18:27better understand how pivot tables work
  8265. 5:18:29and how you can use them when you are
  8266. 5:18:31working within Excel. Thank you guys so
  8267. 5:18:33much for watching. I really appreciate
  8268. 5:18:35it. If you like this video, be sure to
  8269. 5:18:36like and subscribe below and I'll see
  8270. 5:18:38you in the next video.
  8271. 5:18:51What's going on everybody? Today we're
  8272. 5:18:53going to be looking at formulas in
  8273. 5:18:54Excel.
  8274. 5:18:58[music]
  8275. 5:19:01Now, I know what you're thinking.
  8276. 5:19:02There's absolutely no way that you're
  8277. 5:19:03going to be able to show us every single
  8278. 5:19:05formula in Excel. And you're absolutely
  8279. 5:19:07right. But I am going to show you some
  8280. 5:19:09of my favorites and the ones that I
  8281. 5:19:10found the most useful. And then you can
  8282. 5:19:12go ahead and practice those and try
  8283. 5:19:14those out. And if there are ones that
  8284. 5:19:16you really want me to do and you think
  8285. 5:19:17that I missed, put it in the comments
  8286. 5:19:20below and I will see those and I'll try
  8287. 5:19:21to make a list of those and make another
  8288. 5:19:24video on formulas and include all of
  8289. 5:19:26those as well. And now before we jump
  8290. 5:19:28into the actual tutorial, I want to give
  8291. 5:19:29a huge shout out to the sponsor of this
  8292. 5:19:31series and that is Udemy. You guys
  8293. 5:19:33already know if you've watched any of my
  8294. 5:19:35videos that I absolutely love Udemy. I
  8295. 5:19:37mean honestly, they were the ones who
  8296. 5:19:39got me started and were able to give me
  8297. 5:19:40affordable courses for me to get started
  8298. 5:19:42as a data analyst. I learned SQL and
  8299. 5:19:45Excel and Python all through Udemy
  8300. 5:19:47courses. And so if you are looking for a
  8301. 5:19:49platform to take a course, I absolutely
  8302. 5:19:51recommend you look at Udemy. They have
  8303. 5:19:53fantastic sales going on right now,
  8304. 5:19:54especially during the holiday season in
  8305. 5:19:56this new year. And so if you're looking
  8306. 5:19:58to take a full-fledged Excel course, I
  8307. 5:20:00have some of my favorites in the
  8308. 5:20:01description below. And now without
  8309. 5:20:03further ado, let's jump onto my screen
  8310. 5:20:04and get started with the tutorial. All
  8311. 5:20:06right. Now before we start, I want to
  8312. 5:20:07say that this is not like every other
  8313. 5:20:09tutorial that I have created. This one
  8314. 5:20:11is very streamlined. Okay. So, I already
  8315. 5:20:14know exactly what I'm going to do.
  8316. 5:20:15There's not going to be much messing
  8317. 5:20:16around. I've left little notes here and
  8318. 5:20:19there. Um, and I'm going to try to get
  8319. 5:20:21through it because there's a lot of them
  8320. 5:20:22to get through. Um, so all these ones at
  8321. 5:20:24the bottom. Now, these are ones that I
  8322. 5:20:26use a lot that I think are useful.
  8323. 5:20:28Again, if you know other ones that you
  8324. 5:20:30use a lot that think that I should be
  8325. 5:20:32using, which I know there are ones that
  8326. 5:20:33I left out of here, you know, put it in
  8327. 5:20:35the comments. Um, I'll see the ones that
  8328. 5:20:37people are liking and I will I will
  8329. 5:20:39create more videos on these because I
  8330. 5:20:40know there are so many. I also will save
  8331. 5:20:43this um Excel in uh on the GitHub so you
  8332. 5:20:47can go and download it. It'll be exactly
  8333. 5:20:48what you're looking at right now. I
  8334. 5:20:50highly recommend trying these formulas
  8335. 5:20:52out for yourself so you can get a feel
  8336. 5:20:54for how they work and how they're
  8337. 5:20:55actually used and you can mess around
  8338. 5:20:56with it yourself. So, um as you can see
  8339. 5:20:59at the bottom, we're going to start with
  8340. 5:21:01max min and then we're going to go on to
  8341. 5:21:03some more I think a little bit more uh
  8342. 5:21:06difficult things. Um and all these
  8343. 5:21:08things are super useful. I'll try to
  8344. 5:21:09talk about how you can actually use it
  8345. 5:21:11as we go through it. Some are super
  8346. 5:21:13self-explanatory, but some may not be.
  8347. 5:21:16So, this one I think is super
  8348. 5:21:18self-explanatory, but again, one that
  8349. 5:21:20you're going to use all the time. Um,
  8350. 5:21:22and so, uh, what we can do is we can say
  8351. 5:21:24equal, and that's how you kind of start
  8352. 5:21:26off saying this is going to be a formula
  8353. 5:21:28in this cell. Equal means, uh, I am now
  8354. 5:21:31creating a formula. And we're going to
  8355. 5:21:32say m a x. And I'll hit tab. And so,
  8356. 5:21:36it'll kind of populate it. And right
  8357. 5:21:38here, if you've never seen a formula
  8358. 5:21:39before, it'll kind of give you what the
  8359. 5:21:41inputs need to be. So, it's going to say
  8360. 5:21:43max of number one, number two, etc.,
  8361. 5:21:45etc. What we're going to do is we're
  8362. 5:21:47going to give a range. So, we're going
  8363. 5:21:48to go from here down to here. You don't
  8364. 5:21:51have to close the parentheses, but you
  8365. 5:21:52can. I'm going to. And then you hit
  8366. 5:21:54enter. And so, for this date, it's going
  8367. 5:21:57to give us the max date. Now, these are
  8368. 5:21:59um the start dates for these people
  8369. 5:22:02right here. And so if we just kind of
  8370. 5:22:04glance through here, we can see that
  8371. 5:22:062013 was the last year and this one is
  8372. 5:22:09actually the latest in that year. And so
  8373. 5:22:11it gave us the correct one. The min is
  8374. 5:22:13going to do the exact opposite. It's
  8375. 5:22:16going to give us the smallest. And so
  8376. 5:22:19we'll give it the same range. We'll
  8377. 5:22:20close the parenthesis. And it's going to
  8378. 5:22:22say December 7th of 1995. And we can see
  8379. 5:22:26that that is correct. So Michael Scott
  8380. 5:22:29started in 1995, the earliest of all the
  8381. 5:22:31employees. Um, and you can do the exact
  8382. 5:22:33same thing for really any of these
  8383. 5:22:36columns. Um, we can see who the who's
  8384. 5:22:38making the most money or at least what
  8385. 5:22:40the highest salary is. U, so we'll do
  8386. 5:22:43max. And then we'll do the salary range.
  8387. 5:22:46And so this is this one again. Uh,
  8388. 5:22:49Whoops. What did I do? Oh, I did the
  8389. 5:22:51wrong range, didn't I? No, I didn't do
  8390. 5:22:54the wrong range. It's just There it
  8391. 5:22:57goes. uh this column was a date range or
  8392. 5:23:01a date column for whatever reason. So
  8393. 5:23:02let me get rid of that. Uh and then we
  8394. 5:23:05can do equals min and we'll do again
  8395. 5:23:08we'll do the salary. And at a quick
  8396. 5:23:11glance we can see that Beasley is making
  8397. 5:23:13the least and 65,000 is Michael Scott
  8398. 5:23:17who's making uh that. So super simple.
  8399. 5:23:21It shows the max. It shows the min. You
  8400. 5:23:23can select a range. There you go. Let's
  8401. 5:23:25move on to if and ifs. Now, if is um I
  8402. 5:23:30think pretty straightforward. So, all
  8403. 5:23:32you're going to do is you're going to
  8404. 5:23:33say if this then that. Um ifs is a
  8405. 5:23:38little bit different. So, ifs is you can
  8406. 5:23:40you can put multiple conditions. And as
  8407. 5:23:42we're writing it, I'll show you kind of
  8408. 5:23:43what it the conditions that need to be
  8409. 5:23:45met. All right. So, we're going to click
  8410. 5:23:47right here. We're going to say equal.
  8411. 5:23:49We're going to do if hit tab. And we
  8412. 5:23:51need a logical test. Uh, and so we're
  8413. 5:23:53going to give it a range or or or
  8414. 5:23:55something. We're going to say if it's
  8415. 5:23:56equal, greater to um something like
  8416. 5:23:58that. Then we're going to say if the
  8417. 5:24:00value is true, what's the what is going
  8418. 5:24:01to be the output? Or if the value is
  8419. 5:24:03false, what's going to be the output? So
  8420. 5:24:05let's do this right here.
  8421. 5:24:09We'll do this age range. And so if they
  8422. 5:24:12are greater than let's say let's do 30.
  8423. 5:24:17If they're greater than 30, we're going
  8424. 5:24:19to do a comma. And so if the value is
  8425. 5:24:21true, what what should be the output? If
  8426. 5:24:24they're greater than 30, we're going to
  8427. 5:24:25call them old. And then if it is false,
  8428. 5:24:29so if they're younger than 30, what
  8429. 5:24:31should it say? And we're going to say
  8430. 5:24:34young.
  8431. 5:24:36And we'll close the parenthesis. And
  8432. 5:24:38there you go. So if they're over 30,
  8433. 5:24:42then they are going to have young. Or if
  8434. 5:24:44they're younger than 30, they're going
  8435. 5:24:45to have young. Now, this is something
  8436. 5:24:48where you need to specify if you want 30
  8437. 5:24:50and over or over 30. We chose over 30.
  8438. 5:24:54So, 30 is not included in that. Um, so
  8439. 5:24:57they're going to be young.
  8440. 5:24:59Now, uh, let's get We don't actually
  8441. 5:25:01need two of these. That's pretty
  8442. 5:25:03self-explanatory. The ifs is a little
  8443. 5:25:05bit different, right? You can have
  8444. 5:25:06multiple conditions. So, let's open that
  8445. 5:25:08up real quick. So, ifs. And now we have
  8446. 5:25:12a logical test value. If uh that's true
  8447. 5:25:16then you can do logical test two value
  8448. 5:25:18if that's true. Um so you can have
  8449. 5:25:21multiple multiple multiple things. Now
  8450. 5:25:23this one is a little bit different. In
  8451. 5:25:25this one oops let me get out of this. In
  8452. 5:25:29this one you had a value of true a value
  8453. 5:25:31of false. Ifs does not have that. Ifs is
  8454. 5:25:35going to give you um different ranges
  8455. 5:25:38and different specific conditions. And
  8456. 5:25:41you can't say if this one's false.
  8457. 5:25:43you're just going to have multiple
  8458. 5:25:44conditions. So, let's do equals and ifs
  8459. 5:25:48tab and we'll do our first logical test.
  8460. 5:25:50So, let's do um
  8461. 5:25:54if the salesman
  8462. 5:25:56or if that equals to salesman,
  8463. 5:26:01we're going to say we're going to
  8464. 5:26:04respond with sales.
  8465. 5:26:07So, that's if the value is true. That's
  8466. 5:26:09what we want the output to be. Now we're
  8467. 5:26:12going to go on to our logical test two.
  8468. 5:26:14So you're going to see this pattern,
  8469. 5:26:16right? If this is our conditional or
  8470. 5:26:18logical test. So if this is true, this
  8471. 5:26:21is what's going to be returned. So
  8472. 5:26:23you'll notice that's just a a pretty
  8473. 5:26:25simple pattern. We can just do random
  8474. 5:26:26things. So if it's equal to sales, um,
  8475. 5:26:30and we'll just do the same one. If that
  8476. 5:26:33is equal to
  8477. 5:26:36say HR, we can say fire immediately.
  8478. 5:26:42And now we're going to say
  8479. 5:26:45if it's equal to
  8480. 5:26:51regional
  8481. 5:26:54manager
  8482. 5:26:56and we say give Christmas bonus and
  8483. 5:27:02we'll close the parenthesis and let's
  8484. 5:27:03see what we get. So, as [clears throat]
  8485. 5:27:06you can see, there's no default value
  8486. 5:27:08for true or false. Like like this one,
  8487. 5:27:11there was a logical test and if it was
  8488. 5:27:13true, there was a value and if it was
  8489. 5:27:15false, there was a value. So, for every
  8490. 5:27:16single one, you'll get a value. For this
  8491. 5:27:18one, that's not exactly going to happen.
  8492. 5:27:20As you can see, there are these NAS.
  8493. 5:27:23Now, when that happens, it just means
  8494. 5:27:25nothing met that condition. So, we never
  8495. 5:27:27said anything about supplier relations.
  8496. 5:27:29We never said anything about
  8497. 5:27:30accountants. But if it was part of that
  8498. 5:27:33ifs statement then it got something. Um
  8499. 5:27:35and so that is how the ifs works. Now
  8500. 5:27:39let's move on to length. Uh this is
  8501. 5:27:42exactly what we're going to do. But you
  8502. 5:27:44know some of the uses for this u for the
  8503. 5:27:46length I've used it for a lot of
  8504. 5:27:48different things. Um one thing that I've
  8505. 5:27:50used it for in the past and you know max
  8506. 5:27:52and ifs you know you can use it for
  8507. 5:27:54almost anything. Length is there's a lot
  8508. 5:27:57of different use cases. one, I used to
  8509. 5:27:59work with a lot of um customer data or
  8510. 5:28:02or patient data. They had like social
  8511. 5:28:03security numbers and if you know there
  8512. 5:28:05was bad social security numbers, we
  8513. 5:28:07didn't want to include that. And so we
  8514. 5:28:09do like the length of that. And if a
  8515. 5:28:11social security number was let's say 10
  8516. 5:28:13numbers or 11 numbers where it should
  8517. 5:28:15only be nine or or you know, however
  8518. 5:28:18many they are, I think it's nine. Then
  8519. 5:28:20we know that that social security number
  8520. 5:28:21is incorrect. And then we can get rid of
  8521. 5:28:23that or discard it from our results.
  8522. 5:28:25That's just an example, right? Um, so
  8523. 5:28:27for this, oops, why' I do that? I did
  8524. 5:28:30control Z to undo that if you didn't
  8525. 5:28:32know how to do that. Uh, so we're going
  8526. 5:28:33to do equals leen, which is length. Um,
  8527. 5:28:37and again, if you didn't see that, it
  8528. 5:28:39returns the number of characters in a
  8529. 5:28:41text string. So, let's go right here and
  8530. 5:28:45let's go to uh let's go to their last
  8531. 5:28:48name and we'll give it a range. So, it's
  8532. 5:28:51going to tell us how many characters are
  8533. 5:28:54in that string. So for Halpert it's
  8534. 5:28:56seven characters. For Fenderson it's 10
  8535. 5:29:00characters. And we're able to see a
  8536. 5:29:02length. And so again there are a lot of
  8537. 5:29:03different use cases for this. Uh the
  8538. 5:29:05social security number was one. Another
  8539. 5:29:07one is phone numbers. Right? If you look
  8540. 5:29:09at the length of the phone numbers and
  8541. 5:29:10there's uh ones that are like 12 numbers
  8542. 5:29:13long. You know those might not be ones
  8543. 5:29:15that are accurate and you need to go
  8544. 5:29:16look at them and see if you want to
  8545. 5:29:18include them in your results or your
  8546. 5:29:19output. So that is how length is done.
  8547. 5:29:22Let's move right over to the left and
  8548. 5:29:24right. Um I I might be going a little
  8549. 5:29:28fast, but uh you know, I'm keeping it
  8550. 5:29:30I'm keeping it live. I'm keeping us on
  8551. 5:29:31our feet. Uh so let's keep going. Left
  8552. 5:29:34and right um are kind of like
  8553. 5:29:37substrings. If you've taken the the SQL
  8554. 5:29:40um tutorial series that I've done, uh
  8555. 5:29:43substrings are where you can choose a
  8556. 5:29:44certain part of the text string and you
  8557. 5:29:47can extract data from that. Um and it
  8558. 5:29:50usually have to reference a certain
  8559. 5:29:51number. So, a certain amount of
  8560. 5:29:53characters. That's the exact same thing,
  8561. 5:29:55except uh uh unfortunately there's no
  8562. 5:29:57substring. There's substitute, but
  8563. 5:29:59there's no substring. Left and right is
  8564. 5:30:01really the closest thing that we have.
  8565. 5:30:03So, let's kind of take a look real quick
  8566. 5:30:05and see what we can do. So, we're going
  8567. 5:30:08to do left, and it's going to say
  8568. 5:30:10returns the specified number of
  8569. 5:30:11characters from the start of a text
  8570. 5:30:13string. So, we're starting from the very
  8571. 5:30:14far left, and we need to choose our
  8572. 5:30:17text, and then choose the number of
  8573. 5:30:19characters that we're going to be
  8574. 5:30:20looking over.
  8575. 5:30:22So let's go over here and let's just
  8576. 5:30:24choose, you know, start simple. Uh we'll
  8577. 5:30:27get a little bit more advanced. So we
  8578. 5:30:29have uh this is our text range. So these
  8579. 5:30:31are the the the ones that we want to
  8580. 5:30:33look at. And then how many characters do
  8581. 5:30:34we want to look forward um and we'll
  8582. 5:30:36just choose three as an example. And so
  8583. 5:30:39you can see that it takes the first
  8584. 5:30:41three characters from every single um
  8585. 5:30:44thing. Now you can also do this with
  8586. 5:30:45numbers. It doesn't just have to be um
  8587. 5:30:48you know name with with actual words or
  8588. 5:30:51letters. You can do the exact same
  8589. 5:30:52thing. So you can say write
  8590. 5:30:56um and we're going to choose our our
  8591. 5:30:57string. Uh and let's do this one. So you
  8592. 5:31:00know all of them start with 100 um and
  8593. 5:31:02we'll just say we want to take the last
  8594. 5:31:04one. So this one is going to start from
  8595. 5:31:07the very far right and go over one
  8596. 5:31:09character. So right here you can see
  8597. 5:31:11this is our range and I just chose one.
  8598. 5:31:13So starting from the very far right, we
  8599. 5:31:15go over one character and that's what we
  8600. 5:31:16take. And so that can definitely be
  8601. 5:31:19useful. Another one that you can do and
  8602. 5:31:21this one is one that I have used so many
  8603. 5:31:23times. I mean honestly countless times
  8604. 5:31:25in in actually using this in my job. Uh
  8605. 5:31:28so we're going to go from the right and
  8606. 5:31:29we're going to look at a date. So, you
  8607. 5:31:32know, sometimes you have these date
  8608. 5:31:34structures, month, month, day, day,
  8609. 5:31:36year, year, year or year. Um, you know,
  8610. 5:31:38day, month, year, all these different
  8611. 5:31:40and sometimes you just want to extract
  8612. 5:31:43either the month or the year or or
  8613. 5:31:45something like that, the day. And so, we
  8614. 5:31:47want to come in here and we're just
  8615. 5:31:48going to extract the Oops, I wanted to
  8616. 5:31:50make that a range. We want to extract
  8617. 5:31:52the year of the start dates. So, we're
  8618. 5:31:55going to do that. And then we're going
  8619. 5:31:56to go over four because we want to take
  8620. 5:31:58the first four characters from the right
  8621. 5:32:00to give us the entire year. So let's do
  8622. 5:32:03that. And now we can see exactly the
  8623. 5:32:05year. And this can be just super super
  8624. 5:32:07useful. This is again one that I've used
  8625. 5:32:10a lot. And so that is one that you might
  8626. 5:32:11want to remember in case you're ever
  8627. 5:32:12doing analysis on, you know, start and
  8628. 5:32:14end dates or or anything with um date
  8629. 5:32:16data. Uh again, one that I highly
  8630. 5:32:19recommend remembering. Let's go over to
  8631. 5:32:22date to text. I actually probably should
  8632. 5:32:24have included that. um before because I
  8633. 5:32:27actually used it in this one. Um if you
  8634. 5:32:30notice right here, this is a text. So in
  8635. 5:32:32in this one we just did that was a text.
  8636. 5:32:35You can't do this right on um start and
  8637. 5:32:38end dates when it's a date uh format.
  8638. 5:32:41And let me show you. So this is a date.
  8639. 5:32:44Now if I do equals and you know we just
  8640. 5:32:48did this uh let's do on the end date and
  8641. 5:32:52I mean I'll do the whole range. Give me
  8642. 5:32:54a second and we'll do four.
  8643. 5:32:57It's giving us completely random
  8644. 5:32:58numbers. Why is that? Because underneath
  8645. 5:33:00the date range there are um numbers,
  8646. 5:33:04right? So if I go right here and I make
  8647. 5:33:07this
  8648. 5:33:08general, it's going to have a numbers.
  8649. 5:33:10And look, these are the first four
  8650. 5:33:12characters from the right. And so it's
  8651. 5:33:14doing what it's supposed to do, but uh
  8652. 5:33:16it's not doing what we actually want.
  8653. 5:33:17And that's the issue. So how can we
  8654. 5:33:20convert this? Now there are a ton of
  8655. 5:33:22different ways. Um, but the quickest,
  8656. 5:33:25probably the easiest besides actually
  8657. 5:33:28writing writing it out like this, like
  8658. 5:33:3011-2-201,
  8659. 5:33:33which then converts it to a date format.
  8660. 5:33:36Um, but what you can do, you know, just
  8661. 5:33:38so you know, you can create it as a
  8662. 5:33:40text. You can do 11-2-201.
  8663. 5:33:45And now it will stay a text string. And
  8664. 5:33:48as you can tell, these are a little bit
  8665. 5:33:50different because this one is uh
  8666. 5:33:51formatted or situated on the right and
  8667. 5:33:53this one's on the left. That's how you
  8668. 5:33:54can tell the difference. Now, if you
  8669. 5:33:57don't want to do it by hand uh
  8670. 5:33:59completely manually and waste hours of
  8671. 5:34:01your time, you can do it in a very
  8672. 5:34:04simple way. So, we're going to do uh
  8673. 5:34:07text. So, this is the exact um formula
  8674. 5:34:10that we're going to use. So, let's get
  8675. 5:34:11rid of that one. Oops. There we go. So,
  8676. 5:34:14we're going to do equals. We're going to
  8677. 5:34:17do uh oops text. It says converts a
  8678. 5:34:20value to text in a specific number
  8679. 5:34:22format. So for a date format, we can
  8680. 5:34:26choose a date format and then it'll
  8681. 5:34:28convert it to a text for us, which saves
  8682. 5:34:31so much time, I promise you. Uh let's do
  8683. 5:34:34all of these just like we did. And then
  8684. 5:34:36we need to tell it what the format is.
  8685. 5:34:39If we don't, if we tell it something
  8686. 5:34:41incorrect, it's going to give us a
  8687. 5:34:43completely terrible output or just give
  8688. 5:34:44us an error altogether. So this is a day
  8689. 5:34:47day month year year format and that is
  8690. 5:34:51what we're going to do. So we're going
  8691. 5:34:52to dd/mm/y
  8692. 5:34:55y and close that up. And there you go.
  8693. 5:35:00And now we will because it's in a
  8694. 5:35:02formula what we need to do is
  8695. 5:35:06copy this
  8696. 5:35:09and paste it right over here. And now
  8697. 5:35:11you can see that is a general. This is
  8698. 5:35:14something that we can use as a string.
  8699. 5:35:16And let's just check it just to make
  8700. 5:35:18sure. So we're going to do write, we're
  8701. 5:35:20gonna do this one. Let's do all of them.
  8702. 5:35:23And we'll do four. And there you go. So
  8703. 5:35:27now it works. That is what we are
  8704. 5:35:29looking for. Um, and you can do that.
  8705. 5:35:31Imagine doing that with millions of rows
  8706. 5:35:33or, you know, let's say 10,000 rows.
  8707. 5:35:36It's going to be a breeze, right? It's
  8708. 5:35:38going to take you 2 minutes or a minute
  8709. 5:35:40to do everything that you want to do
  8710. 5:35:42instead of having to just do a bunch of
  8711. 5:35:44mess to convert it to a string, which I
  8712. 5:35:46promise you I've done and it just takes
  8713. 5:35:48forever. It's it's terrible. So, that is
  8714. 5:35:51uh date to text. Super helpful formula.
  8715. 5:35:54Let's go over to trim. Now, I I
  8716. 5:35:57purposefully messed up this column. Now,
  8717. 5:36:00why do I did I mess it up like this?
  8718. 5:36:03Because when you're working with real
  8719. 5:36:04data, you're going to get data like
  8720. 5:36:05this. it it it's messy, it's dirty, it
  8721. 5:36:08just has random spaces at the end for no
  8722. 5:36:12reason. Um because sometimes you're
  8723. 5:36:15going to be working with um data that is
  8724. 5:36:18inputed by a user. It's not like a drop-
  8725. 5:36:21down option. So imagine somebody's
  8726. 5:36:22typing this in, they accidentally put a
  8727. 5:36:24space or they accidentally put an enter
  8728. 5:36:26or something and then they submit it and
  8729. 5:36:28this is how it's going to look in the
  8730. 5:36:29database. Um, and if you're a data
  8731. 5:36:32engineer or you know you're working with
  8732. 5:36:33the raw data, if they don't clean that
  8733. 5:36:35up, then you're going to be working with
  8734. 5:36:37that that dirty data. And I I guarantee
  8735. 5:36:39you if you're working as a data analyst,
  8736. 5:36:41you're going to see stuff like this. Not
  8737. 5:36:43with maybe a last name, but all sorts of
  8738. 5:36:45data. So, we're going to go right here.
  8739. 5:36:47We're going to say equals trim. Do open
  8740. 5:36:50parenthesis. Actually, this says removes
  8741. 5:36:52all spaces from a text string except for
  8742. 5:36:53a single space between words. So like
  8743. 5:36:57you know if it said help space uh or gym
  8744. 5:37:01space helper it won't take the space in
  8745. 5:37:03between there because it it kind of
  8746. 5:37:04understands that the in normal language
  8747. 5:37:07space is supposed to be there. So it
  8748. 5:37:08won't do that. Um but we'll take that.
  8749. 5:37:11We'll give it this range.
  8750. 5:37:14Close that up. And there you go. Now it
  8751. 5:37:16is nice and clean. Much more usable. Now
  8752. 5:37:19let's look at concatenate. one that I
  8753. 5:37:22have used just way way way too many
  8754. 5:37:26times. Um, and something that I've used
  8755. 5:37:29concatenate for, and you'll see this one
  8756. 5:37:31in a lot of demonstrations for a good
  8757. 5:37:33reason, is because a lot of people use
  8758. 5:37:35it for this. Um, so what you can do is
  8759. 5:37:39you can say equals um, and well, let me
  8760. 5:37:42tell you what concatenate does real
  8761. 5:37:44quick.
  8762. 5:37:45So, what concatenate does, oops, I'm
  8763. 5:37:48totally messing up here. Um, but it
  8764. 5:37:51joins two or more text strings into one
  8765. 5:37:53string. It basically joins things
  8766. 5:37:55together and adds them together. So,
  8767. 5:37:58let's do concatenate. And we're going to
  8768. 5:38:00add this first and last name. Again, one
  8769. 5:38:02that gets used all the time, but that's
  8770. 5:38:04because um it really is useful. So, you
  8771. 5:38:07can do this. And you can say now I want
  8772. 5:38:10to include this. So, concatenating this
  8773. 5:38:12and this. And let's take a look. So, it
  8774. 5:38:15says Jim Halbert, but it's all
  8775. 5:38:16connected. And that's typically not how
  8776. 5:38:19people write their names. So, what we
  8777. 5:38:21can do is we can go back in here and we
  8778. 5:38:23can do what my demonstration up here
  8779. 5:38:25already tells us to do, which is we're
  8780. 5:38:27just going to add another thing in here.
  8781. 5:38:29And if we add two parentheses, we can
  8782. 5:38:31include anything in here. We can include
  8783. 5:38:33a dash, we can include an exclamation
  8784. 5:38:35point, or we can just include a space.
  8785. 5:38:38So, let's just include a space really
  8786. 5:38:40quick. And just like that, it works
  8787. 5:38:44perfectly. And so, now we have the full
  8788. 5:38:45name. Now, something that you could use
  8789. 5:38:48it for is something like generating uh
  8790. 5:38:50an email. This is something that you
  8791. 5:38:53absolutely could do. Um, and it's, you
  8792. 5:38:56know, pretty simple. So, I'm going to do
  8793. 5:38:58it like this. I'm going to say, oops,
  8794. 5:39:01what' I do? I'm gonna say um dot and
  8795. 5:39:07then at the end I'm going to say at oops
  8796. 5:39:11comma quotation atgmail.com.
  8797. 5:39:17And now I've created emails for all of
  8798. 5:39:19these people. So just something that you
  8799. 5:39:22can do with this um and something that
  8800. 5:39:24it it absolutely is used for and you'll
  8801. 5:39:26see that demonstration almost everywhere
  8802. 5:39:28because honestly it gets used a lot um
  8803. 5:39:30by data analysts. And so uh you know
  8804. 5:39:33just a good one to know understanding
  8805. 5:39:35how that that concatenation works. Um
  8806. 5:39:38let's go over to the next one. So
  8807. 5:39:40[clears throat] we are going to do
  8808. 5:39:42substitute. Now substitutees really
  8809. 5:39:44interesting. Um there are different ways
  8810. 5:39:46you can do it. I'm going to show it to
  8811. 5:39:48you on these dates real quick. Uh that's
  8812. 5:39:51what we're going to look at. So changing
  8813. 5:39:53a date format, changing how uh what it's
  8814. 5:39:56supposed to look like is absolutely
  8815. 5:39:58something that happens all the time. And
  8816. 5:40:00um you know sometimes you'll even get it
  8817. 5:40:02like this
  8818. 5:40:04where it'll look like it'll be messy.
  8819. 5:40:06It'll be different a different um I
  8820. 5:40:09guess format. So this one has all the
  8821. 5:40:12other ones have um slashes where these
  8822. 5:40:15ones have dashes. And you know what you
  8823. 5:40:19can do is if you want to well let me
  8824. 5:40:23actually go with the no instances real
  8825. 5:40:24quick because this one is uh actually
  8826. 5:40:26makes the most sense. Um, so we'll do
  8827. 5:40:29equals and we're going to say
  8828. 5:40:31substitute.
  8829. 5:40:33And oops, and let me say substitute
  8830. 5:40:34replaces existing text with new text in
  8831. 5:40:38a text string. So if we do an open
  8832. 5:40:41parenthesis, it says we take the text,
  8833. 5:40:43we have the old text, we have the new
  8834. 5:40:45text, and then we have how what instance
  8835. 5:40:48or how many times uh or or or what
  8836. 5:40:51instance are we looking at it? And I'll
  8837. 5:40:52explain that in a little bit.
  8838. 5:40:55So the text that we're going to be
  8839. 5:40:56looking at is this one right here. So
  8840. 5:40:58let's take this range. And the old is
  8841. 5:41:02we're going to take this dash. And so
  8842. 5:41:06let's take the dash.
  8843. 5:41:08And then what do we want to replace it
  8844. 5:41:10with? We want to replace it with this
  8845. 5:41:12slash right here. I think it's a forward
  8846. 5:41:14slash. Isn't that what it's called? Is
  8847. 5:41:15that called a forward slash? Am I crazy?
  8848. 5:41:17Um and we're not going to put an
  8849. 5:41:19instance. Notice that that's in a
  8850. 5:41:20bracket. That means it's optional. We're
  8851. 5:41:22going to do none of that. Um, and what
  8852. 5:41:24it's going to do is it's going to fix
  8853. 5:41:26this. So, this one is now in the correct
  8854. 5:41:28format that we want. Uh, and that's
  8855. 5:41:31fantastic. That's, you know, that's what
  8856. 5:41:33we tried to accomplish given what we
  8857. 5:41:35had. Now, let's fix that. If we want to
  8858. 5:41:37do the exact same thing, uh, we can say,
  8859. 5:41:40uh, what are we doing? Substitute. We
  8860. 5:41:42can do substitute. We can do open
  8861. 5:41:44parentheses. We'll give the range. And
  8862. 5:41:47now, let's say we want to change all of
  8863. 5:41:49them to a different format. So instead
  8864. 5:41:51of the um forward slash, I'm going to
  8865. 5:41:54keep calling it that if that's correct,
  8866. 5:41:57we want to give it a dash. And so then
  8867. 5:41:59we close that. And now all of them are
  8868. 5:42:01in this new format. So it it's able to
  8869. 5:42:03substitute a specific value for a new
  8870. 5:42:06value. And if you don't include an
  8871. 5:42:08instance, then it'll do it to every
  8872. 5:42:11single one in there. So, let's go over
  8873. 5:42:15here and we're going to actually use the
  8874. 5:42:17the um the uh the instance num and I'll
  8875. 5:42:21show you what that does. Uh and so,
  8876. 5:42:24really quick, we'll do the exact same
  8877. 5:42:25thing that we just did. We'll do the
  8878. 5:42:29forward slash. And we want to replace it
  8879. 5:42:32with this one again, this dash, but we
  8880. 5:42:36only want to do it on the first instance
  8881. 5:42:38of that forward slash. And so as you can
  8882. 5:42:42see all the ones that um all the ones
  8883. 5:42:45that were replaced are the very first
  8884. 5:42:46instance whereas the second instance
  8885. 5:42:49which is the second time it appears in
  8886. 5:42:51this string does not get touched.
  8887. 5:42:54So if we take this
  8888. 5:42:56and we put it right over here and we
  8889. 5:43:00move it to two,
  8890. 5:43:02it's kind of the opposite. So the first
  8891. 5:43:04one wasn't touched, the second one was.
  8892. 5:43:06So, we're choosing which instance or
  8893. 5:43:08which time it shows up in that string
  8894. 5:43:10and then it replaces it. If you do not
  8895. 5:43:12choose an instance, it chooses all of
  8896. 5:43:15them. So, this can be super useful if
  8897. 5:43:17you want to do like a bulk replace um
  8898. 5:43:20but you only want to do it on a specific
  8899. 5:43:22column um and you just want to use a
  8900. 5:43:23formula really quick, right? Um and so
  8901. 5:43:25you can use this in a lot of different
  8902. 5:43:27ways. So, that's how you're able to
  8903. 5:43:28actually do it with the first instance,
  8904. 5:43:30the second instance, and if you don't
  8905. 5:43:32include an instance at all. Let's go
  8906. 5:43:34over to the sum. Uh, this is one I think
  8907. 5:43:37everyone knows how to use, but I want to
  8908. 5:43:40show you two other ones um as well. So,
  8909. 5:43:44let's go to the sum and we're just going
  8910. 5:43:45to do equals the sum. And I hope you
  8911. 5:43:47know what this is. Well, not hope. I if
  8912. 5:43:49you don't know what this is, it just
  8913. 5:43:50adds up all the numbers in a range. So,
  8914. 5:43:53we're going to add. Sum means add. So,
  8915. 5:43:55we're going to take this and it's going
  8916. 5:43:56to give us the uh what all these
  8917. 5:43:58salaries are together. So, super super
  8918. 5:44:01simple. Sum is one of probably the most
  8919. 5:44:03basic formulas that you can do. Um, sum
  8920. 5:44:06if is a little bit different. You can
  8921. 5:44:10add an if statement, which we learned
  8922. 5:44:13right back here. You can add an if
  8923. 5:44:15statement and then add it if it meets a
  8924. 5:44:18certain criteria. All right, so we're
  8925. 5:44:21going to do equals sum if and then
  8926. 5:44:24you're going to need to give a range and
  8927. 5:44:26criteria and you can include a sum range
  8928. 5:44:28if you would like.
  8929. 5:44:30So, we're going to do the salary again.
  8930. 5:44:33We're going to do a comma. And now,
  8931. 5:44:34here's our criteria. Let's do if they
  8932. 5:44:37have greater than 50,000 for their
  8933. 5:44:41salary and close that parenthesis. So,
  8934. 5:44:44now it's only going to add up if their
  8935. 5:44:47salary is greater than 50,000. Now, his
  8936. 5:44:50is 50,000 exactly, so that won't count,
  8937. 5:44:52but we have 63 and 65,000, which does
  8938. 5:44:55equal 128,000. So it it just gives a
  8939. 5:44:59specific criteria or an if statement
  8940. 5:45:02then it does the addition. Uh so super
  8941. 5:45:04useful in that one. So that is how you
  8942. 5:45:06do a sum if and sum ifs is kind of the
  8943. 5:45:08same thing as we did back here. There's
  8944. 5:45:11the if and the ifs. So the ifs is going
  8945. 5:45:13to be if it has it meets multiple
  8946. 5:45:16conditions. So let's take a look at that
  8947. 5:45:18one. So let's do um equals some ifs. Now
  8948. 5:45:23uh oops. Now [clears throat] the syntax
  8949. 5:45:26for this one is going to be a little bit
  8950. 5:45:28different. You'll see that in just a
  8951. 5:45:29second. But this adds the cells
  8952. 5:45:32specified by a given set of conditions
  8953. 5:45:34or criteria. So let's do no paren open
  8954. 5:45:37parenthesy. We'll give the sum range. So
  8955. 5:45:39let's do um the same one as before. Then
  8956. 5:45:43we have our criteria range. So what are
  8957. 5:45:46we looking at? What's um this is the
  8958. 5:45:48area that's going to be added after all
  8959. 5:45:50these if statements are done. Right? So,
  8960. 5:45:53[clears throat] we have to initially set
  8961. 5:45:54that. Now, we're going to say, okay,
  8962. 5:45:56what criteria are we basing this off of?
  8963. 5:45:59So, let's put a comma. And we're going
  8964. 5:46:00to base it off of let's do this one.
  8965. 5:46:03We'll say um if the uh gender, so we'll
  8966. 5:46:08do comma if that's female.
  8967. 5:46:12Oops. If that's female. And then we'll
  8968. 5:46:15give another one. We can say if they're
  8969. 5:46:17female and
  8970. 5:46:19let's say they are greater than oops
  8971. 5:46:22greater than 30 and we'll close that up
  8972. 5:46:26and it's going to give us 88,000. So
  8973. 5:46:28female female uh there's one two right
  8974. 5:46:32here. So it's going to be this one and
  8975. 5:46:34this one that equals 88,000. So that's
  8976. 5:46:38how that works. you're able to
  8977. 5:46:39incorporate several different conditions
  8978. 5:46:43into uh the sum formula. So again, I
  8979. 5:46:46know this one's super simple, but you
  8980. 5:46:48you can use it in a much more complex
  8981. 5:46:50way if you use the sum if and the sum
  8982. 5:46:52ifs. Um almost the exact same thing for
  8983. 5:46:56this count. I'm not going to go super in
  8984. 5:46:58depth into this one. Um, I'll just kind
  8985. 5:47:01of show you because count is um count
  8986. 5:47:06and sum are kind of on the same level of
  8987. 5:47:09difficulty. They're both pretty
  8988. 5:47:10beginner. This is just going to give you
  8989. 5:47:12a count of how many cells um are there.
  8990. 5:47:16So, let's give this range. Um, and so
  8991. 5:47:18it's not going to add it. It's just
  8992. 5:47:20going to give us a count. So, if we do
  8993. 5:47:21right here and scroll over them, like
  8994. 5:47:23highlight them, this countdown here,
  8995. 5:47:25oops, this countdown here is nine. And
  8996. 5:47:27so it's going to give us that count. But
  8997. 5:47:31we can do a count with conditions
  8998. 5:47:33exactly how we did it in the sum.
  8999. 5:47:36So if we do count if, oops, I did not
  9000. 5:47:38spell that right. If we do count if,
  9001. 5:47:41we're going to give a range and a
  9002. 5:47:42criteria, exact same as we did before.
  9003. 5:47:45Uh, so let's do this. I mean, you can do
  9004. 5:47:48this on basically any of these. It
  9005. 5:47:49doesn't really for this demonstration,
  9006. 5:47:51it doesn't really matter. um but we'll
  9007. 5:47:53say if their salary is greater than
  9008. 5:47:5645,000. So how many people this is going
  9009. 5:47:59to give us how many people have a salary
  9010. 5:48:01over 45,000 and that's five. So before
  9011. 5:48:04in the sum if we did that um we did
  9012. 5:48:0750,000 it adds everything together. The
  9013. 5:48:10count is just going to count the amount
  9014. 5:48:12of cells that meet that criteria. And
  9015. 5:48:15again count ifs
  9016. 5:48:18uh we're going to have a criteria range
  9017. 5:48:20and then we will specify what if
  9018. 5:48:23statements we want to be uh to occur in
  9019. 5:48:26order to count those cells. So let's do
  9020. 5:48:30we want you know we want to count let's
  9021. 5:48:32it can be any range or it can be any of
  9022. 5:48:34these. We'll do the ID this time. And
  9023. 5:48:37now we can say [clears throat] you know
  9024. 5:48:39we want it to be as our criteria one we
  9025. 5:48:43can say we want it to be greater than we
  9026. 5:48:45want their ID to be greater than 1005
  9027. 5:48:50and let's say we want them to be
  9028. 5:48:56male.
  9029. 5:48:58So they have an ID over a certain um a
  9030. 5:49:01certain range and then they are a male.
  9031. 5:49:04So there's only three people that meet
  9032. 5:49:06that criteria. And so it'll be um
  9033. 5:49:09Michael, Stanley, and Kevin. Those are
  9034. 5:49:11our three people. And so it gives us a
  9035. 5:49:12count. Very useful to give quick numbers
  9036. 5:49:15like this. Something I I genuinely use a
  9037. 5:49:18lot. Um and I know I've said that a lot
  9038. 5:49:21during this tutorial, but that's because
  9039. 5:49:23everything I'm showing you are things
  9040. 5:49:25that I've used a lot. So I don't feel
  9041. 5:49:26like um you know, I'm speaking out of
  9042. 5:49:28turn here. Let's look at this one. This
  9043. 5:49:30one is very
  9044. 5:49:32um has some specific use cases. Um
  9045. 5:49:36notice that this is a text right now. Um
  9046. 5:49:39if you do it when it is uh in a date
  9047. 5:49:42format, it actually will not work. I
  9048. 5:49:44mean I can you can test it out yourself.
  9049. 5:49:46You just got to trust me. It's not going
  9050. 5:49:47to work. So what this does is it's going
  9051. 5:49:51to give you the range from this day to
  9052. 5:49:53this day. That's what it's going to do.
  9053. 5:49:55So let's do uh oops days. is gonna we
  9054. 5:49:59want to choose our end date. So this is
  9055. 5:50:01our end date. That's kind of backward
  9056. 5:50:03from what you think. End date to start
  9057. 5:50:04date. You think start date to end date.
  9058. 5:50:06So you have to start with this one and
  9059. 5:50:08then we're going to choose the start
  9060. 5:50:09date. And now it's going to tell us how
  9061. 5:50:12many um how many uh days was it from
  9062. 5:50:18here to here. And this one it's 5,56.
  9063. 5:50:22So network days is extremely similar
  9064. 5:50:25except it takes out holidays and it
  9065. 5:50:27takes out weekends. And you can see how
  9066. 5:50:29many working days has this person uh how
  9067. 5:50:33many working days or network days has
  9068. 5:50:35this person worked not including you
  9069. 5:50:37know weekends and holidays? Have they
  9070. 5:50:39actually worked since their start date
  9071. 5:50:41and their end date. So let's do network
  9072. 5:50:44days. And we mean our start date, our
  9073. 5:50:46end date. And you can specify extra
  9074. 5:50:49holidays if you'd like, but there are a
  9075. 5:50:51already standard set holidays in there
  9076. 5:50:54that it takes out. Um, so you know, if
  9077. 5:50:57you want to do that, you can. So, we're
  9078. 5:50:59going to do the start date. Again, this
  9079. 5:51:01one's different. This one says start
  9080. 5:51:02date, end date. And then we're going to
  9081. 5:51:04give the end date.
  9082. 5:51:06And if you notice,
  9083. 5:51:08they are going to be different numbers.
  9084. 5:51:10Dramatically lower because it's taking
  9085. 5:51:12out weekends and holidays. So this is
  9086. 5:51:14how many days uh calendar days they've
  9087. 5:51:17worked and this is how many days they've
  9088. 5:51:18actually been in the office and worked.
  9089. 5:51:21And that is it. Um again there are so
  9090. 5:51:25many formulas I mean literally hundreds
  9091. 5:51:27of formulas that you can utilize and use
  9092. 5:51:31and are out there for you to try out
  9093. 5:51:34yourself. If there are specific ones
  9094. 5:51:36that I did not cover in this video,
  9095. 5:51:39please put it in the comments below so
  9096. 5:51:41that I can, you know, show you how to do
  9097. 5:51:44these things. I I I will say I probably
  9098. 5:51:46used a majority of the ones that you're
  9099. 5:51:47going to put in the comments already.
  9100. 5:51:49And if I haven't used it, I'll take a
  9101. 5:51:51look at it and see if it's really useful
  9102. 5:51:52and I'll show you that. So, thank you
  9103. 5:51:55guys so much for watching. I hope that
  9104. 5:51:57this has been helpful. I I feel like a
  9105. 5:51:59lot of these things are not things that
  9106. 5:52:01I learned before I started. Almost all
  9107. 5:52:03these are ones that I learned while I
  9108. 5:52:06was on the job. And so I'm hoping that
  9109. 5:52:07you can get ahead of the curve and you
  9110. 5:52:09can learn these things before you
  9111. 5:52:10actually start so that when you get in
  9112. 5:52:12there, you're just like killing it with
  9113. 5:52:14the formulas and people are like, "Whoa,
  9114. 5:52:16this guy is like this guy knows what
  9115. 5:52:17he's doing in Excel. Give him all the
  9116. 5:52:19Excel work." And then you become like,
  9117. 5:52:20you know, just the Excel guy. Um, and
  9118. 5:52:23everyone, you know, loves you for it. So
  9119. 5:52:25with that being said, thank you so much
  9120. 5:52:26for watching. I really do hope this
  9121. 5:52:28helped. If you like this video, be sure
  9122. 5:52:30to like and subscribe below. and I'll
  9123. 5:52:32see you in the next video.
  9124. 5:52:35[music]
  9125. 5:52:43[music]
  9126. 5:52:45What's going on everybody? Welcome back
  9127. 5:52:46to another video. In this Excel
  9128. 5:52:48tutorial, we'll be looking at XOOKUP.
  9129. 5:52:53[music]
  9130. 5:52:56Now, if you don't already know what
  9131. 5:52:57XLOOKUP is, it is a new feature in Excel
  9132. 5:52:59to kind of replace VLOOKUP or to be a
  9133. 5:53:02much better option, at least in my mind,
  9134. 5:53:04is a much better option than VLOOKUP.
  9135. 5:53:06And so, if you're someone who's either
  9136. 5:53:08used VLOOKUP a lot and you're trying to,
  9137. 5:53:10you know, learn this new option or if
  9138. 5:53:12you've never used it before, this video
  9139. 5:53:13will be super helpful cuz I'll walk you
  9140. 5:53:15through kind of the options and what
  9141. 5:53:17XLOOKUP can do as well as the difference
  9142. 5:53:18between XLOOKUP and VLOOKUP. But before
  9143. 5:53:21we get into the tutorial, I want to give
  9144. 5:53:22a huge shout out to today's sponsor, and
  9145. 5:53:23that is Udemy. Udemy is the go-to place
  9146. 5:53:26if you want a full-fledged course in
  9147. 5:53:27Excel. I have three options of courses
  9148. 5:53:29that I have taken on Udemy. So, I'd
  9149. 5:53:31highly recommend checking those out.
  9150. 5:53:33They are having a huge sale on all their
  9151. 5:53:35courses during this time. And so, if you
  9152. 5:53:37are in the market for a course, I highly
  9153. 5:53:39recommend checking out Udemy and getting
  9154. 5:53:40one there. Now, without further ado,
  9155. 5:53:42let's jump on my screen and start the
  9156. 5:53:43tutorial. All right, so let's get me off
  9157. 5:53:45the screen because we all know why we're
  9158. 5:53:47here. So, I didn't include this in the
  9159. 5:53:49formulas video last week because I knew
  9160. 5:53:52this was going to be a large one and a
  9161. 5:53:54lot of people are going to want to know
  9162. 5:53:55how to do this, what the difference
  9163. 5:53:56between VLOOKUP and XLOOKUP is. So, it
  9164. 5:53:58has its own dedicated video to it. So,
  9165. 5:54:01let's get started. It is a formula. So,
  9166. 5:54:03we're going to come in here in this
  9167. 5:54:04cell. We're going to hit equal and then
  9168. 5:54:06we're going to start typing XLOOKUP.
  9169. 5:54:08Now, I'm going to hit tab in just a
  9170. 5:54:10second, but let's read what this says.
  9171. 5:54:12It says searches a range or an array for
  9172. 5:54:14a match and returns the corresponding
  9173. 5:54:16item from a second range or array. By
  9174. 5:54:18default, an exact match is used. So,
  9175. 5:54:21really useful to know. Um, we'll talk a
  9176. 5:54:23little bit more about that in just a
  9177. 5:54:24second. Let's hit tab and it's going to
  9178. 5:54:27complete it and it's going to start
  9179. 5:54:29giving us or it's going to tell us what
  9180. 5:54:30our input values need to be. We're going
  9181. 5:54:33to have our lookup value. We're going to
  9182. 5:54:35have our lookup array, our return array,
  9183. 5:54:38and then some optional things like if
  9184. 5:54:40not found. So, if your option isn't
  9185. 5:54:42found, you know, what will be um you
  9186. 5:54:45know, the the uh output that it gives us
  9187. 5:54:48a match mode and a search mode. And I'm
  9188. 5:54:50going to show you um kind of how to use
  9189. 5:54:52every single one of these things. As you
  9190. 5:54:54can see at the very bottom, I've kind of
  9191. 5:54:55already set up all of the instructional
  9192. 5:54:58um the instructional content for this
  9193. 5:55:01video. And so, we'll kind of get through
  9194. 5:55:03all these different scenarios. So let's
  9195. 5:55:05just start really quickly with um how to
  9196. 5:55:08use it very simply with the lookup
  9197. 5:55:11lookup array and return array. So we're
  9198. 5:55:13going to come in here and we're going to
  9199. 5:55:15give it our lookup value. Now Toby
  9200. 5:55:17Fenderson right over here in A3 is going
  9201. 5:55:20to be our lookup value. So that's who
  9202. 5:55:22we're going to be searching for. Now
  9203. 5:55:24we're going to hit comma and now we're
  9204. 5:55:26going to be needing to look up uh or to
  9205. 5:55:28input our lookup array. Now an array is
  9206. 5:55:30just uh you know a range basically. So,
  9207. 5:55:33we're going to do this is where it's
  9208. 5:55:35going to be searching for um that value.
  9209. 5:55:38This is where it searches for A3. So,
  9210. 5:55:40here's Toby Fenderson. Here's Toby
  9211. 5:55:42Flenderson. So, it will find it in this
  9212. 5:55:44array right here. Then, we're going to
  9213. 5:55:46hit comma. And now, we need to give it
  9214. 5:55:49the return array, what it's going to
  9215. 5:55:50return on that row when it finds it. So,
  9216. 5:55:53we're going to return his email. Keep it
  9217. 5:55:55really simple. So, what it should do,
  9218. 5:55:57and let's close this parenthesy. What it
  9219. 5:55:59should do is it should take Toby
  9220. 5:56:01Flenderson. It's going to search in this
  9221. 5:56:03column or in this array and then it's
  9222. 5:56:06going to return the email when it finds
  9223. 5:56:10Toby Fenderson. So, it's on Toby
  9224. 5:56:11Fenderson is on row six. So, it's going
  9225. 5:56:14to find Toby Fenderson. It's going to
  9226. 5:56:16come over here and it's going to return
  9227. 5:56:18Toby Flenderson at dundermland
  9228. 5:56:20corporate.com. That's what it should do.
  9229. 5:56:22Let's see what it actually does. Let's
  9230. 5:56:24hit enter and it returns it. Now, if we
  9231. 5:56:28drag it down like this, it'll apply it
  9232. 5:56:30to all of these names right here. And it
  9233. 5:56:33works exactly how it's supposed to. Um,
  9234. 5:56:35again, if you have never used VLOOKUP,
  9235. 5:56:38you don't know how good you have it.
  9236. 5:56:39Okay, VLOOKUP um was extremely useful,
  9237. 5:56:42but just uh a bit complicated and I'll
  9238. 5:56:44talk about that near the end of the
  9239. 5:56:46video when we compare VLOOKUP to XOOKUP.
  9240. 5:56:49But just know that if you're using
  9241. 5:56:50XOOKUP for the first time and you're
  9242. 5:56:52just getting into using Excel, you guys
  9243. 5:56:54have it good. Okay? So just know that.
  9244. 5:56:57Um now let's go over here to XLOOKUP
  9245. 5:57:00multiple rows because you can return
  9246. 5:57:03more than one output with um with
  9247. 5:57:08XOOKUP. So let's go right in here and
  9248. 5:57:11we're going to basically write the exact
  9249. 5:57:12same thing um as we did before. So let's
  9250. 5:57:16write XOOKUP. We're going to do Toby
  9251. 5:57:18Fenderson as our value. We're going to
  9252. 5:57:20search here and we're going to do
  9253. 5:57:23something a little bit different this
  9254. 5:57:24time. we want to include our end date
  9255. 5:57:27and the email. So, what we're going to
  9256. 5:57:29do is we're going to start here. We're
  9257. 5:57:30going to go down all the way to the
  9258. 5:57:32bottom of end date. And then we're also
  9259. 5:57:34going to include the email. And when we
  9260. 5:57:36do that, it will uh in in the output
  9261. 5:57:40give us a row or a column for end date
  9262. 5:57:42and a column for email. So, an output
  9263. 5:57:44for both. So, let's hit enter. And now
  9264. 5:57:48we can see that we have the end date
  9265. 5:57:49here and the email here. Now, one of the
  9266. 5:57:52downsides or or something that I'm not a
  9267. 5:57:56huge huge fan of is well, first off, I
  9268. 5:57:58love that you can do this. That's
  9269. 5:58:00fantastic. Um, but they have to be right
  9270. 5:58:03next to each other. So, you you're only
  9271. 5:58:05going to get that output exactly how it
  9272. 5:58:07is in the columns. So, if I went and did
  9273. 5:58:10this range, um, I would include all of
  9274. 5:58:13that. Um, so, you know, let's just, for
  9275. 5:58:16example, let's pull that down here. So
  9276. 5:58:19let's take this
  9277. 5:58:21and put it right here. If I did instead
  9278. 5:58:25of zero or or 0 O2 to P10, if I
  9279. 5:58:29[clears throat] included age to email,
  9280. 5:58:31this whole range and I hit enter, it's
  9281. 5:58:33all going to be included. So, you know,
  9282. 5:58:36that's one of the small downsides of of
  9283. 5:58:40that functionality of when you can use
  9284. 5:58:41multiple rows is that it's going to use
  9285. 5:58:44the rows exactly as they are. you can't
  9286. 5:58:46really customize it within the formula.
  9287. 5:58:49You can move around um these columns to
  9288. 5:58:52how you want it. Um so that is something
  9289. 5:58:55to note. And again, you can pull this
  9290. 5:58:58down and it'll be applied to all of
  9291. 5:59:00those names. Let's go over to XLOOKUP
  9292. 5:59:03exact match. So let's open this up.
  9293. 5:59:06We're going to do equals XLOOKUP as
  9294. 5:59:08we've been doing. And we're actually
  9295. 5:59:09going to be looking at the if not found
  9296. 5:59:11and the match mode u both you know on
  9297. 5:59:14this tab right here.
  9298. 5:59:15So, let's do what we've been doing
  9299. 5:59:17before. We take our value that we're
  9300. 5:59:19looking up. We take the um array that
  9301. 5:59:23we're looking and we're going to do the
  9302. 5:59:26email. And you know, as you can see,
  9303. 5:59:29this says Toby Flender, not Toby
  9304. 5:59:32Flender. So, what we are going to do is
  9305. 5:59:34we're going to hit comma. And if it's
  9306. 5:59:36not found, you can return um a value or
  9307. 5:59:39a string that you want to return. Now,
  9308. 5:59:42for simple purposes or for simple
  9309. 5:59:45instructional purposes, we're going to
  9310. 5:59:46do not found.
  9311. 5:59:50And then we're going to close that off.
  9312. 5:59:52So, let's do this. And Toby Flenderson
  9313. 5:59:55was not found. And so, it was returned
  9314. 5:59:57not found. If Toby Flender was actually
  9315. 6:00:00in this full name, then it would have
  9316. 6:00:03returned the email. And then if along
  9317. 6:00:05the way, you know, one of these was not
  9318. 6:00:07part of it, then, you know, we would
  9319. 6:00:09have uh we would have had the not found.
  9320. 6:00:12All right. So, let's go right up here.
  9321. 6:00:14We're actually just going to copy this
  9322. 6:00:16uh because I want to reuse it. Um and
  9323. 6:00:19then we're going to go right here. I'm
  9324. 6:00:20going to hit a comma. Now, this is our
  9325. 6:00:22match mode option. And so, we have four
  9326. 6:00:26different options that we can choose
  9327. 6:00:27from. A zero is an exact match. And that
  9328. 6:00:29is uh by default, that is what we have
  9329. 6:00:32or what we use. Then there's a minus
  9330. 6:00:34one. That's an exact match or next
  9331. 6:00:36smaller item. Then there's a one which
  9332. 6:00:38is an exact match or next larger item.
  9333. 6:00:41And then there's a two which is a
  9334. 6:00:42wildcard character match. Now we're
  9335. 6:00:44going to do that and we are going to um
  9336. 6:00:47you know try this out and it's not going
  9337. 6:00:50to work. And not just because I forgot
  9338. 6:00:51to put A4. Um it's doing it because it's
  9339. 6:00:55searching for Beasley but if there's not
  9340. 6:00:58a wildcard option already put in here um
  9341. 6:01:01it doesn't recognize it. So, we need to
  9342. 6:01:03indicate where that wild card needs to
  9343. 6:01:05be. So, we're going to do a double
  9344. 6:01:07apostrophe or quotation marks. We're
  9345. 6:01:08going to put an asterisk right here. And
  9346. 6:01:10then do another one. And we're going to
  9347. 6:01:12hit an amperand. So, we're going to have
  9348. 6:01:15an amperand right here. And what that's
  9349. 6:01:17going to say is anything that comes
  9350. 6:01:19before A4. Anything that comes before
  9351. 6:01:22beasley is okay. Doesn't matter what it
  9352. 6:01:24is. As long as it has Beasley at the
  9353. 6:01:26end, that is going to be okay. So we're
  9354. 6:01:28going to have Pam that comes before
  9355. 6:01:30Beasley and that's going to tell it and
  9356. 6:01:32it's going to say okay I know that
  9357. 6:01:34anything that comes before beasley is
  9358. 6:01:35all right and so when we hit enter is
  9359. 6:01:37now going to return the output that we
  9360. 6:01:40are looking for and we can include that
  9361. 6:01:42on these as well. Now this one is
  9362. 6:01:45Meredith um and so Meredith is at the
  9363. 6:01:49beginning so we have Meredith Palmer.
  9364. 6:01:51So, we can actually take this and we're
  9365. 6:01:54going to put this at the end. Put the
  9366. 6:01:57amberand right here. And now it'll work.
  9367. 6:02:00And the exact same thing for Kevin Malo
  9368. 6:02:04right here. Kevin Malone. So, I just
  9369. 6:02:06didn't include uh the ne at the end. And
  9370. 6:02:10so, it's still going to work if we
  9371. 6:02:12include that asterisk at the end. Now, I
  9372. 6:02:14know I said we were looking at search
  9373. 6:02:16order, but I'm actually going to kind of
  9374. 6:02:17give you an exact match first and then
  9375. 6:02:19search order. but it's just kind of
  9376. 6:02:21easier to show it over here. So, I'm
  9377. 6:02:23going to do X lookup. I'm going to look
  9378. 6:02:26up this value. Do a comma. Here's the
  9379. 6:02:29range. This is our start date that it's
  9380. 6:02:30going to be looking for. And I want to
  9381. 6:02:33return the full name. Now, no value in
  9382. 6:02:37here has 11200.
  9383. 6:02:40But what we can do is we can do comma
  9384. 6:02:43and then a comma for the match mode and
  9385. 6:02:45do an exact match or next larger.
  9386. 6:02:48And I know this is in the exact match
  9387. 6:02:50part, but it, you know, kind of refers
  9388. 6:02:53to search order a little bit um where it
  9389. 6:02:55searches for the next largest value.
  9390. 6:02:58That's what that's what that number one
  9391. 6:02:59represents, the next larger value. So we
  9392. 6:03:01have 11200. And if we look right here,
  9393. 6:03:03the next value above 11200 is 15200. And
  9394. 6:03:08so it should return Angela Martin. Let's
  9395. 6:03:10see if that works. And there it is. Now
  9396. 6:03:14let's look up the actual search order.
  9397. 6:03:16Um, so let's do equals xookup.
  9398. 6:03:20This is the value that we want to be
  9399. 6:03:21searching for and we're going to be
  9400. 6:03:23looking in this start date and comma and
  9401. 6:03:28we want to return the name. Now let's
  9402. 6:03:31get over to search mode. Now the search
  9403. 6:03:33mode performs a search starting at the
  9404. 6:03:36first item. So at the very top going
  9405. 6:03:38down. So by default it searches from
  9406. 6:03:40first to last, but you can reverse that
  9407. 6:03:43and do search from last to first. We're
  9408. 6:03:45going to do a binary search, which is
  9409. 6:03:47where it sorts in ascending order or
  9410. 6:03:49sorts in descending order. Um, and
  9411. 6:03:51that's with the actual value. And so, we
  9412. 6:03:55won't be able to show this binary search
  9413. 6:03:56or um ascending or descending because
  9414. 6:04:00our values are the same. But if we had
  9415. 6:04:03different values and we were looking up
  9416. 6:04:05um using this um next largest, we would
  9417. 6:04:09be able to show that. But I'm going to
  9418. 6:04:10show you the search from first to last
  9419. 6:04:11and last to first. So let's put in by
  9420. 6:04:14default. And this is what it would be.
  9421. 6:04:16Search from first to last. What the
  9422. 6:04:17default would be. So it starts at the
  9423. 6:04:19very top. It goes down and finds the
  9424. 6:04:22first 56 2001 and returns Toby
  9425. 6:04:25Flenderson. Now if we go in here and we
  9426. 6:04:28hit minus one, that is going to search
  9427. 6:04:30from last to first. So it's going to
  9428. 6:04:32start at the bottom and go to the top.
  9429. 6:04:33And the first one that it finds is
  9430. 6:04:35Michael Scott. So that's that first one
  9431. 6:04:37starting from the bottom. And then the
  9432. 6:04:40Michael Scott right there. So these two,
  9433. 6:04:42the exact match and the search order can
  9434. 6:04:44kind of be combined into um this one
  9435. 6:04:46right here where you're using this one
  9436. 6:04:49um which is uh you know exact match or
  9437. 6:04:51next larger and you can include that in
  9438. 6:04:54this binary search in this one as well.
  9439. 6:04:56All right, now let's head over to the
  9440. 6:04:58xookup horizontal. I think we're we only
  9441. 6:05:01have a few left. Yep, xookup horizontal.
  9442. 6:05:02Then we'll do xookup with sum and then
  9443. 6:05:04I'm going to show you the vlookup at the
  9444. 6:05:06end. So let's go right here. Let's say
  9445. 6:05:08equals xookup. The value that we want to
  9446. 6:05:11be searching for is February. That's
  9447. 6:05:12what we're looking for. Hit comma. And
  9448. 6:05:14where do we want to search to find
  9449. 6:05:16February? We want to search in uh these
  9450. 6:05:18calendar months. And then we hit another
  9451. 6:05:21comma. And now we're going to be
  9452. 6:05:22searching for paper. So let's do paper.
  9453. 6:05:26And we'll hit enter. And it found
  9454. 6:05:29February. And it returned paper right
  9455. 6:05:32here. And we can do that for paper,
  9456. 6:05:34printer, and manila folders. And so it's
  9457. 6:05:36going to give us the 310, the 40, and
  9458. 6:05:39the 118 from February. Now, let's go
  9459. 6:05:41right over here to XLOOKUP with some um
  9460. 6:05:43I actually it's basically a carbon copy
  9461. 6:05:46of this. Uh let's take this over here
  9462. 6:05:49real quick
  9463. 6:05:52and place it right there because it's
  9464. 6:05:54the exact same thing except at the end
  9465. 6:05:57we're going to use I'm going to show you
  9466. 6:05:58how to use sum with the XOOKUP at the
  9467. 6:06:02same time. Now, um, we're going to be
  9468. 6:06:05using the formula sum and so we're going
  9469. 6:06:09to do sum and then within the sum, our
  9470. 6:06:12first number is going to be an xookup
  9471. 6:06:14and then our next value is also going to
  9472. 6:06:17be an xookup. So, let's do xookup.
  9473. 6:06:22And now we're going to search for our
  9474. 6:06:23very first value. Oops, our very first
  9475. 6:06:26lookup value. So, we're going to go to
  9476. 6:06:29I1
  9477. 6:06:31and then we're going to search this
  9478. 6:06:33again.
  9479. 6:06:35And we want whatever value oops goes
  9480. 6:06:39into that. So, let's close that
  9481. 6:06:41parenthesis. And now we're going to do a
  9482. 6:06:43colon and another x lookup.
  9483. 6:06:47And now let's do March. So, now we're
  9484. 6:06:51going to search for March. We're going
  9485. 6:06:53to do our search range where we're
  9486. 6:06:55searching for that March. And we want
  9487. 6:06:57the paper as well.
  9488. 6:07:00And let's close that. And then we also
  9489. 6:07:02need to close that parenthesy. So now we
  9490. 6:07:06are basically adding this February and
  9491. 6:07:08this March. So it's going to be 310 +
  9492. 6:07:11150. It's adding those um two values and
  9493. 6:07:14it should be uh what 460. So let's see
  9494. 6:07:17if that is our output and it is. So, you
  9495. 6:07:21can do this with a lot of things, not
  9496. 6:07:23just some, but you're able to use
  9497. 6:07:24XLOOKUP within different formulas. If
  9498. 6:07:27you're searching for a specific value
  9499. 6:07:28and a specific value um in in another um
  9500. 6:07:31cell, you can add those together using
  9501. 6:07:34XLOOKUP, which is uh honestly, it's
  9502. 6:07:36pretty great. So, let's go over to
  9503. 6:07:38VLOOKUP. So, I wanted to show you this
  9504. 6:07:40because I wanted to show you where it
  9505. 6:07:42came from and what we used to do um
  9506. 6:07:45unless you are continuing to use VLOOKUP
  9507. 6:07:47and what we can do now. So, AxOookup, I
  9508. 6:07:49just showed you kind of everything. Um,
  9509. 6:07:51but super quickly, I'm going to show you
  9510. 6:07:52how VLOOKUP used to work um in a super
  9511. 6:07:55short way so that you can understand how
  9512. 6:07:58it used to be used and how it is used uh
  9513. 6:08:00how XLOOKUP is used now. So, let's go in
  9514. 6:08:03here and we're going to say equals and
  9515. 6:08:05we're going to do a VLOOKUP. And so, we
  9516. 6:08:08have a lookup value. And so, we're going
  9517. 6:08:10to click this. We're going to hit comma
  9518. 6:08:13just like we did before. And now we're
  9519. 6:08:14going to do a table array. And the table
  9520. 6:08:17array is a little different in that
  9521. 6:08:19you're searching an entire area. So
  9522. 6:08:22let's do uh H2
  9523. 6:08:26all the way through O oops 010. So
  9524. 6:08:31that's what that's what our table array
  9525. 6:08:34is going to be. Then we're going to do a
  9526. 6:08:36comma. And now we have to do a column
  9527. 6:08:38index number. Which number um are we
  9528. 6:08:42going to be um searching for? which um
  9529. 6:08:45value are we going to be searching for
  9530. 6:08:47in here? And so we want to search for
  9531. 6:08:49eight because this is 1 2 3 4 5 6 7 8.
  9532. 6:08:53We want to return that email and we're
  9533. 6:08:55searching for the name right here in
  9534. 6:08:58this very first column. So we have that
  9535. 6:09:00comma and we're going to do eight. And
  9536. 6:09:02then in the range lookup, you can do
  9537. 6:09:04true, which is an approximate match, or
  9538. 6:09:06false, which is an exact match. And
  9539. 6:09:08we'll do false. I don't know why it's
  9540. 6:09:11not autodoing it, but there we go. And
  9541. 6:09:14now we will do it and it's going to
  9542. 6:09:16return it just as we had it. Um,
  9543. 6:09:20a lot of people uh I guess not everybody
  9544. 6:09:23but some people didn't like and the
  9545. 6:09:25reason why they created XLOOKUP you had
  9546. 6:09:27to do those ranges and if you ever went
  9547. 6:09:30in here and then we let's say we um
  9548. 6:09:34added another column which happens to
  9549. 6:09:37data now it gives us completely
  9550. 6:09:39different um different data. So let's
  9551. 6:09:42say for whatever reason we added uh
  9552. 6:09:44address. So now we have these people
  9553. 6:09:46address. Well, now it's going to give us
  9554. 6:09:48a different um value. It's going to have
  9555. 6:09:50this end date because if we go in here
  9556. 6:09:52now it doesn't um now the eth is this
  9557. 6:09:56end date and the ninth is this email. So
  9558. 6:09:58if you have a VLOOKUP that you use for
  9559. 6:10:02um you know a calculation or a table
  9560. 6:10:04that you've created or different things
  9561. 6:10:06in Excel, you then have to go through
  9562. 6:10:07here and manually change this. And so a
  9563. 6:10:10lot of people didn't like that because
  9564. 6:10:11if you, you know, needed to change data
  9565. 6:10:13or you needed to change something or add
  9566. 6:10:15an additional column, you'd have to go
  9567. 6:10:16back and fix all of your VLOOKUPs, they
  9568. 6:10:19wouldn't just automatically u move with
  9569. 6:10:22it, which is what happens with XLOOKUP.
  9570. 6:10:24And just to prove this, uh, let's go
  9571. 6:10:26back to the very first one, which is the
  9572. 6:10:28XOOKUP. And right now the email is
  9573. 6:10:31looking at O2 and through O10. Um, we're
  9574. 6:10:35just going to insert right here. And
  9575. 6:10:37that will be our new column. We'll do
  9576. 6:10:39address. Oops.
  9577. 6:10:42Address. And notice that it hasn't
  9578. 6:10:43changed. And why is that? Because it
  9579. 6:10:45auto changed for us from P2 to P10.
  9580. 6:10:49Understanding that it wanted to stick
  9581. 6:10:51with when something was inserted here,
  9582. 6:10:52it wanted to stick with the original
  9583. 6:10:54data or the original array that was
  9584. 6:10:56selected. And so XLOOKUP does that work
  9585. 6:10:59for you. and it makes it a little bit
  9586. 6:11:01easier to automate things and create
  9587. 6:11:04these processes in Excel without having
  9588. 6:11:06to go fix it later, which you had to do
  9589. 6:11:08with VLOOKUP. So, that is it for today.
  9590. 6:11:10I hope that you know how to use Xookup a
  9591. 6:11:12little bit better now that you have
  9592. 6:11:13watched this. Uh, if you enjoyed this
  9593. 6:11:15video, be sure to like and subscribe
  9594. 6:11:17below and I will see you in the next
  9595. 6:11:18video.
  9596. 6:11:31What's going on everybody? Welcome back
  9597. 6:11:33to another Excel tutorial. Today we'll
  9598. 6:11:35be looking at conditional formatting.
  9599. 6:11:39[music]
  9600. 6:11:42Now, if you've never heard of
  9601. 6:11:43conditional formatting before, that's
  9602. 6:11:45okay. I had never heard of it before I
  9603. 6:11:47became a data analyst. And so, now that
  9604. 6:11:49I've been using Excel a lot, of course,
  9605. 6:11:50I use it quite a bit. And so I want to
  9606. 6:11:52show you how to use it. Conditional
  9607. 6:11:54formatting is basically just a way to
  9608. 6:11:56see patterns and trends in data. And
  9609. 6:11:57that's a super simple way of putting it.
  9610. 6:12:00Um, but it's very easy to use and so
  9611. 6:12:03hopefully I can show you how to use it
  9612. 6:12:05uh really easily and a lot of the things
  9613. 6:12:06that I use the most and some of the
  9614. 6:12:08things that I use it for so that you can
  9615. 6:12:10also know how to use conditional
  9616. 6:12:11formatting. Now before we jump into the
  9617. 6:12:13tutorial, I want to give a huge shout
  9618. 6:12:14out to the sponsor of this Excel series
  9619. 6:12:16and that is Udemy. You guys know by now
  9620. 6:12:18that I absolutely love Udemy. I've been
  9621. 6:12:20using them for years and I've taken
  9622. 6:12:21literally hundreds of courses on Udemy
  9623. 6:12:24and I've learned so so much especially
  9624. 6:12:25when I was first starting out as a data
  9625. 6:12:27analyst. Uh I learned a lot through
  9626. 6:12:29their Excel courses on Udemy and so I
  9627. 6:12:32have actually put the ones that I really
  9628. 6:12:33like and I have taken and enjoyed and
  9629. 6:12:35think you would as well in the
  9630. 6:12:37description. So if you want to take
  9631. 6:12:38those, be sure to check those out.
  9632. 6:12:40Again, huge shout out to Udemy for
  9633. 6:12:41sponsoring the series. Now without
  9634. 6:12:43further ado, let's jump onto my screen
  9635. 6:12:44and get started with the tutorial. All
  9636. 6:12:46right, so let's jump right into it. On
  9637. 6:12:47this home tab right here, if we go all
  9638. 6:12:49the way over to the right, there is
  9639. 6:12:51conditional formatting. And the
  9640. 6:12:53description that it gives us is easily
  9641. 6:12:54spot trends and patterns in your data
  9642. 6:12:56using bars, colors, and icons to
  9643. 6:12:58visually highlight important values. And
  9644. 6:13:00that is exactly how I would have defined
  9645. 6:13:03it. U really good job, Microsoft.
  9646. 6:13:05Exactly how I would have done it. So
  9647. 6:13:06what you'll see right away is nothing
  9648. 6:13:08too complex. So we have some highlight
  9649. 6:13:10cell rules. Um, we have some top bottom
  9650. 6:13:13rules, data bars, color scales, icon
  9651. 6:13:16sets, and then at the bottom we can
  9652. 6:13:18create a rule, we can clear the rule,
  9653. 6:13:19and we can manage our rules. So, if you
  9654. 6:13:21create a rule, then you can manage it.
  9655. 6:13:24So, we're going to start with these icon
  9656. 6:13:26sets, and I'm going to show you how to
  9657. 6:13:27use those, and we'll work our way to the
  9658. 6:13:29top, and then I'll show you how to
  9659. 6:13:30create some rules yourself, and how that
  9660. 6:13:33all works. So, let's start off with the
  9661. 6:13:36icon sets. I'm going to go over here to
  9662. 6:13:37sales. Um and for this data we kind of
  9663. 6:13:41have this um you know trend or or
  9664. 6:13:44pattern that you can kind of see over
  9665. 6:13:46time. So over the months um so if we go
  9666. 6:13:49right here and let's use that
  9667. 6:13:52conditional forming let's use that icon
  9668. 6:13:54sets and right here we can use these
  9669. 6:13:57directional. So you know we have this
  9670. 6:13:59kind of time series each month that
  9671. 6:14:01shows us how much paper they're selling.
  9672. 6:14:03And if we do this right here, it's going
  9673. 6:14:05to show us if it's kind of average or if
  9674. 6:14:08it's below average or if it's above
  9675. 6:14:11average or if it's going up. So, at a
  9676. 6:14:13really quick glance, you can kind of see
  9677. 6:14:15the pattern of this data set. It's kind
  9678. 6:14:17of going mostly yellow and red. There's
  9679. 6:14:20only two months where it's going up
  9680. 6:14:22significantly. Now, we don't have to
  9681. 6:14:24only do that for one row or one column.
  9682. 6:14:27You can apply it to all of them. But, as
  9683. 6:14:30you can see, all of these are red. Now,
  9684. 6:14:32why are they all red? It's because
  9685. 6:14:34they're using numbers for everything.
  9686. 6:14:36So, they're comparing these 24s and
  9687. 6:14:38these 50s and 65s against these 450s and
  9688. 6:14:42750s. And so, they're all going to be
  9689. 6:14:44red. But, if we do it individually, if
  9690. 6:14:46we do it each row, if we take it just
  9691. 6:14:49like this, and then we go to icon sets
  9692. 6:14:51and do it, it's going to be much more
  9693. 6:14:53representative of the actual printers,
  9694. 6:14:56not of all the numbers as a whole. And
  9695. 6:14:58you can do other things. The arrows are
  9696. 6:15:00ones that you'll probably see the most
  9697. 6:15:02often. That's the one I've used if I
  9698. 6:15:04ever do use them. Um, but you can, you
  9699. 6:15:07know, do ones like this where they have,
  9700. 6:15:10you know, kind of a trend upward or a
  9701. 6:15:12trend downward. Um, and so there's just
  9702. 6:15:14several more arrows. This one only gives
  9703. 6:15:16you three. As you can see, this one
  9704. 6:15:18gives you five. Um, and you can do, you
  9705. 6:15:21know, colors or shapes or or different
  9706. 6:15:23indicators and all these different
  9707. 6:15:25things. Um, and honestly, it's kind of
  9708. 6:15:27whatever you want to use, whatever makes
  9709. 6:15:28sense for your data, but you know, I've
  9710. 6:15:30really only ever seen like these colors
  9711. 6:15:32being used. I've never really seen these
  9712. 6:15:34flags or anything like that. But again,
  9713. 6:15:36it just depends on what industry you
  9714. 6:15:38work in. You might you might see that.
  9715. 6:15:39Let's go right over here to the
  9716. 6:15:41demographics. Um, and let's look at our
  9717. 6:15:45color scales. Now, color scales are
  9718. 6:15:47going to be the probably the most
  9719. 6:15:48obvious thing that in data bars are
  9720. 6:15:50going to be the most obvious things in
  9721. 6:15:52here. Um, if you go right here and and
  9722. 6:15:55you look at this color scale, if it's
  9723. 6:15:57high, if it's among the top ones, it's
  9724. 6:16:00green, the lowest, it's red. And you can
  9725. 6:16:03change that um to really any colors you
  9726. 6:16:05want, any colors that they offer you.
  9727. 6:16:07Um, and it it does exactly what it does.
  9728. 6:16:11It's a color scale, a gradient of the
  9729. 6:16:13colors from high to low or low to high.
  9730. 6:16:16And so any color that you do, you'll be
  9731. 6:16:18able to kind of see um, you know, what's
  9732. 6:16:20good and what's not good. That really is
  9733. 6:16:24um color scales in a nutshell. Data bars
  9734. 6:16:28are again super super straightforward.
  9735. 6:16:31It's going to be either a gradient fill
  9736. 6:16:33or a solid fill. So let's look at the
  9737. 6:16:34gradient fill. If we do a blue gradient
  9738. 6:16:37fill, actually let's get rid of our um
  9739. 6:16:40let's go over here. Let's go to clear
  9740. 6:16:42rules from selected cells. We haven't
  9741. 6:16:44looked at that yet, but that's how you
  9742. 6:16:46clear it. Let's go to data bars and
  9743. 6:16:49we'll use this blue gradient. So with
  9744. 6:16:52this blue gradient, you know, this one
  9745. 6:16:53is or sorry, this one is the highest
  9746. 6:16:55one. So it's going to be completely
  9747. 6:16:57filled. And this one is 36,000 almost
  9748. 6:16:59half of this. Um pretty close. And so
  9749. 6:17:02it's almost half. Um this one again, you
  9750. 6:17:05know, it's not used very often. I you
  9751. 6:17:09don't see these a lot to be honest. You
  9752. 6:17:11just don't. Um but if you do see it,
  9753. 6:17:14that's how you use it. That's how it can
  9754. 6:17:16be done. Again, pretty easy. Uh, as I
  9755. 6:17:19just showed a second ago, if you want to
  9756. 6:17:21clear the rules, you can clear it from
  9757. 6:17:22the selected cells. That's what we're
  9758. 6:17:23doing. So, I have column G selected, and
  9759. 6:17:25I'm going to I'm going to clear that. If
  9760. 6:17:27you want to clear the rules, the entire
  9761. 6:17:28sheet, you can do that as well. So, it
  9762. 6:17:30would affect every single column and
  9763. 6:17:32row. We'll just do this for now. So, now
  9764. 6:17:36let's go look at the top bottom rules.
  9765. 6:17:38So, this is the top 10 items, top 10%,
  9766. 6:17:41bottom 10 items, bottom 10%, above
  9767. 6:17:44average, and below average. and they're
  9768. 6:17:45going to do exactly what you think they
  9769. 6:17:47are going to do. If you select above
  9770. 6:17:49average, it is going to select or
  9771. 6:17:51highlight the cells that are above the
  9772. 6:17:54average in column G. So, let's look at
  9773. 6:17:56the salaries that are above average. All
  9774. 6:17:58right. And so, uh the ones that are at
  9775. 6:18:01the very top are Michael Scots, Toby
  9776. 6:18:03Flenderson's, and Dwight Shroo. Uh no
  9777. 6:18:07shock there. Um I believe the average is
  9778. 6:18:09somewhere around like 48,500
  9779. 6:18:12or something. So, I think this one just
  9780. 6:18:14is just below it. And so, all these
  9781. 6:18:16other ones are below average. And that's
  9782. 6:18:18just because, you know, Michael Scott
  9783. 6:18:20and Dwight Tru are and Toby are kind of
  9784. 6:18:23bringing up that average quite a bit.
  9785. 6:18:24So, everyone else is going to fall
  9786. 6:18:26beneath that. And so, at a super quick
  9787. 6:18:28glance, you're able to just highlight
  9788. 6:18:30the cells and you're able to see who is
  9789. 6:18:33above average. And, you know, you can do
  9790. 6:18:36this in a lot of different ways in
  9791. 6:18:37Excel, but this is just a really simple,
  9792. 6:18:39fast way to do that. Um, let's get rid
  9793. 6:18:42of that real quick and let's go back up
  9794. 6:18:44here. And now we can Oops. Let's go to
  9795. 6:18:47top bottom rules. And now we can see the
  9796. 6:18:48below average. And it's going to
  9797. 6:18:50highlight all the other ones. And so it
  9798. 6:18:52works exactly how you think it is going
  9799. 6:18:54to work. And this is the default way
  9800. 6:18:56that it highlights these cells. So it
  9801. 6:18:58highlights them this kind of um
  9802. 6:19:00see-through red and then it highlights
  9803. 6:19:02the actual text or or the um characters
  9804. 6:19:05in there red as well. Now, I'm not going
  9805. 6:19:07to go through and show you every single
  9806. 6:19:09one of these top bottom rules. I think
  9807. 6:19:11they're pretty self-explanatory. I just
  9808. 6:19:13kind of wanted to show you what happens
  9809. 6:19:14when you do use one of them. It's going
  9810. 6:19:16to highlight that cell. So, let's go up
  9811. 6:19:19here to the highlight cells rules. And
  9812. 6:19:21honestly, these are the ones that I use
  9813. 6:19:24by far the most. Uh all these other ones
  9814. 6:19:26combined I do not use more than this
  9815. 6:19:29highlight cells rules. Um and the one in
  9816. 6:19:31here that I use more than any other
  9817. 6:19:33conditional formatting rule is this
  9818. 6:19:34duplicate values. So, I'll start with
  9819. 6:19:36that really quick and I'll kind of show
  9820. 6:19:38you a few of these other ones. But this
  9821. 6:19:40duplicate values to me is one of the
  9822. 6:19:43most useful ones. Um, and so let's kind
  9823. 6:19:46of show you how that works. If we go to
  9824. 6:19:49the start date, you can see that we have
  9825. 6:19:51a duplicate value right here. And if we
  9826. 6:19:54go over here to conditional formatting,
  9827. 6:19:56highlight cells, rules, and duplicate
  9828. 6:19:58values. It is going to highlight um the
  9829. 6:20:02duplicate. And that says duplicate right
  9830. 6:20:03here. Now, we can go through here and
  9831. 6:20:06click on unique. Um, and then it would
  9832. 6:20:08highlight all the ones that are not
  9833. 6:20:10duplicates. Um, so you can use it, you
  9834. 6:20:13know, kind of in a similar inverse way.
  9835. 6:20:15Uh, it's just different different, but I
  9836. 6:20:17use the duplicate almost always. Um,
  9837. 6:20:20another thing that you can do is go over
  9838. 6:20:22here and you can change the color. Um,
  9839. 6:20:25or you can even do a custom um, which I
  9840. 6:20:28just never do that. It's not um,
  9841. 6:20:30something I spend a lot of time doing. I
  9842. 6:20:32typically just stick with this one. So,
  9843. 6:20:34you can do that and it's going to
  9844. 6:20:35highlight um you know something that has
  9845. 6:20:38a duplicate value in there. Now, why do
  9846. 6:20:41I use this so much? Well, I work with a
  9847. 6:20:44lot of different types of data sets, but
  9848. 6:20:46one thing that you'll find in almost all
  9849. 6:20:48of them is they have some type of ID and
  9850. 6:20:52they're going to have some type of um
  9851. 6:20:54personal information, whether that's a
  9852. 6:20:57social security number or an address or
  9853. 6:21:01um you know
  9854. 6:21:03or a cell phone number or something like
  9855. 6:21:05that. There is going to be data that is
  9856. 6:21:08going to identify that person. Now, I
  9857. 6:21:10work a lot with pharmaceutical data, a
  9858. 6:21:12lot with pharmacy data, um, as well as
  9859. 6:21:16healthcare data. So, like names, social
  9860. 6:21:18security numbers, addresses, phone
  9861. 6:21:19numbers, all of those things, all that
  9862. 6:21:21customer or or client information. And
  9863. 6:21:23oftent times when I get a new data set
  9864. 6:21:25and I have it in Excel or I convert it
  9865. 6:21:27to Excel, I will start using these
  9866. 6:21:29duplicates to try to find issues with
  9867. 6:21:32the data and I find them all the time.
  9868. 6:21:34either there's an employee ID or some
  9869. 6:21:36type of customer ID or client ID that
  9870. 6:21:38has a duplicate in there that should not
  9871. 6:21:40be in there or there's multiple social
  9872. 6:21:42security numbers or there's an issue in
  9873. 6:21:44some other way and I'm able to find
  9874. 6:21:45those things and spot those patterns
  9875. 6:21:48using this duplicates and I promise you
  9876. 6:21:50I use this one almost every single time
  9877. 6:21:52I open a new data set or I work with a
  9878. 6:21:54new client working with their data. Um
  9879. 6:21:56and so I wanted to show you this one. I
  9880. 6:21:58wanted to really press upon you that
  9881. 6:22:00this one is a really, really, really
  9882. 6:22:02good one to know and learn how to use.
  9883. 6:22:04It's not complicated. It's not hard. It
  9884. 6:22:06just shows you, you know, you know, if
  9885. 6:22:09there's a duplicate value, but I wanted
  9886. 6:22:10you to know how I use it and how often I
  9887. 6:22:13use it so that you can, you know, pick
  9888. 6:22:15that up and put that in your toolkit in
  9889. 6:22:16your back pocket so that you can use
  9890. 6:22:18that later on if you have uh if you have
  9891. 6:22:20a similar need or if you're trying to do
  9892. 6:22:22something similar to what I was just
  9893. 6:22:24talking about. So, that is how
  9894. 6:22:26duplicates work. Again, super great.
  9895. 6:22:29It's obviously not super useful when
  9896. 6:22:31you're only using um 10 rows, but when
  9897. 6:22:32you have, you know, 50,000, 100,000, and
  9898. 6:22:35there should be zero duplicates in
  9899. 6:22:37there, and you highlight it, and then uh
  9900. 6:22:40you come right here, use the filter,
  9901. 6:22:43and we're going to filter, and we're
  9902. 6:22:45going to sort by the color, and it
  9903. 6:22:48allows you to sort by the color, and you
  9904. 6:22:50have duplicates in there, then that's a
  9905. 6:22:51problem. And you identified a problem
  9906. 6:22:53super quickly. Uh, and you know, some of
  9907. 6:22:56those things they slip by because nobody
  9908. 6:22:58checks it. And so that's something that
  9909. 6:23:00I I often check. And if you go here and
  9910. 6:23:02you sort by color and there isn't an
  9911. 6:23:03option to do um this this pink red
  9912. 6:23:06color, then that means there aren't any
  9913. 6:23:07duplicates. And that's a really good
  9914. 6:23:09thing. Most of the time that's a really
  9915. 6:23:10good thing. So let's go ahead and we're
  9916. 6:23:13going to clear that as well as
  9917. 6:23:16get rid of our conditional formatting
  9918. 6:23:19rules.
  9919. 6:23:20Now, another one that I use a lot is
  9920. 6:23:23this one right here, which is the text
  9921. 6:23:27that contains. Honestly, this one comes
  9922. 6:23:30a lot in handy, especially when you're
  9923. 6:23:32looking for like a specific keyword. In
  9924. 6:23:35my uh case, a lot of times I was using
  9925. 6:23:39this when I was going through drug
  9926. 6:23:41names. I am not a doctor. I do not
  9927. 6:23:43pretend to be a doctor. And so when I
  9928. 6:23:44was looking for Lorazzipam or something
  9929. 6:23:46like that, um I would just search for
  9930. 6:23:48like Lorazz or something and and not
  9931. 6:23:51Lorax but Lauraz, you know, I I would
  9932. 6:23:53just search for it and then all the ones
  9933. 6:23:56that contain that would pop up. I can
  9934. 6:23:57bring them to the top and I can see
  9935. 6:23:59them. And to me that's super super
  9936. 6:24:02useful and I would do that all the time.
  9937. 6:24:04And so in this case we're looking at
  9938. 6:24:05emails. And let's say we all only wanted
  9939. 6:24:08to pull all the ones that are Gmail. And
  9940. 6:24:10so now we can go through and we can you
  9941. 6:24:12know click okay and that's going to pop
  9942. 6:24:14up or we want all the ones that have
  9943. 6:24:17dunder oops dunder mifflin. And if we
  9944. 6:24:21click on that all the ones that are
  9945. 6:24:22dunder mifflin come up or have dunder
  9946. 6:24:24mifflin in it. And again we can um sort
  9947. 6:24:27by or we can um and so we can sort by
  9948. 6:24:31right here and we can bring all those to
  9949. 6:24:33the top. And so super super useful. Um,
  9950. 6:24:36and another use for it that you may not
  9951. 6:24:38think of is something like if it's, you
  9952. 6:24:41know, there's some incorrect data in
  9953. 6:24:43there. This happens often with phone
  9954. 6:24:45numbers, addresses, um, start dates or
  9955. 6:24:49or or dates in general, date formats
  9956. 6:24:52where you can go in here and you can say
  9957. 6:24:55text that contains and if you know you
  9958. 6:24:57put in a oops a dash and it has it in
  9959. 6:25:01there, then you know that that is that
  9960. 6:25:03is wrong. Now that is really all I
  9961. 6:25:05wanted to show you in the highlight
  9962. 6:25:06cells [clears throat] rules. Uh the
  9963. 6:25:07duplicate values and the text contains
  9964. 6:25:09are by far the ones I use the most. All
  9965. 6:25:12the other ones I have used. Um these
  9966. 6:25:14ones not so much. But in these highlight
  9967. 6:25:16cells rules I use you know these two all
  9968. 6:25:18the time. Um sometimes I use this
  9969. 6:25:21between I don't really use these other
  9970. 6:25:23ones as much although I have used them.
  9971. 6:25:25And so if you got nothing else from this
  9972. 6:25:27video I just wanted you to know that
  9973. 6:25:28these two are super useful. and if you
  9974. 6:25:31haven't used them before to maybe try
  9975. 6:25:32them out and see how you can apply them
  9976. 6:25:34to your own data sets. Now, we've looked
  9977. 6:25:36at all of these preset ones and
  9978. 6:25:38conditional formatting, but you can also
  9979. 6:25:41do a new rule. And so, if we click on
  9980. 6:25:43new rule right here, and we go down to
  9981. 6:25:45use a formula to determine which cells
  9982. 6:25:47to format, we can add our own formula in
  9983. 6:25:50here that will then highlight exactly
  9984. 6:25:53what we want. And so if there isn't a
  9985. 6:25:55preset rule that you like and it doesn't
  9986. 6:25:58have the option that you want, you can
  9987. 6:26:00do almost any formula that you want in
  9988. 6:26:02our formulas video that we did a few
  9989. 6:26:04weeks ago and you can put it in here.
  9990. 6:26:05And then you can format uh what you want
  9991. 6:26:08the cell to look like if it meets that
  9992. 6:26:10criteria. So let's take this right over
  9993. 6:26:12here. Um and before we start this
  9994. 6:26:14formula, I just want you to note that,
  9995. 6:26:17you know, I have H11 highlighted. That's
  9996. 6:26:19going to come into play in just a little
  9997. 6:26:21bit, but I wanted you to be aware that
  9998. 6:26:23H11 is the cell that we're highlighted.
  9999. 6:26:25So, what we're going to do is we are
  10000. 6:26:27going to create our formula. Now, if
  10001. 6:26:30you've never created a formula, I highly
  10002. 6:26:32recommend uh watching my formulas
  10003. 6:26:34tutorial because that is going to show
  10004. 6:26:35you how to do this. Um, but we're all
  10005. 6:26:37we're going to do is we're going to do
  10006. 6:26:39equals. That's how you start the uh how
  10007. 6:26:42you actually create a formula. And we're
  10008. 6:26:44going to give it this range right here.
  10009. 6:26:46And so it's going to take everything
  10010. 6:26:48from G2 to G10. Now, these dollar signs
  10011. 6:26:51are super important. If you don't know
  10012. 6:26:53how to use them or you don't know what
  10013. 6:26:54they do, um you're going to mess up this
  10014. 6:26:57formula a lot. Uh and so what this
  10015. 6:27:00dollar sign basically does is it's
  10016. 6:27:02basically hard coding it in there. It is
  10017. 6:27:04only going to look at G2 and is only
  10018. 6:27:06going to look at G10 or through G10
  10019. 6:27:09because that colon. And this can come
  10020. 6:27:11into play because if you have something
  10021. 6:27:14selected like the H11, it's going to
  10022. 6:27:16mess it up because now if you have H11
  10023. 6:27:19selected like we do, you'll see this in
  10024. 6:27:20a second. It's not going to be applied
  10025. 6:27:23to this. Um, and again, I'll show you
  10026. 6:27:26that in just a minute. But we don't want
  10027. 6:27:27this hardcoded in there. Okay. But we do
  10028. 6:27:31have to select the proper range in a
  10029. 6:27:33second. Um, so we're going to get rid of
  10030. 6:27:35this. We're going to get rid of the
  10031. 6:27:36dollar signs because we want it to be
  10032. 6:27:38pretty fluid and be able to applied to
  10033. 6:27:40be applied basically anywhere we want.
  10034. 6:27:42Let's go into this formula. Um, if it
  10035. 6:27:46meets our criteria, let's give it um
  10036. 6:27:49let's give it a border and we'll give it
  10037. 6:27:52um we'll give it some color. We're going
  10038. 6:27:55to say if this is greater than 50,000.
  10039. 6:27:58So, let's hit okay. And nothing
  10040. 6:28:01happened. So, let's go back and see why.
  10041. 6:28:04So, if we go to our manage rules, you
  10042. 6:28:06can see that it still has the G2 to G10
  10043. 6:28:08is greater than 50,000, but it only is
  10044. 6:28:10being applied to this H11 cell, which
  10045. 6:28:13really makes no sense. Um, so if we had
  10046. 6:28:16wanted to get it done the first time, we
  10047. 6:28:18needed to have basically selected that
  10048. 6:28:19G2 to G10 right away. Um, but we can do
  10049. 6:28:22that now. So, let's get rid of this. And
  10050. 6:28:25we're going to say G2 to G10.
  10051. 6:28:30And that is hardcoded in there. That
  10052. 6:28:32should be fine still. Um but let's see
  10053. 6:28:35what it does.
  10054. 6:28:37And so now every single thing is
  10055. 6:28:39highlighted. And why is that? Uh that's
  10056. 6:28:42because when we changed it, it also
  10057. 6:28:45changed the format of it because we
  10058. 6:28:47changed the cell that we were looking
  10059. 6:28:48at. So we need to come back here. And
  10060. 6:28:51that's why again you want to do this the
  10061. 6:28:52right way the first time. We're going to
  10062. 6:28:53come back here. We're going to give it
  10063. 6:28:54this range.
  10064. 6:28:56And we're going to get rid of these
  10065. 6:28:58dollar signs.
  10066. 6:29:02And now we're going to hit okay. And so
  10067. 6:29:05now it's being applied G2 to G10 and G2
  10068. 6:29:09to G10. And we'll keep it like that. And
  10069. 6:29:11we'll apply it. And now it works
  10070. 6:29:13properly. So now everything that's above
  10071. 6:29:1550,000 is being highlighted. Again, if
  10072. 6:29:17that was confusing, um it it is
  10073. 6:29:19confusing. It genuinely is. And so if
  10074. 6:29:22you wanted to do this right the first
  10075. 6:29:23time without having to make a bunch of
  10076. 6:29:25changes, you'd want to highlight these
  10077. 6:29:27before you start. And then you want to
  10078. 6:29:29go in and create the rule. We'll do this
  10079. 6:29:32really quick just to kind of show you
  10080. 6:29:33what I'm talking about. We'll say
  10081. 6:29:34equals. We'll give it this range.
  10082. 6:29:39Get rid of these real quick because
  10083. 6:29:42again, I don't want this
  10084. 6:29:45hardcoded in there. It will ruin our
  10085. 6:29:46formula. And then we'll say greater than
  10086. 6:29:4930. Um, and we'll give it this nice
  10087. 6:29:52green. Uh, and so now if they're over
  10088. 6:29:55the age of 30, it will be highlighted.
  10089. 6:29:57And we didn't have to go back and change
  10090. 6:29:58anything. We didn't have to go back and
  10091. 6:30:00fix anything like we did in the first
  10092. 6:30:01one. Um, that was all for demonstration
  10093. 6:30:04purposes. But again, you need to really
  10094. 6:30:06be aware of that. That is something that
  10095. 6:30:08I think almost everybody's going to mess
  10096. 6:30:10up at some point. If you don't already
  10097. 6:30:12know about it, then you definitely are
  10098. 6:30:14going to make that mistake. Now, if we
  10099. 6:30:16come over here in this area, uh, we go
  10100. 6:30:18to our manage rules and not just the
  10101. 6:30:20current selection, but this whole
  10102. 6:30:21worksheet, then you can see that we have
  10103. 6:30:23these two formulas. Now you can go in
  10104. 6:30:25and edit any of these by double clicking
  10105. 6:30:26or clicking on it and then hitting edit
  10106. 6:30:28rule. You can also delete these rules or
  10107. 6:30:31duplicate these rules. Um I just wanted
  10108. 6:30:33to show you what you are able to do with
  10109. 6:30:34them. But if we uh go ahead and we get
  10110. 6:30:37rid of this. Um so let's say we delete
  10111. 6:30:40that rule and we hit apply uh you know
  10112. 6:30:42the rule is going to go away. That's
  10113. 6:30:44that I mean it's as simple as that. So
  10114. 6:30:46that is how you can create your own
  10115. 6:30:48rule. I want to be again very specific
  10116. 6:30:52in the fact that that is a confusing
  10117. 6:30:54piece. And if you mess that up, you're
  10118. 6:30:56going to be, you know, fixing a bunch of
  10119. 6:30:58different stuff and not understanding
  10120. 6:31:00why your rule is not working properly.
  10121. 6:31:02It's just because it's confusing. Those
  10122. 6:31:04dollar signs are are really important to
  10123. 6:31:06watch out for. And that is all there is
  10124. 6:31:08to it with conditional formatting.
  10125. 6:31:10Again, conditional formatting is um you
  10126. 6:31:12know, it's not anything super confusing.
  10127. 6:31:15We've looked at more complicated things,
  10128. 6:31:16but it's a really really useful tool to
  10129. 6:31:19use to look at these patterns and trends
  10130. 6:31:21super quickly and to find um these
  10131. 6:31:24outliers or these specific values that
  10132. 6:31:25you're looking for very quickly. And if
  10133. 6:31:27you're looking at just thousands and
  10134. 6:31:30tens of thousands or hundreds of
  10135. 6:31:31thousands of rows, this is one of the
  10136. 6:31:33fastest ways to find these things
  10137. 6:31:35without having to kind of wait and
  10138. 6:31:37filter and use these um these these
  10139. 6:31:40filters right here because again, this
  10140. 6:31:41can just take forever. Um, and so if you
  10141. 6:31:44haven't or if you've never worked with a
  10142. 6:31:46ton of data and tried to use this
  10143. 6:31:47before, it can take honestly like 10
  10144. 6:31:50minutes for something simple that you
  10145. 6:31:52could do with conditional formatting in
  10146. 6:31:53like 10 seconds. So definitely something
  10147. 6:31:55to mess with and use when you are
  10148. 6:31:57working with your own data sets. Uh, I
  10149. 6:31:59hope this was helpful. I mean, honestly,
  10150. 6:32:01I use this all the time. So, you know, I
  10151. 6:32:03hope that somebody out there can can use
  10152. 6:32:05this uh for their own work that they're
  10153. 6:32:07currently using. Thank you guys so much
  10154. 6:32:09for watching. I really appreciate it.
  10155. 6:32:10Again, huge shout out to Udemy for
  10156. 6:32:12sponsoring this Excel series. If you
  10157. 6:32:14like this video, be sure to like and
  10158. 6:32:15subscribe below. I'll see you in the
  10159. 6:32:17next video.
  10160. 6:32:20[music]
  10161. 6:32:30What's going on everybody? Welcome back
  10162. 6:32:31to another Excel tutorial. Today we will
  10163. 6:32:33be looking at charts.
  10164. 6:32:40Now, if you have data in Excel and you
  10165. 6:32:42want to visually show that with bars or
  10166. 6:32:44graphs or anything like that, you can do
  10167. 6:32:46that really simply. And I'm going to
  10168. 6:32:48show you how to do that today. And a lot
  10169. 6:32:50of people are a little bit intimidated
  10170. 6:32:51because they think it's a little bit
  10171. 6:32:53complicated. But I promise you, by the
  10172. 6:32:55end of this video, you will know how to
  10173. 6:32:57do it like a pro. It's not that
  10174. 6:32:59difficult. It's just you need to know
  10175. 6:33:01where to look, where to click, and how
  10176. 6:33:02to actually filter through things to
  10177. 6:33:04make sure that you're visually showing
  10178. 6:33:05the things that you want to show. But
  10179. 6:33:07before we actually jump into the
  10180. 6:33:08tutorial, I want to give a huge shout
  10181. 6:33:09out to the sponsor of this Excel series,
  10182. 6:33:11and that is Udemy. You may not know
  10183. 6:33:13this, but I probably get at least 15 to
  10184. 6:33:1550 companies every single month reaching
  10185. 6:33:17out to me wanting to sponsor the channel
  10186. 6:33:19and promote their product. And I turn
  10187. 6:33:21down almost every single one because I
  10188. 6:33:23either don't know their product or I
  10189. 6:33:24don't believe in their product. And so,
  10190. 6:33:26I'm not going to, you know, go and
  10191. 6:33:27promote that on my channel. But Udemy is
  10192. 6:33:29one that I have consistently promoted
  10193. 6:33:31over the past year. And that's because I
  10194. 6:33:32truly believe in their product. I've
  10195. 6:33:34been taking courses off their platform
  10196. 6:33:35for years and I've honestly learned so
  10197. 6:33:38much and I cannot recommend them enough.
  10198. 6:33:40So, if you want to take a full-fledged
  10199. 6:33:41Excel course, I have my recommendations
  10200. 6:33:44in the description if you want to check
  10201. 6:33:45those out. Thank you again to Udemy for
  10202. 6:33:48sponsoring this Excel series. So,
  10203. 6:33:49without further ado, let's jump on my
  10204. 6:33:51screen and get started with this
  10205. 6:33:52tutorial. All right, so let's jump right
  10206. 6:33:54into it. Right here we have the Dunder
  10207. 6:33:55Mifflin sales report and over here we
  10208. 6:33:58have all the products that they were
  10209. 6:33:59selling along with the months that they
  10210. 6:34:01were sold in. And so in January they
  10211. 6:34:03sold 450 reams of paper. Down here we
  10212. 6:34:07have the total items per month. And so
  10213. 6:34:09in January they sold 898 units of uh
  10214. 6:34:13products or or things that they sold.
  10215. 6:34:15And at the very end we have the year-end
  10216. 6:34:17total. So this is the total amount of
  10217. 6:34:18paper that they sold throughout the
  10218. 6:34:20year. Now we're going to use this data
  10219. 6:34:22right here for all of our charts. Now
  10220. 6:34:25you may not have data exactly like this.
  10221. 6:34:27It can come in lots of different
  10222. 6:34:28flavors, but you're going to get the
  10223. 6:34:30basic gist of how to use charts, how to
  10224. 6:34:33edit it, how to customize it to fit what
  10225. 6:34:36you need, and then we're going to kind
  10226. 6:34:37of put it right over here and kind of
  10227. 6:34:39create its own sheet where we can kind
  10228. 6:34:42of visualize all the things that we want
  10229. 6:34:44to show.
  10230. 6:34:46So, let's jump right back over here into
  10231. 6:34:48sales. And first thing we need to do is
  10232. 6:34:51kind of highlight the data that we're
  10233. 6:34:52going to be working with. Now, I'm going
  10234. 6:34:54to start with everything, but um you
  10235. 6:34:56know, I'll show you along the way. We
  10236. 6:34:57don't actually want everything, but we
  10237. 6:34:59can filter that stuff out as we go. So,
  10238. 6:35:02let's go right here, and we're going to
  10239. 6:35:04insert, and we're going to go over to
  10240. 6:35:07charts. Now, this is the chart section.
  10241. 6:35:08There's lots of different types of
  10242. 6:35:10charts. Um but the first thing that
  10243. 6:35:12we're going to be looking at is right
  10244. 6:35:14here. This is a 2D column or kind of
  10245. 6:35:16like a bar chart. And we're just going
  10246. 6:35:18to click right here. And we're going to
  10247. 6:35:20pull this down.
  10248. 6:35:22So, now that we have this down here,
  10249. 6:35:24there are a few things that I want to
  10250. 6:35:26show you before we actually really get
  10251. 6:35:28into it, and I kind of want to show you
  10252. 6:35:29the options that you have. So, if you go
  10253. 6:35:31up here, we have different uh chart
  10254. 6:35:34styles. And so, if I hover over them,
  10255. 6:35:37you can see that each one kind of looks
  10256. 6:35:40a little bit different. And it really
  10257. 6:35:42doesn't matter. Uh it doesn't really
  10258. 6:35:45change the data in any way, just how you
  10259. 6:35:47visualize it. And so if that is
  10260. 6:35:49important, if that is something that you
  10261. 6:35:51um you want to stick with a certain
  10262. 6:35:53theme or a certain look, then go for
  10263. 6:35:55that. Uh the other thing that's really
  10264. 6:35:58nice to have over here is this switch
  10265. 6:36:00row and column. So right down here, you
  10266. 6:36:02can see this purple and you can see this
  10267. 6:36:04red. Those are our rows and columns. And
  10268. 6:36:07we can switch that right here. So if we
  10269. 6:36:09go like this now, instead of the months
  10270. 6:36:11being right here, the months are the
  10271. 6:36:13colors and the actual product is right
  10272. 6:36:16here. Let's click it again and it'll go
  10273. 6:36:18back. And so now we have this kind of
  10274. 6:36:20time series. So now we have January
  10275. 6:36:22through the end of year total. Now this
  10276. 6:36:24one is one that I think is super
  10277. 6:36:27helpful. You know it you can do it down
  10278. 6:36:29here as well. If you go to this filter
  10279. 6:36:31um but both of these are super helpful
  10280. 6:36:34because you sometimes just want to
  10281. 6:36:36select all the data and then kind of get
  10282. 6:36:37in there and mess with it. Something
  10283. 6:36:39that we want to get rid of is this total
  10284. 6:36:41items per month. So we want to remove
  10285. 6:36:43that. And then we also want to remove
  10286. 6:36:45this year-end total because both of
  10287. 6:36:47those are are kind of the end result.
  10288. 6:36:51They're not the actual data per month or
  10289. 6:36:53or per product. So, we're going to get
  10290. 6:36:55rid of those and we're going to apply
  10291. 6:36:56that. And as you can see, just right off
  10292. 6:36:59the bat, our data has changed
  10293. 6:37:00dramatically. Uh, and that's because we
  10294. 6:37:02aren't including these these large large
  10295. 6:37:05numbers that were kind of throwing off
  10296. 6:37:07uh the visualization for us. So, this
  10297. 6:37:10one right here as is already pretty
  10298. 6:37:13good. Um, what we can do right here is
  10299. 6:37:15we can change this and we're just going
  10300. 6:37:17to say
  10301. 6:37:19products sold
  10302. 6:37:22per month.
  10303. 6:37:25Now, what we can do if we want to move
  10304. 6:37:27it to another um to another sheet is we
  10305. 6:37:30can actually move the chart and we can
  10306. 6:37:32select where we want to move it. We can
  10307. 6:37:34move it to chart sheet and we can do
  10308. 6:37:35that. Or something that I do um almost
  10309. 6:37:3899% of the time is I just copy and I
  10310. 6:37:41come over here and I'm going to paste
  10311. 6:37:43it. And so now we have this um this
  10312. 6:37:47chart right over here as well as back
  10313. 6:37:50here. And so I typically tend to do that
  10314. 6:37:53because now we can still go over here
  10315. 6:37:55and change this one as much as we want.
  10316. 6:37:57So if we want to go in here, we can
  10317. 6:37:58alter this one and it won't affect the
  10318. 6:38:00other one. So we just have basically two
  10319. 6:38:02copies. So, we're going to keep this one
  10320. 6:38:04right here. This is going to be our
  10321. 6:38:05first visualization.
  10322. 6:38:07Um, and as I said, it's it's fairly
  10323. 6:38:09straightforward. If you've ever done any
  10324. 6:38:11types of charts or graphs before, um,
  10325. 6:38:13right here, it's January, February,
  10326. 6:38:15March, April, May. And if you hover over
  10327. 6:38:17these, you can see that that's the the
  10328. 6:38:19paper. And if we just glance, you know,
  10329. 6:38:22the paper is their biggest product by
  10330. 6:38:23far. And so, that blue um, which is
  10331. 6:38:26their paper, is going to be the biggest
  10332. 6:38:27every single month. So, that makes
  10333. 6:38:30perfect sense. Now, what if we want to
  10334. 6:38:32change up uh the the kind So, what if we
  10335. 6:38:35want to change up the kind of
  10336. 6:38:37visualization that it offers us? Well,
  10337. 6:38:40we have a lot of different options.
  10338. 6:38:42Let's go right over here to change chart
  10339. 6:38:44type. Now, this is going to offer you
  10340. 6:38:47just about everything you could possibly
  10341. 6:38:50imagine or want and even things that you
  10342. 6:38:52absolutely would never ever want ever.
  10343. 6:38:55Um, and so I'm going to show you some of
  10344. 6:38:57the good ones and I'm going to show you
  10345. 6:38:58some just absolutely insane ones that uh
  10346. 6:39:01Excel came up with which cannot I I
  10347. 6:39:04could not imagine a scenario that these
  10348. 6:39:06are ever used. Um, but within these
  10349. 6:39:08columns you can do they're called
  10350. 6:39:10cluster columns. Uh, these stacked
  10351. 6:39:13columns. So it would look just like
  10352. 6:39:14this. Those are often used as well.
  10353. 6:39:18Um, and then we have ones that they're
  10354. 6:39:21just not used often. Let's look let's
  10355. 6:39:22take a look at this one right here.
  10356. 6:39:25I mean, it's tough. It's tough to look
  10357. 6:39:27at. Um, but let's let's put it right
  10358. 6:39:29here. This is basically the same thing
  10359. 6:39:32that we just had except visualized in a
  10360. 6:39:35different um we'll call it more unique
  10361. 6:39:37way. Uh, and let's for the sake of it,
  10362. 6:39:40let's put it over here. Um, these two
  10363. 6:39:42things show the same information. They
  10364. 6:39:45show the same data. Just one is shown
  10365. 6:39:48well and one is not shown well. Um, I'm
  10366. 6:39:51not a fan of these 3D type of
  10367. 6:39:54visualizations.
  10368. 6:39:55I I just don't like them. But maybe you
  10369. 6:39:58do and and you want to use that. That's
  10370. 6:40:00fantastic. Let's go back. Um, something
  10371. 6:40:04else that you'll probably use a lot are
  10372. 6:40:06things like these um these line graphs.
  10373. 6:40:09Okay, so these are line graphs and
  10374. 6:40:11they're different types. So there are
  10375. 6:40:12these stacked um 100% stacked line lines
  10376. 6:40:16with markers, different flavors for this
  10377. 6:40:20this type of line graph. And so you can
  10378. 6:40:22go in here and take a look. Again, um
  10379. 6:40:26not my favorite, but they have it as an
  10380. 6:40:29option if you ch so choose to do this.
  10381. 6:40:32Um but I kind of I'm kind of a simple
  10382. 6:40:33guy. Um but I'm going to go in here and
  10383. 6:40:36it's pretty clustered. Um, I want to
  10384. 6:40:39kind of take the ones that have the
  10385. 6:40:41highest sales
  10386. 6:40:43or the highest total amount sold. So,
  10387. 6:40:45that would be paper, manila folders, and
  10388. 6:40:49three ring binders. So, let's go in
  10389. 6:40:51here. We want to keep paper. We want to
  10390. 6:40:55keep uh manila folders.
  10391. 6:40:58And we want to keep three ring binders.
  10392. 6:41:01And let's apply that. And so, now it's a
  10393. 6:41:03lot cleaner. And we're just going to
  10394. 6:41:06copy this. and we're going to put it
  10395. 6:41:08over here. And I'm just putting these
  10396. 6:41:10all over here for you u because we'll
  10397. 6:41:11look at this at the end and just kind of
  10398. 6:41:13see different options and and ways to do
  10399. 6:41:15things as we have gone through this
  10400. 6:41:17tutorial. So let's go back here. Now
  10401. 6:41:20something else that we haven't looked at
  10402. 6:41:22is the actual colors and color schemes
  10403. 6:41:25that you can do. So let's go right here
  10404. 6:41:27to these chart styles and we can go to
  10405. 6:41:29color. Now, color is um something that
  10406. 6:41:33probably is quite overlooked um in
  10407. 6:41:36actual charts and graphs. Some terrible
  10408. 6:41:38colors like this or or this um where
  10409. 6:41:41they're really close together,
  10410. 6:41:42especially when you have a lot of them.
  10411. 6:41:44Um for example, let's just pretend we
  10412. 6:41:47put all of them back really quickly. It
  10413. 6:41:52is near impossible to distinguish these
  10414. 6:41:54colors. Um we wouldn't
  10415. 6:41:57we wouldn't want that. Let's go back to
  10416. 6:41:59this color. You know, when you have it
  10417. 6:42:01like uh in some of these colors at
  10418. 6:42:03least, it at least distinguishes them so
  10419. 6:42:06you can kind of see what you're working
  10420. 6:42:07with, but when you have it in these
  10421. 6:42:09monochromatic options, sometimes they're
  10422. 6:42:12just impossible to distinguish. So, be
  10423. 6:42:14sure to choose the right colors that
  10424. 6:42:16you're using so that if somebody who's
  10425. 6:42:19never seen this data before looks at it,
  10426. 6:42:21they can easily distinguish uh the
  10427. 6:42:23product and the month that you are
  10428. 6:42:26looking at. But let's go just back up
  10429. 6:42:28here. We'll choose this default option.
  10430. 6:42:30Um, oh, let's choose this one right
  10431. 6:42:32here. This one's nice, although there's
  10432. 6:42:33lots of yellows and oranges. Let's see
  10433. 6:42:35this one. This one's not bad. Greens,
  10434. 6:42:38blues, uh, and like [snorts] yellows.
  10435. 6:42:41So, that's nice. Um, other things that
  10436. 6:42:44we want to look at, and there are these
  10437. 6:42:46chart elements right here. Other things
  10438. 6:42:48that we can add are things like data
  10439. 6:42:51labels. Um, and right here, it's super
  10440. 6:42:54messy. Um, but if we went back and we
  10441. 6:42:57got rid of some of these things like the
  10442. 6:43:00printer, staples, highlighters, pens,
  10443. 6:43:03and total, if we apply that, it's a
  10444. 6:43:05little bit easier to distinguish. Um,
  10445. 6:43:08and that's, you know, something that you
  10446. 6:43:10may be interested in doing. You can also
  10447. 6:43:12add this data table at the bottom, which
  10448. 6:43:15is the actual columns and rows that you
  10449. 6:43:18have for this visualization right here.
  10450. 6:43:19Now, let's expand this quite a bit. I'm
  10451. 6:43:21going to make this extremely large. If
  10452. 6:43:24you have something like this, it
  10453. 6:43:25actually can be pretty nice. Um, you
  10454. 6:43:27know, maybe we get rid of these data
  10455. 6:43:29labels, but it can be easy because
  10456. 6:43:32you're putting it all in one place. You
  10457. 6:43:33can also make this two separate
  10458. 6:43:35visualizations. So, you can have one
  10459. 6:43:36visualization just like this, and right
  10460. 6:43:38underneath it, you can have the actual
  10461. 6:43:40rows and columns, but this option allows
  10462. 6:43:42you to put it all in one. So, let's put
  10463. 6:43:44this back down because that is way too
  10464. 6:43:47big. And uh, wait, let's expand it a
  10465. 6:43:51little bit. Now, if you notice right
  10466. 6:43:52here, we have our legend up top. Um, it
  10467. 6:43:55is possible to actually change that. You
  10468. 6:43:57can go right here and you can move this
  10469. 6:44:00um kind of wherever you want. Um, but
  10470. 6:44:03it's not exactly easy to put based off
  10471. 6:44:06how we have it right here. If we go in
  10472. 6:44:08to this chart elements, we go down to
  10473. 6:44:10legend and we hit this little arrow
  10474. 6:44:12right here. We can select it on the
  10475. 6:44:15right, the top, the left, and the
  10476. 6:44:17bottom. Or we can just go to more
  10477. 6:44:19options, uh, which allows us to push it
  10478. 6:44:21anywhere. But, um, let's say I want to
  10479. 6:44:24do it just like this. I'm going to put
  10480. 6:44:25on the right. And I actually want to
  10481. 6:44:27bring it down right here. And, you know,
  10482. 6:44:31that's just an option if you want to
  10483. 6:44:33kind of customize it a little further.
  10484. 6:44:34Makes it a little cleaner. Uh, you can
  10485. 6:44:36do that with almost any of these things.
  10486. 6:44:37So, if you click on this, oops. If you
  10487. 6:44:39click on this, you can move this
  10488. 6:44:41anywhere as well. So, if you want to
  10489. 6:44:43move this over here on top of it, you
  10490. 6:44:44can and make it look terrible. or you
  10491. 6:44:46can move it uh right back over here. You
  10492. 6:44:48know, this is something that you can
  10493. 6:44:50move around. Uh you just kind of want to
  10494. 6:44:52make sure you're doing it the right way.
  10495. 6:44:54So, let's get this back where it was.
  10496. 6:44:56There we go. Now, before we go any
  10497. 6:44:57further, let's copy that and put it
  10498. 6:45:00right over here with our other uh charts
  10499. 6:45:03and graphs. And if you see over here on
  10500. 6:45:06this side, we have this format chart
  10501. 6:45:08area. Notice I haven't showed you this
  10502. 6:45:10at all yet. That is because I genuinely
  10503. 6:45:12just don't use this almost at all. Um,
  10504. 6:45:16there are some good stuff in here. Um,
  10505. 6:45:18and I'm sure that, you know, if you are
  10506. 6:45:20someone who really wants to go in there
  10507. 6:45:21and super customize it, you can do that.
  10508. 6:45:24Um, but I honestly I just never get in
  10509. 6:45:26here and I never, you know, change the
  10510. 6:45:28glow or the shadows. Um, just not
  10511. 6:45:32something I use. And and some of these
  10512. 6:45:33are only for these three 3D formatting,
  10513. 6:45:35which I never use. And so, I'm not going
  10514. 6:45:38to show you and walk through these
  10515. 6:45:39things. Again, I I really don't use it.
  10516. 6:45:41And so if you want to go in there and
  10517. 6:45:43mess with it, uh, you know, by all
  10518. 6:45:45means, go for it. It's just not
  10519. 6:45:46something that I want to take the time
  10520. 6:45:48to show you. And with that being said,
  10521. 6:45:50let's go back over to this chart sheet
  10522. 6:45:52that we have. And it was super super
  10523. 6:45:55easy to get these um charts and graphs
  10524. 6:45:59and and whatnot. There are lots of
  10525. 6:46:01different options. Again, if we go back
  10526. 6:46:03here and we go up here to chart design
  10527. 6:46:05and go to the change chart type and
  10528. 6:46:08again there are a ton of different
  10529. 6:46:10options like a pie chart um like this.
  10530. 6:46:13It's it's you know you can try to figure
  10531. 6:46:16this out and use these. Um but you know
  10532. 6:46:20I wanted to show you the ones that
  10533. 6:46:21you'll probably use the most which are
  10534. 6:46:22these columns and line charts. And they
  10535. 6:46:25all kind of are similar in their own
  10536. 6:46:28way. This bar chart is basically, you
  10537. 6:46:30know, this column chart just on its
  10538. 6:46:32side. And so they all have their
  10539. 6:46:34different flavor. They all have their
  10540. 6:46:35different way of visualizing the data,
  10541. 6:46:37but in essence, they're using the data
  10542. 6:46:39in a similar way to to visualize it and
  10543. 6:46:41represent the data itself, especially
  10544. 6:46:43things like these box and whisker plots
  10545. 6:46:45or these waterfall charts. Uh, you know,
  10546. 6:46:47these are things that usually require
  10547. 6:46:50specific data to kind of use. Uh, and
  10548. 6:46:52and so I'm just using data that you'll
  10549. 6:46:54probably see the most of. um like this
  10550. 6:46:57this sales data. So, I hope that this
  10551. 6:46:59has given you a pretty good um you know
  10552. 6:47:02quick understanding of how to use these,
  10553. 6:47:04how to customize them, how to copy and
  10554. 6:47:06paste them over to a different sheet to
  10555. 6:47:09create some type of little uh chart and
  10556. 6:47:12visualization sheet that you can use to
  10557. 6:47:14show your employers and visualize the
  10558. 6:47:16data that you are working with. Thank
  10559. 6:47:18you guys so much for watching. I really
  10560. 6:47:20appreciate it. Again, huge shout out to
  10561. 6:47:21Udemy for sponsoring this Excel series.
  10562. 6:47:23If you like this video, be sure to like
  10563. 6:47:25and subscribe [music] below, and I'll
  10564. 6:47:27see you in the next video.
  10565. 6:47:36[music]
  10566. 6:47:40What's going on everybody? Welcome back
  10567. 6:47:41to the Excel tutorial series. Today we
  10568. 6:47:43will be looking at how to clean data in
  10569. 6:47:45Excel.
  10570. 6:47:51Now, knowing how to clean data in Excel
  10571. 6:47:53is actually extremely useful, and there
  10572. 6:47:55are a ton of techniques to do this. I'm
  10573. 6:47:57going to be showing you the ones that I
  10574. 6:47:58probably use the most, and I feel like
  10575. 6:48:00are the most helpful to kind of do the
  10576. 6:48:02bulk or the majority of the data clean
  10577. 6:48:04that you're going to do in Excel. Like I
  10578. 6:48:06said, there's so many different ways and
  10579. 6:48:08very specific things that you can do,
  10580. 6:48:10but I'm going to highlight some of the
  10581. 6:48:12bigger ones that I find the most useful.
  10582. 6:48:13And some of you may be thinking, well,
  10583. 6:48:15I'll just do my data cleaning in SQL or
  10584. 6:48:17Python or when I get it ready to put it
  10585. 6:48:18in Tableau. Um, but honestly, a lot of
  10586. 6:48:21the data cleaning, at least a lot of the
  10587. 6:48:23big stuff, I tend to do in Excel if the
  10588. 6:48:25data set is small enough to fit in
  10589. 6:48:27Excel. And so, I think it's actually
  10590. 6:48:28really, really useful to know how to do
  10591. 6:48:30this because you'll most likely be doing
  10592. 6:48:32it more than you think. Now, before we
  10593. 6:48:34jump into the tutorial, I want to give a
  10594. 6:48:36shout out to the sponsor of this video
  10595. 6:48:37and is a brand new sponsor. It is
  10596. 6:48:39Unlocked by Z by HP. Unlocked is a movie
  10597. 6:48:42that's actually broken up into four
  10598. 6:48:43parts and each of them have a unique
  10599. 6:48:45data science challenge associated with
  10600. 6:48:47it. Now, I'm going to read this next
  10601. 6:48:48part because it's extremely interesting.
  10602. 6:48:50Each challenge represents a different
  10603. 6:48:52topic. So, there's data visualization,
  10604. 6:48:54text analysis, audio signal processing,
  10605. 6:48:56and computer vision. And you can submit
  10606. 6:48:58your answers and your work on their
  10607. 6:48:59website for a chance to win one of 10
  10608. 6:49:01ZBook Studio laptops or a free trip to
  10609. 6:49:03the Kaggle World Championships. So, I'll
  10610. 6:49:06leave a link in the description where
  10611. 6:49:07you can go watch the movie and then do
  10612. 6:49:08the challenges and then submit your
  10613. 6:49:09answers for a chance to win. You should
  10614. 6:49:11also go check out their hackathon where
  10615. 6:49:12you can do these projects with other
  10616. 6:49:14people just like you who are trying to
  10617. 6:49:15figure out these answers and submit them
  10618. 6:49:17to win as well. So, go check that out.
  10619. 6:49:19Thank you again to the sponsor of this
  10620. 6:49:21video, Unlocked by Z by HP. Now, without
  10621. 6:49:24further ado, let's jump onto my screen
  10622. 6:49:25and get started with the tutorial. All
  10623. 6:49:27right, so let's jump right into it. I
  10624. 6:49:28have this US president's data set. I got
  10625. 6:49:30the base data set from Kaggle. Uh, but I
  10626. 6:49:33added some of my own data and then I
  10627. 6:49:35messed some stuff up as well just to
  10628. 6:49:37kind of demonstrate some of these things
  10629. 6:49:39that we're going to be looking at today.
  10630. 6:49:40This is not a full project. So, you
  10631. 6:49:43know, we're not actually going to be
  10632. 6:49:44using this to create any visualizations
  10633. 6:49:46or anything like that. So, you know, all
  10634. 6:49:47this is just for demonstration purposes,
  10635. 6:49:50but we will be doing a full project in
  10636. 6:49:53about two or three videos uh in this
  10637. 6:49:56Excel series where we're going to be
  10638. 6:49:57doing from start to finish with a real
  10639. 6:49:59data set. So, you know, if that's
  10640. 6:50:00something that you're you're wanting,
  10641. 6:50:02then we will absolutely be doing that.
  10642. 6:50:04Now, something that you may be wondering
  10643. 6:50:05is how do you actually identify what you
  10644. 6:50:07need to clean in the data. What do you
  10645. 6:50:09know to look for? Well, some of the
  10646. 6:50:11obvious things are things like
  10647. 6:50:12formatting and standardization. So,
  10648. 6:50:15things like, you know, this James Monroe
  10649. 6:50:16is in all caps. That happens all the
  10650. 6:50:18time with real data. Um, and and so, you
  10651. 6:50:21know, you want to standardize that or
  10652. 6:50:23this all lowercase. You want to
  10653. 6:50:24standardize that. You want that all to
  10654. 6:50:25be the same. There's also things like um
  10655. 6:50:29right here where we have this wig and
  10656. 6:50:31this wig with a bunch of random stuff
  10657. 6:50:33after it. This happens all the time
  10658. 6:50:36where it's not completely standardized.
  10659. 6:50:38Um and you may even notice um you know
  10660. 6:50:41there are some spelling errors in here
  10661. 6:50:43and I'll we'll kind of look through that
  10662. 6:50:44in a little bit. And then you know there
  10663. 6:50:47are things like additional spaces where
  10664. 6:50:50there shouldn't be spaces. There are
  10665. 6:50:51things like currencies that you need to
  10666. 6:50:53be aware of if you were importing this
  10667. 6:50:55into or going to be importing this into
  10668. 6:50:56a SQL database. Um, things like
  10669. 6:50:58currencies can be just a problem or be
  10670. 6:51:03really um unnecessary. It may actually
  10671. 6:51:06cause more issues in the long run. So,
  10672. 6:51:07you may just want to, you know, take
  10673. 6:51:09that to the base uh value. And then
  10674. 6:51:12dates are always an issue. Always,
  10675. 6:51:14always, always. Um, so always look at
  10676. 6:51:16your dates. Make sure they're they're
  10677. 6:51:17formatted correctly. Make sure they're
  10678. 6:51:19all the same. These are the types of
  10679. 6:51:21things that right when I glance at this
  10680. 6:51:22data set, these are things that I'm
  10681. 6:51:24looking for. Um, one other thing that is
  10682. 6:51:27actually the first thing that we're
  10683. 6:51:28going to start out with is you want to
  10684. 6:51:30make sure that your data is
  10685. 6:51:31[clears throat] not duplicated because
  10686. 6:51:34if your data has duplicate data in it
  10687. 6:51:36and you don't want that, it's not
  10688. 6:51:38supposed to be there. There are some
  10689. 6:51:40specific use cases where duplicated data
  10690. 6:51:42is okay. Um, you know, you want to get
  10691. 6:51:45rid of that and it's very easy to do in
  10692. 6:51:47Excel. Uh the first thing we're going to
  10693. 6:51:49do, we're going to go up uh to this data
  10694. 6:51:51tab. We're going to go right over here
  10695. 6:51:52and we're going to get see if there's
  10696. 6:51:54any uh duplicates in our data. So, we're
  10697. 6:51:56just going to go up to remove
  10698. 6:51:57duplicates. It's going to automatically
  10699. 6:51:59choose all of your columns to to check
  10700. 6:52:02against. So, it's going to for from A
  10701. 6:52:04all the way through I, it's going to see
  10702. 6:52:06is the exact same data in all these
  10703. 6:52:08rows. And if it is, it's going to get
  10704. 6:52:09rid of it. Um and so, we're going to
  10705. 6:52:11click okay.
  10706. 6:52:13And it did find one duplicate. And I'll
  10707. 6:52:15show you that one real quick. um because
  10708. 6:52:17you know it was right here. So Barack
  10709. 6:52:20Obama was here twice and then I'm going
  10710. 6:52:22to hit control I hit control Z to go
  10711. 6:52:24back. I'm going to hit control Y to go
  10712. 6:52:26forward and it removed that uh that row
  10713. 6:52:29completely. Now in this example you may
  10714. 6:52:32be able to spot that with your eye but
  10715. 6:52:33in a real data set where you have 10,000
  10716. 6:52:36100,000 rows there's absolutely no way
  10717. 6:52:38you're going to see that or very very
  10718. 6:52:40unlikely that you are going to see that
  10719. 6:52:42there's duplicated data in there. So
  10720. 6:52:44just running a a a quick um ddup or or
  10721. 6:52:47removing of duplicates that is really
  10722. 6:52:49important to make sure that you um have
  10723. 6:52:52gotten rid of those things. So that's
  10724. 6:52:54one of the first things that I do. Um
  10725. 6:52:56we're going to go into a lot of these
  10726. 6:52:58different uh columns and I'm going to
  10727. 6:53:00kind of show you different techniques or
  10728. 6:53:01things that I do when I look at actual
  10729. 6:53:04data. So I'm going to come right over
  10730. 6:53:06here. I'm going to insert. And this is
  10731. 6:53:08what I actually do. I I usually create a
  10732. 6:53:10separate column especially when I'm
  10733. 6:53:11working with this because I don't want
  10734. 6:53:12to change this one. Um I don't want to
  10735. 6:53:16go in here and you know say um equals
  10736. 6:53:19upper equals proper etc. There's a lot
  10737. 6:53:22of different ways that you can change um
  10738. 6:53:23names or not a lot but the main ones
  10739. 6:53:26that you can change names and all of
  10740. 6:53:27them are completely okay. So for example
  10741. 6:53:30I'm going to hit equal upper oops upper
  10742. 6:53:33and I'm going to go like this and close
  10743. 6:53:35my parenthesy. So, I selected this cell.
  10744. 6:53:37I closed my parenthesy. I hit enter. It
  10745. 6:53:40is and I'm going to hit um in the bottom
  10746. 6:53:42right. I'm going to hit double click
  10747. 6:53:43this. It's going to apply it to all of
  10748. 6:53:45them. It is completely okay to have your
  10749. 6:53:47data like this if you want it to be like
  10750. 6:53:49that. Um if you want it to be all lower,
  10751. 6:53:51you can do that. If you want it to be in
  10752. 6:53:52proper case, you can do that. Um there
  10753. 6:53:55are oops, there are different um uses
  10754. 6:53:59for all of them. And honestly, as long
  10755. 6:54:01as it's all the same, typically it's
  10756. 6:54:03okay. But if um you know, for example,
  10757. 6:54:05if you're selling this to like a
  10758. 6:54:06thirdparty company or something like
  10759. 6:54:08that, they may have um what they want
  10760. 6:54:11for their ingestion process when they
  10761. 6:54:13take your file in. If you send, you
  10762. 6:54:15know, a weekly file or a monthly file,
  10763. 6:54:17they may want it exactly how they want
  10764. 6:54:19it, and you can change that to to what
  10765. 6:54:21they want. Um but as long as it's
  10766. 6:54:23standardized for you, it's all the same
  10767. 6:54:25for you, that is a good thing. So now we
  10768. 6:54:28have all of these um in the proper case.
  10769. 6:54:31That's typically what I I do or I use
  10770. 6:54:34upper. Those are the ones I use the
  10771. 6:54:36most. I don't usually use um lower. And
  10772. 6:54:39if you go in here and you type in lower,
  10773. 6:54:42you know, it changes it to all lower. I
  10774. 6:54:44don't typically do that. Um and I'm
  10775. 6:54:46going to add I'm going to Oops. I'm
  10776. 6:54:48going to say president dash fixed. And
  10777. 6:54:52so now all of these names um all of
  10778. 6:54:55these uh different uppercase and
  10779. 6:54:57lowercase these are all fixed and and it
  10780. 6:54:59just makes it so much easier to read and
  10781. 6:55:02you don't have different um uppercase
  10782. 6:55:04and lowerase issues. It's all the same.
  10783. 6:55:06So I'm going to keep that right there.
  10784. 6:55:08Uh if we move a little bit to the right,
  10785. 6:55:13if you look at this prior, now this
  10786. 6:55:15prior is a mess. It's it has stuff all
  10787. 6:55:19over. And to be honest, this is not
  10788. 6:55:21really something that I would probably
  10789. 6:55:23be using um like in a real data set. I
  10790. 6:55:27would look at this column and I would
  10791. 6:55:28say this is pretty useless. Um if I had
  10792. 6:55:30a very specific use case for this this
  10793. 6:55:33data in this column, I might try to, you
  10794. 6:55:35know, parse it out and do something. But
  10795. 6:55:37I don't uh this this is a completely
  10796. 6:55:39useless column to me. So I'm actually
  10797. 6:55:40going to skip this one. I'm going to go
  10798. 6:55:42to this party one. And this party one to
  10799. 6:55:45me is looks pretty important because
  10800. 6:55:47this is something that I know I can
  10801. 6:55:48group by um and I can create
  10802. 6:55:50visualizations with and and kind of
  10803. 6:55:52break that out. And if you look right
  10804. 6:55:55here, we're going to add um we're going
  10805. 6:55:57to add a filter. So now let's open up
  10806. 6:55:59party and take a look. So, uh, if we
  10807. 6:56:02look right here, we have Democratic,
  10808. 6:56:04Democratic-Republican,
  10809. 6:56:05Federalist, nonpartisan, Republican,
  10810. 6:56:07Republicans, wig, and wig with a a date
  10811. 6:56:10and some information in the back of it,
  10812. 6:56:12and then some blanks. Um, and it's
  10813. 6:56:15really important when we're when we're
  10814. 6:56:17looking at these um ones that we think
  10815. 6:56:18we might group by that we have these um
  10816. 6:56:22properly grouped. So, Republican and
  10817. 6:56:24Republicans to me right off the bat
  10818. 6:56:26looks like a spelling error. And so, I'm
  10819. 6:56:28just going to deselect all. I'm going to
  10820. 6:56:30go to Republican. Republicans.
  10821. 6:56:33And it's literally Republican all the
  10822. 6:56:36way down except for this last one. And
  10823. 6:56:38to me, that's just something that I
  10824. 6:56:40would update. So I would just go right
  10825. 6:56:41here. I do that. If I didn't do that and
  10826. 6:56:44then I try to create, let's say, a pivot
  10827. 6:56:46table on here, I'll have its own group
  10828. 6:56:48of Republicans, and it wouldn't be added
  10829. 6:56:50to Republican. And maybe that's on
  10830. 6:56:52purpose, but let's just presume that we
  10831. 6:56:55know this data extremely well. That's
  10832. 6:56:56not supposed to be like that, right?
  10833. 6:56:58Again, that that just comes back to
  10834. 6:56:59knowing your data really well,
  10835. 6:57:02understanding what it um you know what
  10836. 6:57:04it should look like, and we know that it
  10837. 6:57:05should not be like that. So, we're going
  10838. 6:57:07to fix that. Uh the next thing that
  10839. 6:57:09we're going to fix um and as you can
  10840. 6:57:10see, it it got rid of it. Next thing
  10841. 6:57:12we're going to fix is this wig. Um
  10842. 6:57:16that's just like an error. That's that's
  10843. 6:57:18some issue on the the data side, and
  10844. 6:57:23we're just going to [clears throat] fix
  10845. 6:57:23that by updating it. And that's it. I
  10846. 6:57:27would always be keeping um a a copy of
  10847. 6:57:30this with the raw data uh somewhere else
  10848. 6:57:33because this is presumably like a
  10849. 6:57:35working document. This is not a um you
  10850. 6:57:39know you you aren't saving over your
  10851. 6:57:41original file. Let's just say that. And
  10852. 6:57:43then let's take a look at these blanks
  10853. 6:57:44real quick. Um okay. So there are these
  10854. 6:57:49rows right here that have nothing. I I
  10855. 6:57:51think we're okay. But if we see anything
  10856. 6:57:53different 47 48. Okay. So, yeah, it's
  10857. 6:57:56just these ones right here that have no
  10858. 6:57:58data in it anyways. It's just seeing it
  10859. 6:58:00in the filter. So, not an issue at all.
  10860. 6:58:03So, okay, we're looking good. We've gone
  10861. 6:58:06all the way over. We we fixed this
  10862. 6:58:07president. We skipped this one. Um we we
  10863. 6:58:10cleaned up this party. And I kept this
  10864. 6:58:12one in here because I'm not exactly sure
  10865. 6:58:14if that's a Democratic or Republican.
  10866. 6:58:16So, I'm going to keep it its own thing.
  10867. 6:58:18Um I'm not a huge uh history buff on
  10868. 6:58:22that aspect. The next one right here is
  10869. 6:58:25um the next one right here is really
  10870. 6:58:28easy. Uh this is something that happens
  10871. 6:58:30all the time especially on actually uh
  10872. 6:58:33most often it's happens on numerical
  10873. 6:58:35data. So like uh you know there'll be a
  10874. 6:58:39number of 101 then there'll be a space
  10875. 6:58:41after it for absolutely no reason. Uh
  10876. 6:58:43and it happens all the time. It does
  10877. 6:58:46happen like this as well um where you'll
  10878. 6:58:48see this and all you got to do is do
  10879. 6:58:50trim and select the uh the cell. We're
  10880. 6:58:53going to close that parenthesy and we're
  10881. 6:58:55going to apply that all the way down.
  10882. 6:58:57What is so fantastic about the trim is
  10883. 6:58:59that it's really intuitive and it knows
  10884. 6:59:02basically everything it needs to do. For
  10885. 6:59:05example, um it gets rid of the um spaces
  10886. 6:59:09before. It gets rid of extra spaces in
  10887. 6:59:11the middle and um it'll get rid of extra
  10888. 6:59:15spaces at the end um which you wouldn't
  10889. 6:59:17be able to see but they are there and
  10890. 6:59:19they they absolutely can cause issues.
  10891. 6:59:21If you have spaces at the end that you
  10892. 6:59:23cannot see um let's take this one for
  10893. 6:59:25example like if I had spaces at the end
  10894. 6:59:27that can cause issues when you insert or
  10895. 6:59:30or or put that into a database. Um that
  10896. 6:59:32happens a lot with numbers. um you know
  10897. 6:59:35when you're putting that into SQL that
  10898. 6:59:37can cause issues and so you really it is
  10899. 6:59:39important to actually do that trim um
  10900. 6:59:41and you can do that on all of your
  10901. 6:59:43columns or just ones that you know
  10902. 6:59:45you're having issues with but once you
  10903. 6:59:47import that data into SQL you will know
  10904. 6:59:48if there's an issue or not um when you
  10905. 6:59:50actually try to start using it. So we're
  10906. 6:59:52going to say vice and we're going to say
  10907. 6:59:55fixed. Oops. There we go.
  10908. 6:59:58Uh this next one is one that you'll run
  10909. 7:00:02into a lot when you're working with
  10910. 7:00:03numerical data. You will encounter so
  10911. 7:00:07many different issues. Um one that I run
  10912. 7:00:10into a lot is I I've worked with a lot
  10913. 7:00:12of cost data or pricing data. And when
  10914. 7:00:15it's in an Excel, it sometimes comes in
  10915. 7:00:18with um these currencies like a dollar
  10916. 7:00:20sign, a pound sign, things like that.
  10917. 7:00:23And when you put that into SQL, it just
  10918. 7:00:27is a nuisance, right? You're not going
  10919. 7:00:29to be able to run um it's going to go in
  10920. 7:00:33as a text or it's going to be like a
  10921. 7:00:35string, right? Because it has that
  10922. 7:00:37special character and you don't want
  10923. 7:00:38that. You don't want to have to then go
  10924. 7:00:40in and then change things around. You
  10925. 7:00:42just want to be able to start um you
  10926. 7:00:44know doing calculations on those
  10927. 7:00:46numbers. So, what you can do is
  10928. 7:00:48sometimes it'll come in as a text.
  10929. 7:00:50Sometimes it'll come in as um a
  10930. 7:00:52currency, which I think this one's a
  10931. 7:00:54currency. We are just going to change
  10932. 7:00:55that to be a number. And then we're
  10933. 7:00:58going to get rid of these. Oops.
  10934. 7:01:02And get rid of those. That it doesn't
  10935. 7:01:05look as pretty, but that is much more
  10936. 7:01:07useful than actually having the currency
  10937. 7:01:10on there um with the decimals. This
  10938. 7:01:12actually is so much easier when you when
  10939. 7:01:14you want to use it for almost anything
  10940. 7:01:16because you're able to add and uh do
  10941. 7:01:19things properly in other systems. In
  10942. 7:01:21Excel, I think it does understand it. Um
  10943. 7:01:23but you know that can cause issues. So
  10944. 7:01:26there is how you do that. The next thing
  10945. 7:01:29that we're going to look at is these
  10946. 7:01:30dates. And just notoriously whenever I
  10947. 7:01:33see a date field, I know there's going
  10948. 7:01:34to be an issue with it. It's very rare
  10949. 7:01:37that I get a date field that is perfect.
  10950. 7:01:40uh it just it it is genuinely is um is a
  10951. 7:01:44novelty when that happens and most of
  10952. 7:01:47the time it has to do with um let's say
  10953. 7:01:49a date comes into Excel and it's in a
  10954. 7:01:52text format or a date comes into Excel
  10955. 7:01:53and they're not the same. In this
  10956. 7:01:55example they are not the same um and we
  10957. 7:01:58just want them to all be similar. They
  10958. 7:02:00say date on if you look right here it
  10959. 7:02:02says date. It says date. It looks like
  10960. 7:02:05it should be the same. Um, but if we go
  10961. 7:02:09like this, it all looks the same, right?
  10962. 7:02:12There's no issues at all. If we were to
  10963. 7:02:16um try to use that, it may or may not be
  10964. 7:02:19an issue, but we don't want to leave
  10965. 7:02:21that to chance later on if you're using
  10966. 7:02:22this with Python or something like that,
  10967. 7:02:24it can cause issues. Uh, maybe not in
  10968. 7:02:26SQL because it may um see the underlying
  10969. 7:02:29um what's in the underlying cell, not
  10970. 7:02:31just what we see, but some systems
  10971. 7:02:34won't. And so, you want to make sure
  10972. 7:02:35that they're all the same. And so you
  10973. 7:02:37know what we were doing back here with
  10974. 7:02:39um oops with a party and we were looking
  10975. 7:02:42at this uh this filter and identifying
  10976. 7:02:44the issues. I usually do that on date
  10977. 7:02:47fields as well. And and oftent times um
  10978. 7:02:49you know just for just for demonstration
  10979. 7:02:51purposes oftent times I will get
  10980. 7:02:54something like that and then I'll come
  10981. 7:02:56up here and I'll notice that there's
  10982. 7:02:58this one random number that happens all
  10983. 7:03:01the time. All the time. Um, and so, you
  10984. 7:03:04know, you want to make sure that you um
  10985. 7:03:07that you look at these things and just
  10986. 7:03:09just do at least a quick glance, if not
  10987. 7:03:12kind of doing a kind of a deep dive into
  10988. 7:03:14it. But all we're going to do is we're
  10989. 7:03:16going to do both of these and we're
  10990. 7:03:18going to do a short date and let's take
  10991. 7:03:20a look and see if that fixed it. And so
  10992. 7:03:22now that they are all the same format
  10993. 7:03:24and that is fantastic. That is exactly
  10994. 7:03:26what we want. Uh we're going to go back
  10995. 7:03:28through here. We're going to get rid of
  10996. 7:03:31these. Um, again, this is a working um
  10997. 7:03:36this is a working document. Oops. Uh, we
  10998. 7:03:39need to we're I'm going to do um control
  10999. 7:03:42shift down. Oops. Let me go back up. Do
  11000. 7:03:46control shift down and copy. And what
  11001. 7:03:49I'm going to do right now is I'm
  11002. 7:03:50actually going to copy. And let me do it
  11003. 7:03:53right here. I'll show you. Sometimes I
  11004. 7:03:54do this. Doesn't just depends. I'm going
  11005. 7:03:56to go right here. I'm going to hit
  11006. 7:03:58rightclick. And I'm going to paste as a
  11007. 7:04:01value, which means it's not going to
  11008. 7:04:03take the um calculation or the formula
  11009. 7:04:05that I just did. Uh it's going to
  11010. 7:04:07actually paste it as that value. So, we
  11011. 7:04:09just replaced it. Um right here, you can
  11012. 7:04:12see up here it says equals trim of G2.
  11013. 7:04:15This now, now that I copied and pasted
  11014. 7:04:17it over as a value, um it got rid of
  11015. 7:04:22that um calculation and now it is
  11016. 7:04:24actually a string. So, we don't need
  11017. 7:04:26this anymore. And I'll do the same thing
  11018. 7:04:29over here as well.
  11019. 7:04:31I'm going to controll shift down copy
  11020. 7:04:37and I just hit the right key uh or the
  11021. 7:04:39left key sorry. Now I'm going to
  11022. 7:04:41rightclick and I'm going to do paste as
  11023. 7:04:44a value. And again has this proper and
  11024. 7:04:47now it doesn't have the proper. It's
  11025. 7:04:49actually the value that was here. So
  11026. 7:04:51that's really important to note. Uh and
  11027. 7:04:53we're going to get rid of that one. And
  11028. 7:04:55so now what we have is is already
  11029. 7:04:58looking much better. Now one of the last
  11030. 7:05:00things I want to look at is deleting
  11031. 7:05:01columns that we are not going to use.
  11032. 7:05:03And this is why it's so important to
  11033. 7:05:05keep a backup or or the raw data not in
  11034. 7:05:08this file because if you start saving
  11035. 7:05:10over this file and this is your raw file
  11036. 7:05:12uh that can mess up a lot of things and
  11037. 7:05:14that happened to me before and it's
  11038. 7:05:16terrible and then you have to request
  11039. 7:05:18another file or you have to go back and
  11040. 7:05:20find it or something like that. It's
  11041. 7:05:21terrible. Um, so, so this is our working
  11042. 7:05:24document. So, we can mess with this and
  11043. 7:05:26do whatever we want for our purposes.
  11044. 7:05:28Now, for us, um, I can already tell you
  11045. 7:05:31that this prior is a bunch of nonsense.
  11046. 7:05:33And we do not need it. We're not going
  11047. 7:05:35to use it for anything. And it and if we
  11048. 7:05:37have, um, this is a small very small
  11049. 7:05:39data set. This only has like um, let's
  11050. 7:05:41say, you know, one, two, three, four,
  11051. 7:05:44five, six, seven, eight. We have like
  11052. 7:05:46eight columns that we're, you know, kind
  11053. 7:05:47of using that has data. Eight or nine.
  11054. 7:05:50Now, that's a small data set. I've had
  11055. 7:05:52ones with literally like hundreds um and
  11056. 7:05:55and it has so many columns uh so much
  11057. 7:05:58data and sometimes it's good to just
  11058. 7:06:00trim it back to the things you know
  11059. 7:06:02you're going to use. This to me is
  11060. 7:06:03absolutely useless. Um we're going to
  11061. 7:06:05delete that. And then right over here,
  11062. 7:06:07it's pretty redundant. Um it's just one
  11063. 7:06:10number off. But if we scroll down just a
  11064. 7:06:12little bit, um it goes it's basically
  11065. 7:06:15just counts. It's a I you could even
  11066. 7:06:17call it a unique um identifier if you
  11067. 7:06:20want. Sure, why not? But we don't need
  11068. 7:06:22both. Um, so we're going to get rid of
  11069. 7:06:23this first one. And now we have more of
  11070. 7:06:25the useful and relevant data rather than
  11071. 7:06:27the stuff that we absolutely know that
  11072. 7:06:29we are not going to use. Um, these date
  11073. 7:06:31updateds and date created, we may never
  11074. 7:06:33use them, but we might. Um, so it's it
  11075. 7:06:36doesn't hurt to keep it on hand. Those
  11076. 7:06:38other ones are ones that we are almost
  11077. 7:06:39certain we will never use again. Keep a
  11078. 7:06:42backup just in case you need it. You can
  11079. 7:06:44always go back and get it. So, you know,
  11080. 7:06:47if you go back to what we started with
  11081. 7:06:48and you look at what we have now, it is
  11082. 7:06:50much cleaner. It's much more usable. And
  11083. 7:06:53these are small, subtle changes. Um,
  11084. 7:06:55especially with this very small data set
  11085. 7:06:57of only like 50 rows or or 46 rows. But
  11086. 7:07:00you're going to be working with data
  11087. 7:07:01sets that are thousands, tens of
  11088. 7:07:03thousands, hundreds of thousands of
  11089. 7:07:05rows. And you need to know how to kind
  11090. 7:07:07of look at this data, standardize it,
  11091. 7:07:09um, format it properly for what you're
  11092. 7:07:11going to be using it for. If you're
  11093. 7:07:13keeping it in Excel, there are different
  11094. 7:07:15things that you may do than if you're
  11095. 7:07:16putting it into a database or going to
  11096. 7:07:18be using it in, you know, um using
  11097. 7:07:22Python to to access it. So, you need to
  11098. 7:07:25kind of know your use case. But these
  11099. 7:07:27are some things that I do all the time
  11100. 7:07:30to kind of clean up the data before I
  11101. 7:07:32use it for something. Whether I'm
  11102. 7:07:33creating pivot tables or I'm inserting
  11103. 7:07:35it into or I'm putting it into SQL,
  11104. 7:07:38these are things I do all the time. And
  11105. 7:07:39so hopefully that helps give you kind of
  11106. 7:07:41an idea of some of the things that you
  11107. 7:07:43should be looking for when you're
  11108. 7:07:45actually cleaning data. And it's really
  11109. 7:07:46important to understand why you're
  11110. 7:07:48actually making these changes and the
  11111. 7:07:50reason you're making these changes
  11112. 7:07:51because some of the things that I did
  11113. 7:07:52today may not be things you want to do
  11114. 7:07:54on a different data set that has
  11115. 7:07:56different uses and different um purposes
  11116. 7:07:58for. So, you know, take everything that
  11117. 7:08:00I've said and and apply it um with a
  11118. 7:08:03little grain of salt to your data set
  11119. 7:08:05because your specific needs may be
  11120. 7:08:06different than what I wanted when I was
  11121. 7:08:09cleaning my data set. So, I hope this
  11122. 7:08:11was helpful. I hope you this gave you a
  11123. 7:08:13small glimpse of some of the things that
  11124. 7:08:14I'm looking for when I clean a data set
  11125. 7:08:16or I get a new data set in and I'm kind
  11126. 7:08:18of, you know, analyzing it, figuring out
  11127. 7:08:20what I need to fix in it. I hope this
  11128. 7:08:22has been helpful. Uh with that being
  11129. 7:08:24said, thank you so much for watching. I
  11130. 7:08:26really appreciate it. If you like this
  11131. 7:08:28video, be sure to like and subscribe
  11132. 7:08:29below. And I'll see you in the next
  11133. 7:08:31video.
  11134. 7:08:43What's going on everybody? Welcome back
  11135. 7:08:45to the Excel tutorial series. Today
  11136. 7:08:47we're going to create an entire project
  11137. 7:08:48in Excel.
  11138. 7:08:51[music]
  11139. 7:08:54Now, if you've never done a complete
  11140. 7:08:56project in Excel where you take the
  11141. 7:08:58data, you clean it, and then you create
  11142. 7:09:00an actual dashboard where people can
  11143. 7:09:01click on things and filter things, this
  11144. 7:09:04is going to be a really great learning
  11145. 7:09:05opportunity, as well as potentially, you
  11146. 7:09:07know, a simple project that you can use
  11147. 7:09:09for your portfolio. Or you can spice
  11148. 7:09:10things up and go a little farther than
  11149. 7:09:12what we're going to be doing in today's
  11150. 7:09:13video. I will walk you through every
  11151. 7:09:15single step of the way, and hopefully we
  11152. 7:09:16learn something together. And without
  11153. 7:09:18further ado, let's jump right into it.
  11154. 7:09:20Let's jump onto my screen and get
  11155. 7:09:21started with the project. All right, so
  11156. 7:09:23this is the data set that we're going to
  11157. 7:09:25be working with. I will leave a link in
  11158. 7:09:26the description to my GitHub where you
  11159. 7:09:28can go and download it so you can be
  11160. 7:09:29working with the exact same data set
  11161. 7:09:30that I am using. Now, before we actually
  11162. 7:09:33get into this data and start looking at
  11163. 7:09:34it, I'm going to show you what the final
  11164. 7:09:36dashboard is going to look like. Um,
  11165. 7:09:38we're going to create a few different
  11166. 7:09:39types of visualizations. Nothing too
  11167. 7:09:41crazy. Um, and then we'll create some
  11168. 7:09:43filters as well, so we can kind of, you
  11169. 7:09:45know, create some interactive filters
  11170. 7:09:47with our data. So, let's go right on
  11171. 7:09:49over to our data set. Now, I'm going to
  11172. 7:09:53hide this because we are not going to
  11173. 7:09:55use that. But what I am going to do
  11174. 7:09:56before we do anything is I'm going to
  11175. 7:09:58create a dashboard
  11176. 7:10:01and I'm going to create a pivot table.
  11177. 7:10:04Oops.
  11178. 7:10:06And I'm going to create a
  11179. 7:10:09working sheet. So, um, all these things
  11180. 7:10:13have different uses and I'll explain
  11181. 7:10:16that as we go along. So, this is our
  11182. 7:10:18data set. Um, I'm going to copy this
  11183. 7:10:21over to our working sheet. When I go
  11184. 7:10:23into, you know, an Excel and I'm working
  11185. 7:10:26on something, I don't like to, you know,
  11186. 7:10:28use just the one that I was using in
  11187. 7:10:30case I mess something up and it saves
  11188. 7:10:31over it or some issue. I like to create
  11189. 7:10:33a working sheet and keep the raw data
  11190. 7:10:35right over here. It just makes my life
  11191. 7:10:37easier. I don't have to save it and
  11192. 7:10:38then, you know, open up a different
  11193. 7:10:40Excel to compare them. So, we have our
  11194. 7:10:42bike buyers. This is our working sheets.
  11195. 7:10:44This is our raw data. This is the one
  11196. 7:10:45we're actually be working on today. So,
  11197. 7:10:48let's um let's start looking at it
  11198. 7:10:50really quick and just kind of glance and
  11199. 7:10:51see what data we're working with and
  11200. 7:10:54then we'll start cleaning it up, making
  11201. 7:10:56it more useful for what we are going to
  11202. 7:10:57be using it for and then we'll start
  11203. 7:11:00building out the dashboard. So, right
  11204. 7:11:03here we have an ID that should be a
  11205. 7:11:06unique ID to each person. Uh this is
  11206. 7:11:08their marital status, so married or
  11207. 7:11:10single. This is their gender, male,
  11208. 7:11:13female. We have their income, children,
  11209. 7:11:16their education, their occupation, do
  11210. 7:11:18they own a home, how many cars they own,
  11211. 7:11:21how long their commute is, the region
  11212. 7:11:24where they live, their age, and if they
  11213. 7:11:26purchased a bike. And this column right
  11214. 7:11:28here is extremely important. This is
  11215. 7:11:30going to tell us whether they did or did
  11216. 7:11:31not buy a bike. So, we got their
  11217. 7:11:33information. They're looking for a bike,
  11218. 7:11:35but they either decided not to buy a
  11219. 7:11:36bike or they did buy a bike. And we're
  11220. 7:11:38going to be using that one a lot in in
  11221. 7:11:40this video. And so um you know this is
  11222. 7:11:44basically the data set that we're
  11223. 7:11:46working with um some of the demographics
  11224. 7:11:48and and information behind the person.
  11225. 7:11:51So what we want to do when we are
  11226. 7:11:53cleaning the data before we do anything
  11227. 7:11:56uh I like to see if there are any
  11228. 7:11:57duplicates in here um what we're going
  11229. 7:11:59to do is come right up here. We can go
  11230. 7:12:02to uh
  11231. 7:12:05where is it? Right here we got remove
  11232. 7:12:07duplicates. So we're going to click on
  11233. 7:12:08that. It selects every single one. We
  11234. 7:12:11just want to see if there's any useless
  11235. 7:12:13duplicated data that we do not need. Uh,
  11236. 7:12:16and the data is a header. So, we're
  11237. 7:12:17going to click okay.
  11238. 7:12:19All right. So, we had a ton of
  11239. 7:12:20duplicates in there. Uh, for whatever
  11240. 7:12:22reason. So, we do have duplicates in
  11241. 7:12:24there. So, I'm glad we did that.
  11242. 7:12:25Otherwise, we would have uh, you know,
  11243. 7:12:28not good data. We don't want that. Let's
  11244. 7:12:32start right over here. Um, the ID, of
  11245. 7:12:34course, we're not going to change. The
  11246. 7:12:35marital status and gender are M's, S's,
  11247. 7:12:39Fs, and M's. Um, this isn't inherently a
  11248. 7:12:43bad thing to have it like this, but, you
  11249. 7:12:45know, we have to think about it from the
  11250. 7:12:46perspective of someone who's going to be
  11251. 7:12:48using this dashboard. Do they know what
  11252. 7:12:50M and S is? Do they know what M uh and F
  11253. 7:12:53is? And if they don't, it's better to
  11254. 7:12:55just spell it out for the most part. Um,
  11255. 7:12:58so let's just do that. So, we're going
  11256. 7:13:00to click on the column B. We're going to
  11257. 7:13:02hit CtrlH. That's going to bring up our
  11258. 7:13:04find and replace. Now, there's an M in
  11259. 7:13:07both of these columns and there's
  11260. 7:13:09different things. One is married and one
  11261. 7:13:11means male. So, what we're going to do
  11262. 7:13:13is we're going to search by columns. Um,
  11263. 7:13:17and we'll have match case. I don't think
  11264. 7:13:18that's going to change anything, but
  11265. 7:13:19that just means an exact match. Uh, and
  11266. 7:13:21we're going to do M equals and we're
  11267. 7:13:24going to replace it with married. And
  11268. 7:13:26we'll replace all. Awesome. And then
  11269. 7:13:29we'll do S is single. This one is super
  11270. 7:13:33easy. We're going to do the exact same
  11271. 7:13:35thing right here. So, column C and hit
  11272. 7:13:38control H. We'll do still has by column.
  11273. 7:13:41So, we'll do M is male.
  11274. 7:13:46We'll replace all of those and F is
  11275. 7:13:50female. And replace all those. That's
  11276. 7:13:53great.
  11277. 7:13:55Uh, you know, the next column right here
  11278. 7:13:57is income. And in a se in a previous
  11279. 7:14:00video, I talked about how I don't
  11280. 7:14:01typically like it in this format. And
  11281. 7:14:03that's true. Um, if you're doing
  11282. 7:14:05calculations on it or or any other
  11283. 7:14:07thing, it can mess it up sometimes
  11284. 7:14:08having the dollar sign or it being a
  11285. 7:14:10currency. We're not really going to mess
  11286. 7:14:13with it too much right now. Um, what we
  11287. 7:14:15can do is just kind of we'll make sure
  11288. 7:14:19all of it's currency. Um, we'll just go
  11289. 7:14:21like that to make it a little simpler,
  11290. 7:14:23but we're not going to change it to like
  11291. 7:14:25a numeric. Um, we will use this in the
  11292. 7:14:29visualization. We'll see how it looks
  11293. 7:14:30and if we need to, we'll come back and
  11294. 7:14:32change it. If not, we'll keep it how it
  11295. 7:14:34is. Um, so that's all we're going to do
  11296. 7:14:36to that one. Uh, the children, those
  11297. 7:14:39look good. We have education,
  11298. 7:14:42partial college, partial high school.
  11299. 7:14:44This looks fine to me. Um, if there's
  11300. 7:14:46any spelling errors or anything like
  11301. 7:14:48that, of course, we need to clean that
  11302. 7:14:49up. It doesn't look like there is.
  11303. 7:14:51Occupation,
  11304. 7:14:54skilled manual, manual. Okay, those
  11305. 7:14:56should be separate. Are they a
  11306. 7:14:58homeowner?
  11307. 7:14:59Should just be yes or no. All right, we
  11308. 7:15:03have cars. 1 2 3 4. Good night. Who owns
  11309. 7:15:06four cars? Um, and then that we have the
  11310. 7:15:07commute distance. Uh, and you know,
  11311. 7:15:09there's nothing terrible about this.
  11312. 7:15:11It's giving you ranges. Um, which can be
  11313. 7:15:13a good thing. I say let's keep it for
  11314. 7:15:17now, but I have a feeling when we get
  11315. 7:15:19further and we start using it in the
  11316. 7:15:20visualization, we may want to change
  11317. 7:15:22this. So, let's just hold off for now.
  11318. 7:15:24Um, but if needed, we will come back to
  11319. 7:15:27this and we will change this. Um, and
  11320. 7:15:30then we have our region and that looks
  11321. 7:15:33totally fine. And we have our age. Now,
  11322. 7:15:36when you're using ages, typically you
  11323. 7:15:38have some type of like age bracket or or
  11324. 7:15:41age range. And you do that because there
  11325. 7:15:44are so many ages in here, right? It's 25
  11326. 7:15:47all the way down to 89. And if you're
  11327. 7:15:49using that on some type of
  11328. 7:15:50visualization, it could just get really
  11329. 7:15:52messy. And so you'll create kind of, you
  11330. 7:15:54know, just brackets around these so that
  11331. 7:15:57you can kind of condense it and make it
  11332. 7:15:59a little bit easier to understand. So
  11333. 7:16:02let's do that and just create a new
  11334. 7:16:04column and then we can use that for our
  11335. 7:16:07dashboard. So let's go right up here.
  11336. 7:16:08We're just going to create a new column.
  11337. 7:16:11Uh we'll call this age brackets.
  11338. 7:16:15And what we can do is we can use an if
  11339. 7:16:18statement to kind of say if it's older
  11340. 7:16:22than or less than and and and kind of
  11341. 7:16:24give them these ranges. Um that's one
  11342. 7:16:27way to do it and that's the way we're
  11343. 7:16:28going to do it right now. So let's go up
  11344. 7:16:31here and what we want to do is we want
  11345. 7:16:34to say is going to we're going to say
  11346. 7:16:36equals and we're going to do if and
  11347. 7:16:38we're going to close that parenthesis.
  11348. 7:16:40Now, what we're going to say is if this,
  11349. 7:16:44we'll go right back up here. If this is
  11350. 7:16:47less than, so we're going to do this 31
  11351. 7:16:51and we're going to say comma. So, if
  11352. 7:16:53they are less than 31, what do we want
  11353. 7:16:56to call them? What do we want their
  11354. 7:16:58their, you know, name to be? We'll call
  11355. 7:17:02them adolescent. Oops, that's not how
  11356. 7:17:06you spell adolescent. Adolescent. Um,
  11357. 7:17:09and then if they're not, what we're
  11358. 7:17:10going to do is we're going to say it's
  11359. 7:17:12invalid.
  11360. 7:17:15Okay. And let's just see if this one
  11361. 7:17:16works first.
  11362. 7:17:18All right. It's not working at all. Um,
  11363. 7:17:21okay. So, basically what we did was um
  11364. 7:17:24incorrect. We did it backward. Uh, we
  11365. 7:17:26want to do I said, uh, L2 is greater
  11366. 7:17:29than 31. No, we want to do like this.
  11367. 7:17:32So, let's do that now.
  11368. 7:17:35All right. and it should pull up where
  11369. 7:17:37if they're under the age of 31. So if
  11370. 7:17:40they're 30 or below is basically what
  11371. 7:17:42it's saying. So if they're 31 they'll be
  11372. 7:17:45invalid, but if they're 30 or below it's
  11373. 7:17:47adolescent. So it is working properly.
  11374. 7:17:50Um and let's see what it see what it
  11375. 7:17:52says. Perfect. So this one is working
  11376. 7:17:54and and now what we want to do is we
  11377. 7:17:56actually want to build on this and make
  11378. 7:17:58it uh kind of like a nested if statement
  11379. 7:18:01if you've ever heard of that or done
  11380. 7:18:03that before. So this is our first if
  11381. 7:18:05statement and this is going to be this
  11382. 7:18:08is invalid. This is our value if false
  11383. 7:18:10statement. This whole statement is going
  11384. 7:18:13to become our value if false for a
  11385. 7:18:16different if statement. Um so let let me
  11386. 7:18:20write it out and hopefully that'll make
  11387. 7:18:22sense. But we're going to say if do open
  11388. 7:18:25parenthesis and we're going to do it
  11389. 7:18:26like this. And let's just get rid of
  11390. 7:18:27this for a second.
  11391. 7:18:31All right. Uh what did I do? And let me
  11392. 7:18:34do oops, give me a second.
  11393. 7:18:39Okay, we have our if. Let me just write
  11394. 7:18:41that out again. We have our if. There we
  11395. 7:18:44go. So now what we're going to do is
  11396. 7:18:46we're going to write basically the next
  11397. 7:18:49part of it. So we're going to say if
  11398. 7:18:51that L2 is and we're going to do this
  11399. 7:18:54time we're going to do greater than or
  11400. 7:18:55equal to 31. So now it's going to
  11401. 7:18:58include that 31. So right here we did
  11402. 7:19:00anything less than 31. So is 30 and
  11403. 7:19:03below. This one is going to be 31 and
  11404. 7:19:06above. So we're gonna say these people
  11405. 7:19:08are middle age.
  11406. 7:19:12And if not, then it's going to go to
  11407. 7:19:15this if statement. And then we need to
  11408. 7:19:17close it, I believe. So now let's try
  11409. 7:19:18this.
  11410. 7:19:20All right.
  11411. 7:19:22Fantastic. Now if um everybody should be
  11412. 7:19:25in one of these areas, right? everyone
  11413. 7:19:27should either be an adolescent or
  11414. 7:19:29middle-ag because basically all we're
  11415. 7:19:30saying is is if they're older than 31 or
  11416. 7:19:3330 or below. That's all these two
  11417. 7:19:35statements do. So we have um you know
  11418. 7:19:38our next group. Now we can add and go
  11419. 7:19:41even further into this and now we can
  11420. 7:19:44use this entire thing as the um what was
  11421. 7:19:47it called? The value if false uh
  11422. 7:19:50section. So that's what we're going to
  11423. 7:19:52do. We're going to do one more. So we're
  11424. 7:19:53going to have three different
  11425. 7:19:54categories. So, we're going to say if
  11426. 7:19:56and do an open parenthesis. And we're
  11427. 7:19:59going to say if Oh, actually, let's do
  11428. 7:20:01it. Um,
  11429. 7:20:03let's not do it to this one. Let's do it
  11430. 7:20:06to this top one just easier.
  11431. 7:20:09Uh, so we're going to say if open
  11432. 7:20:11parenthesis, we're going to say L2. And
  11433. 7:20:15this time we're going to say anybody
  11434. 7:20:17over the age of 50. Uh, or we can do 55.
  11435. 7:20:21Let's do 55. So, we do 55. and we're
  11436. 7:20:24going to call them old and we'll do
  11437. 7:20:28comma and this is the value if statement
  11438. 7:20:31and we need to close the parenthesis. So
  11439. 7:20:33let's try this. Anybody over the age of
  11440. 7:20:3655 should have old. Um you know maybe
  11441. 7:20:39we'll do 54. So anybody who is 55 is
  11442. 7:20:43considered old. I think that's fair. I
  11443. 7:20:45think that's fair guys. Oops. I should
  11444. 7:20:47have done I should have done that to
  11445. 7:20:49this one. Let me get out of this and
  11446. 7:20:51we'll do 54. Uh my dad is 55. That's why
  11447. 7:20:56I'm doing it like this. This is for you,
  11448. 7:20:57Dad. Uh because he should be in this old
  11449. 7:21:00category to be fair. So now we have
  11450. 7:21:02adolescent, adolescent, middle-ag, and
  11451. 7:21:05old. These are three categories. So we
  11452. 7:21:07can now have these buckets, these
  11453. 7:21:09different groups of ages, and it's much
  11454. 7:21:12more usable than these individual ages.
  11455. 7:21:14Um and so we will be using this in our
  11456. 7:21:17in our dashboard for sure. Now, our next
  11457. 7:21:19one is the purchased bike. Uh, and we're
  11458. 7:21:22not going to do anything with that. So,
  11459. 7:21:24uh, you know, that is that is that one.
  11460. 7:21:27And, you know, there wasn't a ton to
  11461. 7:21:30clean up here. We removed some
  11462. 7:21:31duplicates. Um, I don't know why it says
  11463. 7:21:34that. What did I do? Married.
  11464. 7:21:38Married. What does this mean even mean?
  11465. 7:21:42I don't Did I write that? Did I mess
  11466. 7:21:43this up, guys? Oh,
  11467. 7:21:47when I did the M and the S uh
  11468. 7:21:51replacement in there, it replaced it
  11469. 7:21:53with married and single. It's supposed
  11470. 7:21:55to say marital status. Oops.
  11471. 7:21:59Thanks for catching that, guys. Thanks
  11472. 7:22:00for catching that. I hope that's how you
  11473. 7:22:02spell marital. Uh we'll see. So, uh we
  11474. 7:22:06are going to keep it just like this. Now
  11475. 7:22:08what we are going to now
  11476. 7:22:12now what we are going to do is build
  11477. 7:22:15pivot tables with this data. So we had
  11478. 7:22:17our raw data, we have our working sheet
  11479. 7:22:20and now we want to create pivot tables.
  11480. 7:22:22And pivot tables is how you actually
  11481. 7:22:24help build your dashboards or help build
  11482. 7:22:26your visualizations. So we're going to
  11483. 7:22:28go right here. We're going to hit
  11484. 7:22:30Whoops. Get rid of that. We're going to
  11485. 7:22:33go right here. We're going to insert and
  11486. 7:22:35we're going to say pivot table. And it's
  11487. 7:22:37going to ask us what range.
  11488. 7:22:40So we're going to go back to the working
  11489. 7:22:41sheet and we'll just click here and hit
  11490. 7:22:43control A.
  11491. 7:22:46This is going to select all of our data
  11492. 7:22:48for us. So it's really easy. And we're
  11493. 7:22:51going to hit okay. And so now we have
  11494. 7:22:54all of our
  11495. 7:22:56uh pivot I don't need I don't need to
  11496. 7:22:57pull it out that far. That was way too
  11497. 7:22:58far. And now we have all of our pivot
  11498. 7:23:00table information over here. And so that
  11499. 7:23:03should make it really easy to you know
  11500. 7:23:05actually build out. So what we're going
  11501. 7:23:07to do is start selecting what columns
  11502. 7:23:09and what data we actually want to work
  11503. 7:23:11with. So the first one that we are going
  11504. 7:23:12to build out is a dashboard that is
  11505. 7:23:15basically looking at the average income
  11506. 7:23:17of somebody who either bought or did not
  11507. 7:23:19buy a bike. So we need in this one we're
  11508. 7:23:24going to need their income. That's
  11509. 7:23:25definitely going to be a value right
  11510. 7:23:26here. Um but we want to break it out by
  11511. 7:23:30male and female. So let's look at their
  11512. 7:23:32gender. We're going to pull that down
  11513. 7:23:34into the rows. So, um, this is basically
  11514. 7:23:36a sum and no, let's look at
  11515. 7:23:40let's make this an average. So, I just
  11516. 7:23:41went to the, um, I clicked right here. I
  11517. 7:23:44went to the value field settings and
  11518. 7:23:46we're just going to do an average.
  11519. 7:23:49All right. And then we are going to make
  11520. 7:23:51these, um, and as you can see, there's
  11521. 7:23:55four decimal points. Um, we'll keep it
  11522. 7:23:57as is right now, but we may need to go
  11523. 7:23:58back and change something. Then we're
  11524. 7:24:00going to look at if they purchased a
  11525. 7:24:01bike or not, and we're going to put that
  11526. 7:24:03right here.
  11527. 7:24:05So we can see that uh right here for the
  11528. 7:24:08people who did not buy a bike the
  11529. 7:24:10females their their average salary was
  11530. 7:24:1253,000 the average salary for the
  11531. 7:24:15average salary for males was 56,000 for
  11532. 7:24:17yes the ones who did buy a bike the
  11533. 7:24:20average salary was 55 for female and 60
  11534. 7:24:23for males. So the people who had a
  11535. 7:24:25little bit more money are buying bikes
  11536. 7:24:27and you can also see that uh the men are
  11537. 7:24:29making more money in this data set just
  11538. 7:24:31overall in general. Um, so
  11539. 7:24:35let's make the visualization really
  11540. 7:24:37quick, but you know, I don't know. I'm
  11541. 7:24:39not a huge fan of these decimal points.
  11542. 7:24:41And maybe we can just change that in the
  11543. 7:24:42visualization. We'll see. Um,
  11544. 7:24:46oops. That's not what I meant to do.
  11545. 7:24:49Um, let's do that. So, what we are going
  11546. 7:24:53to do is we're going to click into here.
  11547. 7:24:54We're going to click insert and we're
  11548. 7:24:56going to go to these recommended charts.
  11549. 7:24:58And it's going to bring up basically
  11550. 7:25:00every single type that we would want.
  11551. 7:25:02Um, and we can just click in here and
  11552. 7:25:04see which one looks good. Uh, oh yeah, I
  11553. 7:25:07love those 3D ones. Those are my
  11554. 7:25:09favorite. You guys know that. Uh, let's
  11555. 7:25:11let's use this one right here. Pretty
  11556. 7:25:13simple. Um, whoops. Let's pull this
  11557. 7:25:15right over here. And as is, it looks
  11558. 7:25:19pretty good. Um, you know, it shows
  11559. 7:25:22male, female. We have the average or the
  11560. 7:25:25incomes right here, whether they did or
  11561. 7:25:27did not purchase it. Um, and so at a
  11562. 7:25:30glance, it's pretty easy to see. Let's
  11563. 7:25:32see if there's anything. Um, you know,
  11564. 7:25:36if you want to change up style-wise, go
  11565. 7:25:38for it. I'm just going to keep it as is.
  11566. 7:25:40Um, but let's see if there's anything we
  11567. 7:25:42need to add, right? Do we want to add
  11568. 7:25:43these access titles? Uh, for the most
  11569. 7:25:46part, I I tend to do that. Um, it makes
  11570. 7:25:50it pretty easy to see. So, we can go in
  11571. 7:25:52here and we can just click it like this
  11572. 7:25:54and we'll say income
  11573. 7:25:57and we'll say
  11574. 7:26:00we'll do gender. So, that's what that
  11575. 7:26:03is.
  11576. 7:26:05And let's go back in here. Do we want to
  11577. 7:26:07add a chart title? We definitely want to
  11578. 7:26:10add a chart title. Uh, for most of
  11579. 7:26:11these, we'll add a chart title for sure.
  11580. 7:26:13So, we'll say average income
  11581. 7:26:16per purchase.
  11582. 7:26:18Um, I don't know if that's 100% right,
  11583. 7:26:20but we'll we'll we'll use it. Uh, if we
  11584. 7:26:22need to change it to be, you know, by
  11585. 7:26:24gender or something, we can. But, um,
  11586. 7:26:26for now, let's see. Do we want to add
  11587. 7:26:28data labels? Uh, definitely not. Uh, a
  11588. 7:26:31data table. Um, we can do this. It may
  11589. 7:26:34make it a little easier to read. I will
  11590. 7:26:36say that again, these numbers are just
  11591. 7:26:38these decimal points are really throwing
  11592. 7:26:39me off. Let's go see if um, we can
  11593. 7:26:41change it in here. Let's go to
  11594. 7:26:45see if we can just make these numbers.
  11595. 7:26:47Okay. And um we can keep it like that or
  11596. 7:26:51we can even do something like this. Add
  11597. 7:26:54commas.
  11598. 7:26:56Yeah, I'm going to keep it just like
  11599. 7:26:57this. I I think this just looks the
  11600. 7:26:59best. Um again, I'm I'm getting adding
  11601. 7:27:01commas here. I'm changing the um decimal
  11602. 7:27:04place right here. It just makes it look
  11603. 7:27:07a little nicer, a little cleaner. Um so,
  11604. 7:27:10let's keep this exactly how it is. um we
  11605. 7:27:15can always change things if we want to
  11606. 7:27:17uh if we want to come back to it. So
  11607. 7:27:19that we created our pivot table and then
  11608. 7:27:20we created our visualization. Basically
  11609. 7:27:23exactly what we're going to do for all
  11610. 7:27:24of these because again all of these need
  11611. 7:27:27um you know all of these need pivot
  11612. 7:27:29tables in order to create the
  11613. 7:27:30visualization. So let's um get out of
  11614. 7:27:32here. We are going to scroll down and
  11615. 7:27:35we're going to create our next pivot
  11616. 7:27:37table. And once we get done with all of
  11617. 7:27:39the pivot tables that we need or all the
  11618. 7:27:41visualizations that we need, then we
  11619. 7:27:42will um we will start. So we're going to
  11620. 7:27:46do control A
  11621. 7:27:48do okay and basically do the exact same
  11622. 7:27:50thing that we did. Um this time we're
  11623. 7:27:52going to look at the distance. So for
  11624. 7:27:54this one I wanted to see you know I try
  11625. 7:27:57to you know I created this already. I've
  11626. 7:27:58already done this entire project through
  11627. 7:28:00but I haven't really talked about why or
  11628. 7:28:02what we're going to look at for this
  11629. 7:28:04one. you know, we're looking at is their
  11630. 7:28:08income, does it change whether they
  11631. 7:28:10bought or didn't buy one? Um, so if they
  11632. 7:28:12said yes, you know, is there a reason?
  11633. 7:28:15Are they making more money? Is, you
  11634. 7:28:16know, our price points are the
  11635. 7:28:18customers, do they make more money, so
  11636. 7:28:20should we cater to them or not? Uh,
  11637. 7:28:22that's a good question. Uh, another
  11638. 7:28:24thing is, you know, we're we sell bikes
  11639. 7:28:26or this person sells bikes. So,
  11640. 7:28:28commuting distance definitely makes a
  11641. 7:28:30difference. you know, does the person
  11642. 7:28:32who is buying a bike live one mile away
  11643. 7:28:35from where they work or 20 miles away?
  11644. 7:28:37Uh, this will help us determine, this
  11645. 7:28:39next visualization will help us
  11646. 7:28:40determine, you know, who who is doing
  11647. 7:28:42that or who's buying it. So, what we're
  11648. 7:28:45going to do is we are going to look at
  11649. 7:28:48the um that one that we were looking at
  11650. 7:28:52earlier, the commute distance. So, we're
  11651. 7:28:54going to bring that right over here. So,
  11652. 7:28:55we have these, you know, one mile, 10
  11653. 7:28:58mile, 1.2, etc.
  11654. 7:29:01Now we are going to uh again we're going
  11655. 7:29:03to look at if they purchased a bike.
  11656. 7:29:05That's really important. And let's make
  11657. 7:29:08that the column as well. So now what we
  11658. 7:29:10have is a count of these nos and yeses
  11659. 7:29:12whether they did or did not buy a bike.
  11660. 7:29:14Um one of the issues I already see and
  11661. 7:29:17we'll I'm going to visualize it and then
  11662. 7:29:18I'll show you this 10 miles you know
  11663. 7:29:21it's right next to the 0.1. So it's not
  11664. 7:29:23an order. Um and that could be that
  11665. 7:29:27could be an issue. Um, so we may have to
  11666. 7:29:30revise that somehow to put it at the
  11667. 7:29:32very bottom because we can either do
  11668. 7:29:34ascending or descending. Uh, either one
  11669. 7:29:38I don't think is going to work. So, we
  11670. 7:29:40may have to work through that in just a
  11671. 7:29:41second. Um, don't know if I did that in
  11672. 7:29:43my plan for that. Um, yeah. So, it has
  11673. 7:29:46this big dip. Um,
  11674. 7:29:50yeah. So, let's let's create it. Um,
  11675. 7:29:52that's okay. We're going to figure this
  11676. 7:29:54one out together because I honestly um I
  11677. 7:29:57didn't plan for this one. So, okay, we
  11678. 7:29:59have 0.1 miles. That's exactly where it
  11679. 7:30:01needs to be. The one, the two, the five,
  11680. 7:30:04that's exactly where it needs to be.
  11681. 7:30:05This 10 miles is not. And let's see if I
  11682. 7:30:09change that 10 m 10 plus miles to 10
  11683. 7:30:12miles plus. Let's see if that'll put it
  11684. 7:30:15down here because I I don't know if it's
  11685. 7:30:17looking at I don't know if it's reading
  11686. 7:30:20it weird. Um, but let's go into this
  11687. 7:30:22working sheet and let's go right here
  11688. 7:30:26and we're going to do Ctrl H and we'll
  11689. 7:30:28do Oops, not this one.
  11690. 7:30:31Um, 10 miles plus. Let's get that in
  11691. 7:30:35there. And we're going to do 10
  11692. 7:30:38uh miles
  11693. 7:30:40plus. I I don't know if that's actually
  11694. 7:30:42going to work. Um, we will see. So,
  11695. 7:30:45let's go back to the pivot table. Let's
  11696. 7:30:48re go to the data. Let's refresh. Uh,
  11697. 7:30:52no, it didn't. It didn't change it. Um,
  11698. 7:30:54okay. So, let's think about this. Maybe
  11699. 7:30:57if we change it to like a letter, it
  11700. 7:31:00might change down here. So, start it
  11701. 7:31:01with uh miles. That could work. Um,
  11702. 7:31:04let's try it. Okay, it's already
  11703. 7:31:07selected.
  11704. 7:31:09Let's do is it 10 plus miles? Okay. So,
  11705. 7:31:12let's do
  11706. 7:31:15um
  11707. 7:31:17m uh more than 10 miles
  11708. 7:31:22and we'll replace all. Let's get rid of
  11709. 7:31:25this.
  11710. 7:31:27Let's go to the pivot and refresh. All
  11711. 7:31:31right. Okay. So, it's not perfect, but
  11712. 7:31:34it works. Um and for what we're doing, I
  11713. 7:31:37think we'll keep it how it is. So, we
  11714. 7:31:40have our second one. Uh, and
  11715. 7:31:44you know, there are different ways you
  11716. 7:31:45can kind of change this one. Um, you
  11717. 7:31:48know, on the last one, we did a ton of
  11718. 7:31:49different stuff. We can do
  11719. 7:31:53just do
  11720. 7:31:56commute distance.
  11721. 7:31:58And we can say,
  11722. 7:32:01what do we want to say on this one? What
  11723. 7:32:02is this? Oh, this is the count. Um, do
  11724. 7:32:06we have to do we have to keep this one?
  11725. 7:32:10Um, no. There we go. I'm just going to
  11726. 7:32:13do um just one and say
  11727. 7:32:19commute distance.
  11728. 7:32:22And let's add a title
  11729. 7:32:25chart title. We can make this one um
  11730. 7:32:28let's say distance
  11731. 7:32:33per customer. Uh that's not 100% true
  11732. 7:32:36because it's no or yes. Um that's that's
  11733. 7:32:38the important part of this. It's
  11734. 7:32:41distance um average distance. Uh let's
  11735. 7:32:45see. We'll just say customer commute.
  11736. 7:32:52All right. And we'll keep it just like
  11737. 7:32:53that. All right. Perfect. I don't think
  11738. 7:32:57um let me see. I don't think there's
  11739. 7:32:59anything else we need to add on that
  11740. 7:33:00one. All right. Now, let's go right down
  11741. 7:33:02here. We're going to create our very
  11742. 7:33:04last one. Uh, we only had three. So, you
  11743. 7:33:07know, sometimes you'll have a ton.
  11744. 7:33:08Sometimes you'll have like one on each
  11745. 7:33:11sheet and you'll create multiple sheets.
  11746. 7:33:12But, um, do control A. Um, now we have
  11747. 7:33:17our thing. Now, this one we're going to
  11748. 7:33:19be looking at these age brackets that we
  11749. 7:33:22were looking at that we created. Um,
  11750. 7:33:24something that I do honestly a lot is is
  11751. 7:33:28kind of bracket things in into groups
  11752. 7:33:30like this. And you know, for this I'm
  11753. 7:33:32just kind of made them up, but um you
  11754. 7:33:35know, it's good to know how to do this
  11755. 7:33:39because I I promise you this one happens
  11756. 7:33:41a lot or I use this one a ton. And then
  11757. 7:33:44we just want to look at who purchased a
  11758. 7:33:46bike. Uh so the same thing as we did
  11759. 7:33:48before. So like purchased a bike, count
  11760. 7:33:50of the purchase. Um you know, pretty
  11761. 7:33:52easy. So we just have the count of
  11762. 7:33:53either no or yes for these age ranges.
  11763. 7:33:56Um and let's go to the insert. We'll go
  11764. 7:34:00to recommendation. Um, I personally like
  11765. 7:34:03a good line for this one. Um, so let's
  11766. 7:34:08This is already interesting. You could
  11767. 7:34:10do something like this.
  11768. 7:34:13That's nice. See this one versus this.
  11769. 7:34:16It just adds a dot. Oh, it looks nice.
  11770. 7:34:18We'll keep that one. Um,
  11771. 7:34:21so just really quick at a glance, really
  11772. 7:34:24interesting. People under the age of 30
  11773. 7:34:25are not buying that many bikes. um age
  11774. 7:34:2830 to 54.
  11775. 7:34:31Uh 31 to 54 buying a ton of bikes. Uh
  11776. 7:34:34they are they buy more bikes or look at
  11777. 7:34:37bikes more than anybody. Really
  11778. 7:34:38interesting. Um but we'll make the
  11779. 7:34:40dashboard a little bit. Um let's make
  11780. 7:34:43these chart titles. We'll do
  11781. 7:34:46ver oops the horizontal.
  11782. 7:34:49We'll just call this
  11783. 7:34:51age bracket.
  11784. 7:34:55Um, and then we'll add a chart title.
  11785. 7:34:58Um, again, you can add some extra stuff
  11786. 7:35:01if you want to. Um, but you don't need
  11787. 7:35:04to. Uh, none of this other stuff we
  11788. 7:35:06really need. I'm just kind of looking at
  11789. 7:35:07the stuff we do need or do want. Uh, so
  11790. 7:35:10what do we want to call this one? Let's
  11791. 7:35:12call it customer age
  11792. 7:35:15brackets. Um, and it's not perfect, but
  11793. 7:35:19we'll keep it as is for comparison. Um,
  11794. 7:35:22let me see if I can copy um
  11795. 7:35:26or or use this um real quick. Instead of
  11796. 7:35:29the age brackets, I'm going to get rid
  11797. 7:35:32of this and use the age.
  11798. 7:35:36And then let's use
  11799. 7:35:39um let's insert recommendation.
  11800. 7:35:42We use a line and we'll use this. So
  11801. 7:35:48this compared to this, just think of it
  11802. 7:35:51like if a customer or consumer or or not
  11803. 7:35:55a customer, if somebody you're working
  11804. 7:35:57with is trying to use this dashboard,
  11805. 7:35:58understand this dashboard, this is going
  11806. 7:36:00to be just it's going to I don't know.
  11807. 7:36:03It might melt their brain. It just makes
  11808. 7:36:05no sense. It makes sense. It's just all
  11809. 7:36:07over the place. It's really hard to make
  11810. 7:36:08sense of this. It really is. I mean, you
  11811. 7:36:10can kind of see a pattern going up
  11812. 7:36:12around like the mid30s and then it
  11813. 7:36:14trends downward, but it's hard to see.
  11814. 7:36:17Um, it really is. So, doing these um
  11815. 7:36:20these brackets really helps. And you can
  11816. 7:36:22even add, you know, adolescent um you
  11817. 7:36:26know, 0 to 30 underneath it. And in
  11818. 7:36:29fact, we may want to do that. Um why
  11819. 7:36:31not? Why not? Let's do that. Whoops.
  11820. 7:36:34Um so, why don't why don't we do that?
  11821. 7:36:37Why don't we go back? I'm just gonna I'm
  11822. 7:36:39doing this on the fly. Why don't we go
  11823. 7:36:40back?
  11824. 7:36:42Uh, what am I doing? Whoops.
  11825. 7:36:44And this is all calculated, but let's do
  11826. 7:36:47adolescent
  11827. 7:36:490 to
  11828. 7:36:5130.
  11829. 7:36:54Let's do middle-aged
  11830. 7:36:5631 through 54
  11831. 7:37:00and then old 55 plus. Let's see if this
  11832. 7:37:03breaks anything. I hope it doesn't.
  11833. 7:37:06Um, and we'll go back to our pivot
  11834. 7:37:08table. Let's refresh the data.
  11835. 7:37:14Uh, okay. It did mess with stuff.
  11836. 7:37:17Okay, never mind, guys. That was a
  11837. 7:37:19terrible idea. Don't do that. Um,
  11838. 7:37:22perfect. [clears throat]
  11839. 7:37:23Uh, let's get rid of that. That was a
  11840. 7:37:25terrible idea. Don't do that. I'm glad
  11841. 7:37:27we tested it out, though. I like I like
  11842. 7:37:29to see if it was going to work. No, it
  11843. 7:37:31messed with the um the order of things.
  11844. 7:37:34Um, I I intentionally named them
  11845. 7:37:37adolescent, middle-ag, and old because
  11846. 7:37:39it's it it makes sense for the
  11847. 7:37:41visualization. Um, but you know, if if I
  11848. 7:37:46change something and it messes with it,
  11849. 7:37:48I'm not going to mess with it. It was
  11850. 7:37:49just an idea on the fly, guys. Come on.
  11851. 7:37:51All right. So, let's start building out
  11852. 7:37:53our dashboard. Now, um, when we're
  11853. 7:37:56building our dashboard, what I
  11854. 7:37:57personally like to do is to have this
  11855. 7:37:59pivot table sheet, and then I will copy
  11856. 7:38:02them over. And later, we'll hide these
  11857. 7:38:04other sheets. Um, and I'll explain that
  11858. 7:38:07in a little bit, but I like to have this
  11859. 7:38:09this one for us. So, we're going to copy
  11860. 7:38:11this. So, I just click on it, hit C.
  11861. 7:38:13We're going to paste it right over here.
  11862. 7:38:17Uh, let's just make them small for now.
  11863. 7:38:19That's Oh gosh, no, let's not do that.
  11864. 7:38:21Oh, these look terrible. Okay. Anyways,
  11865. 7:38:24um
  11866. 7:38:25let's copy this one over.
  11867. 7:38:29Oops.
  11868. 7:38:31Okay. What did I just do?
  11869. 7:38:34Oh, I didn't copy this one. Whoops.
  11870. 7:38:38It's not copying. Okay, we're going to
  11871. 7:38:42go copy.
  11872. 7:38:44Hit paste.
  11873. 7:38:46Fantastic.
  11874. 7:38:48Oops. Guys, look away. This is This is
  11875. 7:38:51tough to watch. This is tough for me to
  11876. 7:38:52watch. I'm the one doing it and it's
  11877. 7:38:54tough for me to watch. All right, let's
  11878. 7:38:55go to this last one.
  11879. 7:38:58I'm going to try it again. All right, it
  11880. 7:39:00worked this time. So, now we have um our
  11881. 7:39:04our three visualizations. This is
  11882. 7:39:06perfect. But now we actually want to
  11883. 7:39:08create a dashboard. Now, how do you do
  11884. 7:39:09that? How do you make it look nice? Um
  11885. 7:39:11and then we're going to add some, you
  11886. 7:39:12know, filters and stuff like that. How
  11887. 7:39:13do we make it look nice? Um what
  11888. 7:39:16happened here? What changed? What do we
  11889. 7:39:18do?
  11890. 7:39:21Oh my goodness gracious. All right,
  11891. 7:39:23let's copy this.
  11892. 7:39:26Let's paste this.
  11893. 7:39:29Let's get rid of this. I don't even know
  11894. 7:39:30how that happened. I've never seen that
  11895. 7:39:31before. That was wild. Uh, Excel is
  11896. 7:39:34trying to destroy my whole video. I
  11897. 7:39:36mean, I'm doing this for you, Excel.
  11898. 7:39:38Good night. Okay,
  11899. 7:39:41no problem at all. What we're going to
  11900. 7:39:42do and how you make this at least look
  11901. 7:39:44nice. Um, first off, we can get rid of
  11902. 7:39:47these grid lines pretty easily. And I
  11903. 7:39:50recommend when you do that when you make
  11904. 7:39:51a dashboard. It just makes it look
  11905. 7:39:52cleaner. It makes it look like an actual
  11906. 7:39:53dashboard. Um, let's go to view and grid
  11907. 7:39:57lines. So, we can get rid of these grid
  11908. 7:39:59lines. It just makes it look nicer. Um,
  11909. 7:40:01we're going to make, you know, we can
  11910. 7:40:03choose any color here. I'm just going to
  11911. 7:40:05get choose a color.
  11912. 7:40:08I like this. And let's We're basically
  11913. 7:40:12creating like a header, right? if you're
  11914. 7:40:13using like Tableau or something. Um
  11915. 7:40:15we're going to merge and center. So it
  11916. 7:40:16takes every single cell that we have
  11917. 7:40:18highlighted, creates into one. Let's
  11918. 7:40:20call this um bike sales. Uh I have I
  11919. 7:40:24think I called it bike sales dashboard.
  11920. 7:40:26Let's just call it that. Um you know,
  11921. 7:40:29see what happens. Let's get that. Let's
  11922. 7:40:33make it white and make it much larger
  11923. 7:40:36than it is.
  11924. 7:40:38Okay. Okay.
  11925. 7:40:41Sure. Let's do that. Doesn't look bad.
  11926. 7:40:46Um, what is it doing? There we go. Uh,
  11927. 7:40:49let's make that center. Perfect. Um,
  11928. 7:40:52it's not perfect, but we're going to use
  11929. 7:40:53it. All right. So, now we kind of want
  11930. 7:40:56to organize these. And, you know,
  11931. 7:40:58everybody has their different way of
  11932. 7:41:00doing it. Uh, I'm just going to start
  11933. 7:41:03building it out myself and just see how
  11934. 7:41:06it looks.
  11935. 7:41:09Uh, and then we'll go from there. I like
  11936. 7:41:10this one there. Um, we could put
  11937. 7:41:14this one. I This one's a kind of a
  11938. 7:41:16longer one, so I'll probably put it at
  11939. 7:41:17the bottom. Let's see how it looks.
  11940. 7:41:20Um, but we'll put this one right here.
  11941. 7:41:24Try to line it up. Jeez. Let's Let's
  11942. 7:41:27zoom in a little bit. Let's try to line
  11943. 7:41:29this up. See what it looks like.
  11944. 7:41:33Let's extend it to the end.
  11945. 7:41:36That doesn't [clears throat] look too
  11946. 7:41:37bad. Uh, needs to move up just a hair.
  11947. 7:41:40Uh, and I'll show you how to kind of
  11948. 7:41:41align these in a second. But, um, that
  11949. 7:41:45looks [clears throat] not bad. And we'll
  11950. 7:41:47kind of try to align these as well. And
  11951. 7:41:49let me zoom out and extend this the
  11952. 7:41:52length of this just to make it look
  11953. 7:41:54nice. Um, you know, now what you can do,
  11954. 7:41:59and you know, this is something that's
  11955. 7:42:01pretty simple, is you can get both of
  11956. 7:42:04these, and we're going to go to shape
  11957. 7:42:06format, and we can just align these. is
  11958. 7:42:08really nice to align especially if like
  11959. 7:42:10the top um maybe like the left to right
  11960. 7:42:13but like we're gonna align these to the
  11961. 7:42:14top and they just kind of align
  11962. 7:42:16themselves on the very top. Now these
  11963. 7:42:18look much better. This one is a larger
  11964. 7:42:21dashboard or a larger visualization. So
  11965. 7:42:23I'm going to keep it how it is. Um and
  11966. 7:42:27I'm going to keep this one how it is. So
  11967. 7:42:28it is going to be a little bit smaller
  11968. 7:42:30as you can tell. And then we'll have
  11969. 7:42:31this one. Um and I'm going to do that.
  11970. 7:42:36Um I this is going to bother me if I
  11971. 7:42:39don't align these. So let me do this. Go
  11972. 7:42:43shape format align to the right.
  11973. 7:42:47And it's not exactly what I wanted to
  11974. 7:42:50happen because
  11975. 7:42:53oh jeez, what am I doing? That's not
  11976. 7:42:55exactly what I wanted to happen. I
  11977. 7:42:56actually wanted this one to align uh
  11978. 7:42:58this one to align with this one. It did
  11979. 7:43:00the opposite. Um so let me just scoot
  11980. 7:43:02this back. All right. Visually it looks
  11981. 7:43:05fine. But that's how you do it if you
  11982. 7:43:06want to do it. Um I I I if you have
  11983. 7:43:09multiple of them like this, it you can
  11984. 7:43:11make it look bad. So we have our
  11985. 7:43:13dashboards. This is already looking
  11986. 7:43:14really good. I I like how this looks.
  11987. 7:43:17Colors are coordinated. It we have a
  11988. 7:43:19kind of a theme throughout. Um and it
  11989. 7:43:22looks nice. I actually I actually kind
  11990. 7:43:24of want to change this one um to
  11991. 7:43:28um
  11992. 7:43:30let's see.
  11993. 7:43:34Maybe if I did like that it look nicer
  11994. 7:43:36than all of them. Yeah, this does look
  11995. 7:43:37nicer. Um it doesn't change much either.
  11996. 7:43:41Guys, I'm Should I do it? All right,
  11997. 7:43:43we're going for it. We're changing the
  11998. 7:43:45design on the fly. Should I do it for
  11999. 7:43:47all of them?
  12000. 7:43:49Let's see.
  12001. 7:43:52It doesn't fit. Doesn't fit. Um, all
  12002. 7:43:54right, guys. Just ignore what I'm doing.
  12003. 7:43:57Uh, don't do any of this. I'm just
  12004. 7:43:58messing around at this point. So, this
  12005. 7:44:01[clears throat] is really great to have.
  12006. 7:44:02It really is. And what we want to do is
  12007. 7:44:05there are other elements. There are
  12008. 7:44:07other things that people would like to
  12009. 7:44:08be able to filter by and be able to look
  12010. 7:44:10at, but it's not in this visualization.
  12011. 7:44:12Um, to be more specific, one field
  12012. 7:44:16that's could be really interesting is
  12013. 7:44:17married versus single. are single people
  12014. 7:44:19buying more or um married people buying
  12015. 7:44:22more. You know, it it'd be nice to
  12016. 7:44:24filter on it. So, we're going to click
  12017. 7:44:25on uh any of these actually and we're
  12018. 7:44:27going to go up to pivot chart analyze
  12019. 7:44:30and we'll click insert slicer. Now, we
  12020. 7:44:33can choose which ones we want to be able
  12021. 7:44:35to filter on all at the same time or one
  12022. 7:44:37at a time. I'm just going to do the
  12023. 7:44:38first one by itself and then I'll show
  12024. 7:44:40you how to do other ones. Um but this
  12025. 7:44:43one is the marital status. So, this is
  12026. 7:44:44the married single, the one we were just
  12027. 7:44:46looking at. And we can drag this right
  12028. 7:44:49over here.
  12029. 7:44:51Bring it a little bit.
  12030. 7:44:54All right. And we don't need all that
  12031. 7:44:56space. So, we're going to boop boop boop
  12032. 7:44:58boop all the way up. Now,
  12033. 7:45:01while we're doing this, um it only
  12034. 7:45:04because we selected this uh this
  12035. 7:45:06visualization, it only is working on
  12036. 7:45:07that one right now. We of course wanted
  12037. 7:45:10to apply to all of them. Is not hard to
  12038. 7:45:12do. All we're going to do is we're going
  12039. 7:45:14to click on we're going to make sure
  12040. 7:45:16we're clicking on this. We're going to
  12041. 7:45:17go up to slicer. We're going to hit
  12042. 7:45:18report connections. Um and if you
  12043. 7:45:21remember, we have this um this pivot
  12044. 7:45:23table that we're working with. Um and
  12045. 7:45:26this is where all of our pivots are
  12046. 7:45:28coming from. So, we're going to actually
  12047. 7:45:30apply it to all of them. This is our
  12048. 7:45:32sheet. Um and this is the name of the
  12049. 7:45:34pivot table. Now, again, we created that
  12050. 7:45:36fourth one. We're not using it, but
  12051. 7:45:37we're going to apply it to all of them.
  12052. 7:45:39So now when we click on it, it's going
  12053. 7:45:42to apply to all of them. So at a quick
  12054. 7:45:44glance, let's see what single people are
  12055. 7:45:46doing. Um,
  12056. 7:45:50interesting. Interesting. Um, you know,
  12057. 7:45:53when I'm looking at the just these
  12058. 7:45:54numbers right here, married people,
  12059. 7:45:56these individuals are making a lot more,
  12060. 7:45:59like eight
  12061. 7:46:02um sometimes 8 to like 10,000 more on
  12062. 7:46:05average uh than their single
  12063. 7:46:06counterpart. Um, you know, again, that's
  12064. 7:46:09a rough estimate, but it's it's
  12065. 7:46:10interesting. So, now what we can do is
  12066. 7:46:12we're going to create more of these. So,
  12067. 7:46:14we're going to go to uh pivot chart
  12068. 7:46:16analyze. We're going to go to slicer.
  12069. 7:46:18Now, we already did marital status, but
  12070. 7:46:20what if we want to look at things like
  12071. 7:46:22uh region and maybe something like their
  12072. 7:46:26education. So, let's bring up both of
  12073. 7:46:29those. And look, now two of them come
  12074. 7:46:31up. So, let's add the region right here.
  12075. 7:46:35Bring that in just a little bit. See if
  12076. 7:46:37we can match it. Nailed it. All right.
  12077. 7:46:40Now, we're going to put that up. We'll
  12078. 7:46:43bring this one down.
  12079. 7:46:45Just like this. Bring it over. See if I
  12080. 7:46:48can match it again. Come on.
  12081. 7:46:52Nail. Almost nailed it. I don't know if
  12082. 7:46:54I nailed it, but it's close. All right.
  12083. 7:46:56Kind of bring this up a little bit.
  12084. 7:46:58Bring this up. And we have to do the
  12085. 7:47:01exact same thing that we did with this
  12086. 7:47:03one because right now again it only
  12087. 7:47:04applies to that one um chart. So what we
  12088. 7:47:07want to do is we want to go to slicer
  12089. 7:47:09report connections. Add it to all of
  12090. 7:47:11them. Okay. Do the same thing with
  12091. 7:47:15education
  12092. 7:47:16for connections. Bada bing bada boom. We
  12093. 7:47:19are looking good. And now uh let's get
  12094. 7:47:23rid of all of them. It's just going to
  12095. 7:47:24be everybody. So now we can kind of
  12096. 7:47:27slice and dice and choose what we want.
  12097. 7:47:30We want to look at people who have a
  12098. 7:47:31bachelor's degree who live in Europe and
  12099. 7:47:34are single. And this is the information
  12100. 7:47:36that we have on those people. So now we
  12101. 7:47:38can narrow it down by certain
  12102. 7:47:40demographics even further and look at
  12103. 7:47:42this key information. So we may not, you
  12104. 7:47:45know, look at counts and averages of
  12105. 7:47:46these things, but we're able to filter
  12106. 7:47:48on them. Uh, and that's really great to
  12107. 7:47:51know. So, bachelor's degrees on average
  12108. 7:47:53are making 60s 70,000. Um, let's look at
  12109. 7:47:58um let's look at graduate degrees. Okay,
  12110. 7:48:01a little more.
  12111. 7:48:03Um, but you know, again, I'm just
  12112. 7:48:06looking at random stuff. Um, but you can
  12113. 7:48:08mess around with this. Take a look at
  12114. 7:48:10some stuff. Um, this to me, I want to
  12115. 7:48:13make this color darker. Feel like it'
  12116. 7:48:15look nicer darker. There we go. Oh yeah,
  12117. 7:48:18that's way better. This to me is it's a
  12118. 7:48:21good dashboard, right? You have key
  12119. 7:48:24information that you're looking at, nice
  12120. 7:48:27visualizations, it's colorcoordinated,
  12121. 7:48:29you have these slicers on the side. Um,
  12122. 7:48:32to me, this is a fantastic just simple
  12123. 7:48:36dashboard. And there are so many other
  12124. 7:48:38things that you can do with this data
  12125. 7:48:40and you can make it unique and you can
  12126. 7:48:42add your own spin on it. And I highly
  12127. 7:48:44recommend that you do that. Push
  12128. 7:48:45yourself. go past what we just did today
  12129. 7:48:48and add your own stuff and and use this
  12130. 7:48:50and then you can add this to your
  12131. 7:48:51portfolio website and show this off and
  12132. 7:48:53show people that you know how to use
  12133. 7:48:55Excel, which is a fantastic thing to
  12134. 7:48:57know how to use and show off. So, with
  12135. 7:49:00that being said, I hope that this
  12136. 7:49:01project was helpful. I hope that you
  12137. 7:49:03learned something along the way. I know
  12138. 7:49:05I did. Um, I was learning things as we
  12139. 7:49:07were going and I hope that you didn't
  12140. 7:49:08mind that I took some detours along the
  12141. 7:49:10way um for your amusement as well as my
  12142. 7:49:13learning. Uh, so with that being said,
  12143. 7:49:15thank you so much for joining me. I
  12144. 7:49:17really appreciate it. I hope you have a
  12145. 7:49:19good day and goodbye.
  12146. 7:49:33What's going on everybody? Welcome back
  12147. 7:49:35to another video. Today we are starting
  12148. 7:49:36our Tableau tutorial series.
  12149. 7:49:44Now, this series is for absolute
  12150. 7:49:46beginners. So, if you have never used
  12151. 7:49:47Tableau before, you are in the perfect
  12152. 7:49:49place. I'm going to take you all the way
  12153. 7:49:50from the very beginning of installing it
  12154. 7:49:52and just understanding what Tableau is
  12155. 7:49:54and how you can use it all the way to
  12156. 7:49:56creating dashboards and sharing it. Now,
  12157. 7:49:58personally, I hate those videos that are
  12158. 7:50:00like 3 hours long and they just expect
  12159. 7:50:02you to go through it. Uh, I like to
  12160. 7:50:04break my videos up into chunks. So, if
  12161. 7:50:06you have ever done my SQL tutorials,
  12162. 7:50:08you'll know that I like to break things
  12163. 7:50:09up so it gives you time to try them out
  12164. 7:50:11and do them yourself and then you can
  12165. 7:50:13move on to the next video. So, I'm going
  12166. 7:50:14to be breaking this up into five
  12167. 7:50:16separate videos. But in this video, I'm
  12168. 7:50:18going to show you how to install Tableau
  12169. 7:50:19for free. I'm going to show you the user
  12170. 7:50:21interface. We're going to download a
  12171. 7:50:23data set that you can find on Kaggle.
  12172. 7:50:25And then we will build our first
  12173. 7:50:26visualization together. With that being
  12174. 7:50:28said, let's jump over to my screen and
  12175. 7:50:29we'll get started. All right. So, the
  12176. 7:50:31very first thing that we need to do is
  12177. 7:50:32you need to actually download Tableau.
  12178. 7:50:35So, we're not going to be using Tableau.
  12179. 7:50:36We're going to be using a free version
  12180. 7:50:38called Tableau Public. It has a lot of
  12181. 7:50:40the same features except, of course,
  12182. 7:50:42it's not uh every single feature that
  12183. 7:50:44regular Tableau has, but it is
  12184. 7:50:46absolutely perfect for learning it and
  12185. 7:50:48for using it and and you can even build
  12186. 7:50:51um you know, dashboards and share those
  12187. 7:50:52for your portfolio. Um I'm going to put
  12188. 7:50:56this link in the description so you can
  12189. 7:50:57just go and click on that and and all
  12190. 7:51:00you have to do is input your email right
  12191. 7:51:01here. We're going to click download the
  12192. 7:51:03app. Um, and then it should start to
  12193. 7:51:05download. And then you can save that.
  12194. 7:51:07And then you're going to open this up.
  12195. 7:51:09Now, I'm going to open it up. I don't
  12196. 7:51:11know what it's going to do. I already
  12197. 7:51:12have it downloaded. Um, but it should
  12198. 7:51:15open up and look hopefully like what
  12199. 7:51:17you're seeing on uh my screen in just a
  12200. 7:51:19second. Let's see what it does. Um, I
  12201. 7:51:22hope you can see this, but it says
  12202. 7:51:24Tableau Public. Um, it says I already
  12203. 7:51:27have it set up, but you're going to
  12204. 7:51:28click install and go through all that um
  12205. 7:51:30all that setup stuff. Uh, so I'm going
  12206. 7:51:31to exit out of here, but I'm going to go
  12207. 7:51:34over here and type in Tableau Public.
  12208. 7:51:37Uh, and it's 2021.3. That's the current
  12209. 7:51:40version that they have out if you're
  12210. 7:51:42doing this in the f.
  12211. 7:51:46Um, so you should be able to pull this
  12212. 7:51:48up right here. Now, um, I'm going to go
  12213. 7:51:52and get our data set that we're going to
  12214. 7:51:54be using, and I'm going to show you how
  12215. 7:51:55to get that as well, and then we will
  12216. 7:51:56actually jump into Tableau and start,
  12217. 7:51:59uh, using it. So, let's go over here.
  12218. 7:52:01I'm going to get a data set from Kaggle.
  12219. 7:52:03I wanted something pretty generic uh to
  12220. 7:52:05show you. In future videos, I'm going to
  12221. 7:52:07show you some special or not special,
  12222. 7:52:10but just different visualizations that
  12223. 7:52:12you might use. Um, and we'll get
  12224. 7:52:14different data sets for those because,
  12225. 7:52:15of course, not one data set covers all
  12226. 7:52:18these other types of visualizations. So,
  12227. 7:52:20um, we're starting off pretty simple
  12228. 7:52:21right here. We're going to be getting
  12229. 7:52:22one called video game sales. Um, and we
  12230. 7:52:26can take a really quick look at it. Um,
  12231. 7:52:28here are some of the fields that you're
  12232. 7:52:29going to be having. Uh, like rank, name,
  12233. 7:52:31platform, the year, genre, and then some
  12234. 7:52:34sales data. And this is what it actually
  12235. 7:52:36looks like. It's called VG sales. So,
  12236. 7:52:38video game sales. It's in a CSV. And um,
  12237. 7:52:41you know, here are the fields. And we
  12238. 7:52:44have our data. And all we are going to
  12239. 7:52:46do is we're going to download that.
  12240. 7:52:49And I will save it. Now, when you
  12241. 7:52:51download it, it's going to be saved into
  12242. 7:52:53a zip file. So, we need to go to our
  12243. 7:52:55downloads. Uh, let's refresh this.
  12244. 7:52:59Here's our archive. We need to go in
  12245. 7:53:01here. You can just copy it and paste it
  12246. 7:53:04right back into here. Um, and just so
  12247. 7:53:07you know, that is a uh a CSV, so be
  12248. 7:53:11aware of that. So, what we want to do is
  12249. 7:53:13we want to come in here. Now, since it
  12250. 7:53:14is a CSV, this is not we're not going to
  12251. 7:53:16be using Microsoft Excel. We're going to
  12252. 7:53:18be using the text file. So, we'll come
  12253. 7:53:20in here. We'll take VG sales. Now, uh,
  12254. 7:53:24one thing I want to do before I do that
  12255. 7:53:25is I'm going to rename mine, uh, VGSK
  12256. 7:53:29sales_1.
  12257. 7:53:30Um, I've already prepared for this and
  12258. 7:53:33so I already have that in there. Um, but
  12259. 7:53:36so I want to make a distinct one for
  12260. 7:53:37myself. You do not have to do that. So,
  12261. 7:53:39we'll come back here. Um, and then we're
  12262. 7:53:42going to do text file and VG sales.
  12263. 7:53:45We're going to open that up.
  12264. 7:53:48And
  12265. 7:53:50when it pulls up right here, um, you can
  12266. 7:53:53bring in other tables and then you can
  12267. 7:53:55start to join them together and create
  12268. 7:53:57those relationships. We are not going to
  12269. 7:53:59be doing that in this video. We'll do
  12270. 7:54:00that in a separate one. Um, as for, you
  12271. 7:54:04know, just getting started, you know,
  12272. 7:54:05we're not going to be using that. But
  12273. 7:54:06you can see um, some of these
  12274. 7:54:10things or some of these fields. And if
  12275. 7:54:13you notice, they they um they're either
  12276. 7:54:17ABC or they're a number. So it starts to
  12277. 7:54:20categorize
  12278. 7:54:21what this field type is. So is it a
  12279. 7:54:24string? Is it numeric? It starts to
  12280. 7:54:26automatically do that. And that's all
  12281. 7:54:28done within Tableau.
  12282. 7:54:30And so it just kind of reads it and
  12283. 7:54:32that's what it does. Um what we're going
  12284. 7:54:34to do is we're going to click right down
  12285. 7:54:36here. It's called go to worksheet. Um,
  12286. 7:54:38the worksheets are where you're going to
  12287. 7:54:39actually start being able to build your
  12288. 7:54:41visualizations, your charts, your
  12289. 7:54:43graphs, all these things. Um, and so,
  12290. 7:54:45you know, we have this in here now. And
  12291. 7:54:47so, we're just going to click right here
  12292. 7:54:49on go to worksheet. As you can see here
  12293. 7:54:52is VG sales_1.
  12294. 7:54:55You will not have the underscore one if
  12295. 7:54:56you did not add that like I did. Uh, but
  12296. 7:54:59right down here, you can see all the
  12297. 7:55:00fields that we just imported from that
  12298. 7:55:02data set. And they even created one
  12299. 7:55:03right here for us. Uh, they just
  12300. 7:55:06generated that field. um based on the
  12301. 7:55:08file. So it's a count of all the rows
  12302. 7:55:10really. So what I'm going to do is I'm
  12303. 7:55:13just going to walk you through uh
  12304. 7:55:16basically what we're looking at some of
  12305. 7:55:17the things that we're going to be using
  12306. 7:55:18today. There will be things that I don't
  12307. 7:55:20talk about, but I'm going to highlight
  12308. 7:55:23those in in future videos when we start
  12309. 7:55:25using those or going over them. Um and
  12310. 7:55:28so let's just start with the most
  12311. 7:55:29obvious one. It's way over here. I'm
  12312. 7:55:32sure you saw it when we uh this first
  12313. 7:55:34came up on the screen because it has all
  12314. 7:55:36these different charts and
  12315. 7:55:37visualizations and graphs. And uh these
  12316. 7:55:41will become available as you start
  12317. 7:55:43dragging and dropping our data into this
  12318. 7:55:46sheet. And so if I go right here, it
  12319. 7:55:49says four scatter plots try zero or more
  12320. 7:55:51dimensions, two to four measures. So
  12321. 7:55:54what our dimensions are are right here
  12322. 7:55:56and what our measures are are right down
  12323. 7:55:58here. And so typically uh things like
  12324. 7:56:01like you say genre or names or or
  12325. 7:56:04strings like that are going to be these
  12326. 7:56:07uh dimensions and then a lot of a lot of
  12327. 7:56:09times the numerical is going to be are
  12328. 7:56:11going to be measures. Next what I want
  12329. 7:56:14to show you is right here. So you can
  12330. 7:56:17take something like global sales and you
  12331. 7:56:20can drag it right here into your rows
  12332. 7:56:23and then it takes your rows and so it
  12333. 7:56:26automatically created a sum of global
  12334. 7:56:28sales. Now if we take that away, let's
  12335. 7:56:31say we drag it right here, it's going to
  12336. 7:56:33give us a column. Now you can also do it
  12337. 7:56:36right up here. You don't have to um drag
  12338. 7:56:39it on screen. You can also
  12339. 7:56:42just add it to the column or the row.
  12340. 7:56:44That's typically what I do. I it's just
  12341. 7:56:46more intuitive to me. Um or you can drop
  12342. 7:56:49it in this section right here and it
  12343. 7:56:51does its best to assign it some type of
  12344. 7:56:54um some type of visualization. And so
  12345. 7:56:57that's [clears throat] what it always is
  12346. 7:56:58trying to do. It is trying to say okay
  12347. 7:57:01this is what you're trying to do. Let me
  12348. 7:57:03try to get the best visualization for
  12349. 7:57:05the data that you're giving me. Now,
  12350. 7:57:08while we are here, um, it went down here
  12351. 7:57:11into [clears throat] marks. And marks is
  12352. 7:57:13a very important area. It's where you
  12353. 7:57:16can add color, size, text, detail, and
  12354. 7:57:19tool tip. And I'm not going to go into
  12355. 7:57:21what all those are cuz I'm just going to
  12356. 7:57:22show you. So, let's start pulling some
  12357. 7:57:24fields in here and creating a
  12358. 7:57:25visualization. And then I'm going to
  12359. 7:57:27show you how all of that works,
  12360. 7:57:29including filters as well. So, the first
  12361. 7:57:31thing that we are going to look at is
  12362. 7:57:33global sales. And let's put that in the
  12363. 7:57:36rows. And then I'm going to take year
  12364. 7:57:39and I'm [clears throat] going to make
  12365. 7:57:40that the column. And this is basically
  12366. 7:57:43exactly what uh I wanted to do. Now, as
  12367. 7:57:46of right now, it has only the year and
  12368. 7:57:49it's looking at global sales for
  12369. 7:57:52everything. But we want to break that
  12370. 7:57:53out a little bit better. I want to break
  12371. 7:57:56it out by let's do genre. So different
  12372. 7:57:59genre of games. Now, if I add that right
  12373. 7:58:02here to this columns, it is going to
  12374. 7:58:05break it up by year and genre. If I add
  12375. 7:58:09it right here is going to break it out
  12376. 7:58:12by the year, of course, but then in each
  12377. 7:58:15individual row has the different genre.
  12378. 7:58:18That's not what we want. We want to keep
  12379. 7:58:20this type of line graph. Uh, and what
  12380. 7:58:25we're going to do is we're going to add
  12381. 7:58:26it to marks. And you can't really see it
  12382. 7:58:29based off of these colors, but they're
  12383. 7:58:31all different. So, we have action genre,
  12384. 7:58:34we have the sports genre, racing, uh,
  12385. 7:58:37role playing, all these different genres
  12386. 7:58:39within it. Now, we can get rid of that
  12387. 7:58:41because we don't need it anymore. Uh,
  12388. 7:58:43and this is where these um these marks
  12389. 7:58:46really come in handy because you can
  12390. 7:58:48start basically doing what you want with
  12391. 7:58:51them. So, for the genre, I want to be
  12392. 7:58:54able to see all these different genres
  12393. 7:58:55with different colors. To me, that just
  12394. 7:58:57makes the most sense. So, I'm going to
  12395. 7:58:58put color right here. And automatically,
  12396. 7:59:00it assigns every single genre its own
  12397. 7:59:03color and gives us this legend right
  12398. 7:59:06over here. And so, it's really easy to
  12399. 7:59:10see. Well, when you have smaller
  12400. 7:59:11numbers, it's much easier. But I know
  12401. 7:59:13that red is sports. And I can go right
  12402. 7:59:15here and find red. And that is sports.
  12403. 7:59:18So, it makes it a lot easier than when
  12404. 7:59:19it is all the same color, blue. So what
  12405. 7:59:23you can do after that is you can also
  12406. 7:59:25add things like uh a label to it. So if
  12407. 7:59:28we take label and we or we take genre,
  12408. 7:59:31put label, you can click right here and
  12409. 7:59:34you can get rid of the labels that you
  12410. 7:59:36have and you can see them right down
  12411. 7:59:37here. Or you can also change uh the
  12412. 7:59:40font. So if you want to make it orange
  12413. 7:59:42or or whatever color, you can do all
  12414. 7:59:44those same things. And you can also do
  12415. 7:59:47things like changing where you see these
  12416. 7:59:49things. So for action, you're going to
  12417. 7:59:52see it a ton because for each year
  12418. 7:59:54action is is at the is on the higher end
  12419. 7:59:57and so you're seeing those in those mins
  12420. 7:59:59and maxes. You can also do it for a
  12421. 8:00:01selected area. So if I come in here and
  12422. 8:00:03I select it, it's then going to show me
  12423. 8:00:06what those are. So label is really
  12424. 8:00:08really uh useful, really helpful. Let me
  12425. 8:00:11get rid of that really quick. Uh you can
  12426. 8:00:13also do it where the lines end. So line
  12427. 8:00:16ends is at the beginning and the end.
  12428. 8:00:18And you can also take that away or put
  12429. 8:00:21that back on. So labels are really
  12430. 8:00:23important. Labels aren't very helpful
  12431. 8:00:25when you're doing, at least I don't find
  12432. 8:00:26that it's super helpful when you're
  12433. 8:00:28doing things like genre. So when you're
  12434. 8:00:30doing your dimensions. So I'm going to
  12435. 8:00:31get rid of that. And I'm actually going
  12436. 8:00:33to bring our global sales over here. And
  12437. 8:00:36let's label that.
  12438. 8:00:39And right now I think it's labeling the
  12439. 8:00:42uh line ends. We want to do the min and
  12440. 8:00:44max. Now, if we do min and max on the
  12441. 8:00:47table, it's just going to give us the
  12442. 8:00:49max and the min, which is zero, and then
  12443. 8:00:52139.4,
  12444. 8:00:54it's a little bit more useful if we do
  12445. 8:00:55it per each line. Uh, this at least
  12446. 8:00:58gives us some context. I probably
  12447. 8:00:59wouldn't do this in an actual visual
  12448. 8:01:01visualization. But to give you some um
  12449. 8:01:03understanding of just how it works. So
  12450. 8:01:05now I know that um right over here the
  12451. 8:01:08min and the max or the min uh sorry the
  12452. 8:01:11max for these for action and for sports
  12453. 8:01:14is right around 138 139. So it's pretty
  12454. 8:01:17easy to see. Um and you can again go in
  12455. 8:01:21here and you can remove the max or
  12456. 8:01:24remove the mins whichever one you feel
  12457. 8:01:26is best. Uh you'll probably keep the
  12458. 8:01:29maximums in there for each category. And
  12459. 8:01:31so this is a really quickly becoming uh
  12460. 8:01:33a pretty usable visualization. And it's
  12461. 8:01:36not the only label that you can add. We
  12462. 8:01:38still are using year over here. So we
  12463. 8:01:41can always drop year in there as well.
  12464. 8:01:43Create a label. And so now we have let's
  12465. 8:01:46see for this one is a puzzle genre. So
  12466. 8:01:49we also have the year that it had the
  12467. 8:01:52maximum uh sales. And so you know just
  12468. 8:01:56some [clears throat] things that you can
  12469. 8:01:57do. You don't have to add that.
  12470. 8:02:00Now, let's go up here and we're going to
  12471. 8:02:01take a look at filters because filters
  12472. 8:02:04are really important. You know, if you
  12473. 8:02:05are making this for a client or you are
  12474. 8:02:08making this for somebody, you want them
  12475. 8:02:10to be able to filter down uh to very
  12476. 8:02:13specific information that they want to
  12477. 8:02:15see. So, let's take uh the platform.
  12478. 8:02:18Lots of different platforms.
  12479. 8:02:20Um as you can see, you know, PS4, Xbox,
  12480. 8:02:23um if you're familiar with these, we'll
  12481. 8:02:26click all of these. Um, and we'll click
  12482. 8:02:29okay. So now this is an option as a
  12483. 8:02:32filter and all we're going to do is
  12484. 8:02:33we're going to click on this arrow right
  12485. 8:02:35here and we're going to say show filter.
  12486. 8:02:38Now right now all of them are selected.
  12487. 8:02:41So every single one is being taken into
  12488. 8:02:43account for this visualization. But
  12489. 8:02:46let's say we come down here and we say
  12490. 8:02:48okay I don't want to see sales for any
  12491. 8:02:50of these PS the original PlayStation 2,
  12492. 8:02:53three or four. So, I'm going to get rid
  12493. 8:02:54of this one, this one, this one, and
  12494. 8:02:58this one. And you could immediately see
  12495. 8:03:00the the changes that were happening. So,
  12496. 8:03:03now none of the numbers, none of those
  12497. 8:03:05sales are being accounted for and and
  12498. 8:03:07being added to the sum of global sales
  12499. 8:03:10right here at all.
  12500. 8:03:12So, uh that is just how a filter can
  12501. 8:03:16work. And you can also do that. and you
  12502. 8:03:21can get rid of all of them and you can
  12503. 8:03:23go in and actually just pick very
  12504. 8:03:25specific sales. So if you only want to
  12505. 8:03:27see the PlayStation sales, you can go in
  12506. 8:03:29there and do that as well. So really
  12507. 8:03:32really handy filters are things that you
  12508. 8:03:35you'll at least want to have as an
  12509. 8:03:37option for most of your your
  12510. 8:03:39visualizations. At least that's what I
  12511. 8:03:40found, especially when you're doing
  12512. 8:03:41client facing work. They like to uh get
  12513. 8:03:44in there and mess around and look at
  12514. 8:03:45different look at it in different ways.
  12515. 8:03:47And so that's one that I I think is is
  12516. 8:03:50really useful to to have.
  12517. 8:03:53The very last thing that we want to do
  12518. 8:03:57is we want to actually add this to a
  12519. 8:04:00dashboard. Now let's say we come right
  12520. 8:04:03down here and we add a new worksheet.
  12521. 8:04:05And actually we might change one more
  12522. 8:04:06thing on that last one, but we'll just
  12523. 8:04:08make a really simple one. Um we'll just
  12524. 8:04:11give it genre and we'll give it global
  12525. 8:04:14sales as the rows. Um, and this nifty
  12526. 8:04:18button right up here, which is a sorting
  12527. 8:04:20button. So, I'm going to sort like that.
  12528. 8:04:23I'm going to add the genre in just as we
  12529. 8:04:26did. I'll give it different colors.
  12530. 8:04:28Perfect now, we have two really quick
  12531. 8:04:30different visualizations. Right. What I
  12532. 8:04:33want to do is just show you how to
  12533. 8:04:34combine those because what you are going
  12534. 8:04:37to do is you're going to actually come
  12535. 8:04:39in here and you're going to do new
  12536. 8:04:42dashboard. That's what this button is
  12537. 8:04:43right here. Now, when we come in here,
  12538. 8:04:45the size is extremely small. It's very
  12539. 8:04:48easy to fix that. All we're going to do
  12540. 8:04:50is click right here. We're going to go
  12541. 8:04:52to this range or this dropdown, and
  12542. 8:04:54we're going to click automatic. So, now
  12543. 8:04:56it is a much larger size for us to
  12544. 8:04:58actually drop our visualizations into.
  12545. 8:05:01Uh, and let's put sheet one. And we'll
  12546. 8:05:05put uh let's put it up top. So, now it
  12547. 8:05:08looks a little bit like this. Uh, not
  12548. 8:05:10perfect, but again, if I wanted to make
  12549. 8:05:13this look a lot better, I definitely
  12550. 8:05:14would. And then you can go over here and
  12551. 8:05:17you can rename these things. You can
  12552. 8:05:18also do that back when we were in our
  12553. 8:05:20actual worksheets, but you can also do
  12554. 8:05:22it here as well and then start um, you
  12555. 8:05:25know, customizing and building it out.
  12556. 8:05:27That's not what this video is for. That
  12557. 8:05:28is the last video. We're going to build
  12558. 8:05:30an entire dashboard. It'll be kind of
  12559. 8:05:32like a small project. You can put that
  12560. 8:05:33in your portfolio. Um, if you have
  12561. 8:05:36gotten this far and you want to jump
  12562. 8:05:38straight into it and you don't want to
  12563. 8:05:40wait for these other videos to come out
  12564. 8:05:42or you don't you just want to jump
  12565. 8:05:43straight into creating an entire
  12566. 8:05:45portfolio project, I have an entire
  12567. 8:05:47portfolio project series that covers
  12568. 8:05:50SQL, Python, and Tableau. And so, go
  12569. 8:05:53check out that series. I have one video
  12570. 8:05:56dedicated to Tableau. It's like 45
  12571. 8:05:58minutes or an hour long and it covers a
  12572. 8:06:01lot of the things that we're going to
  12573. 8:06:02hear in here as well as a few other
  12574. 8:06:04things. But I appreciate you checking
  12575. 8:06:07out this video. In future videos, we're
  12576. 8:06:09going be going over things like creating
  12577. 8:06:10bins, calculated fields, doing joins,
  12578. 8:06:13and then creating a final project and
  12579. 8:06:15putting it all together. So, thank you
  12580. 8:06:17so much for joining me. I really
  12581. 8:06:19appreciate it. If you like this video,
  12582. 8:06:21be sure to like and subscribe below, and
  12583. 8:06:23I will see you in the next video.
  12584. 8:06:37What's going on everybody? Welcome back
  12585. 8:06:38to the Tableau tutorial series. In this
  12586. 8:06:40video, we're going to be going over bins
  12587. 8:06:42and calculated [music] fields.
  12588. 8:06:49All right, so let's jump right into it.
  12589. 8:06:51The first thing that we're going to look
  12590. 8:06:52at are bins. And bins are basically just
  12591. 8:06:55groupings or ranges of numerical values.
  12592. 8:06:58So we cannot create bins uh for genre,
  12593. 8:07:01name, platform or anything like that. We
  12594. 8:07:03have to do something with this sign
  12595. 8:07:04right here, which means that it is a
  12596. 8:07:06numeric. So year or all of this sales
  12597. 8:07:09data or this ranking data and we're
  12598. 8:07:11going to use what we worked on in our
  12599. 8:07:13very first tutorial. And so what we're
  12600. 8:07:16going to be using to kind of demonstrate
  12601. 8:07:17how bins work is this year right down
  12602. 8:07:19here. So, right now we have a range of
  12603. 8:07:221993 all the way up to 2018. And we're
  12604. 8:07:25going to create some bins to group and
  12605. 8:07:27create ranges for these years. And it's
  12606. 8:07:30pretty simple. All we're going to do is
  12607. 8:07:32we're going to come right over here to
  12608. 8:07:34year and this little drop down on the
  12609. 8:07:36side and we're going to go down to
  12610. 8:07:37create and go down to bins. Now, it's
  12611. 8:07:41going to say the size of bin and it's
  12612. 8:07:43going to give you a recommendation based
  12613. 8:07:46off of the information that is already
  12614. 8:07:48provided. The min and the max, the
  12615. 8:07:50ranges of these values. You know, you
  12616. 8:07:52don't have to do this, but usually um it
  12617. 8:07:55it does give some good estimation on
  12618. 8:07:57what you might be considering. If you
  12619. 8:07:59were thinking, hey, maybe do a bit of
  12620. 8:08:01like 20 and they're recommending two.
  12621. 8:08:03Think about why they might be doing
  12622. 8:08:04that. We're going to change ours to
  12623. 8:08:06five. And you can always change what
  12624. 8:08:08this field is going to be. I'm just
  12625. 8:08:10going to give it an old exclamation
  12626. 8:08:12point just to um really spice things up
  12627. 8:08:14here. So, we're going to click okay. And
  12628. 8:08:18as you can see, it adds it right up
  12629. 8:08:19here. Is no longer um it is no longer a
  12630. 8:08:23numeric. Now, it is a categorical. So,
  12631. 8:08:26now it's this is no longer just uh 1 2 3
  12632. 8:08:294 5. It's ranges. It's groups. And we're
  12633. 8:08:32going to get rid of this year really
  12634. 8:08:33quick. Actually, let's keep it up there
  12635. 8:08:35for a second. Uh see what happens. But
  12636. 8:08:37we're going to bring this up and we'll
  12637. 8:08:39get rid of this year. And this is is
  12638. 8:08:43what kind of it spits out for us. Now, I
  12639. 8:08:46did look at the data when I was prepping
  12640. 8:08:48for this. There are some nulls in the
  12641. 8:08:49years. Um, and so all we're going to do
  12642. 8:08:51for this is we're just going to go like
  12643. 8:08:52this and we're going to exclude the
  12644. 8:08:55nulls. Uh, probably not something you
  12645. 8:08:58should be doing uh if you're doing this
  12646. 8:08:59for work, but this is for demonstration
  12647. 8:09:01purposes, so we can do whatever we want.
  12648. 8:09:04But as you can see, we now have these
  12649. 8:09:07ranges. So this range starts at 1990
  12650. 8:09:11and it includes 1990 all the way up to
  12651. 8:09:141994 and then it's 1995 to 1999.
  12652. 8:09:18And so just really quickly, we can tell
  12653. 8:09:21that the years 2000 to 2004 were a huge
  12654. 8:09:25huge huge uh season or group of of years
  12655. 8:09:28for game sales. So these are the global
  12656. 8:09:31sales for for these video games. And so
  12657. 8:09:34it is really helpful. It's very useful.
  12658. 8:09:37Um you can do this on a lot of different
  12659. 8:09:39information. We could do this on this
  12660. 8:09:41sales data. You can do this on age. You
  12661. 8:09:43can do it on years like we did. And it
  12662. 8:09:45can be very very useful. And so uh
  12663. 8:09:48really quickly that is how bins work. I
  12664. 8:09:51would say it's pretty straightforward.
  12665. 8:09:53Now this is a perfect time to segue into
  12666. 8:09:56the next part of the video which is
  12667. 8:09:57calculated fields. uh right over here on
  12668. 8:10:00this left hand side. We see that the
  12669. 8:10:02global sales which are in millions goes
  12670. 8:10:04all the way up to 900 million and
  12671. 8:10:06created these beautiful bins right down
  12672. 8:10:08here. But let's look at within these
  12673. 8:10:11from 1999 to 2015. Let's see which of
  12674. 8:10:14these has the highest percentage. Of
  12675. 8:10:16course, it's going to be this one. But
  12676. 8:10:18we can do something called a quick table
  12677. 8:10:21calculation. Um we'll create a our own
  12678. 8:10:23calculation later. I'll show you how to
  12679. 8:10:25do that. But we're going to do a quick
  12680. 8:10:26table calculation and we're going to do
  12681. 8:10:28the percent of total. And so now we have
  12682. 8:10:31these bins and instead of just seeing
  12683. 8:10:33the total amount of sales that they had,
  12684. 8:10:35we see the actual percentages based off
  12685. 8:10:37these year ranges, which is really
  12686. 8:10:40useful, something that you could
  12687. 8:10:41absolutely put uh in some real work that
  12688. 8:10:43you do for a client. Now, really quick,
  12689. 8:10:46just to show you something that you can
  12690. 8:10:47do, if you click control and you drag
  12691. 8:10:50this over here, you can actually save
  12692. 8:10:52that calculation. So we can say
  12693. 8:10:54percentage of global sales and that
  12694. 8:10:59actually saves it as uh you know a
  12695. 8:11:01measure for us. So that was a quick
  12696. 8:11:03calculation but let's look how to
  12697. 8:11:04actually create a calculated field. So
  12698. 8:11:08if we do this right here what is going
  12699. 8:11:10to come up is just the global sales and
  12700. 8:11:13you can do a lot of what you would
  12701. 8:11:14basically do in Excel. Multiplication
  12702. 8:11:16division subtraction a few other things
  12703. 8:11:18but we're going to keep it super super
  12704. 8:11:19simple today. All I'm going to do is I'm
  12705. 8:11:22going to take global sales and I'm going
  12706. 8:11:24to subtract. I'm going to do an open
  12707. 8:11:26bracket and I'm going to say EU sales
  12708. 8:11:28and it auto completes for me. I'm going
  12709. 8:11:31to click okay. And it created
  12710. 8:11:33calculation two. I'm going to come in
  12711. 8:11:35here and I'm just going to say global
  12712. 8:11:38sales minus
  12713. 8:11:41EU sales.
  12714. 8:11:43And let's drag this over. These are
  12715. 8:11:46different. Um, one's percentage, one is
  12716. 8:11:51in terms of sum. And so I'm just going
  12717. 8:11:54to bring this in right here. And so now
  12718. 8:11:56we are comparing against the same thing.
  12719. 8:11:58And if we look at the global sales, we
  12720. 8:12:00have probably right around 950
  12721. 8:12:04millionish in this 2000 uh to 2004 bin.
  12722. 8:12:08And for global sales minus the EU sales,
  12723. 8:12:10we're looking at, you know, 650 million.
  12724. 8:12:13So there is a noticeable difference. And
  12725. 8:12:15this is just one of the ways that you
  12726. 8:12:17can use uh calculated fields to actually
  12727. 8:12:20just show the difference between two
  12728. 8:12:22numbers or you can do more advanced
  12729. 8:12:24calculations depending on the data that
  12730. 8:12:25you actually have. So that's it for this
  12731. 8:12:27video. I hope you learned a little bit
  12732. 8:12:28more about bins and calculated fields.
  12733. 8:12:31In the next video, we're going to be
  12734. 8:12:32looking at a ton of different
  12735. 8:12:34visualizations and graphs and charts and
  12736. 8:12:36just exploring what options are really
  12737. 8:12:39are out there for visualizing our data.
  12738. 8:12:41Thank you guys so much for joining me. I
  12739. 8:12:43really appreciate it. If you like this
  12740. 8:12:45video, be sure to like and subscribe
  12741. 8:12:47below and I will see you in the next
  12742. 8:12:48video.
  12743. 8:12:50[music]
  12744. 8:12:58[music]
  12745. 8:13:01What's going on everybody? Welcome back
  12746. 8:13:02to the Tableau tutorial series. In this
  12747. 8:13:05video, we're going to be looking at lots
  12748. 8:13:06of different visualizations, including
  12749. 8:13:08the scatter plot and density maps.
  12750. 8:13:09[music]
  12751. 8:13:16Now, before we jump into the tutorial, I
  12752. 8:13:18have some very exciting news. In just
  12753. 8:13:20two days, on October 7th, I am going to
  12754. 8:13:22be partnering with AlterX to host a
  12755. 8:13:23webinar. This webinar is completely for
  12756. 8:13:26data analysts who are wanting to change
  12757. 8:13:28careers to become a data analyst. Now,
  12758. 8:13:30you did hear that right. I will be the
  12759. 8:13:31host of the event, but we will be
  12760. 8:13:33bringing on guests as well who are
  12761. 8:13:34industry experts who actually change
  12762. 8:13:36careers to become data analysts, much
  12763. 8:13:38like myself. They'll be sharing their
  12764. 8:13:39stories of how they actually transition
  12765. 8:13:41careers along with the tools that they
  12766. 8:13:43found extremely useful and helpful to
  12767. 8:13:45make that switch and they'll be giving
  12768. 8:13:46lots of advice along the way. So, if you
  12769. 8:13:49are somebody who is wanting to change
  12770. 8:13:50careers to become a data analyst or just
  12771. 8:13:52wanting to learn about data analytics,
  12772. 8:13:54this is an absolute fantastic place to
  12773. 8:13:57learn a lot more about that. I will
  12774. 8:13:58leave a link in the description. So, be
  12775. 8:14:00sure to go and sign up for that. Again,
  12776. 8:14:01I'm going to be there, so it should be
  12777. 8:14:03really fun. Without further ado, let's
  12778. 8:14:05jump on my screen and start the
  12779. 8:14:06tutorial. Now, we are about to look at a
  12780. 8:14:08ton of different visualizations. Uh over
  12781. 8:14:11here, you can see just an array of them,
  12782. 8:14:14but not all of them are ones that I
  12783. 8:14:17actually think are useful or ones that I
  12784. 8:14:19would actually recommend using. And so,
  12785. 8:14:21I'm going to take you through some of
  12786. 8:14:22the ones that I absolutely think are
  12787. 8:14:25worth learning and using and trying out.
  12788. 8:14:27Uh, and I'm just going to kind of just
  12789. 8:14:30show you how I might use them, how they
  12790. 8:14:32might look, how you can navigate them a
  12791. 8:14:34little bit. Now, before we do that, we
  12792. 8:14:36do need to go download one data set.
  12793. 8:14:39It's this Starbucks location worldwide.
  12794. 8:14:41Yes, we're going to do a little bit of
  12795. 8:14:43longitude latitude here. And all we have
  12796. 8:14:46to do is click this downloads button and
  12797. 8:14:49it will download. We're going to do that
  12798. 8:14:51into downloads. We'll save that. Uh,
  12799. 8:14:54yeah, I've already done that, but you
  12800. 8:14:56know, I'm doing this with you guys. I'm
  12801. 8:14:58doing it for you. So, let's go to our
  12802. 8:15:00downloads.
  12803. 8:15:02Now we have here we want to come in
  12804. 8:15:04here. We're going to copy it or um you
  12805. 8:15:07can cut it. Uh and then we're going to
  12806. 8:15:10paste it here. Yeah. Replace it.
  12807. 8:15:12Perfect. And now we have it ready to go.
  12808. 8:15:16We'll come in here. Let's do a new
  12809. 8:15:18sheet. And I already have it in there,
  12810. 8:15:20but uh I'm just going to show you what I
  12811. 8:15:22would do. Do new data source. Uh we'll
  12812. 8:15:24do text file. We'll do directory. And we
  12813. 8:15:28will open it.
  12814. 8:15:31And let's see what data we have in here
  12815. 8:15:33before we actually begin. Uh just super
  12816. 8:15:35quickly. We have the brand. So, um
  12817. 8:15:39whatever company has it. And then a
  12818. 8:15:41bunch of um location information. Street
  12819. 8:15:45address, city, the state. This is all in
  12820. 8:15:48the United States. So, that's basically
  12821. 8:15:51it. And what we are going to do is we're
  12822. 8:15:53going to go over to this sheet three.
  12823. 8:15:56And we have this directory 2. That's the
  12824. 8:15:58one I just pulled in. uh exact same
  12825. 8:16:00thing as directory but so the first
  12826. 8:16:02visualization that we are going to look
  12827. 8:16:04at is a bar and line graph. So what
  12828. 8:16:06we're going to take is the year right
  12829. 8:16:08here and take these global sales and
  12830. 8:16:11these NA sales and we're going to be
  12831. 8:16:14doing this one right here. So this has a
  12832. 8:16:17combination of two separate uh types of
  12833. 8:16:20visualizations. So sometimes you just
  12834. 8:16:22have line, sometimes you just have these
  12835. 8:16:24uh these bar graphs or these bar charts.
  12836. 8:16:27Uh, and we're combining the two. And
  12837. 8:16:29it's very nice. I like how this looks.
  12838. 8:16:32Now, if you notice, if I put this NA
  12839. 8:16:35sales behind it, now it kind of cuts
  12840. 8:16:37off. So, now this global sales is in
  12841. 8:16:39front. We're going to, you know, put
  12842. 8:16:41that back. I just wanted to show you
  12843. 8:16:43that uh right here there's all sum of
  12844. 8:16:46global sales, sum of NA sales. So, if we
  12845. 8:16:48go into this all, we click this
  12846. 8:16:50dropdown, we can change it to a line.
  12847. 8:16:52Uh, we can change it basically whatever
  12848. 8:16:54we want. I just hit control-z to reverse
  12849. 8:16:56that. But what we can do is we can go in
  12850. 8:16:59here and we can change this color. And
  12851. 8:17:03let's see if we can just make it red. Is
  12852. 8:17:05that possible?
  12853. 8:17:08See what I did? I made it orange. That
  12854. 8:17:10works for me. Um, just something to
  12855. 8:17:12stick out a little bit more. Choose
  12856. 8:17:14whatever color you want. And this is a
  12857. 8:17:16really nice visualization. This is one
  12858. 8:17:17that I have used in the past. We're
  12859. 8:17:19looking at global sales versus the NA
  12860. 8:17:21sales. And so it's very easy to see the
  12861. 8:17:24distinction between the two and how one
  12862. 8:17:26was doing a specific year versus how the
  12863. 8:17:28other one was doing in that same year.
  12864. 8:17:31And so I really like this. If you want
  12865. 8:17:32to do something uh like keeping it
  12866. 8:17:34consistent, you can do two bars. I don't
  12867. 8:17:37really like this one as much. Um and you
  12868. 8:17:40can again you can really change it up.
  12869. 8:17:42Um there's lots of different ones that
  12870. 8:17:44you can do. Again, I prefer the line,
  12871. 8:17:46but you know, do whatever you think is
  12872. 8:17:49best. I'm going to change it back
  12873. 8:17:50because this is not how I want to keep
  12874. 8:17:52it. But there you go. So that is the
  12875. 8:17:54[clears throat] first one that we are
  12876. 8:17:55going to look at. Let's move on to the
  12877. 8:17:58second one. And we actually will be
  12878. 8:18:00using our our Starbucks data here. Now
  12879. 8:18:04when you bring in data that has um any
  12880. 8:18:07type of map or or um address or postal
  12881. 8:18:11code or things like that or or country,
  12882. 8:18:13it's typically going to create this
  12883. 8:18:15latitude and longitude and it's going to
  12884. 8:18:17generate that. Now, what we want to do
  12885. 8:18:19is bring this longitude right up here
  12886. 8:18:22and this latitude right there.
  12887. 8:18:26And if you do the show me right now,
  12888. 8:18:28it's giving us this. But what we want to
  12889. 8:18:30do is add what we're looking for. So,
  12890. 8:18:33what will we actually be trying to
  12891. 8:18:36search for on this map? You can do
  12892. 8:18:38anything from like a postal code. Um,
  12893. 8:18:41and it will drag us right here. Let's
  12894. 8:18:44come over to this. This allows us to
  12895. 8:18:46kind of scroll around a little bit. Um,
  12896. 8:18:50we're going to mess around with this one
  12897. 8:18:51for just a little bit. And see if I can
  12898. 8:18:56That's nice. That might be too big. Let
  12899. 8:18:59me back up one. So, at least in the
  12900. 8:19:02continental US, a little bit down here.
  12901. 8:19:05This these are the postal codes. So,
  12902. 8:19:06right now, we're looking at postcodes.
  12903. 8:19:08Uh, and
  12904. 8:19:11there are a lot that you can do with
  12905. 8:19:13this. Um really color will make almost
  12906. 8:19:15no difference. It just becomes this
  12907. 8:19:17mess. So you don't typically want to do
  12908. 8:19:19something like that. At least not for
  12909. 8:19:21this. Let's go to size. And if we make
  12910. 8:19:25it really small, you can kind of see
  12911. 8:19:29these groupings, these pairings um
  12912. 8:19:31typically of like larger cities or major
  12913. 8:19:34major metropolitan areas. And so you can
  12914. 8:19:37do this and it's and it's really really
  12915. 8:19:39easy. I don't recommend uh labeling
  12916. 8:19:42this. I don't even know if it'll do it.
  12917. 8:19:43Um, it would be an absolute mess to try
  12918. 8:19:46to label all these postcodes.
  12919. 8:19:48But let's bring this out and let's bring
  12920. 8:19:50these state and provinces in. Now, right
  12921. 8:19:53now, we have these little tiny tiny uh
  12922. 8:19:56dots on here. And I think what we want
  12923. 8:19:59to do is not increase the size, but over
  12924. 8:20:04here we want to actually do this and
  12925. 8:20:06make it a map. And so now it's going to
  12926. 8:20:08fill in all the states. And we can, you
  12927. 8:20:11know, why not? We'll add some color
  12928. 8:20:12here. Um, but we can
  12929. 8:20:16Oh, it has a numbered. I didn't think
  12930. 8:20:17they were numbered. Um,
  12931. 8:20:20oh, that's interesting. I haven't seen I
  12932. 8:20:22didn't look at that before. I was just
  12933. 8:20:24uh found that interesting. But now we
  12934. 8:20:26can see what uh what states Starbucks is
  12935. 8:20:29in. And as you can see, they're in all
  12936. 8:20:3150 states. But it's something
  12937. 8:20:33interesting to um look at to think
  12938. 8:20:35about. Now, if we go right up here, we
  12939. 8:20:38can again choose a different type. and
  12940. 8:20:40we're going to go to the density. Now,
  12941. 8:20:43right now, it's just doing a density on
  12942. 8:20:44the uh the state. We're get rid of that.
  12943. 8:20:47We're going to bring back postal code.
  12944. 8:20:49I'm just switching it up on you a little
  12945. 8:20:50bit. And you can do it as small or as
  12946. 8:20:53big as you'd like. Um you know, I like
  12947. 8:20:56to do somewhere in the middle. Um
  12948. 8:20:58probably right
  12949. 8:21:00right about there is fine. Um I don't
  12950. 8:21:03think it's going to make sense to really
  12951. 8:21:04add any color here. Again, all these
  12952. 8:21:05poster codes are different, so it's just
  12953. 8:21:07going to be complete mish mash. But uh
  12954. 8:21:09this is kind of how you can use a
  12955. 8:21:11density map. And you can do this AC with
  12956. 8:21:14uh countries, you can do this with
  12957. 8:21:16postal codes, you can do this with any
  12958. 8:21:18type of kind of like address or
  12959. 8:21:19locationbased data. So that is how you
  12960. 8:21:23can use a map. Again, there's lots of
  12961. 8:21:26different ways to use a map. And so I'm
  12962. 8:21:28not going to show you every single way,
  12963. 8:21:30but in a really brief way, this is how
  12964. 8:21:31you can use a map to actually visualize
  12965. 8:21:33your data that does have location uh
  12966. 8:21:36based information in it. So, let's go
  12967. 8:21:38over to sheet three. Uh, and this data
  12968. 8:21:40that we have over here, it just allows
  12969. 8:21:43for a lot of different types of
  12970. 8:21:44visualizations. So, we're going to use
  12971. 8:21:46this one. Um, and there are lots of
  12972. 8:21:48other ones that you might see out there,
  12973. 8:21:51like this one right here. Uh, we
  12974. 8:21:53obviously wouldn't be using this. We
  12975. 8:21:55might do something like this. Change the
  12976. 8:21:59label.
  12977. 8:22:00Um, and maybe add Why are both of these
  12978. 8:22:03in here? Um, let's get rid of this.
  12979. 8:22:06Oops, that's not what I meant. Let's
  12980. 8:22:07actually add that. Let's do the sum of
  12981. 8:22:10global sales and we'll just make that
  12982. 8:22:12into a label as well. So,
  12983. 8:22:16what you can do with these and and how
  12984. 8:22:18you're able to use them and visualize
  12985. 8:22:20them. Again, these are not you'll see
  12986. 8:22:23these often, but these are not often
  12987. 8:22:25ones that I would recommend you use.
  12988. 8:22:27That's very similar to these packed
  12989. 8:22:29bubbles. Um, you can add these global
  12990. 8:22:33sales in here. again add the label. It
  12991. 8:22:37just uh it sometimes is not as
  12992. 8:22:39straightforward the information that
  12993. 8:22:42it's trying to tell you, right? You kind
  12994. 8:22:44of have to search for it a little bit.
  12995. 8:22:45You kind of have to look around. Um but
  12996. 8:22:49you can find some good visualizations in
  12997. 8:22:51here for very specific types of data.
  12998. 8:22:54And so these are just ones to consider.
  12999. 8:22:56Uh one that you'll see all the time is
  13000. 8:23:00uh this guy right here. And uh let me
  13001. 8:23:03see if I can expand this a little bit
  13002. 8:23:06cuz this is
  13003. 8:23:08very small. Um let's see. I have this I
  13004. 8:23:13just want global sales
  13005. 8:23:15and let's label that
  13006. 8:23:19the size.
  13007. 8:23:22How do I expand this? Haven't done this
  13008. 8:23:25in a while. Let me just expand this. I
  13009. 8:23:28don't use pie charts. What is happening?
  13010. 8:23:32This is a incredibly large pie chart. Oh
  13011. 8:23:35my gosh. I am making this um this is
  13012. 8:23:38becoming a problem. There we go. Uh and
  13013. 8:23:41what I actually wanted to do was label
  13014. 8:23:42the uh genre as well as I've been doing
  13015. 8:23:45in all the other ones. Uh and we'll
  13016. 8:23:48label this. Now look, whether you are a
  13017. 8:23:52fan of pie charts or not, you have to
  13018. 8:23:55understand that people use them. Uh some
  13019. 8:23:57people just like how they look. And for
  13020. 8:24:00certain data, it can do well. For things
  13021. 8:24:04that have a lot of different um
  13022. 8:24:06groupings or categories, it usually
  13023. 8:24:08isn't super great. Uh but it does give
  13024. 8:24:11you some type of order of things, give
  13025. 8:24:14you a quick glance, and people use them,
  13026. 8:24:16right? So, let's not pretend like
  13027. 8:24:20it's like the the the hideous stepchild.
  13028. 8:24:22All right? People use it. People have it
  13029. 8:24:25in their dashboards and their
  13030. 8:24:26visualizations all over. So, it's best
  13031. 8:24:28to just know what they look like, know
  13032. 8:24:30how to do them, know um how to use them
  13033. 8:24:32best. Again, I'm not a super huge huge
  13034. 8:24:35fan of it myself. I've used it once or
  13035. 8:24:38twice, but one to look out for. And
  13036. 8:24:41again, you can come over to here and use
  13037. 8:24:43is called a box and whisker plot. Um
  13038. 8:24:46it's good for these large um
  13039. 8:24:49distributions. You know, this is like
  13040. 8:24:53the median, upper, upper, lower, lower.
  13041. 8:24:55I don't use these a lot, but I know a
  13042. 8:24:57lot of people who love them. Something
  13043. 8:25:00to just look at and consider, mess
  13044. 8:25:03around with it a little bit. It's
  13045. 8:25:04pretty, I think, straightforward, and it
  13046. 8:25:07does give you some good insight into
  13047. 8:25:09your data if you know how to use it.
  13048. 8:25:11Now, there is one last one that I want
  13049. 8:25:13to show you. I'm just going to create it
  13050. 8:25:14on a new sheet. Make it easy. Uh, we'll
  13051. 8:25:18do year here. We'll do sum of Let's do
  13052. 8:25:22NA sales. Why not?
  13053. 8:25:25And we are going to make this like this.
  13054. 8:25:28Now, it's very similar to a line chart.
  13055. 8:25:31But when we break it out by the genre
  13056. 8:25:34and we add some color, you know, it's
  13057. 8:25:37just a different way to visualize this
  13058. 8:25:40information. You can uh you know,
  13059. 8:25:43potentially add some stuff in here like
  13060. 8:25:45some labels if you uh want to depending
  13061. 8:25:48on how it looks for you. But this is
  13062. 8:25:51just another way to visualize the data.
  13063. 8:25:53So, wanting to give you guys some
  13064. 8:25:55options, wanting to give you some things
  13065. 8:25:58that you might want to look at if you
  13066. 8:26:01haven't already used these before. These
  13067. 8:26:03are ones all every single one that I've
  13068. 8:26:04showed you are ones that I've at least
  13069. 8:26:06used once. Um, this one I maybe have
  13070. 8:26:09literally only used once, but the first
  13071. 8:26:12ones that I showed you, the ones I
  13072. 8:26:13pointed out as the ones that I really
  13073. 8:26:15wanted you to know are great
  13074. 8:26:18visualizations to learn how to use and
  13075. 8:26:21learn how to make useful for the data
  13076. 8:26:23that you have. With that being said,
  13077. 8:26:24that is all that we are looking at in
  13078. 8:26:26this video. Again, I tried to keep it
  13079. 8:26:28super easy. Just wanted to show you some
  13080. 8:26:30different visualizations, the data that
  13081. 8:26:31you can use to get those visualizations,
  13082. 8:26:33and just some other options in case you
  13083. 8:26:35wanted to get a little bit uh
  13084. 8:26:37spontaneous, a little bit out there, a
  13085. 8:26:39little bit funky uh to show your boss or
  13086. 8:26:41something like that. Thank you guys so
  13087. 8:26:43much for watching. I really appreciate
  13088. 8:26:45it. If you like this video, be sure to
  13089. 8:26:47like and subscribe below and I will see
  13090. 8:26:49you in the next video.
  13091. 8:26:52[music]
  13092. 8:26:58>> [music]
  13093. 8:27:05>> What's going on everybody? Welcome back
  13094. 8:27:06to another video. Today we're looking at
  13095. 8:27:08joins in Tableau.
  13096. 8:27:13[music]
  13097. 8:27:15Now before we get into the tutorial, I
  13098. 8:27:17want to give a huge shout out to today's
  13099. 8:27:18sponsor and that is Udemy. They are
  13100. 8:27:20having a massive Black Friday sale.
  13101. 8:27:22Everything is about 85% off. So, if
  13102. 8:27:25you've been looking at a course, now is
  13103. 8:27:26the time to buy it. If you are looking
  13104. 8:27:29at learning and taking a actual full
  13105. 8:27:31Tableau course, there are fantastic ones
  13106. 8:27:33on Udemy that I have taken myself. So,
  13107. 8:27:35be sure to go and check out Udei while
  13108. 8:27:37they're having this huge sale. I will
  13109. 8:27:38include a link in the description if you
  13110. 8:27:40want to check them out. Now, let's get
  13111. 8:27:42into the tutorial. All right, let's get
  13112. 8:27:43started. And first, we're going to start
  13113. 8:27:44off in Excel. I'm going to kind of walk
  13114. 8:27:46you through the data that we're working
  13115. 8:27:47with and then we're going to put it into
  13116. 8:27:49Tableau and I'm going to show you how to
  13117. 8:27:51do all those joins in Tableau. So the
  13118. 8:27:53first table that we have is this
  13119. 8:27:55demographics table. We have employee ID,
  13120. 8:27:57name of employee, employee age and
  13121. 8:27:59employee gender. Now look right here
  13122. 8:28:01because this will be important uh going
  13123. 8:28:03forward. In the demographics table, we
  13124. 8:28:06have 10 uh individuals and they each
  13125. 8:28:09have an employee ID. Now, when we go to
  13126. 8:28:11the job title, we have our employee ID,
  13127. 8:28:14employee name, and the job title. But
  13128. 8:28:17this one is missing Ryan Howard is
  13129. 8:28:19missing his employee ID. And then the
  13130. 8:28:22very last one, there are only seven
  13131. 8:28:25employee IDs and no names. Um, and so
  13132. 8:28:28we're going to use all of that and I'm
  13133. 8:28:29going to show you how to actually do the
  13134. 8:28:31joins in Tableau. Tableau does a really
  13135. 8:28:34fantastic job of visualizing it for you,
  13136. 8:28:36so it takes a lot of the guesswork out.
  13137. 8:28:38Um, I am going to include a link to my
  13138. 8:28:40joins video in SQL because these two are
  13139. 8:28:42very closely connected and and if you
  13140. 8:28:45understand how the joins work in in SQL,
  13141. 8:28:48you'll understand how the joins work in
  13142. 8:28:49Tableau, it's almost the exact same
  13143. 8:28:52thing. So, with that being said, let's
  13144. 8:28:55jump over to Tableau. So, I'm going to
  13145. 8:28:57pull this up and go right over here. And
  13146. 8:29:00now we have uh where we can connect to
  13147. 8:29:03our data. And so, we're going to click
  13148. 8:29:05Microsoft Excel. I'm going to scroll
  13149. 8:29:07down here to Tableau joins file. I'm
  13150. 8:29:10going to open this up. And I have it
  13151. 8:29:11open so I can't use it. So, let me get
  13152. 8:29:13rid of that and let's open it again.
  13153. 8:29:16Perfect. So, now what we're going to do,
  13154. 8:29:19and I'm going to show you how to
  13155. 8:29:20actually open up the joins um in a
  13156. 8:29:22second. But what you need to understand
  13157. 8:29:23is when you first come here, Tableau
  13158. 8:29:26doesn't automatically allow you to to
  13159. 8:29:29use the joins. They use something called
  13160. 8:29:31relationships. And there are joins on
  13161. 8:29:33the back end, but they call it
  13162. 8:29:35relationships because they are inferring
  13163. 8:29:36all of these things. They're trying to
  13164. 8:29:38go in and make that inference for you.
  13165. 8:29:40So, it takes a lot of the work off of
  13166. 8:29:42you. And most of the time that works.
  13167. 8:29:44And and you know, you just plug these
  13168. 8:29:46two things in here like a demographics
  13169. 8:29:48and the job title. And it is going to,
  13170. 8:29:52you know, help you build those what they
  13171. 8:29:54call relationships. And you can click on
  13172. 8:29:57this and learn how the relationships
  13173. 8:29:58differ from joins. Again, there's not a
  13174. 8:30:00huge difference, but it's not as
  13175. 8:30:02customizable, and you can't as easily do
  13176. 8:30:05left joins or full joins or all these
  13177. 8:30:07things that we're about to look at. So,
  13178. 8:30:09uh, I'm going to take this one off. And
  13179. 8:30:11what we're going to do to actually be
  13180. 8:30:13able to look at the joins and and choose
  13181. 8:30:16what joins we want to use is we're going
  13182. 8:30:17to do this dropdown. We're going to
  13183. 8:30:19click open. And so, now we are in a
  13184. 8:30:22place where we can actually create the
  13185. 8:30:25joins. Uh, and again, it's just much
  13186. 8:30:28more customizable. And so, um, back when
  13187. 8:30:31I was using Tableau regularly, I would
  13188. 8:30:35use the relationships when it was pretty
  13189. 8:30:36simple and straightforward because
  13190. 8:30:38almost they almost always got it right.
  13191. 8:30:40But, uh, you know, the joins, it it just
  13192. 8:30:44makes more sense in the way it
  13193. 8:30:45visualizes it for me. So, most of the
  13194. 8:30:47time I'd be using the joins. So, let's
  13195. 8:30:50pull over this job title right here.
  13196. 8:30:53And it's going to make this connection.
  13197. 8:30:55Now, before if you remember just about,
  13198. 8:30:57you know, 30 seconds ago when it
  13199. 8:30:59connected them, it was just a line. And
  13200. 8:31:01and so it gave us this option down here
  13201. 8:31:03to kind of edit the relationship. But
  13202. 8:31:05now it's giving us this visualization.
  13203. 8:31:07And so let's click on it really quick.
  13204. 8:31:09And what is going to come up is the
  13205. 8:31:11different types of joins that you can
  13206. 8:31:13do. You can do an inner join, a left
  13207. 8:31:14join, a right join, and a full outer
  13208. 8:31:17join. And then you can actually choose
  13209. 8:31:20the different uh data sources and how
  13210. 8:31:22you're connecting them. So again, um I'm
  13211. 8:31:25going to walk through a little bit of
  13212. 8:31:26this, but I think the SQL video that I
  13213. 8:31:29did on this shows it so well. Um I would
  13214. 8:31:32just highly recommend using that. Um and
  13215. 8:31:34I recommend learning SQL, too.
  13216. 8:31:36[clears throat] So, you know, two birds,
  13217. 8:31:37one stone. So, I'm going to get into
  13218. 8:31:40each of the joins, how they work, what
  13219. 8:31:43data is going to be displayed. Um and
  13220. 8:31:45these visualizations are really going to
  13221. 8:31:47be helpful, and I think that it's it's
  13222. 8:31:50just nice that they have it because it's
  13223. 8:31:51a little reminder. Okay. um you know
  13224. 8:31:54this is what this joint is or this is
  13225. 8:31:55what that joint is. So super super
  13226. 8:31:57simple. So right now we have the
  13227. 8:31:59demographics table and we have the job
  13228. 8:32:02title table. And so what it's doing
  13229. 8:32:04right now and let's get rid of this.
  13230. 8:32:06What it's doing right now is it's doing
  13231. 8:32:07an injoin. And so it's pulling
  13232. 8:32:10everything that overlaps if it matches
  13233. 8:32:12on the employee ID and the employee ID.
  13234. 8:32:16And so right now you only see one
  13235. 8:32:18through nine. But if you remember in the
  13236. 8:32:20demographics table, we had uh 1,000 all
  13237. 8:32:23the way through 10. So where is that
  13238. 8:32:2510th one? Well, the 10th one is not
  13239. 8:32:27there. And that is because in this job
  13240. 8:32:30title employee ID, it only went up to
  13241. 8:32:331009. And then Ryan Howard just didn't
  13242. 8:32:37have an employee ID in there for
  13243. 8:32:38whatever reason. So that data is going
  13244. 8:32:39to be missing. Now when you are using
  13245. 8:32:42actual data sets very large data sets
  13246. 8:32:45which we will use in the next video when
  13247. 8:32:47we walk through an entire project
  13248. 8:32:50um when you use large data sets this can
  13249. 8:32:53be the difference between clean data and
  13250. 8:32:56very wrong data and and visualizing it
  13251. 8:32:59correctly and showing completely wrong
  13252. 8:33:01numbers. And so you really need to be
  13253. 8:33:03sure you understand how your data works
  13254. 8:33:05together when you're doing these joins.
  13255. 8:33:07So how can we fix this? How can we um
  13256. 8:33:11make it to where we can see all of the
  13257. 8:33:13data? Well, right now we're only making
  13258. 8:33:15it to where if the employee ID is equal
  13259. 8:33:17to the employee ID. So, we only are
  13260. 8:33:19going to see through 1009 and through
  13261. 8:33:211009. We're never going to see Ryan. So,
  13262. 8:33:24there are two different types of joins
  13263. 8:33:25that we could do to make it see it. And
  13264. 8:33:28then there's something else that we can
  13265. 8:33:29join on to where we can see that data.
  13266. 8:33:31The first one that we can look at is the
  13267. 8:33:33right uh join. And what this does is
  13268. 8:33:36it's going to take everything that is
  13269. 8:33:38the same, but also everything from this
  13270. 8:33:41job title table regardless of if it has
  13271. 8:33:43a match in the demographics table. So
  13272. 8:33:45it's pretty, you know, this
  13273. 8:33:46visualization does it all. It's going to
  13274. 8:33:48show everything in the right table
  13275. 8:33:49regardless. And it's only going to show
  13276. 8:33:52things from this table if there's a
  13277. 8:33:54match. So let's try this one. And we
  13278. 8:33:56should see Ryan Howard in the job title
  13279. 8:33:58table. So let's click on it. And if we
  13280. 8:34:01scroll down, there's going to be null,
  13281. 8:34:02null, null, null, null until we get to
  13282. 8:34:06over here where we now have the data
  13283. 8:34:09that we had in that actual table. But
  13284. 8:34:12again, this wasn't a match. And so we
  13285. 8:34:14weren't able to see that data. So this
  13286. 8:34:16gives us a way to where we can see all
  13287. 8:34:19of it. Um, all everything from that
  13288. 8:34:22right table, this job title table. And
  13289. 8:34:24now we're going to click on the full
  13290. 8:34:25outer. Now, the full outer is going to
  13291. 8:34:28take everything from both regardless of
  13292. 8:34:30if there is a match at all. And so,
  13293. 8:34:33right here, you're going to see Ryan
  13294. 8:34:34Howard and Ryan Howard. Now, why are
  13295. 8:34:35there two different rows for it? Well,
  13296. 8:34:37because in the demographics table, there
  13297. 8:34:40was an employee ID. So, we're seeing the
  13298. 8:34:42employee ID, Ryan Howard, his age, and
  13299. 8:34:44his gender. And over here, there was no
  13300. 8:34:48match, right? But in the job title
  13301. 8:34:51table, again, this one didn't have an
  13302. 8:34:53employee ID. And so we we are going to
  13303. 8:34:55be able to see this data, but over here
  13304. 8:34:59it has no match. And so that's why it's
  13305. 8:35:02showing us two different rows is because
  13306. 8:35:04there was no connection. There was no
  13307. 8:35:06match there. That's what a full outer
  13308. 8:35:08join is going to do. Now, just for uh
  13309. 8:35:12the purposes of seeing what this one
  13310. 8:35:13does as well, we have the lefth hand
  13311. 8:35:15table. Um and now we are able to see the
  13312. 8:35:19110 or or that we didn't see before. um
  13313. 8:35:23and it's putting in nulls over here
  13314. 8:35:25because there's no match. So that's that
  13315. 8:35:27is um what we have so far. Now like I
  13316. 8:35:31said just a second ago, there is a way
  13317. 8:35:33that we can do this without using the
  13318. 8:35:36employee IDs. We're allowed to use a
  13319. 8:35:38different join clause. Now there is the
  13320. 8:35:41name of the employee in both of them.
  13321. 8:35:42This one is called name of employee and
  13322. 8:35:44in the job title it's called employee
  13323. 8:35:46name. They don't have to have the same
  13324. 8:35:48column name in order to join it. You can
  13325. 8:35:50do whatever you want. So, I'm going to
  13326. 8:35:54get rid of this one.
  13327. 8:35:56And now we are only tying it on the
  13328. 8:35:59employee name. And let's do an inner
  13329. 8:36:02join. And it should be basically
  13330. 8:36:06everything um except the only piece of
  13331. 8:36:08data that wasn't filled in, which is
  13332. 8:36:10that 1,0 over on the job title table.
  13333. 8:36:14And so this way was a slightly different
  13334. 8:36:17maybe uh less thought of way because
  13335. 8:36:19normally you do it if there's an ID you
  13336. 8:36:21go on the IDs but because we had a lack
  13337. 8:36:26of data for in in one of the tables in
  13338. 8:36:28the job title table we decided to use a
  13339. 8:36:31different column to to join on and now
  13340. 8:36:34we're able to look at all the data
  13341. 8:36:36together. So, super quickly, that is an
  13342. 8:36:40inner join, a left joint, a right joint,
  13343. 8:36:42and a full outer join. And it's pretty
  13344. 8:36:44easily visualized here. And you're able
  13345. 8:36:47to uh change what you're joining on
  13346. 8:36:50right here. But you're also you can do
  13347. 8:36:52multiple. So, if we want to do the
  13348. 8:36:54employee ID and the employee ID, you can
  13349. 8:36:56do that as well. And you can keep going
  13350. 8:36:58as as many as you'd like. Um, and right
  13351. 8:37:03here, you can change some of these
  13352. 8:37:05things. Uh I don't there aren't a lot of
  13353. 8:37:08use cases for this. Um but you know you
  13354. 8:37:11can absolutely do this um and mess
  13355. 8:37:13around with this as seen. I'm not going
  13356. 8:37:14to go through it in the tutorial because
  13357. 8:37:16again 95 plus% of the joins you're
  13358. 8:37:20doing, you're going to want to do it to
  13359. 8:37:21where this equals this. Um and if you
  13360. 8:37:23want to get into where it doesn't equal
  13361. 8:37:25or or all these other things, which is
  13362. 8:37:27more complicated, I think it's much
  13363. 8:37:30better to learn that in SQL. Uh that's
  13364. 8:37:32my personal preference. And so, um,
  13365. 8:37:34again, all in the SQL tutorial if you
  13366. 8:37:36want to check that one out. So, you're
  13367. 8:37:37able to join on multiple things. Now,
  13368. 8:37:39let's get rid of that one because we can
  13369. 8:37:42actually bring in this salary one as
  13370. 8:37:44well. And what you'll see right down
  13371. 8:37:46here
  13372. 8:37:48is that we have our employee ID and this
  13373. 8:37:51is all coming from the demographics. So,
  13374. 8:37:52employee ID, name of employer, employee
  13375. 8:37:55age, employee gender. Then right over
  13376. 8:37:58here, we have the job title table. So
  13377. 8:38:01employee ID, job title, employee name,
  13378. 8:38:04job title, and then right over here was
  13379. 8:38:08or is our salary table. And so we have
  13380. 8:38:10employee ID, salary, and employee
  13381. 8:38:12salary. So again, this is a way that you
  13382. 8:38:15can put all of this data into one place.
  13383. 8:38:17And in just a second, we'll go into the
  13384. 8:38:19worksheet right down here. I'm going to
  13385. 8:38:21show you kind of how it looks because it
  13386. 8:38:23looks a little bit different um than
  13387. 8:38:24previous tutorials. And so I want to
  13388. 8:38:27show you how that actually all works
  13389. 8:38:29together. Um, but again, you can create
  13390. 8:38:32these joins um as well and do the exact
  13391. 8:38:36same thing that we just looked at and
  13392. 8:38:37customize the joins, customize what
  13393. 8:38:39you're what you're um uh joining on. And
  13394. 8:38:43then you have your finished product. And
  13395. 8:38:45so right now we have our demographics
  13396. 8:38:47plus Tableau joins file. And we can
  13397. 8:38:50rename that if we want. I'm going to
  13398. 8:38:52call this um demographics plus joins
  13399. 8:38:56demo and click enter. And so now that is
  13400. 8:39:00saved. So now let's go down to the go to
  13401. 8:39:03worksheet. We're going to click on that.
  13402. 8:39:05And so up here on our left side, this
  13403. 8:39:07may look a little bit different than it
  13404. 8:39:08normally does. Um because it's broken
  13405. 8:39:11out um on the measure names and the
  13406. 8:39:13measure values. It's broken out by the
  13407. 8:39:15tables that they were joined on. So, we
  13408. 8:39:18can pull in the employee gender now, and
  13409. 8:39:20we can pull in the employee name now.
  13410. 8:39:23Um, and [snorts] we can pull in the
  13411. 8:39:24employee ID again if we want to from the
  13412. 8:39:27job title table, and we can pull in the
  13413. 8:39:30employee ID from the salary table. We
  13414. 8:39:31could do that if we wanted to. It makes
  13415. 8:39:33no sense uh uh for actually creating any
  13416. 8:39:35visualizations, but you know, you can do
  13417. 8:39:37that. And so, you probably you wouldn't
  13418. 8:39:39be able to do that if you hadn't joined
  13419. 8:39:40these together. And so down here in the
  13420. 8:39:43measure values, the values that we have
  13421. 8:39:45are from the demographics table and the
  13422. 8:39:47salary table. All of the um all of the
  13423. 8:39:51stuff from the employee title, none of
  13424. 8:39:54those things were um values. And so we
  13425. 8:39:57can't use there are going to be no
  13426. 8:39:58values down here. And so really quick,
  13427. 8:40:01let's take the name of the employee.
  13428. 8:40:03Let's take their salary. Sure, why not?
  13429. 8:40:06Um let's order that.
  13430. 8:40:10Let's take the employee salary.
  13431. 8:40:13We'll do color.
  13432. 8:40:15And uh let's expand this out a little
  13433. 8:40:19bit.
  13434. 8:40:21Maybe one more time. Oops. Just like
  13435. 8:40:24that. And there you go. So that is how
  13436. 8:40:26you do joins in Tableau. And I think
  13437. 8:40:28Tableau does a really fantastic job of
  13438. 8:40:30making it pretty simple. They have the
  13439. 8:40:32different types of joins when you click
  13440. 8:40:34on that that join button. And it shows
  13441. 8:40:36you the inner and the left and the right
  13442. 8:40:37and the full outer. and they make it
  13443. 8:40:39pretty simple. Um, and and it's just
  13444. 8:40:42really useful to be able to see that
  13445. 8:40:45while you're creating it and see the
  13446. 8:40:46output below like we just did a second
  13447. 8:40:48ago. It just makes it so simple to
  13448. 8:40:51create those joins and then just keep
  13449. 8:40:52going because you already know what your
  13450. 8:40:54output is going to be and you can kind
  13451. 8:40:55of mess around with it and make sure
  13452. 8:40:57you're getting the data that you need.
  13453. 8:40:58In the very next video, we're going to
  13454. 8:41:00be doing an entire project in Tableau.
  13455. 8:41:02We're going to be using a lot more data
  13456. 8:41:04and it's going to be a a complete
  13457. 8:41:06project that you can add to your
  13458. 8:41:07portfolio and it's going to be a really
  13459. 8:41:09good time. So, I hope that you join me
  13460. 8:41:11for that one. I appreciate your time. I
  13461. 8:41:13hope that this was helpful. Thank you
  13462. 8:41:15guys so much for watching. I really
  13463. 8:41:16appreciate it. If you like this video,
  13464. 8:41:18be sure to like and subscribe below and
  13465. 8:41:20I'll see you in the next video.
  13466. 8:41:23[music]
  13467. 8:41:33What's going on everybody? Welcome back
  13468. 8:41:35to the Tableau tutorial series. This is
  13469. 8:41:36our very last video in the series and
  13470. 8:41:39today we'll be doing an entire project.
  13471. 8:41:43[music]
  13472. 8:41:46Now, if you watching this video, I hope
  13473. 8:41:48that you watch the other four videos in
  13474. 8:41:49this series just so you can get the
  13475. 8:41:51basics down. You kind of know what
  13476. 8:41:52you're doing. Uh this won't be a crazy
  13477. 8:41:55hard project. This is a beginner
  13478. 8:41:57tutorial series, so I'm trying to make
  13479. 8:41:58this super easy so you can follow along.
  13480. 8:42:01Nothing super complicated, I promise.
  13481. 8:42:03And if you were wanting to go above and
  13482. 8:42:04beyond and just make a lot of different
  13483. 8:42:06dashboards or try a lot of different
  13484. 8:42:07things, there's a ton of data in here.
  13485. 8:42:10And so I'll show you some of the things
  13486. 8:42:11that I would do, you know, as we go
  13487. 8:42:13through it of the things that I would be
  13488. 8:42:14looking at and some of the different
  13489. 8:42:15visualizations that I might do as well.
  13490. 8:42:18But again, in this video, we're going to
  13491. 8:42:19be singing to a lot of the basics. But
  13492. 8:42:21I'll switch over to my screen in just a
  13493. 8:42:22second. and I will show you the final
  13494. 8:42:23product and then we will actually walk
  13495. 8:42:25through step by step of how to do the
  13496. 8:42:27entire dashboard and at the end you
  13497. 8:42:29should have a completed project that you
  13498. 8:42:30can add to your portfolio or you know
  13499. 8:42:32just share on LinkedIn if you want to do
  13500. 8:42:34that as well. With that being said,
  13501. 8:42:35let's jump over to my screen and let's
  13502. 8:42:37get started. All right, so let's get me
  13503. 8:42:38off screen and show you what we're going
  13504. 8:42:40to be working on today. This is the
  13505. 8:42:41final dashboard that we're actually
  13506. 8:42:43going to be building. And so it it's
  13507. 8:42:45nothing crazy, right? I'm sure you have
  13508. 8:42:47seen all of these things before. Um, and
  13509. 8:42:49I'm just going to help you kind of build
  13510. 8:42:50it out, show you what to do, the buttons
  13511. 8:42:53to click. Um, and it's really going to
  13512. 8:42:55be a simple walkthrough. By the end of
  13513. 8:42:57this, you should be able to do all these
  13514. 8:42:58things very easily. And I highly
  13515. 8:43:01encourage looking at the data and
  13516. 8:43:03looking at these visualizations and
  13517. 8:43:04seeing what else you can do with it.
  13518. 8:43:06There's a lot of different colors, a lot
  13519. 8:43:08of different visualizations um, that you
  13520. 8:43:10can do with this data. I'm just showing
  13521. 8:43:12you this today. And so the more you go
  13522. 8:43:15out there and the more you do this on
  13523. 8:43:16your own and you mess around with stuff
  13524. 8:43:19and and choose different things and see
  13525. 8:43:20how it all works, the better you're
  13526. 8:43:22going to get. And so I highly highly
  13527. 8:43:23encourage doing that. Uh so what we are
  13528. 8:43:26going to be working with today is an
  13529. 8:43:28Airbnb data set. I'm going to show you
  13530. 8:43:30that in just a second and I'm going to
  13531. 8:43:32show you the data and we're going to
  13532. 8:43:34just jump right into it. All right. So
  13533. 8:43:36this is the data set that we are going
  13534. 8:43:37to be using. This is the Seattle Airbnb
  13535. 8:43:40open data set. And let's scroll down
  13536. 8:43:43really quick. Um there's three different
  13537. 8:43:45CSVs in here. And so this is some of the
  13538. 8:43:48data that we're going to be working
  13539. 8:43:49with. Um some date and listings, and
  13540. 8:43:52some pricing. And then there's the
  13541. 8:43:54actual listing that shows um the actual
  13542. 8:43:57street address, the location, the price,
  13543. 8:44:00the bedrooms, all of these good stuff.
  13544. 8:44:02And then there's a reviews.
  13545. 8:44:05Um, and it has, you know, some comments
  13546. 8:44:07and, you know, talks about some of the
  13547. 8:44:09reviews. So, this is what we're going to
  13548. 8:44:12be working with, but you don't have to
  13549. 8:44:14go in here and download it. I have
  13550. 8:44:16already combined all of these CSVs into
  13551. 8:44:19one. I've put it on the GitHub, so I'll
  13552. 8:44:22have a link below, so you can just click
  13553. 8:44:23on that and you don't have to do all the
  13554. 8:44:25stuff that I did to get this set up. Um,
  13555. 8:44:27just so you know, this is from 2016, so
  13556. 8:44:29this data set is a little bit old. If
  13557. 8:44:32you want to, you can come right here and
  13558. 8:44:34I will leave this link as well and you
  13559. 8:44:36can get the data set from you know what
  13560. 8:44:38is this a couple weeks ago. Uh this is
  13561. 8:44:41they they are continuing to update this.
  13562. 8:44:43This is always updated and so you can go
  13563. 8:44:44ahead and download these but some of
  13564. 8:44:46these are the CSV.gz. Um so you may need
  13565. 8:44:49to like convert it. I don't want to go
  13566. 8:44:51through that process um on you know in
  13567. 8:44:54the video and so I am just going to go
  13568. 8:44:57with what is literally in Kaggle um and
  13569. 8:45:00use that. But if you want to have an
  13570. 8:45:02updated one for your project, I just
  13571. 8:45:04advise you to go in here and grab it
  13572. 8:45:06yourself and that should be perfectly
  13573. 8:45:08good. So go ahead and download the data
  13574. 8:45:11set from the GitHub and we should be
  13575. 8:45:13good to go. So this is the Excel that I
  13576. 8:45:15was just talking about. This has all of
  13577. 8:45:17our CSVs in one place. This is, you
  13578. 8:45:19know, an Excel workbook. So in this
  13579. 8:45:22reviews, actually, let's start with the
  13580. 8:45:24listings cuz that's kind of where it all
  13581. 8:45:25stems from. Uh we have our listing and
  13582. 8:45:28the date or the data in here is um you
  13583. 8:45:31know really extensive. There's a lot of
  13584. 8:45:33data in here. So let's get over really
  13585. 8:45:35quick. Um the listing refers to the
  13586. 8:45:38actual home that they're renting out the
  13587. 8:45:41Airbnb. So it shows their location.
  13588. 8:45:45Um and there's a lot more location
  13589. 8:45:47information over here. I'm getting into
  13590. 8:45:48it in in just a second. So, there's the
  13591. 8:45:50neighborhood, the city, state, um, zip
  13592. 8:45:53code, all stuff that, you know, may be
  13593. 8:45:55useful. There's a latitude and
  13594. 8:45:57longitude.
  13595. 8:45:59It shows what type of property it is, so
  13596. 8:46:01that's really good. Um, right over here,
  13597. 8:46:04it has, you know, how many bathrooms,
  13598. 8:46:06bedrooms, and beds. Um, you know,
  13599. 8:46:08sometimes if it's a five bedroomedroom
  13600. 8:46:09house, it's has seven beds. So, that's
  13601. 8:46:12why there's those two different um
  13602. 8:46:14fields. I don't know if you're familiar
  13603. 8:46:16with Airbnb and and you know what they
  13604. 8:46:18have on there, but just something to
  13605. 8:46:20note. Uh they have the price. This is
  13606. 8:46:22the price per day. There's a weekly
  13607. 8:46:24price, a monthly price, and if there's a
  13608. 8:46:26deposit needed, uh and then a cleaning
  13609. 8:46:29fee as well. So, a bunch of financial
  13610. 8:46:32data that's, you know, super useful. We
  13611. 8:46:34go into it a little bit, but there's so
  13612. 8:46:36much you can do with that. Um, you know,
  13613. 8:46:38if you want to dig into that, and that's
  13614. 8:46:40kind of it. The rest of it's pretty uh
  13615. 8:46:42pretty useless. Um, and there's a lot
  13616. 8:46:44of, so there's so much data in here,
  13617. 8:46:45almost, you know, more than half by far
  13618. 8:46:48is nothing you would put in any type of
  13619. 8:46:50visualization. Um, and this is pretty
  13620. 8:46:52common. Uh, you're not going to get
  13621. 8:46:55data every column where you're going to
  13622. 8:46:57be able to use it. A lot of times it's
  13623. 8:46:59just a lot of useless junk. And so you
  13624. 8:47:01have to know what you're looking for and
  13625. 8:47:02know uh, you know, what's actually
  13626. 8:47:04useful. So that's the listing. Then we
  13627. 8:47:06have reviews. Now
  13628. 8:47:09what's really a little bit confusing in
  13629. 8:47:11here and something that you just need to
  13630. 8:47:12kind of understand about the data u and
  13631. 8:47:14something that if you're if you get a
  13632. 8:47:16data analyst job you need to understand
  13633. 8:47:18your data because it's very easy to come
  13634. 8:47:20in here and say okay there's an ID ID
  13635. 8:47:22field and here's an ID field. So that
  13636. 8:47:25means that those are the same. Well not
  13637. 8:47:27in this case um this ID field is
  13638. 8:47:29actually the reviews ID not the reviewer
  13639. 8:47:32ID that refers to like the person. This
  13640. 8:47:35is the reviews ID. this listing ID is
  13641. 8:47:38the actual ID right there. So, really
  13642. 8:47:43important to note. Um, and then the line
  13643. 8:47:47and so then they just have their comment
  13644. 8:47:48there, what they left as a review. And
  13645. 8:47:50then on the calendar, um, I don't know
  13646. 8:47:52why I'm scrolled down. Uh, we have this
  13647. 8:47:55listing ID again. So, again, that
  13648. 8:47:57listing ID is equal to the ID in this
  13649. 8:47:59listing table. And we have a date and a
  13650. 8:48:02price. So, this refers to a specific
  13651. 8:48:03location. and on this day they got $85
  13652. 8:48:07for it. Somebody rented it out. Um, and
  13653. 8:48:10so then there's these like T's and Fs.
  13654. 8:48:12Um, let's try to find a blank one really
  13655. 8:48:14quick. Here's a blank one. So there's
  13656. 8:48:16these T's and Fs. Uh, the T means that
  13657. 8:48:20it was taken. Um, the F means that it's
  13658. 8:48:22vacant. Uh, I don't know exactly what it
  13659. 8:48:25means. Uh, what the TF means, but that
  13660. 8:48:27we can deduce that much from this. And
  13661. 8:48:29so you can see when and how much this
  13662. 8:48:32person was making or this home made uh
  13663. 8:48:34in that time. So really really good data
  13664. 8:48:38in here. There's a lot to work with. Um
  13665. 8:48:41and and so we're just going to be kind
  13666. 8:48:42of I'll give you a little bit of a use
  13667. 8:48:44case for it in a second and then we're
  13668. 8:48:46going to start trying to answer some of
  13669. 8:48:48those the building out some of the
  13670. 8:48:50visualizations for that use case. Uh
  13671. 8:48:53again, you could have 20 different use
  13672. 8:48:55cases for this data or more um honestly
  13673. 8:48:58for this data where you could build out
  13674. 8:48:59different dashboards and different
  13675. 8:49:00reports literally with just this data,
  13676. 8:49:03but you know, we're doing a pretty
  13677. 8:49:05general broad project and so it's hard
  13678. 8:49:08to answer all of them. So, let's jump
  13679. 8:49:11over to Tableau. We're going to get
  13680. 8:49:13started on this and we are going to
  13681. 8:49:15build out everything. All right, so
  13682. 8:49:18let's come right here. Uh this is a
  13683. 8:49:20Microsoft Excel. We'll open that up. Do
  13684. 8:49:24this one. We will open it
  13685. 8:49:28and give it just a second. Says it's
  13686. 8:49:30executing the query. It's pulling the
  13687. 8:49:32data in. All right. So, we have our
  13688. 8:49:36calendar, our listing, and our reviews.
  13689. 8:49:38Those are the different tabs at the
  13690. 8:49:40bottom. We're going to start with the
  13691. 8:49:41listing. This is the the kind of the
  13692. 8:49:44main one has um you know the there's I
  13693. 8:49:47didn't show you, but there's about 3,600
  13694. 8:49:50locations that they had in there. Uh
  13695. 8:49:54let's just have it update automatically.
  13696. 8:49:57I don't know why we need to click on
  13697. 8:49:59that, but um so we have this listings,
  13698. 8:50:02we have [clears throat] our uh calendar
  13699. 8:50:04and our reviews.
  13700. 8:50:06What we're going to do is we're going to
  13701. 8:50:07come in here and we're going to open it
  13702. 8:50:09as we did in our very last video uh for
  13703. 8:50:12the joins. So, now that we've opened it,
  13704. 8:50:14we can kind of go in here and we can do
  13705. 8:50:16the joins as um as needed. And so, let's
  13706. 8:50:21go over here and we're going to uh let's
  13707. 8:50:24start with calendar.
  13708. 8:50:26Put it right there. That was super slow.
  13709. 8:50:28I apologize.
  13710. 8:50:31[clears throat and cough] All right,
  13711. 8:50:32let's wait for it to
  13712. 8:50:36get the data. Start setting everything
  13713. 8:50:38up.
  13714. 8:50:41Did not think it would take this long. I
  13715. 8:50:43apologize.
  13716. 8:50:47No, take your time. So, let's click on
  13717. 8:50:50here. And right now, it has the uh the
  13718. 8:50:53join based on the price, which obviously
  13719. 8:50:56is not going to work. Um, and if you
  13720. 8:50:58remember, there is no ID in this
  13721. 8:51:01calendar. It's just the listing ID. Um,
  13722. 8:51:03we can actually look right here. There's
  13723. 8:51:05just the listing ID. So, we're actually
  13724. 8:51:06going to put listing ID is equal to ID.
  13725. 8:51:12And right down here, we can see that we
  13726. 8:51:14have a lot of of well, you can't see it
  13727. 8:51:17u, but we show that there is a lot of
  13728. 8:51:19data. Um, and so we know that that is
  13729. 8:51:23correct. We know that that is now
  13730. 8:51:24pulling in data correctly because it's
  13731. 8:51:26showing up down here. So, that's a good
  13732. 8:51:28thing. Now, in this listings, there are
  13733. 8:51:32about 3,600
  13734. 8:51:34um about 3,600 listings. And so,
  13735. 8:51:39that all the data that's in listings is
  13736. 8:51:41going to be in there. But on the
  13737. 8:51:43calendar, because we converted from a
  13738. 8:51:46CSV to an Excel workbook, it isn't able
  13739. 8:51:48to store as much information. So, some
  13740. 8:51:49of the ones in calendar may have gotten
  13741. 8:51:51cut off. So, we can just keep it this
  13742. 8:51:53inner join because we know that if it's
  13743. 8:51:55in listings, it's going to be in
  13744. 8:51:56calendar. We know that it if it um there
  13745. 8:52:00may be some in calendar that aren't in
  13746. 8:52:02listings. So, if we really um you know,
  13747. 8:52:06if we really really wanted to, we could
  13748. 8:52:08do a full outer or something like that.
  13749. 8:52:10I I haven't really thought through this
  13750. 8:52:12as I'm talking through it in my head,
  13751. 8:52:13but we know that uh everything that's in
  13752. 8:52:16listing is going to be in calendar. Uh,
  13753. 8:52:18and so, you know, we don't really need
  13754. 8:52:20to do anything other than an inner join.
  13755. 8:52:24And we can also pull in these reviews.
  13756. 8:52:29And it's going to do the same thing as
  13757. 8:52:30before where it's just kind of pulling
  13758. 8:52:31in the data. And it defaults to ID
  13759. 8:52:34equals ID. Now, we know that that is not
  13760. 8:52:37correct um because the ID in here is
  13761. 8:52:40referring to the review ID. We need to
  13762. 8:52:42go to the listings ID. So, we need the
  13763. 8:52:44ID be able to, you know, be part of that
  13764. 8:52:47listings ID. If we do the ID,
  13765. 8:52:51it goes down to 2555
  13766. 8:52:54rows. If we do how it's supposed and
  13767. 8:52:56there because that's just, you know,
  13768. 8:52:57it's random luck. There happen to be
  13769. 8:52:58some numbers that are in both fields um
  13770. 8:53:01that tie together. If we do the correct
  13771. 8:53:04one where we hit the listing ID, it
  13772. 8:53:06bumps it up to I think 2,373,000.
  13773. 8:53:09Oh, maybe more than that. Uh 23 million
  13774. 8:53:13rows, right? A lot lot lot more. And so
  13775. 8:53:16it's super important to get these joins
  13776. 8:53:18right to tie them together on the right
  13777. 8:53:19fields. If you just do it based off what
  13778. 8:53:21Tableau tells you because it has that
  13779. 8:53:23automated um you know it goes into these
  13780. 8:53:27fields and says okay these are the same
  13781. 8:53:28exact column name. So they're most
  13782. 8:53:31likely going to be what you're looking
  13783. 8:53:33for. Well, it was incorrect in this
  13784. 8:53:35point. So it's really important to check
  13785. 8:53:37those things and make sure you're
  13786. 8:53:38pulling in the right data. Again we're
  13787. 8:53:39going to keep it that inner join. Um,
  13788. 8:53:42you know, if you wanted to, you know,
  13789. 8:53:44try to see if there's any other data
  13790. 8:53:45that correlate. We're keeping it simple
  13791. 8:53:46today, but sometimes you need to join on
  13792. 8:53:48multiple things. Uh, so just, uh, uh,
  13793. 8:53:52you know, a tip. So, let's get out of
  13794. 8:53:54here. Um, and we are good to go. So,
  13795. 8:53:56this is our listings plus Tableau full
  13796. 8:53:59project. That's what we'll that's what
  13797. 8:54:01we'll be working with. Um, and we we
  13798. 8:54:03were able to tie all three of these um,
  13799. 8:54:06you know, I guess you'd call them tables
  13800. 8:54:08or sheets or whatever you want to call
  13801. 8:54:09them. we were able to tie them together.
  13802. 8:54:12So, let's go over here to our first
  13803. 8:54:14worksheet. Uh, and let's see.
  13804. 8:54:18All right. So, this says Tableau public
  13805. 8:54:19only works with less than 15 million
  13806. 8:54:21rows of data. We have 23 million rows of
  13807. 8:54:23data. That is, uh, that's a problem. Um,
  13808. 8:54:26and when I did this before, it didn't do
  13809. 8:54:29that. So, I, you know, we're going to
  13810. 8:54:31work through this together. So, this is
  13811. 8:54:33date reviews. I believe this is date for
  13812. 8:54:36um
  13813. 8:54:39this is date for the calendar which is
  13814. 8:54:43going to be a lot of rows of data and so
  13815. 8:54:45I'm sure that's part of it. Let's see.
  13816. 8:54:50Let's do years.
  13817. 8:54:52We only want 2016. Oops. We only want
  13818. 8:54:562016.
  13819. 8:54:59Let's do Okay,
  13820. 8:55:03let's see what that does. Let's see if
  13821. 8:55:04that gets us under what we need. Um, we
  13822. 8:55:06only want 2016 data anyways.
  13823. 8:55:10So, if it's in 2017, we were going to
  13824. 8:55:12take it out. Um, anyways, so we'll see
  13825. 8:55:15if that gets us underneath. I have
  13826. 8:55:17absolutely no if this take ends up
  13827. 8:55:19taking like 20 minutes, I will just cut
  13828. 8:55:22it and you know, you won't have to wait
  13829. 8:55:24as long as I'm waiting. So, let's see
  13830. 8:55:26how long it takes.
  13831. 8:55:31All right. So, it took about 20 minutes
  13832. 8:55:33and it did absolutely nothing. Um,
  13833. 8:55:37one thing I do know is that we don't
  13834. 8:55:40actually use this review tables at all.
  13835. 8:55:42Uh, this is just for demonstration
  13836. 8:55:44purposes. So, we're going to remove
  13837. 8:55:46that. And let's see if that helps us in
  13838. 8:55:50any way.
  13839. 8:55:53Because if it does, we're just going to
  13840. 8:55:55keep it as is. Um, you know, the reviews
  13841. 8:55:57table is really just for demonstrating
  13842. 8:56:00how to do the joins. Uh, but we weren't
  13843. 8:56:03actually using any of the data from any
  13844. 8:56:04of the visualizations,
  13845. 8:56:05although you could.
  13846. 8:56:08Again, I'm going to see how long this
  13847. 8:56:10takes. Uh, and I'll cut ahead.
  13848. 8:56:15All right. So, that worked uh,
  13849. 8:56:17perfectly. It apparently took out all
  13850. 8:56:19the data that we needed or all the rows
  13851. 8:56:20that we needed to get under that level.
  13852. 8:56:22Again, I was just doing that to show you
  13853. 8:56:24the the that joins how you needed to
  13854. 8:56:26change the columns to make sure that it
  13855. 8:56:29joined properly. We don't actually use
  13856. 8:56:31it for any of the visualizations. So,
  13857. 8:56:32their end product is going to be totally
  13858. 8:56:34fine. I don't know why uh this didn't
  13859. 8:56:37happen to me when I when I created this
  13860. 8:56:38whole thing already. Um so, I'm just
  13861. 8:56:41going to move forward because uh I make
  13862. 8:56:43mistakes. So, uh let's keep moving. The
  13863. 8:56:47first one that we are going to make is
  13864. 8:56:49that uh is that colorful one. I'll
  13865. 8:56:51probably pop it up on screen so you can
  13866. 8:56:53see it. Uh well, if I remember, I'm
  13867. 8:56:55going to pop it up on screen. Um it's
  13868. 8:56:56the colorful one. It's the price by zip
  13869. 8:56:59code. So, we're going to be looking at
  13870. 8:56:59these zip codes and kind of see um you
  13871. 8:57:02know, how expensive
  13872. 8:57:04is each zip code. Um and before we
  13873. 8:57:08actually start, I just remembered I want
  13874. 8:57:11to talk to you about the use case for
  13875. 8:57:12this data.
  13876. 8:57:14I want to imagine you to imagine that
  13877. 8:57:16you're working for somebody and they're
  13878. 8:57:17like, "Hey, where, you know, I want to
  13879. 8:57:20start an Airbnb business. I want to know
  13880. 8:57:22where I should go. Where should I buy up
  13881. 8:57:25buy a home, put it up on Airbnb, and
  13882. 8:57:28start renting it out? Where's the best
  13883. 8:57:29place? You know, what are some of the
  13884. 8:57:31factors that I should be looking at?"
  13885. 8:57:33Uh, and so that's kind of what our use
  13886. 8:57:35case is. So, we're gonna the some of the
  13887. 8:57:37things that he cares about are things
  13888. 8:57:38like bedrooms, um, location, which is
  13889. 8:57:42really important, and how much price
  13890. 8:57:44he's actually going to get, how much
  13891. 8:57:46money can he charge. And so, he's trying
  13892. 8:57:48to optimize that to make sure that
  13893. 8:57:50whatever rental he gets, he can make a
  13894. 8:57:52the most profit from instead of choosing
  13895. 8:57:54something that, you know, he thinks
  13896. 8:57:56would work, but, you know, in the end,
  13897. 8:57:57he's actually not making that much
  13898. 8:57:58money. So, those things are important.
  13899. 8:58:01So, that's our use case. We're trying to
  13900. 8:58:02help this guy out, help him find a
  13901. 8:58:05really good Airbnb. Um, so let's take a
  13902. 8:58:08look at these zip codes real quick. We
  13903. 8:58:09have uh quite a few of them. And there's
  13904. 8:58:13one that's null. Uh, we'll exclude that.
  13905. 8:58:15Or if if it doesn't have a zip code,
  13906. 8:58:16we'll just exclude those because they're
  13907. 8:58:18not going to show up on the these
  13908. 8:58:19visualizations anyways. Um, and so we
  13909. 8:58:22want to look at the price. So we just
  13910. 8:58:24want to find uh the price, which should
  13911. 8:58:27actually be down here,
  13912. 8:58:29and not the sum. Uh,
  13913. 8:58:33no. We want to look at the average
  13914. 8:58:36price. And let's order that. This is
  13915. 8:58:40great. Um, so this is the most expensive
  13916. 8:58:42one. Uh, zip code 98134 at $26
  13917. 8:58:47uh per
  13918. 8:58:49for the average price. Uh, but let's
  13919. 8:58:51give that some color really quick. Let's
  13920. 8:58:54uh Where's the zip code? It's up here.
  13921. 8:58:56So, let's take that zip code. We're
  13922. 8:58:58going to put it right over here. We're
  13923. 8:58:59going to do color. and it's going to
  13924. 8:59:01give it some uh assorted colors. Now,
  13925. 8:59:04these colors are gonna um when we do the
  13926. 8:59:06map just a little bit, these colors will
  13927. 8:59:09um match what we're doing in there. And
  13928. 8:59:11so, you know, I I like to try to color
  13929. 8:59:14coordinate things. Um we're not doing
  13930. 8:59:16going too crazy with the colors today.
  13931. 8:59:18So, this is our very first
  13932. 8:59:19visualization. Congratulations. It is uh
  13933. 8:59:21it is complete. So, uh, we can label
  13934. 8:59:25this one. And we can just do
  13935. 8:59:28price by zip code. And I'll make that
  13936. 8:59:34bold. I don't know. I usually like it
  13937. 8:59:36bold. We'll apply. We'll do like that.
  13938. 8:59:38And boom. First one is done. Uh, and
  13939. 8:59:41this is our starting place to say, uh,
  13940. 8:59:44hey, person who's looking to buy this
  13941. 8:59:46Airbnb, here are the zip codes where
  13942. 8:59:49they are able to charge the most, um,
  13943. 8:59:52for for their Airbnb. So, let's go over
  13944. 8:59:55to the second sheet. And we are going to
  13945. 8:59:57be doing the map. And so, um, map is
  13946. 9:00:00pretty easy, but it it's pretty easy
  13947. 9:00:03once you actually get the data that you
  13948. 9:00:05need. Although there's a lot of
  13949. 9:00:07different data that you can use for the
  13950. 9:00:10actual um map right here, you need
  13951. 9:00:13something that shows um the location and
  13952. 9:00:16there's a lot of things that show
  13953. 9:00:18location in here. In fact, they already
  13954. 9:00:20um provide a latitude and longitude. And
  13955. 9:00:22then at the bottom, they generated a
  13956. 9:00:25latitude and longitude from from some
  13957. 9:00:27different um fields. And then there's
  13958. 9:00:29just a bunch of different um state.
  13959. 9:00:31There's um states, there's zip codes,
  13960. 9:00:35there are uh I think another one I uh
  13961. 9:00:38yeah, like country. There's a lot of
  13962. 9:00:40location data in here. So, which one do
  13963. 9:00:43we want to use? We want to stay
  13964. 9:00:45consistent. We don't want to deviate
  13965. 9:00:47from that and start using different um
  13966. 9:00:49longit long longitude and latitudinal uh
  13967. 9:00:52coordinates because that could throw off
  13968. 9:00:54our our results completely. We want to
  13969. 9:00:56stay consistent with what we're using.
  13970. 9:00:58So, we actually want to use this zip
  13971. 9:01:00code. But when we pull it up here, it's
  13972. 9:01:02going to give us uh basically the same
  13973. 9:01:04um you know, it's going to show these
  13974. 9:01:05zip codes, but we're going to right over
  13975. 9:01:07here, we're going to click on this one.
  13976. 9:01:09And now it's going to separate them out.
  13977. 9:01:11So now we have all of these um you know,
  13978. 9:01:14kind of separated out. What you might
  13979. 9:01:15get when you first do this, um is it
  13980. 9:01:18might look like this. You may have to
  13981. 9:01:20zoom in. Um I know that that happened to
  13982. 9:01:22me the other time.
  13983. 9:01:25Let me go to here. That's what happened
  13984. 9:01:26to me uh just when I first did it. So,
  13985. 9:01:30uh, know that that may happen. And
  13986. 9:01:33we want to change the colors the exact
  13987. 9:01:36same way that we did them before. So,
  13988. 9:01:37we're just going over here. We're doing
  13989. 9:01:39color. And these colors do um they do
  13990. 9:01:45or should match up with the um with the
  13991. 9:01:48other ones. Let me um exclude this. Let
  13992. 9:01:52me see if it does. 98134. That's the
  13993. 9:01:55blue.
  13994. 9:01:57And right over here, 98134, it's a blue.
  13995. 9:02:00I I I believe they are going to be the
  13996. 9:02:02same. Yep. And so, just scrolling back,
  13997. 9:02:05if you look at the zip code on the far
  13998. 9:02:07right, uh they are the same. So, if you
  13999. 9:02:10look at like this section right over
  14000. 9:02:11here, I I just wanting to make sure I'm
  14001. 9:02:13not going crazy uh before I get into
  14002. 9:02:15this and realize I'm not correct at all.
  14003. 9:02:18So, uh now what we want is, you know,
  14004. 9:02:21this doesn't really give us any
  14005. 9:02:22information. If I was just to glance at
  14006. 9:02:24this map, I would have no idea what
  14007. 9:02:27you're trying to show me um any
  14008. 9:02:29information off this. So, we want to
  14009. 9:02:30show some actual information. So, first
  14010. 9:02:33thing that we're going to do is we're
  14011. 9:02:35going to actually add the label to this
  14012. 9:02:37so that you can see it. You know, when
  14013. 9:02:39you're going over here and you see,
  14014. 9:02:41okay, here's this um zip code. Um in the
  14015. 9:02:45dashboard when we create it, you can
  14016. 9:02:46click on this. But if you just want to
  14017. 9:02:49do it visually without having to click
  14018. 9:02:50anywhere, you'll be able to see, okay,
  14019. 9:02:5298134, that's right here. So, this
  14020. 9:02:54location right here is, you know, able
  14021. 9:02:56to charge a lot of money. It's probably
  14022. 9:02:58a really nice neighborhood. So, um, and
  14023. 9:03:01we can back that up by putting the
  14024. 9:03:05average price. So, these these two
  14025. 9:03:07visualizations are really they really go
  14026. 9:03:09hand in hand. We're going to add oops,
  14027. 9:03:12not the sum.
  14028. 9:03:14This one needs to be the average. So you
  14029. 9:03:16go to this measure, the sum, go to
  14030. 9:03:18average, and there you go. And these
  14031. 9:03:22should match. So this should be 206.6.
  14032. 9:03:24Um, I'm looking at the average price
  14033. 9:03:26right here. And then we go over here.
  14034. 9:03:2998134 206.6. So this all matches. Um,
  14035. 9:03:32and we can uh we can actually change
  14036. 9:03:35that size a little bit if you wanted to
  14037. 9:03:36actually get it in um get it within each
  14038. 9:03:40of these things. You know, adjust it as
  14039. 9:03:43you see fit. I think that's fine right
  14040. 9:03:45there. Um, no need to
  14041. 9:03:48mess with it anymore.
  14042. 9:03:51All right. So, let me see. I think that
  14043. 9:03:53is everything for this one. I don't know
  14044. 9:03:54if I want to add anything else. Uh, no.
  14045. 9:03:58I'm going to keep it how it is. So, that
  14046. 9:04:00is our second visualization. Again,
  14047. 9:04:02these ones are directly uh correlated
  14048. 9:04:06and and you know this there's just
  14049. 9:04:08different ways to visualize it. This one
  14050. 9:04:10you can see actually on the map where it
  14051. 9:04:11is and the average price. This one you
  14052. 9:04:13can see from highest to low. So again,
  14053. 9:04:15you know, sometimes when you're doing
  14054. 9:04:16these visualizations, you're going to
  14055. 9:04:18have these accompanying um uh these
  14056. 9:04:22accompanying visualizations in your
  14057. 9:04:24dashboard. That's very normal. So, let's
  14058. 9:04:28move over to the third one. And for this
  14059. 9:04:31third one, um you know, something that
  14060. 9:04:34our guy was looking at is he's like,
  14061. 9:04:36"Okay, well, you know, I'm thinking
  14062. 9:04:38about listing it on Airbnb, but I also
  14063. 9:04:41want to live in it. So, I want to know
  14064. 9:04:42the best times to actually um you know,
  14065. 9:04:46put it on the market for people to be
  14066. 9:04:48able to use. And so, I was like, "Okay,
  14067. 9:04:51man. No problem. Uh let's let's take a
  14068. 9:04:53look at when when are people spending
  14069. 9:04:55the most money in Airbnbs." And we
  14070. 9:04:58actually had that calendar. Um if you
  14071. 9:05:00remember, let's look let's see this
  14072. 9:05:02calendar. So, we had this available, the
  14073. 9:05:05date, the listing, all of that stuff.
  14074. 9:05:08Um, and [clears throat]
  14075. 9:05:10let's look at the date in here. Uh, and
  14076. 9:05:14we obviously don't want it like this. We
  14077. 9:05:16want it to be more uh more of a time
  14078. 9:05:19series. And we're going to do be doing
  14079. 9:05:21that based off of uh the price for the
  14080. 9:05:25calendar. So, let's go see if we can
  14081. 9:05:27find that really quick.
  14082. 9:05:29Football. Okay, here's the price.
  14083. 9:05:33Where is that calendar one?
  14084. 9:05:37Let me see. Okay, there's the calendar.
  14085. 9:05:40Oh, here.
  14086. 9:05:43All right. I totally forgot where that
  14087. 9:05:45was supposed to be. O, that looks
  14088. 9:05:46terrible.
  14089. 9:05:48Okay. Um, let's see. Let's let's start
  14090. 9:05:51working on this cuz this needs some
  14091. 9:05:53work. Obviously, uh, this is the worst
  14092. 9:05:56visualization I have ever seen. Um, so
  14093. 9:05:59we need to work on this a little bit.
  14094. 9:06:01What we need to do is we need to change
  14095. 9:06:04Whoops. we need to change some some the
  14096. 9:06:06way that these dates are are seen. So
  14097. 9:06:09right here is act these are two separate
  14098. 9:06:12things. So if I go right here and I do
  14099. 9:06:13it by quarter, it's just going to change
  14100. 9:06:15the quarters here, right? That's that
  14101. 9:06:17isn't really helpful. We actually want
  14102. 9:06:19to keep the year here. What we want to
  14103. 9:06:21do it is by year. We want to separate it
  14104. 9:06:24by year. Um but we want to separate it.
  14105. 9:06:27Let's just do I don't know. Let's try
  14106. 9:06:28week and see what it looks like. Okay,
  14107. 9:06:30this is great. This is this is what
  14108. 9:06:31we're looking at again. Um, if we went
  14109. 9:06:34back and changed this like quarter, it
  14110. 9:06:37uh changed it quarter and then change it
  14111. 9:06:39to week, it would show the quarters, but
  14112. 9:06:43it wouldn't show
  14113. 9:06:46everything, [snorts] right? This isn't
  14114. 9:06:47all the data that we need. And so, you
  14115. 9:06:49know, you really need to make sure that
  14116. 9:06:51you're doing this correct. I by default,
  14117. 9:06:54it's almost always year. But if you're
  14118. 9:06:56looking at it via quarter, so like let's
  14119. 9:06:58say somebody comes in, you say, "Hey,
  14120. 9:07:00what quarters? I want to break these out
  14121. 9:07:02by quarters um and not year-over-year.
  14122. 9:07:06That's how you would do this. But in the
  14123. 9:07:07year, we want to break it out by uh the
  14124. 9:07:10week. And you see this huge drop off um
  14125. 9:07:16at the end. Well, that is actually
  14126. 9:07:17because the data doesn't go past that.
  14127. 9:07:20Um there's just like one day of data or
  14128. 9:07:22one one um week of data in here with
  14129. 9:07:26actual um with January of 2017 data. So
  14130. 9:07:29it just drops off cuz this is an this is
  14131. 9:07:31a sum. So it only adds up to like um
  14132. 9:07:35591,000 compared to like the 2 million.
  14133. 9:07:38So we want to get rid of that. Um and
  14134. 9:07:41how do we do that? Uh let's see. I think
  14135. 9:07:43it's filterup.
  14136. 9:07:46Is it format? No, it's not format. What
  14137. 9:07:48am I thinking? Bear with me. Uh let's
  14138. 9:07:52filter. Well, I was looking for it. I
  14139. 9:07:54just couldn't find it.
  14140. 9:07:56Uh let's bring it back to the 31st.
  14141. 9:07:59Let's see if that fixes what we need.
  14142. 9:08:02Perfect. Uh that that's all you had to
  14143. 9:08:04do. Um and the reason that this is
  14144. 9:08:07helpful and often times you'd have
  14145. 9:08:10several years worth of data in here. Um
  14146. 9:08:13and then you could have you could do
  14147. 9:08:14even do something like this. Um like
  14148. 9:08:16this one where it has multiple lines.
  14149. 9:08:19The reason that this is helpful is
  14150. 9:08:21because if I'm telling my friend, let's
  14151. 9:08:24I mean just I'm going to say it's a
  14152. 9:08:25friend or business partner, whatever you
  14153. 9:08:27whatever you want to use this use case
  14154. 9:08:29for. I'm going to tell him, hey, the
  14155. 9:08:31beginning of January all the way until
  14156. 9:08:34like, you know, even February, it's like
  14157. 9:08:38really low. It's half. So, there's not a
  14158. 9:08:40lot of people traveling because everyone
  14159. 9:08:42travels when? At the end of the year.
  14160. 9:08:44So, in November, December for the
  14161. 9:08:46holidays to visit family. Um, and then
  14162. 9:08:48in the summer for vacations, I would
  14163. 9:08:51tell him just based off this one thing,
  14164. 9:08:53I would say, "Hey, over the summer and
  14165. 9:08:56then at the end of the year and during
  14166. 9:08:57the holidays, that's when I would be
  14167. 9:09:00renting out your Airbnb." Okay, so just
  14168. 9:09:03this one very simple visualization can
  14169. 9:09:05help him understand the best times um to
  14170. 9:09:08do that. That may have been intuitive.
  14171. 9:09:09You may have already known that, but you
  14172. 9:09:11can prove it with the data, which is
  14173. 9:09:13always really helpful. Um, and let's
  14174. 9:09:16see. Is there anything else that we need
  14175. 9:09:17to do with this?
  14176. 9:09:19Uh, I'm just going to label it. And I'm
  14177. 9:09:22going to say,
  14178. 9:09:23um,
  14179. 9:09:26revenue
  14180. 9:09:28for year.
  14181. 9:09:31Let's do bold. Do apply. There we go.
  14182. 9:09:35Did I label this last one? I didn't.
  14183. 9:09:38Let's label that last one.
  14184. 9:09:42And we'll do
  14185. 9:09:44price per zip code.
  14186. 9:09:48Price per zip code. We'll just keep it
  14187. 9:09:50at that. Let's keep it simple.
  14188. 9:09:53Um and let's do that. All right. I
  14189. 9:09:56believe we have two more.
  14190. 9:09:58So, we have done um we've done three of
  14191. 9:10:02them. Um we got the zip codes, we've got
  14192. 9:10:06the um you know, the time of the year.
  14193. 9:10:09Now, something else that he was wanting
  14194. 9:10:10to know is um you know, just how things
  14195. 9:10:13affect it. And something that's going to
  14196. 9:10:14affect the price of the actual Airbnb is
  14197. 9:10:19going to be the amount of bedrooms. So,
  14198. 9:10:21the the larger the house, the more
  14199. 9:10:22bedrooms, the more it's going to cost
  14200. 9:10:24typically. So, we can take a look at
  14201. 9:10:28that. Let's pull in these bedrooms.
  14202. 9:10:32Um and that will be our columns.
  14203. 9:10:36Uh no, it won't. what we need to do. Um,
  14204. 9:10:39and so I I knew this was going to
  14205. 9:10:41happen. I just forgot it until right uh
  14206. 9:10:42until right now. Well, we this right now
  14207. 9:10:45is actually a um it's a a value, right?
  14208. 9:10:49So it's a number. And that's totally um
  14209. 9:10:52reasonable because if we go right here,
  14210. 9:10:55we do count distinct. That's because
  14211. 9:10:57there's only seven values, right? It
  14212. 9:10:58goes there's zero bedrooms, 1 2 3 4 5 6
  14213. 9:11:017 all the way up to seven bedrooms.
  14214. 9:11:03Right? Now it has it as a numerical
  14215. 9:11:04value. we want to um change that to
  14216. 9:11:08create it as um these measure names, not
  14217. 9:11:12a value. So, we're going to um we're
  14218. 9:11:16going to remove this. We're going to go
  14219. 9:11:18right down here. We're going to click
  14220. 9:11:19this dropdown and we're going to say
  14221. 9:11:21convert to dimension.
  14222. 9:11:24And so now we're going to add it as a
  14223. 9:11:26dimension. So there, that looks um much
  14224. 9:11:29more normal. I really quick. I'm going
  14225. 9:11:31to I'm going to keep these in here for a
  14226. 9:11:33second, but we're going to get rid of
  14227. 9:11:33these nulls and zeros because if a home
  14228. 9:11:35has zero bedrooms, that's a problem. Um,
  14229. 9:11:39and so we want to look at the price
  14230. 9:11:42again. Let's go down here in the
  14231. 9:11:45listings. It should be the price. Now,
  14232. 9:11:47this is the price for the location per
  14233. 9:11:49day. Um, if you want to look at monthly
  14234. 9:11:52or or you know, stuff like that, they
  14235. 9:11:54have that data. Um, but we're just going
  14236. 9:11:56to do the price, the average price, not
  14237. 9:11:58the sum.
  14238. 9:12:00Um, although this is helpful. So, just
  14239. 9:12:02really quick before we change it, this
  14240. 9:12:04is going to show you which ones make the
  14241. 9:12:06which ones are bringing in the most
  14242. 9:12:08money. It also may show you which ones
  14243. 9:12:09are the most common. Um, those are all
  14244. 9:12:11different visualizations that we can do,
  14245. 9:12:13but the one that brings in the most
  14246. 9:12:15money uh that brought in 63 or that has
  14247. 9:12:18$63 million worth of um worth of
  14248. 9:12:23listings. So, they all add up. Those
  14249. 9:12:26onebedrooms are doing phenomenal. half
  14250. 9:12:29of that are two bedrooms at 30 million,
  14251. 9:12:32three bedrooms at 18 million, and so on
  14252. 9:12:33and so forth. So, there's a ton of
  14253. 9:12:36one-bedroom ones. We may even keep we
  14254. 9:12:39could even keep that in there. Um, you
  14255. 9:12:41know, if we wanted to.
  14256. 9:12:44Um, and then we do something similar
  14257. 9:12:46later, but you can keep something like
  14258. 9:12:47this in there. What we will do really
  14259. 9:12:50quick though is we're going to do the
  14260. 9:12:51same thing that we been doing is keeping
  14261. 9:12:53average.
  14262. 9:12:55Um, and we are going to get rid of this
  14263. 9:12:58because if it doesn't have the bedrooms,
  14264. 9:13:00you know, that's not helpful to us. And
  14265. 9:13:02if it has zero bedrooms, that's that's
  14266. 9:13:04genuinely a problem. I will not be
  14267. 9:13:05renting an Airbnb with my family uh that
  14268. 9:13:08has zero bedrooms in it. So, now we have
  14269. 9:13:10this.
  14270. 9:13:12And it would be really helpful to be
  14271. 9:13:13able to see that in the visualization. I
  14272. 9:13:15mean, it's just kind of
  14273. 9:13:17hard to see it as is. I mean, it just
  14274. 9:13:21does not hurt to add that right here.
  14275. 9:13:24do a label. Um, why is it angled like
  14276. 9:13:27that? Maybe I just need to
  14277. 9:13:31move it out more.
  14278. 9:13:34That looks much better. Um, that's the
  14279. 9:13:37average price. That cannot be right.
  14280. 9:13:40That's the sum. That's why. So, let's go
  14281. 9:13:42over here. Let's make that average as
  14282. 9:13:44well. Much better because uh if the
  14283. 9:13:47price was $3 million
  14284. 9:13:50for a three-bedroom, I would not be
  14285. 9:13:52going there. So, this is really really
  14286. 9:13:56useful information for our friend,
  14287. 9:13:58right? If um he wants to, you know, get
  14288. 9:14:01into those one that onebedroom area, you
  14289. 9:14:03know, you're not going to be making a
  14290. 9:14:04lot of money. It may be low cost
  14291. 9:14:06upfront, but he's not going to be making
  14292. 9:14:07a lot of money. It significantly goes up
  14293. 9:14:11when you reach these five and sixbedroom
  14294. 9:14:13homes, which makes sense. I mean, if it
  14295. 9:14:15has five or six bedrooms in it, it's
  14296. 9:14:16probably a really large, really nice
  14297. 9:14:18home, and you can charge a lot more
  14298. 9:14:20money. And our friend is uh extremely
  14299. 9:14:22wealthy. he can buy whatever he wants.
  14300. 9:14:23And so he may be looking at these um
  14301. 9:14:25larger ones, seeing that there's a much
  14302. 9:14:27higher return um on his investment the
  14303. 9:14:30higher and the more bedrooms he goes. So
  14304. 9:14:33we're going to keep it just as it is.
  14305. 9:14:37Um and let me see is there's anything
  14306. 9:14:39else that we want to do with this. No,
  14307. 9:14:41we're going to keep it just like this.
  14308. 9:14:42Uh and the last one is by far the
  14309. 9:14:44easiest and we actually just discussed
  14310. 9:14:45it a little bit. We want to know, you
  14311. 9:14:48know, what's his competition look like?
  14312. 9:14:50So, um, for those for the bedrooms
  14313. 9:14:52specifically, so let's go back up to the
  14314. 9:14:56bedrooms,
  14315. 9:14:58we want that one to be right here in our
  14316. 9:15:01rows. So, we show um these and then we
  14317. 9:15:04just want a count of um how many
  14318. 9:15:08listings there are. So, we can do that
  14319. 9:15:11via the listings ID. So, here's our
  14320. 9:15:13listings. Each ID represents one
  14321. 9:15:16location or one home. So, we're going to
  14322. 9:15:18do that right here. Uh, that looks
  14323. 9:15:21absolutely terrible.
  14324. 9:15:24That looks terrible. What am I doing
  14325. 9:15:26wrong here? Oh, let me see.
  14326. 9:15:31U, one thing we need to do is we want to
  14327. 9:15:33get rid of these nulls and zeros.
  14328. 9:15:35Do that really quick.
  14329. 9:15:38Um, and then [clears throat] we don't
  14330. 9:15:40want to do just the ID because I I'm
  14331. 9:15:42realizing now uh what I'm doing. I need
  14332. 9:15:46to convert this to a numeric so we can
  14333. 9:15:49do a count on it. So let's um Oops. Let
  14334. 9:15:53me see what what is happening. This is
  14335. 9:15:55terrible. All right, let's put this
  14336. 9:15:57back. Let's make Let me see if I can
  14337. 9:15:59just um do an attribute.
  14338. 9:16:04Let's do
  14339. 9:16:07the count
  14340. 9:16:10and let's do
  14341. 9:16:13text.
  14342. 9:16:15Um, no. It needs to be a distinct count
  14343. 9:16:19because that's that's basically like um
  14344. 9:16:23a count of the numbers themselves, not
  14345. 9:16:27each individual ID. Okay, it took some
  14346. 9:16:31figuring out. I'm going to keep that in
  14347. 9:16:32there because you guys need to see uh a
  14348. 9:16:35lot of you guys like seeing when I make
  14349. 9:16:36mistakes, so you know, it makes it feel
  14350. 9:16:38like when you make mistakes, it's okay.
  14351. 9:16:39Um, and I'm all about that. So, I'm
  14352. 9:16:41leaving that in there. You guys can see
  14353. 9:16:42me fail a little bit. Um, I just forgot
  14354. 9:16:44how to do that for a second. And this is
  14355. 9:16:47exactly what we're looking for, right?
  14356. 9:16:49We want, we now, it showed us in that
  14357. 9:16:51visualization that we were looking at
  14358. 9:16:52earlier before we um switched it to the
  14359. 9:16:55average price. This is showing us that
  14360. 9:16:58there are for onebedrooms, there's 1,800
  14361. 9:17:01onebedroom, two that have 483, three
  14362. 9:17:03that have 206, four that have 55, only
  14363. 9:17:06five that have 20, and six that have
  14364. 9:17:07five. So, the more you go up, the less
  14365. 9:17:10and less it is, or the less and less
  14366. 9:17:12competition there's going to be. Now, is
  14367. 9:17:13there a lot of demand for fourbedroom,
  14368. 9:17:155bedroom, sixbedroom? Uh, that's for our
  14369. 9:17:17friend to figure out. Um, well, maybe
  14370. 9:17:19we'll help them out with that later um
  14371. 9:17:22in the with the data. You know, we could
  14372. 9:17:24look at the reviews that we had. Um,
  14373. 9:17:26there's so much data in here and we
  14374. 9:17:28could absolutely figure that out. But
  14375. 9:17:29for what it's worth, we're giving him
  14376. 9:17:31this initial stuff and he'll have
  14377. 9:17:32follow-up questions for us later. That's
  14378. 9:17:34how it always works, I promise. Um, so
  14379. 9:17:37now we're good with this one. Let's
  14380. 9:17:39label this one. Did I label the last
  14381. 9:17:41one? I will go back and look. Um,
  14382. 9:17:45distinct I I'm going to butcher this
  14383. 9:17:47one. I'm going to do distinct count of
  14384. 9:17:51of bedroom listings. I don't that may
  14385. 9:17:55not make sense at all, but we're keeping
  14386. 9:17:57it. So, we're going to do bedroom.
  14387. 9:17:59Apply. Okay. Let me see if I added the
  14388. 9:18:02label on this one. I didn't. Let me do
  14389. 9:18:05that real quick.
  14390. 9:18:08We'll do average
  14391. 9:18:11price per bedroom.
  14392. 9:18:14Again, I'm Oops,
  14393. 9:18:18you didn't see that. I'm just going with
  14394. 9:18:20whatever is coming to my head. This
  14395. 9:18:22probably wouldn't be what I would keep
  14396. 9:18:23if I this were like an actual project,
  14397. 9:18:25but it works for now. So, we have our
  14398. 9:18:29five visualizations. 1 2 3 four and
  14399. 9:18:31five. And let's create our dashboard.
  14400. 9:18:34That's going to be this button right
  14401. 9:18:35here. So, we're going to click that. We
  14402. 9:18:38are going to uh go right here and we're
  14403. 9:18:41going to say automatic because we want
  14404. 9:18:43to use this entire area. And so, now
  14405. 9:18:46we're just going to start um you know
  14406. 9:18:49pulling them over. And I'm just going to
  14407. 9:18:50start from the very first one and go to
  14408. 9:18:53the very last one. Keep it really
  14409. 9:18:55simple. So, this very first one, we'll
  14410. 9:18:58pull it over it. You know, it's going to
  14411. 9:19:00take up the entire space until you start
  14412. 9:19:02adding all the other ones. We'll include
  14413. 9:19:04this one right here. Um, and well, let's
  14414. 9:19:08leave it as it is, you know. We'll
  14415. 9:19:09adjust it once it gets to its final
  14416. 9:19:11place. Now, we have number three. We'll
  14417. 9:19:14add this one on this side. It looks
  14418. 9:19:17terrible right now, but give it a
  14419. 9:19:19second. Uh, then we have number four.
  14420. 9:19:21We're going to add that across the top.
  14421. 9:19:24Okay. It's already starting to look a
  14422. 9:19:25little better.
  14423. 9:19:27And, um, maybe I I You don't have to
  14424. 9:19:31keep this in here. Um,
  14425. 9:19:34but you definitely can. Uh, let's start
  14426. 9:19:37to adjust things a little bit.
  14427. 9:19:41Oops.
  14428. 9:19:43Okay. Let's
  14429. 9:19:45see see if I can zoom in one more. No,
  14430. 9:19:49I'm going to do it just like that.
  14431. 9:19:50Actually, let me see
  14432. 9:19:56if I can make it even just a little bit
  14433. 9:19:58closer. Perfect. Uh, that's the best
  14434. 9:20:00you're going to get. Um, if you didn't
  14435. 9:20:02see, I used this um magnifying and then
  14436. 9:20:04I could click on the area that I wanted
  14437. 9:20:06to see. So, we're going to keep that
  14438. 9:20:08just like that.
  14439. 9:20:10We're going to move this over because
  14440. 9:20:11that is um definitely not as important.
  14441. 9:20:15Um, and then we're going to move this
  14442. 9:20:18way over as well to keep it just like
  14443. 9:20:20that. Again, this is something where if
  14444. 9:20:22you want to, you can click on this. Um,
  14445. 9:20:25it didn't I don't know why uh I can't
  14446. 9:20:27remember how to get those connected, but
  14447. 9:20:28it's you definitely can. Um but okay, I
  14448. 9:20:32was just clicking on the wrong one.
  14449. 9:20:33That's why
  14450. 9:20:35that is why. But you can click over here
  14451. 9:20:38and you you know it'll filter um based
  14452. 9:20:40on So if I go to this one. Oops. Dang.
  14453. 9:20:45Oh jeez, what am I doing? Oh, this is a
  14454. 9:20:47travesty. Okay, let's try to get this
  14455. 9:20:50back.
  14456. 9:20:52All right, I'm not touching it, guys.
  14457. 9:20:53You get the gist. You can mess around
  14458. 9:20:55with it yourself. I'm not messing this
  14459. 9:20:56up. Okay. So, the next thing we need to
  14460. 9:20:58add is the very last one. That's going
  14461. 9:21:00to go right up here. And then we're just
  14462. 9:21:02going to kind of move it off to the
  14463. 9:21:05side.
  14464. 9:21:08And
  14465. 9:21:10let's see.
  14466. 9:21:14Add
  14467. 9:21:17Yeah, this caption. Um, if you've never
  14468. 9:21:20seen something like this before,
  14469. 9:21:23um, and I actually want to make this
  14470. 9:21:24bigger as well.
  14471. 9:21:27Jeez, give me a second. It's It's kind
  14472. 9:21:30of lagging a little bit.
  14473. 9:21:36And make this a little bit. Maybe I
  14474. 9:21:40don't want it as wide, but I definitely
  14475. 9:21:42want a little taller.
  14476. 9:21:47Give it a second. Yeah. Let me scooch
  14477. 9:21:50this back.
  14478. 9:21:53Just like that.
  14479. 9:21:55That's fine. Uh, we can keep it like
  14480. 9:21:58that. In my original one, I didn't have
  14481. 9:22:00this. Um, you can get rid of this if you
  14482. 9:22:02want. You know, you can, um, you know,
  14483. 9:22:06just exit out right here if you want to
  14484. 9:22:07do that. But there you have it. Uh, this
  14485. 9:22:10is the entire thing. So, we started from
  14486. 9:22:13the very start. Um, we started with this
  14487. 9:22:15one, then this one. Uh, did some um, and
  14488. 9:22:19this is, you know, all the zip all of
  14489. 9:22:22our zip code work. Then we took a look
  14490. 9:22:24at the calendar where we looked at the
  14491. 9:22:26price and did some time series
  14492. 9:22:27visualization. And then we're looking at
  14493. 9:22:30the bedrooms and and the count of
  14494. 9:22:32bedrooms. And so this should be really
  14495. 9:22:33helpful for a friend. It should be an
  14496. 9:22:35initial dashboard to get him going. And
  14497. 9:22:37once he sees this, he's going to have a
  14498. 9:22:39million other questions and he's going
  14499. 9:22:40to want another dashboard for different
  14500. 9:22:42data that's in there. He's going to ask
  14501. 9:22:44about, okay, well, what if I want to do
  14502. 9:22:45it weekly or, you know, I want to rent
  14503. 9:22:47it out for the month or, you know, how
  14504. 9:22:49many um reviews are people, fivestar
  14505. 9:22:52reviews are people giving on, you know,
  14506. 9:22:54onebedroom, two-bedroom, threebedroom.
  14507. 9:22:56These are all things that, you know, he
  14508. 9:22:59may ask and then we'd have to build out.
  14509. 9:23:00In the real world, this is what happens
  14510. 9:23:02all the time. You know, they make a
  14511. 9:23:04request and then they're like, "Oh, this
  14512. 9:23:05is great, but I also want this." So, um
  14513. 9:23:08you know, your friend is is going to be
  14514. 9:23:11right in line with just about everyone
  14515. 9:23:12else um that has ever gotten a dashboard
  14516. 9:23:15uh for work or for personal use. With
  14517. 9:23:19that being said, this is it. Um we have
  14518. 9:23:21done the entire thing. Now, if you want
  14519. 9:23:23to share this, it is super super easy to
  14520. 9:23:26share. Um and I'm going to try to
  14521. 9:23:28remember how to share it. Uh, so we're
  14522. 9:23:29going to do save to Tableau public as
  14523. 9:23:33and we're going to do this and we're
  14524. 9:23:34going to make it um let's do air B&B. Is
  14525. 9:23:39it like is it a capital B? Is it like
  14526. 9:23:40that? No, that doesn't look right.
  14527. 9:23:42Airbnb.
  14528. 9:23:44Uh, we'll do full project and we'll
  14529. 9:23:47save.
  14530. 9:23:49And that is being created right now. Um,
  14531. 9:23:52and I will save this. So, if you guys
  14532. 9:23:54want to go look at this, you can. Um,
  14533. 9:23:56and I'll provide a link in the
  14534. 9:23:58description as well for that and see if
  14535. 9:24:00yours looks um similar to mine or better
  14536. 9:24:02than mine.
  14537. 9:24:05Give it a second because it's thinking.
  14538. 9:24:10All right. So, here it is. So, here's
  14539. 9:24:13our final our final project. Um, and if
  14540. 9:24:15you followed step by step, then you
  14541. 9:24:17should get this exact or very very
  14542. 9:24:19similar to this one. Again, I encourage
  14543. 9:24:22you to if you want to have the upto-date
  14544. 9:24:25data to go to that um link in the
  14545. 9:24:27description that has um the the most
  14546. 9:24:31recent data and they update that I
  14547. 9:24:32believe monthly. So, you can go there,
  14548. 9:24:34get the most recent data and then you
  14549. 9:24:36can do stuff and you can create a
  14550. 9:24:37beautiful project just like this um but
  14551. 9:24:39with the you know the most recent data.
  14552. 9:24:40Again, I use the Kaggle data just so you
  14553. 9:24:42guys can remember. And I encourage you
  14554. 9:24:44to look at the different data points
  14555. 9:24:46that are in the Excel. There is so much
  14556. 9:24:48in there and you can use honestly like
  14557. 9:24:51there's probably 30 or 40 other fields
  14558. 9:24:53that you could be using in there that we
  14559. 9:24:55never even touched. Um, but for this
  14560. 9:24:58project, we're keeping it pretty simple.
  14561. 9:25:00And so go do that. Make completely
  14562. 9:25:02unique dashboards and and visualizations
  14563. 9:25:05and create projects and add it to your
  14564. 9:25:07portfolios so that you can create uh a
  14565. 9:25:09fantastic portfolio website and get a
  14566. 9:25:12job. And that's what this is all about.
  14567. 9:25:14Um, it's about upskilling and and
  14568. 9:25:16getting these skills that you can, you
  14569. 9:25:18know, get a job or or do better in your
  14570. 9:25:20job. So, I hope this has been helpful. I
  14571. 9:25:22really appreciate you guys joining me
  14572. 9:25:24and and doing this entire project with
  14573. 9:25:26me. I have no idea how long this is.
  14574. 9:25:28This probably this could be like an hour
  14575. 9:25:29for all I know. Um, so thank you so much
  14576. 9:25:32for sticking with me this entire time.
  14577. 9:25:33If you like this video, be sure to like
  14578. 9:25:35and subscribe below and I will see you
  14579. 9:25:37in the next video.
  14580. 9:25:41>> [music]
  14581. 9:25:51>> What's going on everybody? Welcome back
  14582. 9:25:52to another video. Today we're going to
  14583. 9:25:54be starting our PowerBI tutorial series.
  14584. 9:26:02Now, I am super excited to start this
  14585. 9:26:04series with you guys. We're going to be
  14586. 9:26:05breaking this up in about six or seven
  14587. 9:26:07videos. I don't really like those super
  14588. 9:26:09long videos where it's like four hours
  14589. 9:26:11long. I like breaking mine up into
  14590. 9:26:13chunks. So, that's what we're going to
  14591. 9:26:14do. This is the beginner series. And so,
  14592. 9:26:16we're going to start with the very
  14593. 9:26:17basics and we're just going to work our
  14594. 9:26:18way up. And I'm going to walk you
  14595. 9:26:19through every single step of the way.
  14596. 9:26:20It'll be very easy to follow. Everything
  14597. 9:26:23will be provided for you so that all you
  14598. 9:26:25have to do is really follow along and by
  14599. 9:26:27the end of it, you should know PowerBI a
  14600. 9:26:28lot better and you should have a lot
  14601. 9:26:30more confidence using it. All right. So,
  14602. 9:26:31the first thing I'm going to do is
  14603. 9:26:32download PowerBI desktop. I will leave
  14604. 9:26:34this link in the description. So, you
  14605. 9:26:36can just click on it, go to it and
  14606. 9:26:37download it. We're going to click this
  14607. 9:26:39download free button. And once we click
  14608. 9:26:42it, you can go to the Microsoft Store.
  14609. 9:26:45And I already have it downloaded. So,
  14610. 9:26:46when you see it, uh it'll already say
  14611. 9:26:48downloaded. But, um for you, you can go
  14612. 9:26:51in here, you can click download, and it
  14613. 9:26:53will download it for you. I'm on
  14614. 9:26:54Microsoft, uh but it may look a little
  14615. 9:26:56bit different for you if you're on a
  14616. 9:26:58different system. But once that is done,
  14617. 9:27:00we are going to open up PowerBI. So,
  14618. 9:27:02let's go right down here to our search.
  14619. 9:27:04Let's go to PowerBI.
  14620. 9:27:09And it is going to open up for us. All
  14621. 9:27:11right. So, right away, this is what it's
  14622. 9:27:13going to look like when you open it. And
  14623. 9:27:14we're going to go right over here to get
  14624. 9:27:16data. And let's click on that. It's
  14625. 9:27:20going to open up this window and it's
  14626. 9:27:21going to give us a lot of different
  14627. 9:27:23options for where we can get data from.
  14628. 9:27:26Now some of these are free and some you
  14629. 9:27:28need to upgrade from but you just taking
  14630. 9:27:30a quick glance through here you have a
  14631. 9:27:32ton of options. There's databases
  14632. 9:27:34there's um you know blob stoages there's
  14633. 9:27:38postgrade SQL or different SQL databases
  14634. 9:27:40um there's Google Analytics there's a
  14635. 9:27:42lot of places and you can go through the
  14636. 9:27:44process to connect to that data and you
  14637. 9:27:46can pull that data in from those data
  14638. 9:27:48sources. Now for what we are doing we're
  14639. 9:27:50just going to be using an Excel. I'm
  14640. 9:27:52going to leave the Excel that I'm going
  14641. 9:27:54to be using in the description. You can
  14642. 9:27:56go and download it and walk through this
  14643. 9:27:57with me. So, what we're going to do is
  14644. 9:27:59click on Excel workbook and we're going
  14645. 9:28:01to click connect. So, we're going to go
  14646. 9:28:03right here in our PowerBI tutorials
  14647. 9:28:05folder and we're going to click on
  14648. 9:28:06Apocalypse Food Prep. So, let's click on
  14649. 9:28:09that and it is going to connect and pull
  14650. 9:28:11that data in. Now, right here we have
  14651. 9:28:14our navigator and so if you had a lot of
  14652. 9:28:16different sheets, you can click on that
  14653. 9:28:18and choose which ones to pull in. I just
  14654. 9:28:20clicked on it right over here and we're
  14655. 9:28:22able to preview the data, but I can't
  14656. 9:28:25load or transform it yet. I need to
  14657. 9:28:27select which sheets I'm bringing in. So,
  14658. 9:28:30we only have one. So, that's the only
  14659. 9:28:31one we're going to bring in. So, you can
  14660. 9:28:32go ahead and load the data or you can
  14661. 9:28:34click on transform data. It's going to
  14662. 9:28:36take us to PowerBI Power Query, which is
  14663. 9:28:39going to allow us to transform our data.
  14664. 9:28:41So, I'm going to have an entire video on
  14665. 9:28:43how to transform the data, but I'm going
  14666. 9:28:45to give you a really quick glance at it
  14667. 9:28:47to kind of show you what it is. So right
  14668. 9:28:49up here it says our power query editor
  14669. 9:28:52and this is uh the window to basically
  14670. 9:28:54transform your data and get it ready for
  14671. 9:28:56your visualizations. Now you can do this
  14672. 9:28:58in Excel if you want to and do that
  14673. 9:29:00beforehand or you can do it here. And
  14674. 9:29:02there are lots of things that we can do
  14675. 9:29:03in here as you can see at the top. Again
  14676. 9:29:06I'll have an entire video dedicated to
  14677. 9:29:08just Power Query. But let's take a quick
  14678. 9:29:10look at the data and see if there's
  14679. 9:29:11anything we want to transform quickly
  14680. 9:29:13before we actually go and start building
  14681. 9:29:15our visualizations.
  14682. 9:29:18So over here we have the store where we
  14683. 9:29:20purchased it. We have the product that
  14684. 9:29:22we purchased, the price that we paid,
  14685. 9:29:24and the date that we bought it. Now, the
  14686. 9:29:26first thing that jumps out to me is that
  14687. 9:29:27this just says date on it. Um, we might
  14688. 9:29:30want to say date
  14689. 9:29:34purchased and we're going to hit enter.
  14690. 9:29:36And if you noticed right over here on
  14691. 9:29:38these applied steps, it says renamed
  14692. 9:29:40columns. everything that you do, every
  14693. 9:29:43single step that you apply to transform
  14694. 9:29:45this data is going to be right over
  14695. 9:29:47here. And if I want to, if I go back and
  14696. 9:29:49I say, you know, I really didn't want to
  14697. 9:29:50rename that column, I can just click X,
  14698. 9:29:53and it is going to get rid of that and
  14699. 9:29:55take it back to its original state. So
  14700. 9:29:58again, I'm just going to say purchased,
  14701. 9:30:01and we're going to enter that. Now, this
  14702. 9:30:04is our apocalypse food prep. So this is
  14703. 9:30:06food that we are buying for the
  14704. 9:30:08apocalypse um for this example. And if
  14705. 9:30:10we look at our products, we have bottled
  14706. 9:30:12water, canned vegetables, dried beans,
  14707. 9:30:15milk, and rice. And all of that stuff
  14708. 9:30:16makes sense except for the milk. U milk
  14709. 9:30:19will not stay or last long in the
  14710. 9:30:22apocalypse. So I think what we're going
  14711. 9:30:23to do is we're going to filter that out
  14712. 9:30:24really quickly. And we're going to click
  14713. 9:30:26okay. And right over here again, it says
  14714. 9:30:29filtered rows. And so now, if we scroll
  14715. 9:30:32down, there's no milk. So what we are
  14716. 9:30:34going to do is we are going to go over
  14717. 9:30:36here to close and apply.
  14718. 9:30:39and it is going to actually load the
  14719. 9:30:41data into PowerBI desktop.
  14720. 9:30:45So on this lefth hand side, it
  14721. 9:30:46immediately takes us to the report tab.
  14722. 9:30:49And what we want to do is go right here
  14723. 9:30:51to the data tab
  14724. 9:30:53and take a look at our data. So again,
  14725. 9:30:55there's our date purchased. And as you
  14726. 9:30:58can see, the milk is not in there.
  14727. 9:31:01Another tab that we're going to take a
  14728. 9:31:03look at um and again in this report tab,
  14729. 9:31:05this is where we actually build our
  14730. 9:31:06visualizations. The data is where we can
  14731. 9:31:09see the data and and change it up a
  14732. 9:31:11little bit and change some small things
  14733. 9:31:12about it like sorting the columns or
  14734. 9:31:14even creating a new column. And over
  14735. 9:31:16here we have this other tab and is
  14736. 9:31:18called model. And this is especially
  14737. 9:31:20useful when you have multiple tables or
  14738. 9:31:22multiple Excels and you need to join
  14739. 9:31:24them to kind of connect them together.
  14740. 9:31:26We don't have that, but in a future
  14741. 9:31:28video I'm going to walk through how to
  14742. 9:31:29use this entire tab. So now let's go
  14743. 9:31:31back to the data tab. And I want to just
  14744. 9:31:33look at the data really quickly before
  14745. 9:31:35we go over to the report tab and we
  14746. 9:31:37start building our first visualization.
  14747. 9:31:39As you can see, I've been buying these
  14748. 9:31:41different products in different months.
  14749. 9:31:42So, this rice I've been purchasing in
  14750. 9:31:44January, February, March, and April. And
  14751. 9:31:47I've been buying it from three different
  14752. 9:31:48locations because I wanted to see if I
  14753. 9:31:50was spending less money at one location
  14754. 9:31:52on all of the products. So then I would
  14755. 9:31:54just shop there in the future and save a
  14756. 9:31:56lot of money. Or if there were specific
  14757. 9:31:57products that were really cheap at one
  14758. 9:31:59location, but others they were cheaper
  14759. 9:32:01at a different location and so I should
  14760. 9:32:03just buy like the dried beans at Costco,
  14761. 9:32:06but everything else I should be buying
  14762. 9:32:07at Walmart. And so that's what we're
  14763. 9:32:08going to look at in just a little bit.
  14764. 9:32:10So let's go over to the report tab.
  14765. 9:32:12Right up here at the top there's this
  14766. 9:32:14data section. So you can kind of choose
  14767. 9:32:15if you want to add any more data now
  14768. 9:32:17that we are here. We can also write
  14769. 9:32:20queries or transform the data like we
  14770. 9:32:22were looking at in the power query
  14771. 9:32:23editor window. Over here in the insert,
  14772. 9:32:25we can add a new visualization or a text
  14773. 9:32:27box. And then in the calculation
  14774. 9:32:29section, we can create a new measure or
  14775. 9:32:31a quick measure. And then over here we
  14776. 9:32:33have share where you can actually
  14777. 9:32:35publish your report or your dashboard
  14778. 9:32:37online. Now over on the visualization
  14779. 9:32:38section on this far right, this is a
  14780. 9:32:40very important area. This is where a lot
  14781. 9:32:43of the actual creating of the dashboards
  14782. 9:32:45happen. So, let's take a look really
  14783. 9:32:47quick and we'll get into a lot of these
  14784. 9:32:49things as we're actually building our
  14785. 9:32:51dashboard. So, we're not just sitting
  14786. 9:32:52here looking and talking. We're going to
  14787. 9:32:53be actually building and doing. All
  14788. 9:32:55right. So, we're going to click right
  14789. 9:32:56here on this drop down on sheet one and
  14790. 9:32:59it's going to show us all of our
  14791. 9:33:00columns. Now, two of the things that we
  14792. 9:33:02wanted to look at were where are we
  14793. 9:33:04spending the least amount of money
  14794. 9:33:06buying the exact same product. That'll
  14795. 9:33:08help us determine where we want to shop.
  14796. 9:33:09And the second thing was, should I be
  14797. 9:33:11buying all my products at the same place
  14798. 9:33:13or are there certain products that
  14799. 9:33:15they're going to be cheaper at a
  14800. 9:33:16specific store and I should buy it
  14801. 9:33:17there? So, let's start out with the
  14802. 9:33:19first one, which we're just going to
  14803. 9:33:21see, uh, with the store and the price,
  14804. 9:33:25uh, where we're spending the least
  14805. 9:33:27amount of money. And just at a quick
  14806. 9:33:29glance, we can see we're spending the
  14807. 9:33:30least amount of money at Costco at $210
  14808. 9:33:32versus Target $ 219 and Walmart at 225.
  14809. 9:33:36And that really answers our question,
  14810. 9:33:38but we want to visualize it better, be
  14811. 9:33:40able to see it in a an easier way. So,
  14812. 9:33:42we're going to go right over here, and
  14813. 9:33:44we can click on a lot of these, but the
  14814. 9:33:46one that probably makes the most sense
  14815. 9:33:47is the stocked column chart,
  14816. 9:33:50and it's going to show Walmart, Target,
  14817. 9:33:52and Costco. Now, they're all the same
  14818. 9:33:54color. Let's add a legend. So, we're
  14819. 9:33:56just going to drag store over here down
  14820. 9:33:58to this legend. And let's make this
  14821. 9:34:01larger while we're working on it. So now
  14822. 9:34:04we can see we're spending the most
  14823. 9:34:05amount of money at Walmart. Uh right in
  14824. 9:34:07between at Target and then at Costco is
  14825. 9:34:09the lowest. And so right there we know
  14826. 9:34:11that Costco is the place to go for our
  14827. 9:34:13Apocalypse food prep. But is it going to
  14828. 9:34:16be that way for every product? Uh I
  14829. 9:34:19don't know. Let's take a look. Let's put
  14830. 9:34:22this up in this corner and let's start a
  14831. 9:34:24new one. We're going to need to select
  14832. 9:34:26the product for sure and the price and
  14833. 9:34:30probably additionally the store as well.
  14834. 9:34:33And let's click on
  14835. 9:34:36let's not do this one. We need a
  14836. 9:34:37clustered column chart. That's what we
  14837. 9:34:39need. Let's bring this over here. Let's
  14838. 9:34:42expand this quite a bit. And so really
  14839. 9:34:45at a glance, this is giving us
  14840. 9:34:47everything that we need. We can see each
  14841. 9:34:49product right here and we can see how
  14842. 9:34:51much we're paying per store. And so for
  14843. 9:34:54rice, we're paying it looks like a lot
  14844. 9:34:57more for uh our rice at Walmart, while
  14845. 9:35:00at Target is actually where we are
  14846. 9:35:02paying the least. Now, if we look at all
  14847. 9:35:04of these, it looks like for Costco, the
  14848. 9:35:07only one that we're really paying a lot
  14849. 9:35:08more on is on our rice. But for our
  14850. 9:35:11dried beans, our bottled water, we're
  14851. 9:35:14paying quite a bit less. And really,
  14852. 9:35:16it's pretty negligible for these canned
  14853. 9:35:18vegetables. We're paying maybe what, 60
  14854. 9:35:20cents, 50 60 cents more per can. That's
  14855. 9:35:23pretty negligible. But for the big
  14856. 9:35:25ticket items, um, we're really spending
  14857. 9:35:27a lot less at Costco. If we wanted to sp
  14858. 9:35:30to save just a little bit more money, we
  14859. 9:35:32could go to Target for our rice. Now, if
  14860. 9:35:34I want to make this more like a
  14861. 9:35:36dashboard and we're only keeping these
  14862. 9:35:38two things, I'm going to kind of size
  14863. 9:35:40them kind of like this. Whoops. Going to
  14864. 9:35:43show you that in a little bit. I'm going
  14865. 9:35:44to size them a little bit like this. So,
  14866. 9:35:48now that we have that looking good, we
  14867. 9:35:50want to change the title of both of
  14868. 9:35:51these. So, what we're going to do is go
  14869. 9:35:53over here in our visualizations and
  14870. 9:35:55format your visual. Uh, and we are going
  14871. 9:35:58to go to this general, go to title, and
  14872. 9:36:01now we can name it anything we really
  14873. 9:36:03want. For this, we're going to say best
  14874. 9:36:06store
  14875. 9:36:08for product.
  14876. 9:36:11And while we're in here, one other thing
  14877. 9:36:13that I wanted to do is I want to go to
  14878. 9:36:14this visual. Go right down here to these
  14879. 9:36:17data labels. Now, we haven't added any
  14880. 9:36:19data labels. So, I'm going to click on,
  14881. 9:36:21and you'll see exactly what it does. Uh,
  14882. 9:36:24it just puts the labels and the numbers
  14883. 9:36:25above it, so you don't have to actually
  14884. 9:36:27like hover over it and see what it is.
  14885. 9:36:29Now, it is actually rounding these
  14886. 9:36:30numbers. So, what we're going to do is
  14887. 9:36:32go down here. We're going to go down to
  14888. 9:36:35values and we'll go down to display
  14889. 9:36:38units and it's on auto, so it's auto
  14890. 9:36:40rounding those numbers. And we're just
  14891. 9:36:42going to say none so we can see the
  14892. 9:36:44actual value of these numbers.
  14893. 9:36:47And we can do the exact same thing over
  14894. 9:36:49here. It probably is a good thing to do.
  14895. 9:36:53Um, and it just is going to visualize it
  14896. 9:36:55a little bit differently in here, but
  14897. 9:36:56you can always change that if you want
  14898. 9:36:58to. Go over here to title and we're
  14899. 9:37:02going to say total by store.
  14900. 9:37:06And now we're going to take a look. And
  14901. 9:37:10so in a matter of minutes, we were able
  14902. 9:37:11to take our data from an Excel, put it
  14903. 9:37:14into PowerBI, transform it a little bit.
  14904. 9:37:17Then we were able to create these
  14905. 9:37:18visualizations that gave us concrete
  14906. 9:37:20answers to some very important topics.
  14907. 9:37:23We now know that Costco is the place to
  14908. 9:37:25go for basically every single product
  14909. 9:37:27except if we're buying rice. And if we
  14910. 9:37:30want to save just a few dollars, we're
  14911. 9:37:32going to head over to Target. And that's
  14912. 9:37:33genuinely going to change my shopping
  14913. 9:37:35habits for the next several years until
  14914. 9:37:36the apocalypse happens. So, in future
  14915. 9:37:38videos, we're going to dive into a lot
  14916. 9:37:40of the things that we looked at today,
  14917. 9:37:41but just in more detail. And then at the
  14918. 9:37:43very end of this series, we're going to
  14919. 9:37:44have an entire project where we really
  14920. 9:37:46use every single part of PowerBI and
  14921. 9:37:48create a beautiful dashboard. And so,
  14922. 9:37:50that's all we have for our very first
  14923. 9:37:52video in our PowerBI series. I hope it
  14924. 9:37:54was helpful. If you like this video, be
  14925. 9:37:55sure to like and subscribe below and
  14926. 9:37:57I'll see you in the next video.
  14927. 9:38:10What's going on everybody? Today we're
  14928. 9:38:12continuing our PowerBI tutorial series
  14929. 9:38:13and in this video we're going to be
  14930. 9:38:15looking at Power Query.
  14931. 9:38:22Now [music] Power Query is really great
  14932. 9:38:23because it allows you to actually
  14933. 9:38:24transform the data before you actually
  14934. 9:38:26get it into PowerBI. So, if you want to
  14935. 9:38:28make any changes like adding or deleting
  14936. 9:38:30a column or changing the data type or a
  14937. 9:38:32ton of other things, you can do all of
  14938. 9:38:34that in Power Query. Now, without
  14939. 9:38:36further ado, let's jump on my screen and
  14940. 9:38:38get started with the tutorial. All
  14941. 9:38:39right, so before we jump over to PowerBI
  14942. 9:38:41and start using Power Query, I wanted to
  14943. 9:38:43take a look at the data. And this is the
  14944. 9:38:45Excel from our last video called
  14945. 9:38:47Apocalypse Food Prep. And in that video,
  14946. 9:38:49we went through and we bought some rice,
  14947. 9:38:51some beans, water, vegetables, and milk
  14948. 9:38:53all for the apocalypse getting prepared
  14949. 9:38:56for that. Now, we decided to buy some
  14950. 9:38:58additional things like rope, some
  14951. 9:39:00flashlights, duct tape, and a water
  14952. 9:39:02filter, several water filters. And after
  14953. 9:39:06we purchased those, uh, our boss or
  14954. 9:39:08whoever we're working with there,
  14955. 9:39:10somebody decided to go and make a pivot
  14956. 9:39:12table. Now, in this pivot table, they
  14957. 9:39:14kind of broke it out by Costco, Target,
  14958. 9:39:15and Walmart, and had all the items had
  14959. 9:39:18some subtotals as well as some grand
  14960. 9:39:20totals right here. And then [snorts]
  14961. 9:39:22they decided to kind of copy and paste
  14962. 9:39:25that into this. And you'll see this a
  14963. 9:39:27lot when you're working with uh people
  14964. 9:39:29who use Excel. They like to kind of make
  14965. 9:39:31things like this, maybe make it into
  14966. 9:39:33like a table or or format it a little
  14967. 9:39:35bit differently, but you'll see stuff
  14968. 9:39:36like this a lot. So, this is what we're
  14969. 9:39:38going to actually pull into Power Query
  14970. 9:39:41and work with. Now, we're going to
  14971. 9:39:42imagine that this is all we have. This
  14972. 9:39:45is the only thing we were working with.
  14973. 9:39:46And I'll kind of reference this pivot
  14974. 9:39:48table a little bit, but we're going to
  14975. 9:39:50pretend this is all we have. and we want
  14976. 9:39:52to transform it to make it a lot more
  14977. 9:39:53usable to where we can make
  14978. 9:39:55visualizations with it. So, let's hop
  14979. 9:39:56over to PowerBI and pull this Excel in.
  14980. 9:39:59So, what we're going to do is click
  14981. 9:40:00import data from Excel. We're going to
  14982. 9:40:02click Apocalypse Food Prep and click
  14983. 9:40:03open. And then it's going to bring up
  14984. 9:40:05this window right here. Now, this is
  14985. 9:40:07where we can choose what data to bring
  14986. 9:40:09in. So, we can take a preview and just
  14987. 9:40:11click on it real quick. And this is the
  14988. 9:40:13pivot table that we were looking at. So,
  14989. 9:40:15it does have that pivot table. So, we
  14990. 9:40:17are able to pull in just a pivot table.
  14991. 9:40:19And then we have the purchase overview
  14992. 9:40:21where it's kind of that formatted um
  14993. 9:40:24thing that we were just looking at with
  14994. 9:40:25all the colors. We're going to pull both
  14995. 9:40:26of those in. So we're going to pull in
  14996. 9:40:28the pivot table and the purchase
  14997. 9:40:30overview. Now we could just load it or
  14998. 9:40:32we could transform it and we're going to
  14999. 9:40:34click transform and that's going to
  15000. 9:40:35bring us to power query. So let's click
  15001. 9:40:37on transform data. So now really quick
  15002. 9:40:39before we actually jump into working
  15003. 9:40:41through this and transforming it, I want
  15004. 9:40:43to show you what the Power Query editor
  15005. 9:40:45looks like. So, if we go right over
  15006. 9:40:47here, we have our queries, and these are
  15007. 9:40:48the tables that we actually pulled in,
  15008. 9:40:50and we can click on those and kind of go
  15009. 9:40:52back and forth between them. Now, up
  15010. 9:40:54top, we have our ribbon, and the ribbon
  15011. 9:40:56offers a lot of functionality. We have
  15012. 9:40:58things like remove columns, keep rows,
  15013. 9:41:00remove rows, split columns. These are
  15014. 9:41:03all things that we're likely to use when
  15015. 9:41:05using this Power Query editor. There's
  15016. 9:41:07also another tab called transform where
  15017. 9:41:09there's a lot of functionality here as
  15018. 9:41:11well. things like unpivoting a column or
  15019. 9:41:14transposing columns and rows and using a
  15020. 9:41:17first row as a header. Some of the
  15021. 9:41:18things that we'll be looking at today.
  15022. 9:41:20There's also another tab called add a
  15023. 9:41:22column. And this one's pretty
  15024. 9:41:24self-explanatory where you can add
  15025. 9:41:25additional columns like deleting a
  15026. 9:41:27column, creating an index column, or a
  15027. 9:41:30conditional column. Those are the three
  15028. 9:41:31main ones. There's also view, tools, and
  15029. 9:41:34help, but we're not going to really be
  15030. 9:41:35looking at those today. And then on the
  15031. 9:41:37far right side, we have our query
  15032. 9:41:39settings. You can do things like change
  15033. 9:41:41the name. So we can call it pivot table
  15034. 9:41:442022 and it'll update right over here on
  15035. 9:41:47our query side. And we have our applied
  15036. 9:41:50steps. Now our applied steps are
  15037. 9:41:52extremely important and very very
  15038. 9:41:54useful. Anytime we make any change to
  15039. 9:41:56transform this data, it's going to be
  15040. 9:41:58documented right here. And then we can
  15041. 9:42:00go back and look at it or we could even
  15042. 9:42:02delete that change in the future if we
  15043. 9:42:04want to and go back to a previous
  15044. 9:42:06version of what we just did. So when we
  15045. 9:42:08loaded the data into PowerBI, it did a
  15046. 9:42:10few things for us. It chose the source,
  15047. 9:42:12the navigation, and it promoted the
  15048. 9:42:13headers. And then it also changed the
  15049. 9:42:16data type. So if we want to check, we
  15050. 9:42:18can actually see those things or change
  15051. 9:42:19those things like this source right
  15052. 9:42:21here. We can click on this little icon
  15053. 9:42:23and it's going to bring up the actual
  15054. 9:42:25path where we got this file. So if we
  15055. 9:42:27wanted to change that or or it changes
  15056. 9:42:29in the future, we can come here and we
  15057. 9:42:31can change this file path. But we're not
  15058. 9:42:33going to do that right now. So, let's
  15059. 9:42:34click on cancel and let's go back down
  15060. 9:42:36to change type. So, it promoted these
  15061. 9:42:39headers and obviously these headers are
  15062. 9:42:41not correct. We're looking at this pivot
  15063. 9:42:42table and not the purchase overview, but
  15064. 9:42:44it changed these column headers. And so,
  15065. 9:42:47in the future, if we wanted to, we could
  15066. 9:42:48easily change those, but it did that for
  15067. 9:42:50us. And it changed the type as well. So,
  15068. 9:42:53if you look right here, it says ABC123.
  15069. 9:42:56All the way over here to where it just
  15070. 9:42:58says ABC. ABC means it's only going to
  15071. 9:43:01be text where ABC123 means it could be
  15072. 9:43:03basically anything uh text or it could
  15073. 9:43:06be numeric. So now let's go over to
  15074. 9:43:08purchase overview and this is the one
  15075. 9:43:10that we're actually going to be working
  15076. 9:43:11on the most but we might be looking at
  15077. 9:43:13pivot table just a little bit to kind of
  15078. 9:43:15reference it and see some of the
  15079. 9:43:16differences. So before we do anything
  15080. 9:43:18let's just take a look at how PowerBI
  15081. 9:43:20decided to take this data in. So, it
  15082. 9:43:22chose this apocalypse food prep overview
  15083. 9:43:24as kind of the first column. And that
  15084. 9:43:26was kind of our header or the title of
  15085. 9:43:28what we were looking at before. And then
  15086. 9:43:30all these other columns are basically
  15087. 9:43:31column 1 2 3 4 5s. So, that's something
  15088. 9:43:34that we're going to want to change in
  15089. 9:43:35just a little bit. There's also all
  15090. 9:43:37these blank uh columns right here at the
  15091. 9:43:39top and kind of these null values as we
  15092. 9:43:42go along. And we'll take a look at those
  15093. 9:43:44and we kind of are going to want to get
  15094. 9:43:46rid of some of this and just clean this
  15095. 9:43:47up to make it more usable for our
  15096. 9:43:50PowerBI visualizations. This may be
  15097. 9:43:52perfectly fine and acceptable in an
  15098. 9:43:54Excel, but when you're pulling it into
  15099. 9:43:55PowerBI, the real reason you're pulling
  15100. 9:43:57it in is to create visualizations, not
  15101. 9:43:59just it to look good in an Excel. So,
  15102. 9:44:02we're going to need to clean this up
  15103. 9:44:03quite a bit. So, let's go right up top.
  15104. 9:44:06The first thing that I want to do is I
  15105. 9:44:08want to get rid of these top rows. So,
  15106. 9:44:09we're going to go to this top ribbon and
  15107. 9:44:11we're going to click remove rows. And
  15108. 9:44:13we're going to select remove top rows.
  15109. 9:44:15and we're going to select two cuz we
  15110. 9:44:17have one two rows of all nulls and those
  15111. 9:44:20are completely useless. We just want to
  15112. 9:44:22get rid of them right away. So let's
  15113. 9:44:24click okay and it removed those. The
  15114. 9:44:27next thing that we want to do is these
  15115. 9:44:29this location product and the all these
  15116. 9:44:32dates these are actually the column
  15117. 9:44:34headers that we wanted. So what we need
  15118. 9:44:37to do now is we want to go over to
  15119. 9:44:39transform and we want to say use first
  15120. 9:44:42row as headers
  15121. 9:44:44and just like that we have location
  15122. 9:44:47products and these dates as our headers
  15123. 9:44:49exactly how we wanted them. Now let's
  15124. 9:44:51say for whatever reason you know we made
  15125. 9:44:53a mistake and we needed to go back we
  15126. 9:44:55would just select remove top rows and
  15127. 9:44:58that would be perfectly fine. Now you
  15128. 9:45:00can see over here it promoted the
  15129. 9:45:01headers but it's also changed the data
  15130. 9:45:03type. So before if we went to before we
  15131. 9:45:07removed the headers, these were all
  15132. 9:45:08ABC123
  15133. 9:45:10ABC123 cuz it had a lot of different
  15134. 9:45:12data types in there. So it just kind of
  15135. 9:45:14made a generic data type. But when we
  15136. 9:45:16promoted these headers, the first thing
  15137. 9:45:18that it decided to do was also change
  15138. 9:45:20this data type for us, giving us its
  15139. 9:45:23best guess as to what this data type is.
  15140. 9:45:26And it decided to do this decimal. So
  15141. 9:45:28this one two is a decimal, but we're
  15142. 9:45:30actually going to change that. And all
  15143. 9:45:32you have to do is click on this 1.2 two
  15144. 9:45:34or or the data type that it has right
  15145. 9:45:36here for you. And we're going to click
  15146. 9:45:38on fixed decimal number. And let's do
  15147. 9:45:41replace current. And now it's just a
  15148. 9:45:44little bit better. So now it's 2.70 2.5.
  15149. 9:45:47And that's normally how we would read uh
  15150. 9:45:49values like this because this is money.
  15151. 9:45:52So we would normally read it to the
  15152. 9:45:53second decimal just like that. And if we
  15153. 9:45:55have it on the second decimal for some,
  15154. 9:45:57we should probably have it on the second
  15155. 9:45:58decimal for all of them. So, really
  15156. 9:46:00quickly, I'm going to go through and I'm
  15157. 9:46:02just going to change that. And it should
  15158. 9:46:04be pretty quick. So, hang with me for
  15159. 9:46:06just a second.
  15160. 9:46:08All right, that is perfect. Now, for the
  15161. 9:46:11purposes of what we're about to do, we
  15162. 9:46:13don't actually need these subtotals or
  15163. 9:46:15this Costco total, Target total, and
  15164. 9:46:18Walmart total as well as the grand
  15165. 9:46:19total. Really, we want to get rid of
  15166. 9:46:21those. And so, what we're going to do is
  15167. 9:46:23we're going to go right over here. We're
  15168. 9:46:24going to click on this dropdown and
  15169. 9:46:25we're going to try to filter this data
  15170. 9:46:27before we actually load it into PowerBI.
  15171. 9:46:30So, we're going to filter and we're
  15172. 9:46:32going to say remove empty. And let's
  15173. 9:46:35remove those. And it's going to take out
  15174. 9:46:37all of those nulls. If we wanted to try
  15175. 9:46:39to filter this out by saying something
  15176. 9:46:40like Costco total or Target total, we
  15177. 9:46:44could do that by going right here,
  15178. 9:46:45clicking this drop down on products,
  15179. 9:46:47going to text filters, and saying does
  15180. 9:46:49not contain. And let's do insert. And
  15181. 9:46:54we're going to say does not contain. And
  15182. 9:46:55we want to say total. And let's click
  15183. 9:46:59okay. And again, it filtered out all of
  15184. 9:47:02those things. So there's a few different
  15185. 9:47:03options that you can do if you want to
  15186. 9:47:04filter out rows that contain either null
  15187. 9:47:07values or specific values. Now, the next
  15188. 9:47:09thing that we're going to do is actually
  15189. 9:47:11get rid of a column, this grand total
  15190. 9:47:13column. And so what we're going to do is
  15191. 9:47:14we're going to click on the very top
  15192. 9:47:16part where it says grand total. We're
  15193. 9:47:18going to go back over here to home and
  15194. 9:47:20we're going to click on remove columns
  15195. 9:47:22and it says insert. That's because we're
  15196. 9:47:24on this filtered rows one right here.
  15197. 9:47:26Um, but what we're going to do is just
  15198. 9:47:27insert that and it'll insert it right
  15199. 9:47:29there. That's totally fine. We can just
  15200. 9:47:31move it to the bottom. Now, we got rid
  15201. 9:47:32of this column entirely. Now, this looks
  15202. 9:47:36really good visually. I like how this
  15203. 9:47:38looks. I like how everything is set up.
  15204. 9:47:40The biggest thing about this is that
  15205. 9:47:43when you're actually wanting to use this
  15206. 9:47:44for visualizations, these columns as
  15207. 9:47:46dates doesn't really work too well. And
  15208. 9:47:50so what we're going to want to do is
  15209. 9:47:52we're going to want to transpose this or
  15210. 9:47:54pivot this to where these dates are
  15211. 9:47:56actually rows. So what we're going to do
  15212. 9:47:58is select the first date, which is
  15213. 9:48:00January 1st, all the way through April
  15214. 9:48:021st. And we're going to hit shift and
  15215. 9:48:04click on that April 1st right there to
  15216. 9:48:05select all of them at the same time. And
  15217. 9:48:08then we're going to go over here to the
  15218. 9:48:09transform tab and we're going to click
  15219. 9:48:12unpivot columns and let's see what this
  15220. 9:48:14does. And so now what we've done is
  15221. 9:48:16we've basically recreated our original
  15222. 9:48:19Excel that we had. So let's go back and
  15223. 9:48:20take a look really quickly at that. So
  15224. 9:48:22this looks almost identical to what we
  15225. 9:48:24have in PowerBI right now. And this is
  15226. 9:48:26extremely usable and very good for
  15227. 9:48:28visualizations and is much much better
  15228. 9:48:31than this. But again, we were pretending
  15229. 9:48:33that this is what we were given at the
  15230. 9:48:35beginning. So you have to imagine, you
  15231. 9:48:37know, somebody just handing you this and
  15232. 9:48:38you need to make it much more usable for
  15233. 9:48:40visualizations in the future, which
  15234. 9:48:42happens a lot. And we actually wanted to
  15235. 9:48:45create this. We just weren't given this.
  15236. 9:48:47Now, a few last things that we might
  15237. 9:48:48want to do is we want to clean this up
  15238. 9:48:50just a little bit. We're going to select
  15239. 9:48:51the data type and change this to date.
  15240. 9:48:54And then we're going to select the
  15241. 9:48:55value. And I double clicked on the
  15242. 9:48:58value. And I actually want to call this
  15243. 9:49:00cost uh or product cost. product_cost
  15244. 9:49:07and then for the location I actually
  15245. 9:49:08want this to be called store. So now
  15246. 9:49:12this looks really good but I want to
  15247. 9:49:14show you one thing really quickly on
  15248. 9:49:15this pivot table 2022. So let's go back
  15249. 9:49:18here. This looks very similar to how we
  15250. 9:49:21had it when it first started. One thing
  15251. 9:49:23I wanted to show you uh really quickly
  15252. 9:49:26and I want to click on this first one.
  15253. 9:49:28We're going to make this our column
  15254. 9:49:30header and then we're going to try to
  15255. 9:49:31pivot or unpivot this January, February,
  15256. 9:49:34March, April. So really quickly, let's
  15257. 9:49:36do that. So we're going to transform use
  15258. 9:49:39first row as headers.
  15259. 9:49:42So now we have this January, February,
  15260. 9:49:43March, April. Now if you notice, these
  15261. 9:49:46are not dates. These are actually text.
  15262. 9:49:49It says January, February, March, and
  15263. 9:49:51April. So if we go to do this and we
  15264. 9:49:55click unpivot
  15265. 9:49:57and here's the columns that are created
  15266. 9:49:59when we unpivot it. It is January,
  15267. 9:50:02February, March, and April. These are
  15268. 9:50:04not dates. So we cannot go and change
  15269. 9:50:06this to a date because that would error
  15270. 9:50:09out because it's actually text. So it's
  15271. 9:50:11something that you want to look out for.
  15272. 9:50:12It's something that you need to be aware
  15273. 9:50:13of. And you can change that in the pivot
  15274. 9:50:16table. So you want to be aware of how it
  15275. 9:50:18actually sits and looks in the Excel or
  15276. 9:50:20whatever data source you're pulling from
  15277. 9:50:22before you actually pull it into Power
  15278. 9:50:23Query to transform. And now the very
  15279. 9:50:26last thing that we need to do to
  15280. 9:50:27finalize all of this is go over here to
  15281. 9:50:29close and apply. And once we click that,
  15282. 9:50:32everything that we've worked on is going
  15283. 9:50:33to be applied to the actual data and
  15284. 9:50:35it's going to load into PowerBI to
  15285. 9:50:37create our visualizations. So let's go
  15286. 9:50:38ahead and click on that. And so now the
  15287. 9:50:40data has been pulled into PowerBI. Let's
  15288. 9:50:42go right down here to data and we can
  15289. 9:50:44see the data right here. If we need to
  15290. 9:50:46transform this data again, we can bring
  15291. 9:50:48it back into the Power Query Editor
  15292. 9:50:50window by just clicking the transform
  15293. 9:50:52data button, and it's going to bring us
  15294. 9:50:54right back. So, I hope that this was
  15295. 9:50:55helpful. Thank you so much for watching.
  15296. 9:50:57If you like this video, be sure to like
  15297. 9:50:59and subscribe below and check out all my
  15298. 9:51:01other videos and everything data analyst
  15299. 9:51:03related. I'll see you in the next video.
  15300. 9:51:06[music]
  15301. 9:51:17What's going on everybody? Welcome back
  15302. 9:51:18to the PowerBI tutorial series. Today
  15303. 9:51:20we're going to be taking a look at
  15304. 9:51:21building relationships.
  15305. 9:51:27[music]
  15306. 9:51:29Now, when you import multiple tables
  15307. 9:51:30from either the same data source or
  15308. 9:51:32multiple data sources, you want to tie
  15309. 9:51:34them together so that when you're
  15310. 9:51:35creating your visualizations, everything
  15311. 9:51:37is connected. So, in this tutorial,
  15312. 9:51:39we'll be walking through how to create
  15313. 9:51:40those relationships to make sure that
  15314. 9:51:42all of your tables are connected
  15315. 9:51:43properly. And without further ado, let's
  15316. 9:51:45jump on my screen and get started with
  15317. 9:51:46the tutorial. All right. So, before we
  15318. 9:51:48jump over to PowerBI and start creating
  15319. 9:51:49our relationships and our model, I want
  15320. 9:51:51to take a look at the data in Excel. We
  15321. 9:51:53realized we were buying so many products
  15322. 9:51:55for the apocalypse that we decided to
  15323. 9:51:57start our own store. And we have several
  15324. 9:51:59customers and some client information
  15325. 9:52:01down here. And so, I wanted to take a
  15326. 9:52:03look at some of the columns and these
  15327. 9:52:04tables that we're going to be looking
  15328. 9:52:05at. First thing we have is the
  15329. 9:52:08apocalypse store. These are the things
  15330. 9:52:10that we are selling. I know it's a very
  15331. 9:52:12limited inventory, but these are the
  15332. 9:52:14really high sellers. These are the ones
  15333. 9:52:16that I wanted to sell. So, we have this
  15334. 9:52:18product ID, our product name, price, and
  15335. 9:52:21production cost. Then we have this
  15336. 9:52:23apocalypse sales. This is how many sales
  15337. 9:52:26we've actually made to our customers.
  15338. 9:52:28So, we have this customer ID, our
  15339. 9:52:31customer name, product ID, order ID,
  15340. 9:52:34units sold, and the date it was
  15341. 9:52:35purchased. And then we have our customer
  15342. 9:52:37information right here. Here are all of
  15343. 9:52:40our clients. So, we have this customer
  15344. 9:52:41ID, customer, address, city, state, and
  15345. 9:52:45zip code. So, now that we've taken a
  15346. 9:52:46look at our data, let's go and load it
  15347. 9:52:48into PowerBI. So, we're going to say
  15348. 9:52:50import data from Excel. We're going to
  15349. 9:52:52choose this model right here. And we're
  15350. 9:52:54going to click open. And we are going to
  15351. 9:52:55want all three of these. So, I'm going
  15352. 9:52:57to click on all of them, and we're just
  15353. 9:52:58going to load it. We're not going to
  15354. 9:52:59transform the data at all.
  15355. 9:53:04So, now the data has been loaded. Let's
  15356. 9:53:06go right over here on the left hand side
  15357. 9:53:08to our model tab. And let's scoot this
  15358. 9:53:10over just a little bit and move back.
  15359. 9:53:14And we're going to move these tables up
  15360. 9:53:16to where it's a little bit easier to
  15361. 9:53:18see.
  15362. 9:53:19So, right off the bat, you can already
  15363. 9:53:22see that there are these lines between
  15364. 9:53:23these tables. So, there are already
  15365. 9:53:25relationships that PowerBI has
  15366. 9:53:27automatically detected and created. From
  15367. 9:53:30my experience, PowerBI actually does a
  15368. 9:53:31really good job at creating these
  15369. 9:53:33relationships automatically, but we're
  15370. 9:53:35going to go in and take a look at these
  15371. 9:53:37and kind of see what everything means,
  15372. 9:53:39and then we're going to go back and
  15373. 9:53:40create these relationships from scratch
  15374. 9:53:42just to make sure that we know how to do
  15375. 9:53:43every single part. So, to get us
  15376. 9:53:44started, let's double click on this line
  15377. 9:53:46connecting the customer information
  15378. 9:53:48table to the apocalypse sales table.
  15379. 9:53:51and it's going to bring up this edit
  15380. 9:53:53relationship page right here. So, this
  15381. 9:53:55line right here connecting these two
  15382. 9:53:56tables actually gives us quite a bit of
  15383. 9:53:58information without actually having to
  15384. 9:54:00click into this edit relationship page.
  15385. 9:54:02What this is showing is that we have a
  15386. 9:54:04one to many relationship and there's
  15387. 9:54:07only one or a single cross filter
  15388. 9:54:09direction. And you can find both of
  15389. 9:54:11those things right down here. And I'm
  15390. 9:54:13going to walk through what those mean in
  15391. 9:54:14just a little bit. On this page, you can
  15392. 9:54:16also see the columns that PowerBI
  15393. 9:54:18decided to choose in order to tie these
  15394. 9:54:20two tables together. Now, for our
  15395. 9:54:22example, they decided to use the
  15396. 9:54:24customer and customer right here from
  15397. 9:54:26the customer information table as well
  15398. 9:54:28as the apocalypse sales. But I don't
  15399. 9:54:30really want to use those specifically
  15400. 9:54:32because on this apocalypse sales table,
  15401. 9:54:35I might remove this customer information
  15402. 9:54:37and just keep the customer ID. it may
  15403. 9:54:39have chosen these customer columns
  15404. 9:54:41because they have the exact same name
  15405. 9:54:42and really the same information, but I
  15406. 9:54:45want to use this customer ID anyways.
  15407. 9:54:47So, what I'm going to do is I'm going to
  15408. 9:54:48click on that column and click on this
  15409. 9:54:50column. And then I'm going to click
  15410. 9:54:51okay. And if we go back into it by
  15411. 9:54:54double clicking again, we're going to
  15412. 9:54:56see that it now save that. And if we did
  15413. 9:54:58what we just did before, which is kind
  15414. 9:55:00of hover over it, it's going to show us
  15415. 9:55:01what those two tables are joined on. So,
  15416. 9:55:03opening this back up, let's go down here
  15417. 9:55:05to this cardality and cross filter
  15418. 9:55:07direction. Cardonality has several
  15419. 9:55:09different options that you can choose
  15420. 9:55:10from. You have one to many, one to one,
  15421. 9:55:13one to many, and many to many. Now, for
  15422. 9:55:15this example, we're looking at
  15423. 9:55:17apocalypse sales, and we're going
  15424. 9:55:18apocalypse sales down to customer
  15425. 9:55:20information. Now, there are a lot of
  15426. 9:55:23rows in the apocalypse sales, but
  15427. 9:55:24there's very few in this customer
  15428. 9:55:26information, and there's only one
  15429. 9:55:28customer per row, whereas in the
  15430. 9:55:30apocalypse sales up here, the customer
  15431. 9:55:33can have several rows for several
  15432. 9:55:34different orders. So that's why the
  15433. 9:55:36cardality is many to one. Now if we flip
  15434. 9:55:40this and we say we want the customer
  15435. 9:55:41information here and we want the
  15436. 9:55:43apocalypse sales down here and we tie
  15437. 9:55:46that together. Now it's going to flip
  15438. 9:55:47and it's going to say one to many. Now
  15439. 9:55:49let's look at the cross filter
  15440. 9:55:51direction. And there's only two options
  15441. 9:55:52here. It's either single or both. And if
  15442. 9:55:54we choose both and we click okay, this
  15443. 9:55:57now goes from a single arrow pointing in
  15444. 9:55:59one direction to two arrows pointing in
  15445. 9:56:01both directions. But what does this
  15446. 9:56:03really mean? So, in order to demonstrate
  15447. 9:56:05this, I'm going to put this back to a
  15448. 9:56:07single direction. And what we're going
  15449. 9:56:08to try to do is connect the data over
  15450. 9:56:10here or the columns over here to the
  15451. 9:56:12columns in this apocalypse store. So,
  15452. 9:56:14let's go over here to build a
  15453. 9:56:16visualization. And what we're going to
  15454. 9:56:18do is we're going to take this customer
  15455. 9:56:20information and let's just say we want
  15456. 9:56:21to look at state. So, I'm going to click
  15457. 9:56:24on state right here. And I'm just going
  15458. 9:56:25to make this into a table. And the
  15459. 9:56:28customer information table is only tied
  15460. 9:56:30right now to this sales table. So, we're
  15461. 9:56:33actually going to go over to the
  15462. 9:56:34Apocalypse store, and we want to see how
  15463. 9:56:37many product IDs are being bought in
  15464. 9:56:39these different states. So, really
  15465. 9:56:41quickly, we're going to come up here and
  15466. 9:56:42create a new measure. And all we're
  15467. 9:56:45going to say is this measure is the
  15468. 9:56:46count of Apocalypse store product ID.
  15469. 9:56:51And we're going to create that. And now
  15470. 9:56:53we're going to select it. So, it's added
  15471. 9:56:55to that table. So now what this is
  15472. 9:56:56showing is that there are 10 product IDs
  15473. 9:56:58which there are 10 products for each of
  15474. 9:57:01these states. But that's not actually
  15475. 9:57:03technically correct because not every
  15476. 9:57:06state purchased these 10 different
  15477. 9:57:08items. If we go back to our model and we
  15478. 9:57:11change both of these to
  15479. 9:57:14a both direction,
  15480. 9:57:17then we're going to go back and see what
  15481. 9:57:18changed in our numbers. So now let's go
  15482. 9:57:21back to our visualization. And now we
  15483. 9:57:24can see that Minnesota actually only
  15484. 9:57:25ordered seven different product IDs.
  15485. 9:57:28Missouri 8, New York 9, and Texas 10.
  15486. 9:57:31This is actually much more accurate than
  15487. 9:57:33before. When you use the both option, it
  15488. 9:57:36takes these tables and treats them as if
  15489. 9:57:38they are a single table. But the single
  15490. 9:57:40option is not going to do that. And so
  15491. 9:57:41for our example, if we're trying to
  15492. 9:57:43connect this table to this table and one
  15493. 9:57:45of the last things that I want to show
  15494. 9:57:46you is this option right down here,
  15495. 9:57:48which says make this relationship
  15496. 9:57:50active. Now if we don't click this and
  15497. 9:57:52there are other options in here that
  15498. 9:57:54connect these things like the customer
  15499. 9:57:55to the customer then that may be the
  15500. 9:57:58active relationship. But if I select
  15501. 9:58:00this is the active relationship that
  15502. 9:58:01means this is going to become the
  15503. 9:58:03default relationship between these two
  15504. 9:58:04tables. So now let's come out of here.
  15505. 9:58:06We're going to click cancel.
  15506. 9:58:08We're going to zoom in just a little bit
  15507. 9:58:10and bring these tables a little bit
  15508. 9:58:12closer so we can zoom in just a little
  15509. 9:58:14bit more. Now we are going to go ahead
  15510. 9:58:17and delete these. So we're going to say
  15511. 9:58:19delete. Yes. And delete. Yes. So, just
  15512. 9:58:25for demonstration purposes, we're going
  15513. 9:58:26to build these relationships from
  15514. 9:58:27scratch. So, we're going to come over to
  15515. 9:58:29the customer information table and we're
  15516. 9:58:31going to drag it all the way over here
  15517. 9:58:33and put it on top of this custo ID or
  15518. 9:58:35the customer ID in Apocalypse sales. And
  15519. 9:58:38it's going to automatically create that
  15520. 9:58:40relationship. And we can open this up.
  15521. 9:58:43And as you can see, it created the
  15522. 9:58:44relationship between this customer ID in
  15523. 9:58:46the apocalypse sales and the customer ID
  15524. 9:58:48in the customer information. It also
  15525. 9:58:50defaulted the cardality from many to one
  15526. 9:58:52and the cross filter direction to
  15527. 9:58:54single. So we're going to go ahead and
  15528. 9:58:56change that to both and click okay. And
  15529. 9:58:58then we're going to come over here to
  15530. 9:59:00the product ID and Apocalypse store and
  15531. 9:59:02drag this over the product ID in the
  15532. 9:59:03apocalyp sales.
  15533. 9:59:06And again, if we open it up, it created
  15534. 9:59:08that relationship for us. It created the
  15535. 9:59:10cardality automatically. And we're going
  15536. 9:59:12to change this cross filter direction to
  15537. 9:59:13both and click okay. And so on a really
  15538. 9:59:16small scale, that is how it works. Of
  15539. 9:59:19course, it becomes a little bit more
  15540. 9:59:20complex the more tables that you add and
  15541. 9:59:23the more relationships that are created,
  15542. 9:59:25but this is how you're going to actually
  15543. 9:59:26create the relationships in the model
  15544. 9:59:28tab within PowerBI. I hope that this
  15545. 9:59:30tutorial has helped you understand this
  15546. 9:59:32concept a little bit better. Thank you
  15547. 9:59:34guys so much for watching. I really
  15548. 9:59:35appreciate it. If you like this video,
  15549. 9:59:37be sure to like and subscribe below and
  15550. 9:59:39I'll see you in the next video.
  15551. 9:59:41[music]
  15552. 9:59:52What's going on everybody? Welcome back
  15553. 9:59:53to the PowerBI tutorial series. Today
  15554. 9:59:56we're going to be taking a look at DAX.
  15555. 10:00:01[music]
  15556. 10:00:03Now DAX stands for data analysis
  15557. 10:00:06expressions and it's basically a library
  15558. 10:00:08of functions and operators that help you
  15559. 10:00:10build formulas. You can use DAX to
  15560. 10:00:12create measures and calculated columns
  15561. 10:00:14within PowerBI which can really give you
  15562. 10:00:16a lot of insight into your data.
  15563. 10:00:18Honestly, it is not super complicated
  15564. 10:00:20and hopefully by the end of this video,
  15565. 10:00:21you'll have a lot more confidence
  15566. 10:00:23actually using DAX and PowerBI. So,
  15567. 10:00:25without further ado, let's jump on my
  15568. 10:00:26screen and get started with the
  15569. 10:00:27tutorial. All right, so let's take a
  15570. 10:00:29look at our tables and data before we
  15571. 10:00:31get started. So, we have two tables, the
  15572. 10:00:32Apocalypse Sales, the Apocalypse store.
  15573. 10:00:35For this apocalypse sales table, we have
  15574. 10:00:37the customer, product ID, order ID,
  15575. 10:00:39units sold, and the date it was
  15576. 10:00:41purchased. And then for the Apocalypse
  15577. 10:00:44store, we have product ID, product name,
  15578. 10:00:46price, and production cost. Now, these
  15579. 10:00:49are joined together or they do have a
  15580. 10:00:52relationship together via the product
  15581. 10:00:54ID. So, what we're going to be using are
  15582. 10:00:56these new measures and new columns to
  15583. 10:00:58create our DAX functions. So, really
  15584. 10:01:01quickly, let's go over to this report
  15585. 10:01:03tab and let's drop down our fields over
  15586. 10:01:06here so we can see everything. And so,
  15587. 10:01:08to get us started, we're going to go
  15588. 10:01:09right up here to Apocalypse Sales. We're
  15589. 10:01:11going to rightclick and click new
  15590. 10:01:13measure. And it's going to open up this
  15591. 10:01:15right here, which is basically our bar
  15592. 10:01:17where we can create our functions. And
  15593. 10:01:19so, right here, it's automatically given
  15594. 10:01:21us the name measure, but we can change
  15595. 10:01:23that. And we're going to say count of
  15596. 10:01:26sales. So, now we can start writing our
  15597. 10:01:29DAX function. And that's just going to
  15598. 10:01:30be the name of it and what's going to
  15599. 10:01:31show up right over here once we click
  15600. 10:01:33enter. So let's go over here and we're
  15601. 10:01:36going to say count. And as we're typing,
  15602. 10:01:39it's automatically giving us options. It
  15603. 10:01:41has something called IntelliSense. If
  15604. 10:01:43you've ever used other Microsoft
  15605. 10:01:44products, IntelliSense is their kind of
  15606. 10:01:46autocomp completion that helps you look
  15607. 10:01:49at other options very quickly. And so
  15608. 10:01:51we're just going to click on this count.
  15609. 10:01:53And it's prompting us to put in a column
  15610. 10:01:55name. And so we can come down here and
  15611. 10:01:57we can select one or we can type it out
  15612. 10:01:59and it'll try to predict and help us
  15613. 10:02:01choose which column to select. So for
  15614. 10:02:04us, we're going to use this order ID,
  15615. 10:02:05but let's just start typing it out.
  15616. 10:02:07We'll say order ID. And then we can
  15617. 10:02:10click on it and we're going to close
  15618. 10:02:12this parenthesis and click enter. Or you
  15619. 10:02:14can go over here and click this check
  15620. 10:02:16mark, but we're just going to click
  15621. 10:02:17enter. And so over on this right side,
  15622. 10:02:20it finalized that and saved that. And we
  15623. 10:02:22can actually look at that by clicking on
  15624. 10:02:24this box next to it.
  15625. 10:02:26and we want to look at this in a table.
  15626. 10:02:29So now we can see that there are 74
  15627. 10:02:31sales. Now for this we want to see who's
  15628. 10:02:34buying our products. We want to see what
  15629. 10:02:36our what our client name is. So we're
  15630. 10:02:39going to go over here and we're going to
  15631. 10:02:40choose customer and we're going to put
  15632. 10:02:42customer on top of sales and we're just
  15633. 10:02:45going to take a look at it like this. So
  15634. 10:02:48now we can see that our number one
  15635. 10:02:50customer is Uncle Joe's Prep Shop. He
  15636. 10:02:52has 22 orders. Now, they have the most
  15637. 10:02:54orders with us, but it doesn't
  15638. 10:02:55necessarily mean that they're spending
  15639. 10:02:56the most money with us, but we can take
  15640. 10:02:58a look at that later. The next thing
  15641. 10:03:00that I want to take a look at is how
  15642. 10:03:02many products we're actually selling.
  15643. 10:03:04What are our big products that we're
  15644. 10:03:05selling? We have 10 different items, but
  15645. 10:03:08I don't know exactly which one is
  15646. 10:03:10selling the best. If if one is doing
  15647. 10:03:12really poorly and getting no orders,
  15648. 10:03:14this is something that I want to look
  15649. 10:03:15into. So, all we're going to do is go
  15650. 10:03:16right back up here to Apocalypse Sales
  15651. 10:03:18again, rightclick, and select new
  15652. 10:03:21measure. And for this one, we're going
  15653. 10:03:23to call it the sum of products sold.
  15654. 10:03:28And all [snorts] we're going to start
  15655. 10:03:29out with is by doing sum. And if this
  15656. 10:03:33seems familiar to something like Excel,
  15657. 10:03:36you're 100% correct. It is very similar.
  15658. 10:03:38And remember, these are both Microsoft
  15659. 10:03:40products. So there's going to be similar
  15660. 10:03:42functionality in both of them. And so
  15661. 10:03:45this DAX is going to have a lot of
  15662. 10:03:47similarities to exactly how it has it in
  15663. 10:03:49Excel. So, we're going to do an open
  15664. 10:03:51bracket. And now, what we're going to
  15665. 10:03:53choose is this units sold. We want to
  15666. 10:03:56sum up all of these units sold and see
  15667. 10:03:58how many we're actually selling. So,
  15668. 10:04:00we're going to say units sold. I'm going
  15669. 10:04:03to hit tab. It's going to autocomplete
  15670. 10:04:05that. I'm going to close my parenthesis
  15671. 10:04:07and I'm going to come over here and
  15672. 10:04:08click this check box. So, now it's
  15673. 10:04:11created that measure and we're already
  15674. 10:04:12selected in this table. So, all we have
  15675. 10:04:14to do is click the check mark and it's
  15676. 10:04:17going to show us that we have 3,000
  15677. 10:04:19total products sold and we can go
  15678. 10:04:22through here and see what the big
  15679. 10:04:23sellers are. And probably the biggest
  15680. 10:04:25one that I see right off the bat is this
  15681. 10:04:27multi-tool survival knife. So, these DAX
  15682. 10:04:29functions that you can write can be very
  15683. 10:04:31simple and lead to really good insights
  15684. 10:04:33that you can use for the visualizations
  15685. 10:04:35later on. Now I want to take a look at
  15686. 10:04:37the difference between something like
  15687. 10:04:38sum which is an aggregator function and
  15688. 10:04:40something like sumx which is an iterator
  15689. 10:04:43function. Because if you add x to some
  15690. 10:04:45of these aggregator functions you can
  15691. 10:04:47create them or or make them into an
  15692. 10:04:50iterator function. So you can have sum
  15693. 10:04:52and sumx or average and average x.
  15694. 10:04:55Adding x onto the end of them can make
  15695. 10:04:57them into an iterator function. So let's
  15696. 10:04:59take a look and see how that actually
  15697. 10:05:00works. I'm going to show you the
  15698. 10:05:02difference and then I'm going to talk
  15699. 10:05:03through the difference at the end. So,
  15700. 10:05:05really quickly, let's go back to our
  15701. 10:05:06data and let's go to the Apocalypse
  15702. 10:05:09store. Now, what we have right here is
  15703. 10:05:11we have the price and we have the
  15704. 10:05:13production cost. And we want to see how
  15705. 10:05:14much profit we're getting from each of
  15706. 10:05:16these as well as we can take a look at
  15707. 10:05:18the units sold and see how much money we
  15708. 10:05:20are actually making. So, what we're
  15709. 10:05:23going to do is we're going to come back
  15710. 10:05:24over here. We're going to go to
  15711. 10:05:26Apocalypse store. We're going to
  15712. 10:05:28rightclick and create a measure. And in
  15713. 10:05:30just a little bit, we're going to be
  15714. 10:05:31creating a new column. and that'll kind
  15715. 10:05:32of show the difference really well. So,
  15716. 10:05:35we're going to create this new measure
  15717. 10:05:36and we're going to name it profit
  15718. 10:05:39and we're going to come over here and
  15719. 10:05:41what we're going to do is we're going to
  15720. 10:05:42take the sum oops we're going to start
  15721. 10:05:45with our sums. We're going to take the
  15722. 10:05:46sum of the price and then we're going to
  15723. 10:05:50close that parenthesis and we're going
  15724. 10:05:51to subtract the sum of the production
  15725. 10:05:55cost.
  15726. 10:05:57So, all that does is it says if
  15727. 10:05:58something cost $20, if we sold it for
  15728. 10:06:00$20 and it only cost us $10, that's $10
  15729. 10:06:03in profit for that item. And then what
  15730. 10:06:05we're going to want to do is we're going
  15731. 10:06:07to actually want to encapsulate that
  15732. 10:06:09really quickly because we're about to
  15733. 10:06:10use multiply. And then we're going to
  15734. 10:06:14sum. And now we're going to take the
  15735. 10:06:16units sold. So, how many units were
  15736. 10:06:19actually sold at that profit that we
  15737. 10:06:21just made. So, let's see if that works.
  15738. 10:06:23And let's click the check right here.
  15739. 10:06:26And so we have the profit. So let's
  15740. 10:06:27click on the profit. Oops, that's not
  15741. 10:06:30what I wanted to do. Let's use a new
  15742. 10:06:31one. Let's create a new uh table. We're
  15743. 10:06:34going to click profit.
  15744. 10:06:36And let's make it a table. And I'm going
  15745. 10:06:38to pull this right over here.
  15746. 10:06:40Now, we have our profit, but what I
  15747. 10:06:42really want to know is which customer is
  15748. 10:06:44spending the most money at my store. So,
  15749. 10:06:47we're going to come right over here.
  15750. 10:06:48We're going to click on customer and
  15751. 10:06:51customer at the top. And just at a
  15752. 10:06:52glance, we can see that Uncle Joe's prep
  15753. 10:06:54shop is spending the most money at the
  15754. 10:06:56store. Now, what I want to show you is
  15755. 10:06:58the difference between sum and sumx. So,
  15756. 10:07:01what I'm going to do is I'm going to go
  15757. 10:07:03back to this profit and going to copy
  15758. 10:07:06this
  15759. 10:07:07this entire thing and we're going to go
  15760. 10:07:09back here to this table. Now, we just
  15761. 10:07:12created a measure and we were able to
  15762. 10:07:14break it down by each customer. So,
  15763. 10:07:17let's go back over here. Now, let's go
  15764. 10:07:20up here to home and we're going to
  15765. 10:07:22create a new column. And we're going to
  15766. 10:07:25call this profit
  15767. 10:07:30column. And we're going to literally
  15768. 10:07:32paste the exact same thing into here.
  15769. 10:07:35And we're going to hit enter.
  15770. 10:07:39And each row is the exact same thing.
  15771. 10:07:43So, what it's doing is it is going
  15772. 10:07:44through the price. It's adding all of it
  15773. 10:07:47up and calculating it at the bottom.
  15774. 10:07:49It's adding the production cost. It's
  15775. 10:07:50going all the way down and calculating
  15776. 10:07:52it at the bottom. And then it's going
  15777. 10:07:54over and looking at how many units it
  15778. 10:07:56sold. And then it's performing this
  15779. 10:07:58calculation up here. And then it gives
  15780. 10:08:00us the total. And it's doing it for
  15781. 10:08:02every single row. But that's not really
  15782. 10:08:05what we want it to show. What we want it
  15783. 10:08:07to show is the profit for each row. What
  15784. 10:08:10we want it to say is here's the price
  15785. 10:08:12for the rope, the production cost for
  15786. 10:08:13the rope, and then how many units we
  15787. 10:08:16actually sold. and then it'll calculate
  15788. 10:08:18that and give us the actual profit for
  15789. 10:08:20just that row. But we cannot do it by
  15790. 10:08:23just using this sum. What we need to do
  15791. 10:08:26is use something called sumx. So let's
  15792. 10:08:29add another column. Let's go back to
  15793. 10:08:31home. I'm going to say new column.
  15794. 10:08:34And now we're going to say
  15795. 10:08:37profit
  15796. 10:08:39oops underscorec column
  15797. 10:08:44sum x. And now we're going to use sum x
  15798. 10:08:50and hit tab. And we need to choose the
  15799. 10:08:52table that we want to put this in. So
  15800. 10:08:54we're going to say apocalypse sales
  15801. 10:08:56because that's table that we're looking
  15802. 10:08:57at right here. We're going to say comma.
  15803. 10:09:00And now we need to input an expression
  15804. 10:09:01which it says it returns the sum of an
  15805. 10:09:03expression evaluated for each row in a
  15806. 10:09:06table. Before when you're just using
  15807. 10:09:07sum, it's looking at all of these
  15808. 10:09:09combined. Now it's taking it row by row.
  15809. 10:09:12So what we're going to do is basically
  15810. 10:09:13input the same thing as we did before.
  15811. 10:09:15I'm going to copy. I'm going to paste
  15812. 10:09:16that. It's not going to be correct. I
  15813. 10:09:18need to get rid of these sums,
  15814. 10:09:20but it's basically the exact same
  15815. 10:09:22equation.
  15816. 10:09:23Give me just a second. And let's get rid
  15817. 10:09:26of this sum.
  15818. 10:09:28and let's see if this works. So, let's
  15819. 10:09:31click the check button.
  15820. 10:09:34And now this looks a lot better. So,
  15821. 10:09:37what this is now showing us is at a row
  15822. 10:09:39level, this nylon rope made us 51,000,
  15823. 10:09:42almost $52,000.
  15824. 10:09:44The waterproof matches made us $15,000.
  15825. 10:09:48And we can go down and look at each item
  15826. 10:09:50and see how much that actually made us
  15827. 10:09:53versus this profit column. And so that
  15828. 10:09:56is the biggest difference between sum
  15829. 10:09:58and sumx. Hopefully that made sense. I
  15830. 10:10:00know that sum and sumx and and the
  15831. 10:10:02difference between an aggregator
  15832. 10:10:04function and an iterator function can be
  15833. 10:10:05a little bit confusing, especially if
  15834. 10:10:07you've never done it before, but
  15835. 10:10:08hopefully that was a good example for
  15836. 10:10:10you to understand that concept. Now,
  15837. 10:10:11let's go back over here to apocalypse
  15838. 10:10:14sales. Right here, we have a date
  15839. 10:10:16purchase. Now, in the DAX function, we
  15840. 10:10:18have some ways that we can interact with
  15841. 10:10:20dates. And so, I want to take a look at
  15842. 10:10:22those really quickly. So, we're going to
  15843. 10:10:24go right up here and click on new
  15844. 10:10:25column.
  15845. 10:10:27And we're just going to leave that as
  15846. 10:10:29column, but what we're going to say is
  15847. 10:10:31day. So, there's a few different ones.
  15848. 10:10:33We have day, dates, YTD, next day,
  15849. 10:10:37previous day, and weekday. And they all
  15850. 10:10:40are pretty self-explanatory. If you
  15851. 10:10:42click on it, let's click on weekday. It
  15852. 10:10:45says it's going to return a number from
  15853. 10:10:461 to 7 identifying the day of the week
  15854. 10:10:49of a date. So, let's use this really
  15855. 10:10:52quickly. And so we're going to say date,
  15856. 10:10:55purchased,
  15857. 10:10:56and click tab, hit comma,
  15858. 10:11:00and it's going to give us a three
  15859. 10:11:02different options. Basically, it's a
  15860. 10:11:03one, a two, and a three. Um, right here,
  15861. 10:11:06if you hit this button, read more, you
  15862. 10:11:08can read more on it. This is going to
  15863. 10:11:10say Sunday's equal to 1, Saturday's
  15864. 10:11:11equal to 7. I like this one personally,
  15865. 10:11:13which is Monday equals 1. In my brain,
  15866. 10:11:16it just makes more sense. So, I'm going
  15867. 10:11:17to click on two. I'm going to close that
  15868. 10:11:20parenthesis and we're going to I guess
  15869. 10:11:22I'll say uh let's say day of week for
  15870. 10:11:26the column. Let's click that checkbox.
  15871. 10:11:30And now Saturdays are equal to sixes,
  15872. 10:11:33Mondays are equal to one. This allows us
  15873. 10:11:36to see which day of the week people are
  15874. 10:11:38buying the most products on or or which
  15875. 10:11:40day of the week is somebody submitting
  15876. 10:11:43their orders on. And so let's go over to
  15877. 10:11:45our report. Let's get rid of this. Just
  15878. 10:11:49going to move this. Oh jeez, I hate
  15879. 10:11:52moving stuff sometimes. All right,
  15880. 10:11:54really quickly, I want to show you the
  15881. 10:11:56difference between what we just did and
  15882. 10:11:57what we already have. So, we have this
  15883. 10:12:00um date purchased. And let's make that
  15884. 10:12:04into a bar graph.
  15885. 10:12:07And what we're going to be taking a look
  15886. 10:12:08at is actually the units sold. So, right
  15887. 10:12:12here we have this. And obviously for we
  15888. 10:12:15don't want 2022. We're going to get rid
  15889. 10:12:16of the year. We only have one quarter
  15890. 10:12:19right here. We can see January,
  15891. 10:12:21February, March. So we can tell that
  15892. 10:12:23January has the most sales or the most
  15893. 10:12:26units sold in that month. If we get rid
  15894. 10:12:28of that, we go down to day. We do have
  15895. 10:12:30some information, but we don't know what
  15896. 10:12:32day of the week it is. It could change
  15897. 10:12:34from month to month, and it's really
  15898. 10:12:37hard to tell exactly what if there's any
  15899. 10:12:39pattern there at all. That's where what
  15900. 10:12:41we just created comes in handy. So,
  15901. 10:12:43let's recreate this exact same thing,
  15902. 10:12:45but instead we're going to use day of
  15903. 10:12:47week. So, we're going to select day of
  15904. 10:12:48week in units sold. Let's drag that
  15905. 10:12:52down.
  15906. 10:12:54Move this over right here. And this day
  15907. 10:12:56of the week should be on the x axis.
  15908. 10:12:59And it's really easy now to see if
  15909. 10:13:02there's a pattern here. There's really
  15910. 10:13:03not, at least not for this fake data
  15911. 10:13:05that we have. Um, but just I I want
  15912. 10:13:08these uh data labels on really quickly.
  15913. 10:13:12Um it's not easy to see if there's any
  15914. 10:13:14pattern. Again, Monday has the most. So
  15915. 10:13:17maybe that that I mean it goes down a
  15916. 10:13:19little bit and then it picks back up. So
  15917. 10:13:20maybe middle of the week is our least uh
  15918. 10:13:22sales day. Our Wednesdays and Thursdays
  15919. 10:13:24are a little bit lower than the rest.
  15920. 10:13:26And the beginning and the end of the
  15921. 10:13:28week tend to be the highest. Again, not
  15922. 10:13:30a huge pattern, but you know, it's much
  15923. 10:13:32easier to see if there is a pattern from
  15924. 10:13:34week to week or what day of the week now
  15925. 10:13:36that we use this weekday function. And
  15926. 10:13:38so this can be really, really useful.
  15927. 10:13:41Let's go back here to our data. And now
  15928. 10:13:43we're going to look at our last DAX
  15929. 10:13:44function for this video. Let's go up
  15930. 10:13:46here and create a new column. And we're
  15931. 10:13:49going to be looking at something called
  15932. 10:13:51the if statement. Now, if you've ever
  15933. 10:13:52used Excel, I'm sure you have heard of
  15934. 10:13:54this. And you can do the exact same
  15935. 10:13:56thing here in PowerBI. And so we're
  15936. 10:13:58going to name this one order size. Order
  15937. 10:14:02size. And so all we're going to say is
  15938. 10:14:05if we're going to click on this one
  15939. 10:14:07right here. We need to perform our
  15940. 10:14:09logical test. And then we want to say if
  15941. 10:14:11it's true, what's our value? And if it's
  15942. 10:14:13false, what is our value? So what we're
  15943. 10:14:16going to be looking at is units sold. So
  15944. 10:14:18we're looking at order size. So we're
  15945. 10:14:20going to say if units sold is greater
  15946. 10:14:24than 25.
  15947. 10:14:26What's going to happen? If it is true,
  15948. 10:14:28if the order is larger than 25, you want
  15949. 10:14:30to say it's a big order.
  15950. 10:14:33And if it's not, we want to say it's a
  15951. 10:14:36small order.
  15952. 10:14:38Super simple. We'll close that
  15953. 10:14:40parenthesis. We'll click okay. And now,
  15954. 10:14:43really quickly, we're able to see if
  15955. 10:14:44this is a big order or a small order.
  15956. 10:14:47And so, that is all I have for you
  15957. 10:14:49today. There are a lot of other DAX
  15958. 10:14:51functions, but the ones that we looked
  15959. 10:14:52at today are ones that are very common,
  15960. 10:14:55ones that you'll see the most. And there
  15961. 10:14:57can be a lot of really complex and
  15962. 10:14:59intricate DAX functions that you can
  15963. 10:15:00create. And in our project at the end of
  15964. 10:15:03this series, I will be sure to include
  15965. 10:15:05some more complex DAX functions. But
  15966. 10:15:08hopefully this gave you a good
  15967. 10:15:09introduction into DAX so you know how to
  15968. 10:15:11use it a little bit better. Thank you
  15969. 10:15:13guys so much for watching. I really
  15970. 10:15:15appreciate it. If you like this video,
  15971. 10:15:16be sure to like and subscribe and check
  15972. 10:15:18out all of my other videos on everything
  15973. 10:15:20data analyst related. I will see you in
  15974. 10:15:22the next video.
  15975. 10:15:35What's going on everybody? Welcome back
  15976. 10:15:37to the PowerBI tutorial series. Today
  15977. 10:15:39we're going to be looking at how to
  15978. 10:15:40drill down in visualizations. [music]
  15979. 10:15:48So when I say drill down, I mean you're
  15980. 10:15:50basically adding another layer beneath
  15981. 10:15:52the top layer of the visualization. And
  15982. 10:15:54when somebody clicks or drills down into
  15983. 10:15:56that data, they can see more insights
  15984. 10:15:58and more information on the top level of
  15985. 10:16:01data. When you drill down, you can also
  15986. 10:16:03drill up. And I will show you how to do
  15987. 10:16:04that in this tutorial. So without
  15988. 10:16:06further ado, let's jump on my screen and
  15989. 10:16:07get started with the tutorial. All
  15990. 10:16:08right, so before we get started, I
  15991. 10:16:10wanted to remind you that you can find
  15992. 10:16:11the data that we're going to be working
  15993. 10:16:12with in this tutorial in the
  15994. 10:16:14description. You can go and download it
  15995. 10:16:15from my GitHub. Now, the two tables that
  15996. 10:16:18we're going to be looking at are
  15997. 10:16:18Apocalypse Sales and Purchase Tracker.
  15998. 10:16:21And if you've ever created any
  15999. 10:16:23visualizations, you've probably seen
  16000. 10:16:24something like this where you'll have
  16001. 10:16:26the store and the price. And this is the
  16002. 10:16:28the things that we actually bought. So
  16003. 10:16:30this is the total amount of apocalypse
  16004. 10:16:32prepping uh equipment that we bought.
  16005. 10:16:35And we'll put the store in this legend
  16006. 10:16:37right here. And you've probably seen
  16007. 10:16:39something like this. And if you're
  16008. 10:16:40anything like me, you're going to be in
  16009. 10:16:41a meeting and you're going to be
  16010. 10:16:42presenting this and some higher up is
  16011. 10:16:44going to be like, "Hey, Alex, that looks
  16012. 10:16:45great. But I want to, you know, see what
  16013. 10:16:48things we actually bought and targeted,
  16014. 10:16:49how much this cost. can you create a
  16015. 10:16:50visualization for that? And you're going
  16016. 10:16:52to be like, well, I could or I could use
  16017. 10:16:55drill down. And so, you could have done
  16018. 10:16:57this in the first place, uh, which you
  16019. 10:16:58should have. So, what we're going to do
  16020. 10:17:00is all we're going to do is we're going
  16021. 10:17:01to say we're going to say the product
  16022. 10:17:04right here. And these are going to be
  16023. 10:17:05the actual things. And we're going to
  16024. 10:17:06put it right under store. Now, you can't
  16025. 10:17:08see these things, right? But there is a
  16026. 10:17:11a hierarchy here. So, once we added
  16027. 10:17:14this, these options became available.
  16028. 10:17:16Let's take it out. And all those just
  16029. 10:17:18disappeared.
  16030. 10:17:19And then if we add it back right here,
  16031. 10:17:23they came back. And so you can do right
  16032. 10:17:26here, which is click to turn on drill
  16033. 10:17:28down. You can go to the next level in
  16034. 10:17:30the hierarchy, or you can even expand
  16035. 10:17:32all down one level in the hierarchy. So
  16036. 10:17:34let's look at each of those really
  16037. 10:17:35quickly. So let's click on this one.
  16038. 10:17:37It's just going to turn on drill down
  16039. 10:17:38mode. So now if I go and I click on
  16040. 10:17:41target, it's going to drill down into
  16041. 10:17:43these. And if we want to, I can then put
  16042. 10:17:46product under this legend.
  16043. 10:17:48And we can see all of those things. But
  16044. 10:17:50of course, if we go back up, it's going
  16045. 10:17:53to be all broken up into this clustered
  16046. 10:17:54column chart, which is more like um
  16047. 10:17:57this, which isn't exactly what we were
  16048. 10:18:00going for, but it works. Now, uh let me
  16049. 10:18:02get rid of this. I actually want store
  16050. 10:18:04in the legend. Now, if we turn that off
  16051. 10:18:06and we click, it doesn't do that
  16052. 10:18:08anymore. So, what it does now is it just
  16053. 10:18:11highlights Walmart. It highlights
  16054. 10:18:12Costco. It highlights Target. So, we're
  16055. 10:18:15going to keep that on. Uh but we can
  16056. 10:18:17also do something called going down the
  16057. 10:18:19next level of hierarchy. So let's click
  16058. 10:18:21on that. And so now this is going to go
  16059. 10:18:24down to the next level down to this
  16060. 10:18:26product level because that is the next
  16061. 10:18:27level. And now it's going to show us
  16062. 10:18:29each of those things but it's going to
  16063. 10:18:30have it broken out by the store. And so
  16064. 10:18:33it's a completely different
  16065. 10:18:34visualization but all within the same
  16066. 10:18:37realm of the data that we're looking at
  16067. 10:18:38and what we actually care about. So
  16068. 10:18:40let's go back up in the hierarchy and
  16069. 10:18:43then let's use this one right here which
  16070. 10:18:44is expand all down one level in the
  16071. 10:18:46hierarchy. And so this one is again
  16072. 10:18:47extremely similar except it just
  16073. 10:18:50visualizes it differently. And now what
  16074. 10:18:51it's doing is Walmart rice, Target dried
  16075. 10:18:54beans, Costco rice. So instead of having
  16076. 10:18:56it all uh like this one where it's
  16077. 10:18:59stacked on top of each other, it's
  16078. 10:19:01breaking it down individually. So this
  16079. 10:19:04one column would become three separate
  16080. 10:19:06columns. Now I'm going to minimize this
  16081. 10:19:08right here. Uh, I'm actually going to go
  16082. 10:19:09back up in the hierarchy just for visual
  16083. 10:19:12purposes. Now, I'm going to show you one
  16084. 10:19:14more example. We're going to use this
  16085. 10:19:16Apocalypse sales up here. And this is
  16086. 10:19:18one that I actually use all the time.
  16087. 10:19:20So, the one you've seen, you know,
  16088. 10:19:22you'll get stuff like that, especially
  16089. 10:19:23if you're working with like sales and
  16090. 10:19:25stuff, but I work in operations, right?
  16091. 10:19:27So, I have a lot of order IDs, product
  16092. 10:19:31IDs, stuff like that. Now, this one,
  16093. 10:19:33this one genuinely I use quite often.
  16094. 10:19:36I'll have a customer. And let's make it
  16095. 10:19:38we'll just go like this. We have a
  16096. 10:19:40customer and we have units sold. And
  16097. 10:19:43let's use the customer as the legend. So
  16098. 10:19:47let's make this one quite a bit larger.
  16099. 10:19:51And I'll have something like this. And
  16100. 10:19:53they'll say, okay, well, we want to see
  16101. 10:19:55the order IDs that go with it because we
  16102. 10:19:58want to know what orders are actually
  16103. 10:20:00happening for each of these people.
  16104. 10:20:01Obviously, I'm not using this exact
  16105. 10:20:03data, but very, very, very similar. And
  16106. 10:20:06all you have to do is take these order
  16107. 10:20:08IDs and slide it right under here under
  16108. 10:20:10customer. And this visualization right
  16109. 10:20:13here is something I've done a thousand
  16110. 10:20:15times because what happens is is someone
  16111. 10:20:18some stakeholder in our company is
  16112. 10:20:20saying, "Hey, Alex, we want this and we
  16113. 10:20:21want to know we want to drill down on
  16114. 10:20:23this IP address. We want to drill down
  16115. 10:20:26on this certain database. We want to
  16116. 10:20:28drill down on something and we want to
  16117. 10:20:29see the order IDs within them." So then
  16118. 10:20:32all you do is you turn on drill mode or
  16119. 10:20:34drill down mode. you'll click on it and
  16120. 10:20:36you can see every single order ID that's
  16121. 10:20:38in there and then they can go and look
  16122. 10:20:40those up in their system and resolve
  16123. 10:20:41them or whatever they're trying to do
  16124. 10:20:43with it and it helps a ton and it's very
  16125. 10:20:46very useful. This one is extremely
  16126. 10:20:47applicable and that's really all drill
  16127. 10:20:49down is again you have these different
  16128. 10:20:51hierarchies as well um but for different
  16129. 10:20:53things it's not as useful as you can see
  16130. 10:20:56we also have this hierarchy which again
  16131. 10:20:58is not as useful. So, it just depends on
  16132. 10:21:01the data that you're using and how you
  16133. 10:21:03want to use this drill down effect. But
  16134. 10:21:05I promise you that drill down is used
  16135. 10:21:07all the time, especially when you're
  16136. 10:21:09giving presentations where people want
  16137. 10:21:11to know more information than just the
  16138. 10:21:13the visualization that you're
  16139. 10:21:14presenting. So, I hope that this has
  16140. 10:21:16been helpful. I hope that you understand
  16141. 10:21:17drill down a little bit better. If you
  16142. 10:21:19like this video, be sure to like and
  16143. 10:21:20subscribe and check out all my other
  16144. 10:21:22videos on PowerBI. Thank you and I'll
  16145. 10:21:24see you in the next video.
  16146. 10:21:26[music]
  16147. 10:21:37What's going on everybody? Welcome back
  16148. 10:21:39to the PowerBI tutorial series. Today
  16149. 10:21:41we're going to be taking a look at
  16150. 10:21:42conditional formatting.
  16151. 10:21:48Now, conditional formatting may sound
  16152. 10:21:50familiar because we looked at it in the
  16153. 10:21:52Excel series, and it's very similar how
  16154. 10:21:54you use it in Excel versus how you use
  16155. 10:21:56it in PowerBI. Conditional formatting
  16156. 10:21:58allows you to take a table or a matrix
  16157. 10:22:00within PowerBI and use those cells to
  16158. 10:22:03color code them and create gradients and
  16159. 10:22:04different visualizations within the
  16160. 10:22:06actual table or matrix. I'm excited to
  16161. 10:22:08start this one. So, let's jump over my
  16162. 10:22:10screen and get started with the
  16163. 10:22:11tutorial. All right, so before we get
  16164. 10:22:12started, if you want to use the data
  16165. 10:22:13that we're using in this video, you can
  16166. 10:22:15find it in the description on my GitHub.
  16167. 10:22:17Now, conditional formatting is super
  16168. 10:22:18simple, and you've most likely used it
  16169. 10:22:20in Excel before, but you can also use it
  16170. 10:22:22in PowerBI. And let me show you how to
  16171. 10:22:24do that. So, the first thing we're going
  16172. 10:22:25to do is come over to our Apocalypse
  16173. 10:22:27store, and we're going to pull up our
  16174. 10:22:30product name as well as the price. And
  16175. 10:22:34what we can do is come over here, and
  16176. 10:22:36we're going to go to price. And it has
  16177. 10:22:38to be under the columns. So, you can't
  16178. 10:22:40come over here and do this. We're going
  16179. 10:22:42to come right over here to price and
  16180. 10:22:43we're going to rightclick and let's go
  16181. 10:22:45to conditional formatting and we have
  16182. 10:22:47background color, font color, icons, and
  16183. 10:22:49web URL. Let's take a look at background
  16184. 10:22:52color first. This is most likely the one
  16185. 10:22:53that we'll look at the most. So, we're
  16186. 10:22:55going to get this popup and I'm going to
  16187. 10:22:57slide this over. Now, there's a lot of
  16188. 10:23:00different things we can customize in
  16189. 10:23:01here. And the first thing I want to take
  16190. 10:23:03a look at is format style. We have the
  16191. 10:23:04gradient and what it's going to say is
  16192. 10:23:06the lowest value will be this color,
  16193. 10:23:08highest value will be this color. It'll
  16194. 10:23:10give us this gradient color scale. And
  16195. 10:23:12so we'll use that in just a little bit.
  16196. 10:23:14But we can also create rules kind of
  16197. 10:23:16like an if statement. And if it is
  16198. 10:23:19between this range and this range, we'll
  16199. 10:23:20give it a color. And if it's between a
  16200. 10:23:22different range and a different range,
  16201. 10:23:23we'll give it a different color. So
  16202. 10:23:25we'll also try that one. And then we
  16203. 10:23:27have this field value. Uh and this one
  16204. 10:23:29is one that uh honestly I don't use that
  16205. 10:23:31much. I've used it maybe once. And what
  16206. 10:23:34you can do is select a text field like
  16207. 10:23:36customer and you can do some
  16208. 10:23:38summarizations on the first and last.
  16209. 10:23:40And that is it. So what we're going to
  16210. 10:23:42do is we're going to look at gradient
  16211. 10:23:44specifically for not the customer but
  16212. 10:23:47we're going to go back to the apocalypse
  16213. 10:23:49store and we're going to do it on the
  16214. 10:23:51price.
  16215. 10:23:52Now what I'm going to do is keep it as
  16216. 10:23:54the count because this is what the
  16217. 10:23:55default is and we're going to go back
  16218. 10:23:57and fix it later. But what we want our
  16219. 10:23:59lowest value to be is this bright green
  16220. 10:24:02showing that this it's it's a cheap
  16221. 10:24:03product that's easy to purchase. The
  16222. 10:24:06highv value ones are going to be just
  16223. 10:24:08this shade of red, more expensive. And
  16224. 10:24:10we'll do it on the count. Now remember
  16225. 10:24:12the count is on each of these and we're
  16226. 10:24:14not doing a count of how many are sold.
  16227. 10:24:16We're doing a count of each product. So
  16228. 10:24:17it's just one per row. So it all should
  16229. 10:24:20be the same color. Let's take a look. So
  16230. 10:24:22it is all the same color. But what we
  16231. 10:24:24really want to show is the actual price,
  16232. 10:24:27not just the count of the price. So
  16233. 10:24:29let's go back to conditional formatting.
  16234. 10:24:31We're going to click the background
  16235. 10:24:32color again. And this time we're going
  16236. 10:24:34to change the summarization.
  16237. 10:24:36Now you can do sum, you can do average,
  16238. 10:24:39minimum, maximum. It really doesn't
  16239. 10:24:41matter for this example. The number is
  16240. 10:24:43the same regardless of really which one
  16241. 10:24:45we choose. So we can just choose the
  16242. 10:24:47minimum. And it's going to choose the
  16243. 10:24:48minimum of each row, which is the price.
  16244. 10:24:51So, we're just going to select minimum
  16245. 10:24:52for this example. We'll select okay, and
  16246. 10:24:55it should correct it accordingly, which
  16247. 10:24:57means the bright green is the lowest,
  16248. 10:24:58and it goes all the way up to the
  16249. 10:25:00highest, which is the red. Now, let's go
  16250. 10:25:02over here to apocalypse sales. We'll add
  16251. 10:25:05in the units sold,
  16252. 10:25:07and let's move that out a little bit.
  16253. 10:25:11And I'm doing that on purpose because
  16254. 10:25:12we're about to look at something within
  16255. 10:25:14the conditional formatting. So, let's go
  16256. 10:25:16to units sold, and we'll look at the
  16257. 10:25:17conditional formatting for this one.
  16258. 10:25:19Now, if you noticed, we now have a new
  16259. 10:25:22one on here called data bars. Now, we're
  16260. 10:25:25able to see data bars on units sold and
  16261. 10:25:27not price because units sold is
  16262. 10:25:30something like a sum, an average,
  16263. 10:25:32something that's aggregated. But let's
  16264. 10:25:33take a look at data bars cuz I want to
  16265. 10:25:35show you how to use this and then we'll
  16266. 10:25:36go back to the background color. So, for
  16267. 10:25:39data bars, we are going to taking a look
  16268. 10:25:41at the lowest or the highest value.
  16269. 10:25:44Again, we're going to go from bright
  16270. 10:25:46green all the way to
  16271. 10:25:50this exact red. It's going to be from
  16272. 10:25:52left to right. And what it's going to
  16273. 10:25:54show you is if it is a positive number,
  16274. 10:25:55which all of these are, is going to be a
  16275. 10:25:57green bar basically representing the
  16276. 10:25:59number that you see in here along this
  16277. 10:26:01line. So, let's click okay.
  16278. 10:26:05And we're going to be able to see the
  16279. 10:26:07highest numbers. And let's scooch this
  16280. 10:26:09over quite a bit so you can kind of get
  16281. 10:26:10a better understanding. and we're going
  16282. 10:26:12to do it from highest to lowest. So, we
  16283. 10:26:15sold the most multi-tool survival knives
  16284. 10:26:19at 477. And so, this entire bar, this
  16285. 10:26:22row is entirely filled up or almost all
  16286. 10:26:24the way filled up. While as it gets
  16287. 10:26:26lower and as we sell only 182 solar
  16288. 10:26:30battery flashlights, the bar is going to
  16289. 10:26:32represent that and show that. Now, I'm
  16290. 10:26:34about to completely mess up this
  16291. 10:26:35visualization on purpose because it's
  16292. 10:26:37about to get very messy to show you that
  16293. 10:26:39you can do a little bit too much. Uh, it
  16294. 10:26:41is possible. What we're going to do is
  16295. 10:26:43we're going to go right over here to
  16296. 10:26:45this background color units sold and
  16297. 10:26:46instead of gradient, let's look at
  16298. 10:26:48rules. Now, with the price, we just did
  16299. 10:26:51a gradient scale, but we can do
  16300. 10:26:54basically groups of these and say if a
  16301. 10:26:56number is greater to or equal than this
  16302. 10:26:58number, then it's going to be a certain
  16303. 10:27:00color. And then if it's in a different
  16304. 10:27:01range, we can give it a different color.
  16305. 10:27:03So, we're going to say if it's greater
  16306. 10:27:04than or equal to zero, and we're going
  16307. 10:27:07to say number, not percent. And if it's
  16308. 10:27:10less than 266, because we have got 265
  16309. 10:27:14right here, let's make it a nice uh like
  16310. 10:27:17gold, a beautiful, lovely mustard gold.
  16311. 10:27:20Just just great. Now, we're going to say
  16312. 10:27:22if it's greater than or equal to, we'll
  16313. 10:27:25do 266 because this says less than 266.
  16314. 10:27:28So, it should be greater than or equal
  16315. 10:27:30to 266 number. And if it is less than
  16316. 10:27:34we'll say 500.
  16317. 10:27:36Now, we want to do this one and we'll
  16318. 10:27:39give it uh let's do like a peach. And
  16319. 10:27:41we'll click okay. And now we have
  16320. 10:27:43another conditional formatting on top of
  16321. 10:27:45that that can give us more information.
  16322. 10:27:48Now, again, you should not do this. It's
  16323. 10:27:51just too many. Now, let's go one step
  16324. 10:27:53further and make it even more ridiculous
  16325. 10:27:54and show you one more thing before I
  16326. 10:27:56show you how you may actually want to
  16327. 10:27:58use this. Uh let's go back to unit sold.
  16328. 10:28:01We're going to rightclick, go to
  16329. 10:28:02conditional formatting, and you can do
  16330. 10:28:04something called icons. Um, font color
  16331. 10:28:07is the exact same thing as background
  16332. 10:28:08color except it changes the the font.
  16333. 10:28:10And so I'm not really going to look into
  16334. 10:28:11that one. Icons are very simple,
  16335. 10:28:14extremely similar to Excel and how
  16336. 10:28:16you've seen them. And the rules that you
  16337. 10:28:18can apply to them are basically the same
  16338. 10:28:21as if you're doing like a gradient. And
  16339. 10:28:23it's these if statements that we saw
  16340. 10:28:24before. Now, it auto gives us this right
  16341. 10:28:28here, which basically says 0 to 33%, 33
  16342. 10:28:31to 67, 67 to 100. If it's in the bottom
  16343. 10:28:34third percent, it gives us this red, the
  16344. 10:28:36middle is yellow, and the top is green.
  16345. 10:28:38So, we can go through and change all of
  16346. 10:28:40this. But honestly, this looks pretty
  16347. 10:28:42good. So, let's click on it. And so, the
  16348. 10:28:45ones that are our least sellers are
  16349. 10:28:46these red ones right here. And the top
  16350. 10:28:49sellers are up here. Now, this is just
  16351. 10:28:51based on units sold. And this looks
  16352. 10:28:53absolutely terrible. So, let's kind of
  16353. 10:28:55take this exact information, but make it
  16354. 10:28:58a little bit better. So, we're going to
  16355. 10:29:00create a new visualization or at least a
  16356. 10:29:02new table. So, let's click on product
  16357. 10:29:04name and we'll take the price, units
  16358. 10:29:08sold, and revenue. And what I think
  16359. 10:29:11makes the most sense for looking at
  16360. 10:29:12revenue is these data bars right here.
  16361. 10:29:14But there's only one problem. I can't do
  16362. 10:29:17that because it's not summarized like
  16363. 10:29:20unit sold was. But what I can do is to
  16364. 10:29:23get that those data bars is I can come
  16365. 10:29:25right down here instead of saying don't
  16366. 10:29:26summarize, I can summarize it. I can
  16367. 10:29:29just click the sum. So it now is
  16368. 10:29:32summarized. It's the exact same number.
  16369. 10:29:34But if I right click on here as sum of
  16370. 10:29:37revenue, I go to conditional formatting.
  16371. 10:29:39I can now use those data bars. And so
  16372. 10:29:41we're going to use those data bars. And
  16373. 10:29:43we're going to say for the lowest value
  16374. 10:29:44and the highest value. And let's just
  16375. 10:29:47make it a nice
  16376. 10:29:49a darker green. I don't want it to Well,
  16377. 10:29:51that's that's hideous. Let's make it
  16378. 10:29:53this color right here. A nice dark
  16379. 10:29:55green. And there's no negatives, so it
  16380. 10:29:56doesn't really matter. We're going to go
  16381. 10:29:58left to right. And you can show the bar
  16382. 10:30:00only, but we're going to keep it because
  16383. 10:30:02I want to see it. And we're going to go
  16384. 10:30:04just like this. We're going to order.
  16385. 10:30:07And this is pretty telling. Um,
  16386. 10:30:10honestly, I did not think the
  16387. 10:30:12weatherproof jackets were performing so
  16388. 10:30:14well, but I mean, they are by far our
  16389. 10:30:16number one seller. So, you know, our
  16390. 10:30:18weatherproof jackets, multi-tool,
  16391. 10:30:20survival knives, and the nylon rope are
  16392. 10:30:22perform outperforming all of our other
  16393. 10:30:25products. So, those might be the ones
  16394. 10:30:26that I focus on the most. While duct
  16395. 10:30:29tape, the N95 masks and waterproof
  16396. 10:30:31matches, I mean, those are those are
  16397. 10:30:32garbage. So, I might be looking to
  16398. 10:30:34replace those in the near future with
  16399. 10:30:35some other items that might sell a
  16400. 10:30:37little bit better. So, that's how you
  16401. 10:30:38use conditional formatting, and it's
  16402. 10:30:40actually pretty useful. There are a lot
  16403. 10:30:41of times where I've done something like
  16404. 10:30:42this in an actual visualization for
  16405. 10:30:44work, and it looks something like this.
  16406. 10:30:47It just depends on what you're
  16407. 10:30:48visualizing, but this is very much a
  16408. 10:30:51simple thing that you can do to just add
  16409. 10:30:53a little bit more information and and
  16410. 10:30:55actual visuals to this little chart or
  16411. 10:30:58table that you're going to create.
  16412. 10:30:59Sometimes it's just better to have these
  16413. 10:31:01simple visualizations on this table
  16414. 10:31:03rather than just having the numbers
  16415. 10:31:04themselves. Makes it a little bit more
  16416. 10:31:06easy to read and understand. So again, I
  16417. 10:31:09hope that this was helpful. Thank you
  16418. 10:31:10guys so much for watching. I really
  16419. 10:31:12appreciate it. If you like this video,
  16420. 10:31:13be sure to like and subscribe and check
  16421. 10:31:15out all my other videos on PowerBI. And
  16422. 10:31:17I'll see you in the next video.
  16423. 10:31:23[music]
  16424. 10:31:30What's going on everybody? Welcome back
  16425. 10:31:32to the PowerBI tutorial series. Today
  16426. 10:31:34we're going to be taking a look at bins
  16427. 10:31:35and lists.
  16428. 10:31:42Now, bins and lists are really useful
  16429. 10:31:44because they allow you to group things
  16430. 10:31:45together to analyze and visualize them
  16431. 10:31:47easier. So, in this tutorial, I'll show
  16432. 10:31:49you how to create your bins and lists
  16433. 10:31:51and then we'll create some
  16434. 10:31:52visualizations to show you how it can be
  16435. 10:31:53helpful. So, without further ado, let's
  16436. 10:31:55jump on my screen and get started with
  16437. 10:31:56the tutorial. All right, so before we
  16438. 10:31:58get started, I wanted to let you know
  16439. 10:31:59you can go and download the data that
  16440. 10:32:01we're going to be using in this tutorial
  16441. 10:32:03in the description below. It is on my
  16442. 10:32:05GitHub. So, we are going to be looking
  16443. 10:32:07at bins and lists today. Um, and for
  16444. 10:32:10this, we're going to be going over here
  16445. 10:32:12to this apocalypse sales. Uh, and let's
  16446. 10:32:15open up our data right over here. And we
  16447. 10:32:18want to look at apocalypse sales really
  16448. 10:32:20quickly. I feel like more people would
  16449. 10:32:22know what a bin is. So, we'll kind of
  16450. 10:32:23start with a list. Just go a little bit
  16451. 10:32:24backwards than we normally would. Uh,
  16452. 10:32:26I'm going to use this customer or we're
  16453. 10:32:28going to use this customer column right
  16454. 10:32:30here for a list really quickly. And you
  16455. 10:32:32can do that in two ways. You can come up
  16456. 10:32:33here and you can rightclick on the
  16457. 10:32:35customer and go to new group. Or you can
  16458. 10:32:38come over here under this uh the field
  16459. 10:32:40section on the far right and go to
  16460. 10:32:43customer, rightclick and click new
  16461. 10:32:45group. So let's click on that now.
  16462. 10:32:48And right now is only giving us the list
  16463. 10:32:52type. It's not giving us bins because
  16464. 10:32:54bins have to be numeric. So we really
  16465. 10:32:56can't do that at the moment. Um, so
  16466. 10:32:58we're going to call this just customer
  16467. 10:32:59groups just or or we'll actually call it
  16468. 10:33:02list just so it's easier to recognize
  16469. 10:33:04when we create it. And so all we're
  16470. 10:33:05going to do is we're going to basically
  16471. 10:33:07group these, but it's going to be called
  16472. 10:33:10a list. And so what we're going to do is
  16473. 10:33:12we're going to select and we're going to
  16474. 10:33:14select and we're going to say group and
  16475. 10:33:17click on this group button. And then it
  16476. 10:33:18creates [clears throat] this Alex the
  16477. 10:33:19analyst apocalypse preppers and uh this
  16478. 10:33:22prep for anything prepping store. So
  16479. 10:33:24that it kind of named it for us. But if
  16480. 10:33:27we double click on it, then we can
  16481. 10:33:30rename this and we can call this the
  16482. 10:33:33best prepping stores.
  16483. 10:33:37And then we have these last two and we
  16484. 10:33:40can we can click on one and then click
  16485. 10:33:43control and click on the other one. So
  16486. 10:33:45we get both of them. And then we can
  16487. 10:33:47click group and we can call this and
  16488. 10:33:50we'll double click and we'll call this
  16489. 10:33:52the worst
  16490. 10:33:54prepping stores.
  16491. 10:33:56Um, and then that's it. And that's all
  16492. 10:34:00we have to do. And what we're then going
  16493. 10:34:02to do, and if you want to undo this and
  16494. 10:34:04you want to switch it up and do
  16495. 10:34:05whatever, you can click ungroup, but
  16496. 10:34:06we're not going to do that. We're going
  16497. 10:34:07to click okay.
  16498. 10:34:09And here is the column that it created.
  16499. 10:34:12And it basically tells us what list we
  16500. 10:34:14put it in. If it's Uncle Joe's prep
  16501. 10:34:15shop, that's in the worst prepping
  16502. 10:34:17stores list. And if it's the Alex the
  16503. 10:34:19Analyst Apocalypse preppers, that is in
  16504. 10:34:21the best prepping stores. So, it's kind
  16505. 10:34:23of like an if statement. You could even
  16506. 10:34:25create a calculated column, do it on
  16507. 10:34:28this customer, create an if statement.
  16508. 10:34:30This is just a lot faster and a lot
  16509. 10:34:32easier than doing that, but it basically
  16510. 10:34:34would do the exact same thing. Now, you
  16511. 10:34:36can use lists as well on things like
  16512. 10:34:39numeric. So let's say we have order ID
  16513. 10:34:43and we'll go to new group and it's going
  16514. 10:34:45to auto go to bin because typically
  16515. 10:34:47that's what you'll use but you can do
  16516. 10:34:49list as well. And let's say you know we
  16517. 10:34:52want to say we want to call these like
  16518. 10:34:55we'll group these and call these the
  16519. 10:34:57first
  16520. 10:34:59um we'll call this the first customers
  16521. 10:35:01or the first orders because we're
  16522. 10:35:03looking at order ids. Look at the first
  16523. 10:35:04orders. And then we will go back here.
  16524. 10:35:08We're going on the left side. We're
  16525. 10:35:10going to click. Oops. We're going to go
  16526. 10:35:11back to the top. We're going to hit
  16527. 10:35:13shift group all of these. And we'll say
  16528. 10:35:17the latest orders.
  16529. 10:35:20And you absolutely can do this. Um,
  16530. 10:35:22again, this is kind of like an if
  16531. 10:35:23statement, right? So, you're saying if
  16532. 10:35:25it falls between this range and this
  16533. 10:35:27range, then it's called the first
  16534. 10:35:28orders. And if it's between this range
  16535. 10:35:30and this other range, it's the latest
  16536. 10:35:32orders. Um, again, it's just a much
  16537. 10:35:35simpler version of an if statement. And
  16538. 10:35:37so, you don't have to write it all out.
  16539. 10:35:39you can just have this user interface
  16540. 10:35:40kind of do it for you. Uh, and and it's
  16541. 10:35:43really really useful. So, now let's talk
  16542. 10:35:44about bins. And by far the easiest way
  16543. 10:35:46to demonstrate this, and I'll show you
  16544. 10:35:48one other way. U, but by far the easiest
  16545. 10:35:50way to show this is by using age. And
  16546. 10:35:53so, uh, for absolutely no reason
  16547. 10:35:55whatsoever, these customer IDs, uh, who
  16548. 10:35:58are right here in this customer
  16549. 10:35:59information, they decided to give us
  16550. 10:36:01some of their buyer information who are
  16551. 10:36:03actually buying their products on their
  16552. 10:36:05website or in their store. they just
  16553. 10:36:06decided to give it to us as well as some
  16554. 10:36:08uh simple demographic information. I I
  16555. 10:36:11don't know why. But what we're going to
  16556. 10:36:12use bins for is grouping these age
  16557. 10:36:16brackets. So, you know, you might be
  16558. 10:36:18interested and say, well, I want to know
  16559. 10:36:21if my core population who are buying my
  16560. 10:36:23products are within a certain range. And
  16561. 10:36:25you don't want to look at every single
  16562. 10:36:26age because then it just, you know, in
  16563. 10:36:29your visualizations, it's not going to
  16564. 10:36:30look right. You want to kind of group
  16565. 10:36:32them, make it easier to visualize. So,
  16566. 10:36:34what we're going to do is we're going to
  16567. 10:36:35go through here and we're going to
  16568. 10:36:36basically go by 10. So, 10, 20, 30, 40,
  16569. 10:36:4050, 60, and see what age bracket these
  16570. 10:36:42people fall in. So, we're going to go to
  16571. 10:36:44age. We're going to rightclick and we're
  16572. 10:36:45going to say new group. And we're going
  16573. 10:36:47to go to bin and we'll leave it as a
  16574. 10:36:49default age bins. Um, and you can do two
  16575. 10:36:52things. You can do the size of the bins,
  16576. 10:36:54which splits it uh uh which splits it by
  16577. 10:36:57this number right here. Or you can go
  16578. 10:36:59based on the number of bins. So, if you
  16579. 10:37:02only want to do five different bins,
  16580. 10:37:04it'll calculate that for you and it'll
  16581. 10:37:06say, "Okay, if you only want five bins,
  16582. 10:37:09you're going to have to do it at 12.2.
  16583. 10:37:11If you want 10 bins, it could be 6.1."
  16584. 10:37:15But it is completely up to you on how
  16585. 10:37:17you want to do that. Um, you can do the
  16586. 10:37:19size and we'll just say every 10, which
  16587. 10:37:22is what we're going to do. Or you can go
  16588. 10:37:23through and then you can create, you
  16589. 10:37:25know, the how many bins you actually
  16590. 10:37:26want. So, let's go ahead and click okay.
  16591. 10:37:30and it's going to create those bins for
  16592. 10:37:32us. So, if somebody is 78, they're going
  16593. 10:37:34to be in the 70s bin. If somebody is 41,
  16594. 10:37:37they'll be in the 40 bin. If somebody is
  16595. 10:37:4029, they'll be in the 20 bin. And so on
  16596. 10:37:42and so forth. So, when we go to
  16597. 10:37:44visualize this, we don't have, you know,
  16598. 10:37:4671, 72, 73, 74. Have a lot more things
  16599. 10:37:50on our visualization. It'll just be the
  16600. 10:37:5270 or it'll just be the 20. Now, we can
  16601. 10:37:54also use bins on dates as well. So,
  16602. 10:37:57let's go back to apocalypse sales. we
  16603. 10:37:59have this date purchased. So we can
  16604. 10:38:01create a bin for this as well. So let's
  16605. 10:38:03go to date purchased. Let's go new
  16606. 10:38:05group. Now you can also create a list
  16607. 10:38:08and that's totally fine if you would
  16608. 10:38:10like to do that. Um and it would look
  16609. 10:38:12kind of like this where you can go
  16610. 10:38:14through and you can select it and you
  16611. 10:38:16can say okay this group all these dates
  16612. 10:38:20you can group those and say this is
  16613. 10:38:21going to be January. Uh and you can do
  16614. 10:38:25that and that's totally okay. Um, but
  16615. 10:38:27for this one, we're going to do bins. I
  16616. 10:38:28think it's a little bit easier to do
  16617. 10:38:30bins because what we can do is go right
  16618. 10:38:32here and we can specify if we want
  16619. 10:38:34seconds, minutes, hours, days, months,
  16620. 10:38:36or years. And so, um, for the data that
  16621. 10:38:38we have, it goes January, February, and
  16622. 10:38:41March. So, we're going to do months, and
  16623. 10:38:43we're going to say the bin size is going
  16624. 10:38:45to be one month. So, each month should
  16625. 10:38:47have its own bin. So, it'll be three
  16626. 10:38:48bins total. So, we're going to select
  16627. 10:38:50okay.
  16628. 10:38:52And as you can see on this right side,
  16629. 10:38:54we have January of 2022 and that
  16630. 10:38:56correlates to the January over here.
  16631. 10:38:58Then it goes down to February and then
  16632. 10:39:01it goes down to March. And then when we
  16633. 10:39:04visualize this uh we don't have to do
  16634. 10:39:06this the hierarchy stuff that we do in
  16635. 10:39:08here where we filter it down down to
  16636. 10:39:10months. We can just use this right here
  16637. 10:39:12and that will be our months column. So
  16638. 10:39:14now let's go over to our visualizations
  16639. 10:39:15and we'll see how this looks really
  16640. 10:39:17quickly. We're not going to look at all
  16641. 10:39:18of them but we will take a look at a few
  16642. 10:39:20of them. So the first one that we can
  16643. 10:39:22look at is age. So let's look at the
  16644. 10:39:24buyer ID and then we'll do age as well.
  16645. 10:39:28And so let's spread this out.
  16646. 10:39:32And we can see our distribution of our
  16647. 10:39:34buyers. So it looks like we have very
  16648. 10:39:36few uh who are in the 10 range, thank
  16649. 10:39:39goodness. And we can even put the age
  16650. 10:39:41right under here under the age bins. And
  16651. 10:39:44we have this now we kind of have this
  16652. 10:39:46drill down. And so if we go right here
  16653. 10:39:48and we drill down right there, this will
  16654. 10:39:51actually give us the breakdown. So this
  16655. 10:39:52is what it would have kind of looked
  16656. 10:39:54like, our visualization would have
  16657. 10:39:56looked like if we had just kept it the
  16658. 10:39:57age cuz now we're drilling down into the
  16659. 10:39:59age. And so it looks like we have one
  16660. 10:40:0118-year-old and maybe a 20-year-old as
  16661. 10:40:04well. Um let's go back up. Yeah. So it
  16662. 10:40:07looks like we only have one buyer ID.
  16663. 10:40:08Yeah. So there's only one 18-year-old.
  16664. 10:40:10so of legal age to start buying, you
  16665. 10:40:12know, all these prepping equipment and
  16666. 10:40:14probably uh buying online and stuff like
  16667. 10:40:16that, which makes sense, right? So, uh
  16668. 10:40:19this gives you kind of a quick breakdown
  16669. 10:40:20in the bins rather than um doing it the
  16670. 10:40:23alternative way. So, now let's take a
  16671. 10:40:25look at the customer list as well as the
  16672. 10:40:28units sold. And it looks like the best
  16673. 10:40:31prepping store uh is actually performing
  16674. 10:40:33much worse, surprisingly uh than the
  16675. 10:40:36worst prepping store. And so I hope this
  16676. 10:40:38gave you a really good idea of how to
  16677. 10:40:40use bins and lists within PowerBI. Thank
  16678. 10:40:42you so much for watching. If you like
  16679. 10:40:43this video, be sure to like and
  16680. 10:40:45subscribe and check out all my other
  16681. 10:40:46videos on PowerBI. I'll see you in the
  16682. 10:40:48next video.
  16683. 10:40:50[music]
  16684. 10:40:57[music]
  16685. 10:41:01What's going on everybody? Welcome back
  16686. 10:41:02to the PowerBI tutorial series. Today
  16687. 10:41:05we're going to be taking a look at all
  16688. 10:41:06types of visualizations.
  16689. 10:41:13Now, when you're working in PowerBI,
  16690. 10:41:15there are a lot of different options to
  16691. 10:41:17create visualizations, and you may not
  16692. 10:41:19always be sure which one to use. And so,
  16693. 10:41:21that's what this video is for. I'm going
  16694. 10:41:22to walk you through a lot of the
  16695. 10:41:24visualizations that I like and I use a
  16696. 10:41:26lot as well as kind of point out some of
  16697. 10:41:28the ones that I don't like as much so
  16698. 10:41:30that you get kind of a feel for the ones
  16699. 10:41:32that I think are really popular and that
  16700. 10:41:34are used the most. So without further
  16701. 10:41:35ado, let's jump into PowerBI and start
  16702. 10:41:37taking a look. All right, before we jump
  16703. 10:41:38into it, there is a link in the
  16704. 10:41:40description where you can get the data
  16705. 10:41:41that we're going to be using for these
  16706. 10:41:42visualizations if you want to practice
  16707. 10:41:44them yourself. Before we actually get
  16708. 10:41:47into it, we do need to combine this. And
  16709. 10:41:50if you download that Excel and you see
  16710. 10:41:51this, you'll have to do the same thing.
  16711. 10:41:54All we have to say is that this product
  16712. 10:41:56ID is the same as this product ID
  16713. 10:41:58purchased. And now we are good to go. Do
  16714. 10:42:02one to many. And it's okay if it's one
  16715. 10:42:03way. So right over here under this
  16716. 10:42:05visualizations tab, there are lots of
  16717. 10:42:07different options and it can be a little
  16718. 10:42:09bit overwhelming. You don't really know
  16719. 10:42:11which one to choose. There are some in
  16720. 10:42:13here that I have almost never used for
  16721. 10:42:15my job ever. So, I'll point those out as
  16722. 10:42:17we go through, but the main focus is
  16723. 10:42:19going to be focusing on the ones that I
  16724. 10:42:21do use or that I have used and showing
  16725. 10:42:23you how to actually create that
  16726. 10:42:24visualization, maybe spice it up just a
  16727. 10:42:26little bit. But, we have a lot of them
  16728. 10:42:28to go through. So, let's jump right into
  16729. 10:42:31it. And the very first one that we're
  16730. 10:42:32going to start with, probably the
  16731. 10:42:33easiest one and the one that you'll
  16732. 10:42:34recognize the most is a stacked bar
  16733. 10:42:37chart. And what we're going to do is go
  16734. 10:42:38ahead right over here to the product
  16735. 10:42:41name. And we want this unit sold as
  16736. 10:42:44well. So, we're going to click product
  16737. 10:42:46name, and it's going to go straight into
  16738. 10:42:47the y-axis for us. And then we're going
  16739. 10:42:49to click units sold, and that will go
  16740. 10:42:51into the x-axis automatically. It just
  16741. 10:42:54kind of intuitively knows, but sometimes
  16742. 10:42:56it will make a mistake. And then you can
  16743. 10:42:58just fix it or flip it. And we do want
  16744. 10:43:01this uh let me make this much larger. We
  16745. 10:43:04do want this to be a little bit more
  16746. 10:43:05color-coded. That is what this legend is
  16747. 10:43:07down here. So, what we're going to do is
  16748. 10:43:09drag this product name down to the
  16749. 10:43:11legend. And now we have each product as
  16750. 10:43:14its own color. And in previous videos,
  16751. 10:43:17we have gone through and looked at some
  16752. 10:43:19of these visual and general options that
  16753. 10:43:21you have when you're actually creating
  16754. 10:43:23these visualizations, but we're going to
  16755. 10:43:24do some of them while we're in here as
  16756. 10:43:26well. So, we're just going to go down
  16757. 10:43:28here. We're going to choose data labels
  16758. 10:43:31and we're going to shrink that. And if
  16759. 10:43:34you go higher, the higher you go, the
  16760. 10:43:35less you see. So, if you want all of
  16761. 10:43:37them all the way down to the green,
  16762. 10:43:39we're going to go right about there. and
  16763. 10:43:40we're going to make it smaller. So now
  16764. 10:43:42we can go ahead and click anywhere
  16765. 10:43:43outside of that visualization and now we
  16766. 10:43:45can create a new one. If we had just
  16767. 10:43:47kept it like this where we were still
  16768. 10:43:49interacting with this visualization and
  16769. 10:43:51we clicked on a different one, it would
  16770. 10:43:53have then changed our visualization
  16771. 10:43:55completely which we don't want. So let's
  16772. 10:43:57hit control Z, click out of it and now
  16773. 10:44:00we can create a new one. Let's go right
  16774. 10:44:02over here to this 100% stacked column
  16775. 10:44:04chart. I'm going to click on it, drag it
  16776. 10:44:07over here and make it much larger. And
  16777. 10:44:10we're going to come right over here to
  16778. 10:44:12this customer information. And we're
  16779. 10:44:14going to click on customer. And then
  16780. 10:44:16we're going to go up to units sold and
  16781. 10:44:18click on units sold. And we want to
  16782. 10:44:21break these out. And so basically what
  16783. 10:44:22this is doing is it's breaking it out by
  16784. 10:44:24each of these shops. And we can see the
  16785. 10:44:27total of what they're buying, the units
  16786. 10:44:29sold. But we want to see exactly what
  16787. 10:44:32products make up this percentage or this
  16788. 10:44:34100%. So we're going to go right over
  16789. 10:44:36here to product name. We're going to
  16790. 10:44:38drag that down to the legend. And as you
  16791. 10:44:40can see, now we have each of these
  16792. 10:44:43products and each of the products is up
  16793. 10:44:44here. So this backpack, we can see the
  16794. 10:44:47backpack right here. Backpack right here
  16795. 10:44:49and right here. And we can see which
  16796. 10:44:50customer is buying what percentage of
  16797. 10:44:52their purchases. So for this Prep for
  16798. 10:44:55Anything prepping store, they have a
  16799. 10:44:56very large percentage, 40% is duct tape.
  16800. 10:44:59So they're buying a lot of duct tape. So
  16801. 10:45:02really quickly, we're able to see what
  16802. 10:45:03clients are purchasing or which clients
  16803. 10:45:05are purchasing what products the most.
  16804. 10:45:06So, just like this Alex Analyst
  16805. 10:45:08Apocalypse preppers, they're buying a
  16806. 10:45:10lot of water purifiers. We like drinking
  16807. 10:45:12clean water. Um, you know, that's just
  16808. 10:45:14what my audience likes. And so, you
  16809. 10:45:16know, we can easily get a quick glance
  16810. 10:45:18of that. Again, we're going to go in
  16811. 10:45:20here. I tend to like putting these data
  16812. 10:45:22labels on here. That's just what I
  16813. 10:45:25prefer. So, you know, something like
  16814. 10:45:27this. It looks nice. It looks clean. Um,
  16815. 10:45:29we can always go back and change these
  16816. 10:45:32names, which we'll do for this one. So,
  16817. 10:45:33we're going to go over here, go to
  16818. 10:45:35title. We'll go down to the text and
  16819. 10:45:38we'll do customer.
  16820. 10:45:41Oops.
  16821. 10:45:43Customer purchase. Oh jeez. Breakdown.
  16822. 10:45:49Pretend I'm really good at spelling. And
  16823. 10:45:52we're going to do it just like that.
  16824. 10:45:54We'll get out of there. So now we have
  16825. 10:45:55customer purchase breakdown. And that
  16826. 10:45:57looks really nice. It's a good uh a good
  16827. 10:46:00visualization. And we're going to bring
  16828. 10:46:01that right over here. We're going to
  16829. 10:46:04have a lot on the screen. And so I may
  16830. 10:46:06have to uh make them smaller or larger
  16831. 10:46:09to fit everything. All right, so let's
  16832. 10:46:12go on to our next one. Another really
  16833. 10:46:14common visualization is this one right
  16834. 10:46:17here, which is the line chart. And the
  16835. 10:46:19line chart is great, especially when
  16836. 10:46:21you're using things like dates. I have
  16837. 10:46:24found this one to be the best and a lot
  16838. 10:46:26of people use this as well. So we're
  16839. 10:46:27going to go right over here and click on
  16840. 10:46:29date purchased and then units sold. And
  16841. 10:46:32on the x-axxis, you can see it's broken
  16842. 10:46:34up by year, quarter, month, and day. So,
  16843. 10:46:36we don't want to do it that high level.
  16844. 10:46:37We only have three months of data in
  16845. 10:46:39here. So, we're going to get rid of the
  16846. 10:46:40year. We're gonna get rid of the
  16847. 10:46:42quarter. And then we at least have this.
  16848. 10:46:45And let's break it out because right now
  16849. 10:46:47we're looking at all of the units sold.
  16850. 10:46:49So, we're going to drag the product name
  16851. 10:46:51right down here to the legend. And now
  16852. 10:46:53it breaks it out by the actual product.
  16853. 10:46:55And for each month in January, February,
  16854. 10:46:57or March, you can follow these products
  16855. 10:46:59and see how they did in each of those
  16856. 10:47:01months. And if we wanted to, we can come
  16857. 10:47:02right over here to the filter on the
  16858. 10:47:04product name and we could filter it by
  16859. 10:47:06maybe the top three. So let's do
  16860. 10:47:08multi-tool survival knife, the nylon
  16861. 10:47:12rope, and the duct tape. And we can have
  16862. 10:47:15it just like this. And you know, you can
  16863. 10:47:18do those for any product that you want,
  16864. 10:47:20but again, we just want to do it for
  16865. 10:47:21those three just for an example. And
  16866. 10:47:23that really doesn't give us a ton of
  16867. 10:47:25information. We could even go down to
  16868. 10:47:26the day and, you know, it might give us
  16869. 10:47:29a little bit more information. And so
  16870. 10:47:31we'll keep it like that. And we can go
  16871. 10:47:33over here,
  16872. 10:47:35change the name as well. We're not going
  16873. 10:47:36to do this for all of them. Again, we're
  16874. 10:47:38just looking at the different types of
  16875. 10:47:39visualizations I think are really good
  16876. 10:47:41to know. But we'll change this one as
  16877. 10:47:43well to products purchased
  16878. 10:47:48by date.
  16879. 10:47:50We'll keep it just like that. Again,
  16880. 10:47:52nothing fancy. We're just trying to look
  16881. 10:47:53at a bunch of different stuff. So, let's
  16882. 10:47:55put this over here
  16883. 10:47:57down here. Now, let's click out of
  16884. 10:47:59there. And there are other ones in here
  16885. 10:48:02um that are definitely useful and you
  16886. 10:48:04absolutely can use. Um like this one is
  16887. 10:48:06a stacked bar chart. This one is a
  16888. 10:48:08stacked column chart. It's basically the
  16889. 10:48:09same thing just a different orientation.
  16890. 10:48:12We went to here just a different
  16891. 10:48:14orientation. It's the same thing. Um
  16892. 10:48:17just like this clustered bar chart,
  16893. 10:48:19clust column chart. It's just its
  16894. 10:48:21orientation either horizontal or
  16895. 10:48:22vertical. Then we have things like an
  16896. 10:48:25area chart, a stacked area chart. Not
  16897. 10:48:28really things that I've used too much in
  16898. 10:48:30previous positions. One that I have used
  16899. 10:48:33though is a line and clustered column
  16900. 10:48:35chart. So it kind of combines a few of
  16901. 10:48:38these with, you know, you have these bar
  16902. 10:48:41charts as well as line charts into one
  16903. 10:48:44visualization. So let's look at this one
  16904. 10:48:45because this is one that I have used
  16905. 10:48:47several times in my actual job. So for
  16906. 10:48:49our xaxis, we'll use the product name.
  16907. 10:48:53Then we'll look at something like the
  16908. 10:48:55price. And so let's make this a lot
  16909. 10:48:57larger
  16910. 10:48:59so we can actually see it. So now we
  16911. 10:49:02have the price and now we can look at
  16912. 10:49:04something like the production cost and
  16913. 10:49:06that can be
  16914. 10:49:08our line yaxis. So now we're looking at
  16915. 10:49:11the price of it, how much someone is
  16916. 10:49:12actually paying for it. And then we're
  16917. 10:49:14looking at how much it's costing us to
  16918. 10:49:16actually produce that product. And so
  16919. 10:49:18really quickly at a glance you can kind
  16920. 10:49:19of see that it's around the halfway to
  16921. 10:49:212/3 point on most of these. You can see
  16922. 10:49:24that the production cost is always lower
  16923. 10:49:27than the actual price because of course
  16924. 10:49:29we're out here to make a profit on these
  16925. 10:49:30products. So, let's minimize this one.
  16926. 10:49:33We're going to put this one right down
  16927. 10:49:34here. Let's make it even smaller. Let's
  16928. 10:49:37click out of that. And the next one that
  16929. 10:49:39we're going to take a look at is a
  16930. 10:49:41scatter chart. So, let's click on that
  16931. 10:49:43and make it much larger. Oops.
  16932. 10:49:47There we go. So, let's use the price and
  16933. 10:49:50the production cost again. And so our
  16934. 10:49:53x-axis is the price. Our yaxis is the
  16935. 10:49:56production cost. But now we need to fill
  16936. 10:49:57in this values right here. So let's go
  16937. 10:49:59over here and click on the product name
  16938. 10:50:01and drag that into values. And so now we
  16939. 10:50:03have our values. We just don't know what
  16940. 10:50:05they are, but we can see it. So let's
  16941. 10:50:08drag this down to legend as well. And it
  16942. 10:50:10breaks it out. And we kind of have this
  16943. 10:50:12scatter plot. And you know, for this
  16944. 10:50:14fake data that we're using, it doesn't
  16945. 10:50:16really show a lot. Uh, but if you're
  16946. 10:50:19using real data, you can definitely find
  16947. 10:50:20outliers and trends and patterns using
  16948. 10:50:22this type of visualization. Let's go
  16949. 10:50:24ahead and make that one small as well. I
  16950. 10:50:27get right down into the corner.
  16951. 10:50:30Now, let's go right over here and we
  16952. 10:50:32have the the dreaded pie charts. Um, and
  16953. 10:50:34donut charts. Now, look, I think it's
  16954. 10:50:36kind of a joke in the data analyst
  16955. 10:50:38community about pie charts and doughut
  16956. 10:50:40charts, but at the same time, people use
  16957. 10:50:42them and they request them. And so,
  16958. 10:50:43sometimes you're going to use it whether
  16959. 10:50:45you like it or not. So, let's click on
  16960. 10:50:47the doughut chart and let's make this
  16961. 10:50:50one a lot larger.
  16962. 10:50:52And let's go over here and let's click
  16963. 10:50:54on state. And we're also going to click
  16964. 10:50:57on total purchased. And that's really
  16965. 10:51:00all you have to do. These ones are
  16966. 10:51:03pretty straightforward. You can change a
  16967. 10:51:05few different things like where these
  16968. 10:51:07labels are. If you want them inside, you
  16969. 10:51:09can also do that. That would look
  16970. 10:51:11totally fine. Um, again, I'm just not a
  16971. 10:51:14super huge fan, but you will get this
  16972. 10:51:15one requested. People like this and want
  16973. 10:51:17to see it. And the reason a lot of
  16974. 10:51:19analysts don't like using this is
  16975. 10:51:21because when you start glancing at
  16976. 10:51:23these, it's really hard to tell the
  16977. 10:51:25difference between these sizes. If you
  16978. 10:51:27look at something like this, you can
  16979. 10:51:29easily see that this is larger. Like, if
  16980. 10:51:31you're looking at this one, the
  16981. 10:51:32multi-tool survival knife is obviously
  16982. 10:51:34the longest, and it gets shorter,
  16983. 10:51:35shorter, shorter, shorter. But when you
  16984. 10:51:37start getting in here, it's really hard
  16985. 10:51:38to approximate the size. I would not be
  16986. 10:51:40able to tell the difference between this
  16987. 10:51:425.63, 5.78, two, 7.72. I would not be
  16988. 10:51:47able to tell really the difference
  16989. 10:51:48between these or or kind of the the
  16990. 10:51:50difference between them very easily.
  16991. 10:51:53That's why a lot of people don't want to
  16992. 10:51:54use them in general. So again, I want to
  16993. 10:51:57show you this one because I think it's
  16994. 10:51:59worth noting and worth knowing how to
  16995. 10:52:01use, but I don't really push people
  16996. 10:52:04towards this because I don't think it's
  16997. 10:52:06the best visualization available most of
  16998. 10:52:08the time. All right, the next two are
  16999. 10:52:10super easy, but are used all the time.
  17000. 10:52:13Uh maybe more than some of these even,
  17001. 10:52:15but they're just so easy to use. So, I
  17002. 10:52:18kind of saved them for last. This one is
  17003. 10:52:20the card. And all the card is is it
  17004. 10:52:23displays one number or multiple numbers
  17005. 10:52:25if you want to use a multiro card, but
  17006. 10:52:27we'll just look at the card for now. All
  17007. 10:52:29we're going to look at is the total
  17008. 10:52:30purchased. And it's just going to
  17009. 10:52:32display it just like this. And you can
  17010. 10:52:34make it as large or as small as you'd
  17011. 10:52:36like. And normally it goes on like the
  17012. 10:52:38top. and you'll put card here, a card
  17013. 10:52:40here. Just for example, I'll kind of
  17014. 10:52:43show you how this might look. So, it
  17015. 10:52:44look something like this, right? And at
  17016. 10:52:47the top, it'll have different usually
  17017. 10:52:48high overarching information. And this
  17018. 10:52:51is super common to see, and I'm sure if
  17019. 10:52:53you've looked at other people's
  17020. 10:52:54visualizations, you'll see something
  17021. 10:52:55like this. This is usually totals or
  17022. 10:52:58averages or something like that in here
  17023. 10:53:00where it's super easy to look at. So,
  17024. 10:53:02like right here, this is total
  17025. 10:53:04purchased, and we can go in and look at
  17026. 10:53:06the minimum. And then we can go over
  17027. 10:53:08here and this one can be account. And so
  17028. 10:53:11it gives us a lot of information just at
  17029. 10:53:13a really quick glance. And then we have
  17030. 10:53:15all of our more in-depth colorful
  17031. 10:53:17visualizations that kind of have more
  17032. 10:53:19information than just a single piece
  17033. 10:53:21like the card does. And then the very
  17034. 10:53:22last one that I'm going to show you is
  17035. 10:53:24this one right here, which is the table.
  17036. 10:53:26And this one is obviously extremely
  17037. 10:53:28popular. It's like an little Excel
  17038. 10:53:30table. And we can go in here and we can
  17039. 10:53:32get the customer wherever that is. And
  17040. 10:53:36then we'll also get the units sold. And
  17041. 10:53:38this is what it looks like. And it's
  17042. 10:53:40super easy. And oftentimes you'll have
  17043. 10:53:42it like on the side as well. Uh and all
  17044. 10:53:44the other visualizations over here. And
  17045. 10:53:46so, you know, if we're going to take all
  17046. 10:53:48these visualizations and pretend they
  17047. 10:53:49were like a real thing. You know,
  17048. 10:53:52there's a lot in here, but we'll just
  17049. 10:53:54kind of really quickly do this. Um, you
  17050. 10:53:57know, we [snorts] might have something
  17051. 10:53:58like this. And we'll make this larger
  17052. 10:54:01and make this wider.
  17053. 10:54:04And you know, we have a lot of
  17054. 10:54:06information just in here. And this is
  17055. 10:54:07not a project, so don't go put this on
  17056. 10:54:09your portfolio. I'm just threw a ton of
  17057. 10:54:12random visualizations on, you know, this
  17058. 10:54:14dashboard. But you can already see a lot
  17059. 10:54:17of these you most likely have seen in
  17060. 10:54:19other people's work and other people's
  17061. 10:54:20visualizations on LinkedIn or on
  17062. 10:54:22YouTube. These are very common, very,
  17063. 10:54:25very popular. And again, we did not go
  17064. 10:54:27through all of the ones over here. There
  17065. 10:54:29are maps that you can use, but I haven't
  17066. 10:54:31used maps ever in my job. There are
  17067. 10:54:34things like gauges and decomposition
  17068. 10:54:37trees and waterfall charts and uh tree
  17069. 10:54:40maps and all these different things, but
  17070. 10:54:43I really have never used those in my
  17071. 10:54:45actual job. And I don't see them a lot
  17072. 10:54:48in others people's work either.
  17073. 10:54:49Otherwise, I would be telling you to
  17074. 10:54:51learn these and use these. But again,
  17075. 10:54:53try them out. See which ones you like.
  17076. 10:54:55If you like this video, be sure to like
  17077. 10:54:56and subscribe below and go check out all
  17078. 10:54:58the other PowerBI tutorial videos that I
  17079. 10:55:00have on my channel. and I will see you
  17080. 10:55:02in the next video.
  17081. 10:55:07[music]
  17082. 10:55:15What's going on everybody? Welcome back
  17083. 10:55:16to the PowerBI tutorial series. Today we
  17084. 10:55:19are going to be working on our final
  17085. 10:55:20project.
  17086. 10:55:27Now this is our final project of the
  17087. 10:55:28PowerBI tutorial series. So, if you have
  17088. 10:55:30not watched all of those videos leading
  17089. 10:55:32up to this, I recommend going and
  17090. 10:55:34watching those videos so you can make
  17091. 10:55:35sure that you know all the things we're
  17092. 10:55:37going to be looking at in today's
  17093. 10:55:38project. I am really excited to work on
  17094. 10:55:40this project with you because I think it
  17095. 10:55:41is a really good one and it uses real
  17096. 10:55:43data that we collected about a month ago
  17097. 10:55:45where I took a survey of data
  17098. 10:55:47professionals and this is the raw data
  17099. 10:55:49that we're going to be looking at and so
  17100. 10:55:51I think it's just really interesting
  17101. 10:55:52that we collected our own data now we're
  17102. 10:55:54using it for a project. We're going to
  17103. 10:55:55transform the data using Power Query and
  17104. 10:55:57then we'll actually create the
  17105. 10:55:58visualizations and finalize the
  17106. 10:56:00dashboards as well as create a theme and
  17107. 10:56:02a different color scheme to kind of make
  17108. 10:56:04it a little bit more unique. Without
  17109. 10:56:05further ado, let's jump on my screen and
  17110. 10:56:07get started with the project. All right,
  17111. 10:56:08so before we jump into it, I wanted to
  17112. 10:56:10let you know that you can get the data
  17113. 10:56:11below. It is on my GitHub. You can go
  17114. 10:56:13and download this exact file that we're
  17115. 10:56:15going to be looking at. Now, in the past
  17116. 10:56:17several projects, we have been using
  17117. 10:56:20this fake apocalypse data set. You know,
  17118. 10:56:22it was fun. it was, you know, whatever.
  17119. 10:56:25This data set is real. This is a real
  17120. 10:56:27data set. It was a survey that I took
  17121. 10:56:28from data professionals. I posted on
  17122. 10:56:30LinkedIn and Twitter and all these other
  17123. 10:56:32places. And we had about 600 700 people
  17124. 10:56:34who responded to the questions. So
  17125. 10:56:36before we actually get into it and start
  17126. 10:56:38cleaning the data and doing all this
  17127. 10:56:41stuff in PowerBI, I just wanted to show
  17128. 10:56:43you the data. All right. So this is the
  17129. 10:56:45CSV that I downloaded from the survey
  17130. 10:56:47website that I used. And this is
  17131. 10:56:49completely raw data. I haven't done
  17132. 10:56:51anything to it at all. But let's go
  17133. 10:56:53through the data really quickly and
  17134. 10:56:54we'll kind of see what we have. And we
  17135. 10:56:56are not going to make any changes at all
  17136. 10:56:58in Excel. We're going to do all of our
  17137. 10:57:00transformations or at least a few
  17138. 10:57:02transformations in PowerBI because again
  17139. 10:57:05this is a PowerBI tutorial and project.
  17140. 10:57:07So I want you to kind of learn how to
  17141. 10:57:09use that and not use Excel because you
  17142. 10:57:11can go through my Excel tutorial if you
  17143. 10:57:13want to do that. So let's just look at
  17144. 10:57:15it in Excel and then we'll move it over
  17145. 10:57:16to PowerBI and actually start
  17146. 10:57:18transforming the data. So we have this
  17147. 10:57:20unique ID. These are all the people that
  17148. 10:57:22actually took it. Oops. Don't want to do
  17149. 10:57:24that. We have an email, which this is
  17150. 10:57:26completely anonymous. I didn't collect
  17151. 10:57:27any data or user data on this. Then we
  17152. 10:57:31have the date taken. Um, and let's get
  17153. 10:57:32into the actual good information. Then
  17154. 10:57:35we have all of these questions. So, we
  17155. 10:57:37have question one, which title fits you
  17156. 10:57:39best? And they can choose things. Now,
  17157. 10:57:42uh, let's add a filter really quickly
  17158. 10:57:44that we can look at this. Now you had
  17159. 10:57:47the pre-selected ones which were like
  17160. 10:57:49data analyst, architect, engineer, but
  17161. 10:57:51then there was an option where you could
  17162. 10:57:52say other and you could specify what
  17163. 10:57:54that was. So if you look in here, we're
  17164. 10:57:57going to have all these different other
  17165. 10:58:00please specify with different titles,
  17166. 10:58:02right? And there were a lot of them. Now
  17167. 10:58:07typically what you want to do is really
  17168. 10:58:09clean this up. And we're not going to be
  17169. 10:58:11doing a ton ton ton of data cleaning,
  17170. 10:58:14but we are going to do some in PowerBI,
  17171. 10:58:16but none in here. But typically with
  17172. 10:58:18this amount of data in the way that it's
  17173. 10:58:20formatted, we would do so much data
  17174. 10:58:22cleaning um with this one. I mean,
  17175. 10:58:24there's a lot of work to be done. Um
  17176. 10:58:27like this current year salary, this is
  17177. 10:58:29one that I would absolutely be cleaning
  17178. 10:58:32up because it's a ranges and it has a
  17179. 10:58:34dash and a k and all these numbers. This
  17180. 10:58:37is something that I would be cleaning up
  17181. 10:58:38and using, but we're not going to be
  17182. 10:58:40cleaning this up right now. So, anyways,
  17183. 10:58:43let's just get into it. Let's see what
  17184. 10:58:44questions we asked. Uh, we have the
  17185. 10:58:46yearly salary. What industry do you work
  17186. 10:58:48in? Favorite programming language?
  17187. 10:58:51Then there were a lot of different
  17188. 10:58:53options. So, this was like one question
  17189. 10:58:55where they picked multiple options. So,
  17190. 10:58:57is how happy are you in your current
  17191. 10:58:59position with the following? You have
  17192. 10:59:00your salary, work life balance.
  17193. 10:59:04Um, then we have co-workers, management,
  17194. 10:59:07upward mobility, learning new things.
  17195. 10:59:10Um, and they could rank it from 0 to 10.
  17196. 10:59:12So, some people ranked upward mobility a
  17197. 10:59:1410, some ranked it a zero or a one. Um,
  17198. 10:59:18and again, they can answer however they
  17199. 10:59:20want. How difficult was it to break into
  17200. 10:59:23data? Very difficult, very easy. Um, if
  17201. 10:59:27you're looking for a new job, we have,
  17202. 10:59:29you know, what would you be looking for?
  17203. 10:59:30Remote work, better salary, etc. We have
  17204. 10:59:33fe male, female, which country are you
  17205. 10:59:35from? And then this is more like
  17206. 10:59:36demographics. So, if you're a male, how
  17207. 10:59:38old you are, and this was in a range.
  17208. 10:59:41So, this is like a a a sliding bar. So,
  17209. 10:59:43you can slide it to the exact age you
  17210. 10:59:45had. There's some people who are
  17211. 10:59:48apparently 92. Um, which if that's true,
  17212. 10:59:50I mean, good for you, man. Or
  17213. 10:59:52[clears throat] woman. Actually, really
  17214. 10:59:54quickly, I'm going to see just just
  17215. 10:59:56while we're here, I'm going to see if
  17216. 10:59:57this is a male male or a female. Oh,
  17217. 10:59:59it's a female from India. Very cool. Um,
  17218. 11:00:02so we have all this information and it
  17219. 11:00:05is a lot of information when you have
  17220. 11:00:07something like this. I mean, there is so
  17221. 11:00:10much data cleaning that can be done. I
  17222. 11:00:12mean, I already see like 20 plus
  17223. 11:00:17different things that I would need to do
  17224. 11:00:19to make this a lot better. Um, and we
  17225. 11:00:21also have date taken and the time taken
  17226. 11:00:24as well as how long it they took on it,
  17227. 11:00:26like the time spent. Really just really
  17228. 11:00:29interesting data. But again, this is a
  17229. 11:00:32beginner tutorial series. This is the
  17230. 11:00:34beginner project. So, we're not going to
  17231. 11:00:36get do anything too crazy. I will be
  17232. 11:00:39using this exact data set in a future
  17233. 11:00:41video doing a lot more data cleaning and
  17234. 11:00:45creating a much more advanced
  17235. 11:00:46visualization with what we have and what
  17236. 11:00:48we're looking at right here. But for
  17237. 11:00:50this video, we're just going to be doing
  17238. 11:00:51a pretty simple visualization and
  17239. 11:00:54dashboard that you can use uh to
  17240. 11:00:56practice with or put on your portfolio
  17241. 11:00:58if you know that's where you're at right
  17242. 11:00:59now. So, let's get out of here and let's
  17243. 11:01:02put this into PowerBI. So, let's exit
  17244. 11:01:04out and let's come right over here to
  17245. 11:01:06import data from Excel. We'll click on
  17246. 11:01:08PowerBI final project and open.
  17247. 11:01:12Give that a second. Doing this all in
  17248. 11:01:14real time. and we only have the one. So,
  17249. 11:01:16we'll do we won't be practicing any
  17250. 11:01:18joins or anything, but we're not going
  17251. 11:01:20to load it. We're going to transform
  17252. 11:01:21this data. So, let's put it into Power
  17253. 11:01:24Query editor.
  17254. 11:01:27And now we have all of our data in here.
  17255. 11:01:29And it should look extremely familiar.
  17256. 11:01:33Now, when I'm looking at this, when I
  17257. 11:01:35start looking at this information, I
  17258. 11:01:38kind of need to know beforehand what I
  17259. 11:01:41want to get out of this. Do I need to
  17260. 11:01:43clean every single column? Do I just
  17261. 11:01:45need to clean a few of them? Do I need
  17262. 11:01:46to get rid of columns? That's kind of
  17263. 11:01:48where my head's at. And so, right off
  17264. 11:01:50the bat, I can already tell you that
  17265. 11:01:52there are columns that we can just
  17266. 11:01:53delete to get out of our way. So, we're
  17267. 11:01:55going to do that at the beginning so
  17268. 11:01:57that we don't have to do that later on
  17269. 11:01:59or they're just in our way. So, I'm
  17270. 11:02:00going to click on browser and then I'm
  17271. 11:02:02going to hit shift and I'm going to go
  17272. 11:02:04over here to refer.
  17273. 11:02:06I'm just going to go up here to remove
  17274. 11:02:07columns. And everything that we do is
  17275. 11:02:10going to go over here to this applied
  17276. 11:02:11steps. If you've been following this
  17277. 11:02:13series, um you know, we can remove
  17278. 11:02:15things, add things, but anything we do
  17279. 11:02:18will show up right over here. So, we can
  17280. 11:02:20track it and go back if we need to. Now,
  17281. 11:02:23one column that I know for sure that I'm
  17282. 11:02:25going to be using quite a bit is this
  17283. 11:02:27which title fits you best in your
  17284. 11:02:28current role because I I specifically
  17285. 11:02:30wanted to do a breakdown of diff
  17286. 11:02:32people's roles and how much they make
  17287. 11:02:34and different stuff like that. So I know
  17288. 11:02:36that I want to use this but as we saw
  17289. 11:02:38before
  17290. 11:02:40there's kind of the issue is is it's not
  17291. 11:02:41very clean right it has data analyst
  17292. 11:02:44data architect engineer scientist
  17293. 11:02:46database developer and then like a
  17294. 11:02:49hundred different options and then a
  17295. 11:02:52student or or none of these right um
  17296. 11:02:57and so for the purpose of this video
  17297. 11:03:00right here we are not going to take
  17298. 11:03:02every single one of these options
  17299. 11:03:04because this involves a lot more data
  17300. 11:03:06cleaning. Let me give you an example.
  17301. 11:03:07This says software engineer. This also
  17302. 11:03:10says software engineer. The and with AI.
  17303. 11:03:14These two would typically be combined or
  17304. 11:03:17standardized to software engineer. But
  17305. 11:03:20it's not very easy to do that in
  17306. 11:03:22PowerBI. We could do that in Excel, but
  17307. 11:03:24not really in PowerBI or even SQL if we
  17308. 11:03:27pull this from a SQL database. Um, and
  17309. 11:03:29you can find lots of different, you
  17310. 11:03:31know, options of that. We have data
  17311. 11:03:33manager and data manager. If we
  17312. 11:03:34separated these out, these would be
  17313. 11:03:37different options when we created our
  17314. 11:03:39visualizations, and we don't want that.
  17315. 11:03:40So, what we are going to do, uh, and
  17316. 11:03:43this is going to be kind of a an easy
  17317. 11:03:45way out to just make sure that this is
  17318. 11:03:48pretty clean and doesn't we don't have a
  17319. 11:03:49thousand different options. We're going
  17320. 11:03:51to create this to other. So, we're going
  17321. 11:03:53to simplify this a lot. And then we're
  17322. 11:03:57going to use this. So we'll have maybe
  17323. 11:03:59six or seven options instead of the, you
  17324. 11:04:01know, let's say 50 that we would have if
  17325. 11:04:03we actually did the harder work, which
  17326. 11:04:06is break it out, standardize it, and
  17327. 11:04:08clean it up that way. So what we're
  17328. 11:04:10going to do is we're going to click on
  17329. 11:04:11this right here. We're going to go up
  17330. 11:04:13here to split column in this ribbon up
  17331. 11:04:15top. We'll go to split column, and we
  17332. 11:04:18want to do it by a delimiter. And if you
  17333. 11:04:21notice, let me see if I can move this
  17334. 11:04:23over. If you notice, we have other and
  17335. 11:04:25then we have this parenthesis. and in no
  17336. 11:04:27other option or way is there
  17337. 11:04:29parenthesis. So what we're going to do
  17338. 11:04:31is we're going to use a custom and we're
  17339. 11:04:34going to use this open parenthesis. What
  17340. 11:04:37that's going to do is it's going to
  17341. 11:04:38separate it by this parenthesis. It's
  17342. 11:04:39going to leave the other. It's going to
  17343. 11:04:41create separate columns just one
  17344. 11:04:44separate column for each of these. And
  17345. 11:04:46we can do that at each occurrence or we
  17346. 11:04:48can do the leftmost. And we really we
  17347. 11:04:50only need it for the leftmost cuz
  17348. 11:04:51there's only one of these uh left-handed
  17349. 11:04:54or left-sided uh brackets or or what is
  17350. 11:04:58it whatever this is called. And then
  17351. 11:05:00let's go and click okay. And it should
  17352. 11:05:02create another column. So it's going to
  17353. 11:05:04have 0.1
  17354. 11:05:062. And now we have if we click on this
  17355. 11:05:10now we only have these options. We have
  17356. 11:05:12analyst architect engineer data
  17357. 11:05:14scientist database developer other and
  17358. 11:05:16student looking or none. That is what we
  17359. 11:05:19want. It makes it so much simpler and
  17360. 11:05:21it's not perfect, but again, I'm trying
  17361. 11:05:24to show you what we are able to do in
  17362. 11:05:26PowerBI. So now we're just going to
  17363. 11:05:28remove that column and we're going to go
  17364. 11:05:30and do the exact same thing to this one
  17365. 11:05:32as well because I know that we want to
  17366. 11:05:34use this. And I really wanted to use
  17367. 11:05:37this one as well. But if we look at this
  17368. 11:05:39one also, um there's a lot. So I said,
  17369. 11:05:42"What is your favorite programming
  17370. 11:05:44language?" and people there were
  17371. 11:05:45pre-selected answers like JavaScript,
  17372. 11:05:47Java, C++, Python, R things like that
  17373. 11:05:51and then there was an other option and
  17374. 11:05:53in this other option I mean it was free
  17375. 11:05:55text so they can fill it in as they
  17376. 11:05:57want. I mean there's four, five, six
  17377. 11:05:59[snorts] different ways that people put
  17378. 11:06:01SQL that is something I would
  17379. 11:06:02standardize and you know that would be
  17380. 11:06:06the way I cleaned it but that's not how
  17381. 11:06:08we did it in here. So we're going to do
  17382. 11:06:09the same thing. We're going to keep that
  17383. 11:06:10other. So we're going to split this
  17384. 11:06:12column again. We're use a delimiter. And
  17385. 11:06:15for this delimiter though, we're going
  17386. 11:06:17to use a colon. So we're going to say
  17387. 11:06:20we're going to do a colon right there.
  17388. 11:06:21We'll just do the leftmost. We'll click
  17389. 11:06:24okay. And then we have our options. And
  17390. 11:06:28it's much simpler. Now, I really would
  17391. 11:06:30have rather kept all these and because
  17392. 11:06:32SQL's in there quite a bit, but you
  17393. 11:06:34know, a lot of people don't think SQL is
  17394. 11:06:36even a programming language. So, uh,
  17395. 11:06:38we're going to delete that column. Now,
  17396. 11:06:40one that I just skipped and I kind of
  17397. 11:06:41wanted to go back to is this current
  17398. 11:06:44yearly salary. I really want to use
  17399. 11:06:47this. Let's see if we can use it. I
  17400. 11:06:50Here's what I want to do with it. And
  17401. 11:06:51this is not perfect. Um, but for this
  17402. 11:06:53video, I want to try it. What I want to
  17403. 11:06:55do is break up these numbers 106 125 and
  17404. 11:06:59then take the average of those numbers.
  17405. 11:07:01Then we'll use some docs in there. So,
  17406. 11:07:03we'll take 106 125 create that into two
  17407. 11:07:06separate columns. Then we'll create a
  17408. 11:07:08third column that will give us the
  17409. 11:07:10average of those two numbers. So we'll
  17410. 11:07:11do 106 + 125 / 2 and then we'll have the
  17411. 11:07:16average of that. Now that is not perfect
  17412. 11:07:19but it's going to give us at least you
  17413. 11:07:21know an average a kind of roundabout
  17414. 11:07:23number because they gave us this range.
  17415. 11:07:25They said my salary is between 106
  17416. 11:07:27125,000. So if we say that their salary
  17417. 11:07:29was 112,000
  17418. 11:07:31at least gives us it makes it usable.
  17419. 11:07:33It's a numeric value instead of being
  17420. 11:07:35this which is text which we really we
  17421. 11:07:38could use and and I'll show you how to
  17422. 11:07:40do that because we're going to keep this
  17423. 11:07:41column. I'll create a copy of this and
  17424. 11:07:43I'll show you the difference between
  17425. 11:07:44this and using the average but for but
  17426. 11:07:49for this data cleaning portion let's
  17427. 11:07:51just try it. Let's see what we can do
  17428. 11:07:53and see if we can make it work. So first
  17429. 11:07:56let's create a duplicate. So we're going
  17430. 11:07:59to uh duplicate the column. So now we
  17431. 11:08:03have this copy at the very very end and
  17432. 11:08:06we can use this one instead of having to
  17433. 11:08:08use the original way way way back here.
  17434. 11:08:11So we're going to leave that one how it
  17435. 11:08:12is and we're going to use this one. So
  17436. 11:08:16let's go ahead and split this one up.
  17437. 11:08:18We're going to click on the column
  17438. 11:08:19header. Then we're going to click on
  17439. 11:08:21split column. And we'll do it by digit
  17440. 11:08:23to non-digit.
  17441. 11:08:26And if you look at it right here, it's
  17442. 11:08:29broken it out kind of um in the fact
  17443. 11:08:31that now in this one we just have
  17444. 11:08:34numeric values. And in this one we have
  17445. 11:08:37K dash numeric or just dash numeric. And
  17446. 11:08:42now this can be easily cleaned. Whereas
  17447. 11:08:44this one we can just completely get rid
  17448. 11:08:46of because it's only K. So we'll just
  17449. 11:08:48remove that column. And then in this one
  17450. 11:08:51we're going to rightclick. We're going
  17451. 11:08:53to click on replace values. And so if it
  17452. 11:08:56just has we just do a K. We'll replace
  17453. 11:08:59with nothing. Do okay. And then for the
  17454. 11:09:02last one, we'll go to replace values and
  17455. 11:09:06we'll do the dash or the minus sign and
  17456. 11:09:08we'll place that with nothing. And so
  17457. 11:09:10now we have our values as well. Oh, we
  17458. 11:09:13also have a plus. Let me get rid of that
  17459. 11:09:14because that's when some people had 250
  17460. 11:09:17or 225,000 plus. So for that one, the
  17461. 11:09:20average is just going to be 225. We'll
  17462. 11:09:22have to specify that in our DAX. I
  17463. 11:09:24forgot. But actually, if somebody has
  17464. 11:09:26225, let me find this plus really quick.
  17465. 11:09:30Uh, let me filter by it because it's a
  17466. 11:09:33lot faster. What we actually want to do
  17467. 11:09:36for the purpose of this one is we want
  17468. 11:09:37to put 225 here so that when we do 225 +
  17469. 11:09:41225 / 2, it comes out to 225. That's
  17470. 11:09:44just what we're going to put it as. And
  17471. 11:09:46there's only two people. So, uh, I'm
  17472. 11:09:48actually going to replace this. I'm
  17473. 11:09:50going to do replace values. So I'm going
  17474. 11:09:51to say plus
  17475. 11:09:53with 225
  17476. 11:09:55and we'll click okay. Awesome. We can
  17477. 11:09:58unfilter these. Select all. So we're
  17478. 11:10:02going to go right up here to add column
  17479. 11:10:04and we're going to say custom column.
  17480. 11:10:07And we're going to go right over here.
  17481. 11:10:09Actually, let's make it uh average
  17482. 11:10:13salary.
  17483. 11:10:14Let's make it average salary. So we're
  17484. 11:10:17going to insert this.
  17485. 11:10:19We're going to say
  17486. 11:10:22parentheses and we're going to say plus
  17487. 11:10:26this insert
  17488. 11:10:28and close the parenthesis divided by
  17489. 11:10:31two. And it says no syntax errors have
  17490. 11:10:34been detected. Let's click on okay. And
  17491. 11:10:38it's giving us an error. So it's saying
  17492. 11:10:40we cannot apply operator plus to types
  17493. 11:10:42text and text which makes uh perfect
  17494. 11:10:45sense. These aren't uh numbers. So,
  17495. 11:10:46let's make it a whole number. And let's
  17496. 11:10:48make it a whole number. And then let's
  17497. 11:10:52see if this will actually work now.
  17498. 11:10:56Or maybe just need to try a whole
  17499. 11:10:58another one. So, let's try transform or
  17500. 11:11:01add column. Custom column.
  17501. 11:11:04Let's try this all again. See if uh I
  17502. 11:11:06can make it work.
  17503. 11:11:08Insert
  17504. 11:11:10this one
  17505. 11:11:12plus
  17506. 11:11:14this one.
  17507. 11:11:16and we'll do divided by two. And let's
  17508. 11:11:19try this one. And there we go. So now
  17509. 11:11:22let's get rid of this column.
  17510. 11:11:24Columns. And we can actually remove
  17511. 11:11:27these ones as well
  17512. 11:11:29because now we have this um
  17513. 11:11:33average salary column
  17514. 11:11:37which [clears throat] when we look at
  17515. 11:11:39this or when we use this uh we can let
  17516. 11:11:41me see if I can just move this way way
  17517. 11:11:43way over. All right. I might cut because
  17518. 11:11:45this is taking forever. So if you take
  17519. 11:11:47the average of these two numbers, you'll
  17520. 11:11:49get 53. If you take the average of 0 and
  17521. 11:11:5140, you'll get 20. So now we have this
  17522. 11:11:53average salary. And again, when we get
  17523. 11:11:56to the actual visualization part, I'll
  17524. 11:11:58show you why this isn't as useful as
  17525. 11:12:00having this average salary. And just a
  17526. 11:12:02reminder, this is not perfect. Uh I
  17527. 11:12:05wouldn't typically do this, especially
  17528. 11:12:06if I had it in Excel or if I was, you
  17529. 11:12:09know, creating this survey in a
  17530. 11:12:11different way. I would probably have a
  17531. 11:12:13very specific value where they can do it
  17532. 11:12:14on a slider, but this is how it is. So,
  17533. 11:12:17we've at least made it usable or more
  17534. 11:12:19usable in my mind. And we have a few
  17535. 11:12:22other things that we can change like
  17536. 11:12:23what industry do you work in where we
  17537. 11:12:25can break this one out. So, I'm going to
  17538. 11:12:27go ahead and break this one out as well
  17539. 11:12:29as
  17540. 11:12:31this one right here. Which country do
  17541. 11:12:32you live in? I'm going to break both of
  17542. 11:12:34those out to where it's the country or
  17543. 11:12:36other. I'm not going to have these other
  17544. 11:12:38values, although there are a lot of them
  17545. 11:12:40because there's a lot of people who live
  17546. 11:12:41in these different countries, but we
  17547. 11:12:44can't really do that super well in here
  17548. 11:12:46because again, the same issue kept
  17549. 11:12:48happening. Argentina, Argentina,
  17550. 11:12:50Argentine, a Australia. So, we can't
  17551. 11:12:53normalize those values unless we spend
  17552. 11:12:55just copious amount of time doing that.
  17553. 11:12:58So, I'm going to go ahead and do these.
  17554. 11:13:00I'm going to fast I'm going to fast
  17555. 11:13:02speed this so it goes a lot faster. So,
  17556. 11:13:04I'm just going to go silent and let this
  17557. 11:13:06happen really quick. And then we'll get
  17558. 11:13:08to the end and we'll actually start
  17559. 11:13:09building our visualizations.
  17560. 11:13:19All right. So, we've split them up and
  17561. 11:13:22as you can see we have all these options
  17562. 11:13:23as well as other and I think you know
  17563. 11:13:27there is let me tell you there is so
  17564. 11:13:29much more that we could do with this. I
  17565. 11:13:31mean, just so many other things, but
  17566. 11:13:35this is like what the bare minimum of
  17567. 11:13:37what we need for this project. So, let's
  17568. 11:13:40go ahead and close and apply this. And
  17569. 11:13:43if we need to come back at any point and
  17570. 11:13:45actually fix anything or change
  17571. 11:13:47anything, we can. So, it's not like
  17572. 11:13:49that's permanent. Um, so as you can see,
  17573. 11:13:50we have everything over here. We have
  17574. 11:13:52all of our data as it is transformed in
  17575. 11:13:55here as well. And now we can start
  17576. 11:13:59building out our visualization. So,
  17577. 11:14:01let's go back to our report
  17578. 11:14:03and let's start building something out.
  17579. 11:14:05All right. So, let's add a title to our
  17580. 11:14:07dashboard.
  17581. 11:14:10Make this right at the top.
  17582. 11:14:13Call this the data
  17583. 11:14:16professional
  17584. 11:14:18survey
  17585. 11:14:19breakdown.
  17586. 11:14:22And let's make that quite a bit larger.
  17587. 11:14:26Make it bold. Why not? And we'll put
  17588. 11:14:29that in the center. And now let's um
  17589. 11:14:33let's add some effects. Let's change
  17590. 11:14:35that background to something like that's
  17591. 11:14:38too dark. Something like this. And I do
  17592. 11:14:41not like that bold. Let's take that off.
  17593. 11:14:44There we go. So something like this just
  17594. 11:14:46as a quick title to what we're about to
  17595. 11:14:49do, what we are about to build. So we're
  17596. 11:14:51going to start off with the most simple
  17597. 11:14:53visualizations that we're going to do
  17598. 11:14:54and we'll kind of work our way towards
  17599. 11:14:56kind of the harder ones. So, the first
  17600. 11:14:58one that we're going to start off with
  17601. 11:14:59is a card. And the cards are obviously
  17602. 11:15:02like just super super easy. They usually
  17603. 11:15:05just display one piece of information.
  17604. 11:15:08So, we're going to go right over here to
  17605. 11:15:09the very bottom at the unique ID and
  17606. 11:15:12we're going to select it and we're going
  17607. 11:15:15to say a count of distinct or a count,
  17608. 11:15:18it doesn't matter. Um, and it says 630
  17609. 11:15:21count of unique ID. Now, we're not going
  17610. 11:15:23to keep that as is. We're actually going
  17611. 11:15:24to go right over here. We're going to
  17612. 11:15:26say rename for this visual. And it says
  17613. 11:15:28count of unique ID, but we're going to
  17614. 11:15:30say count of
  17615. 11:15:32survey takers. And you can say whatever
  17616. 11:15:36you want here, but in in general, that
  17617. 11:15:38is what it is. We're we're counting how
  17618. 11:15:40many people um you know took this
  17619. 11:15:43survey. And that's just a kind of a
  17620. 11:15:45total maybe I say total amount or of
  17621. 11:15:48survey takers, but you can say count of
  17622. 11:15:50survey takers. How many people took the
  17623. 11:15:52survey? So, let's click out of there.
  17624. 11:15:54Let's click on card. Let's make it about
  17625. 11:15:57the same size. We're going to drag it up
  17626. 11:15:59here and try to make them about the
  17627. 11:16:02same. We will in a little bit. We'll
  17628. 11:16:04make them the same size. Um, but for
  17629. 11:16:06this one, we're going to look at age.
  17630. 11:16:08So, we're going to look at current age.
  17631. 11:16:10So, we click on that and we'll say want
  17632. 11:16:13the average age. So, our average age
  17633. 11:16:16taker is almost 30 years old. So, let's
  17634. 11:16:18go right over here. We're going to say
  17635. 11:16:20rename for this visual. We'll say
  17636. 11:16:22average age of survey.
  17637. 11:16:27This might be too long.
  17638. 11:16:30Average age of survey taker. Again, name
  17639. 11:16:32it whatever you'd like. So again, these
  17640. 11:16:34are meant to be high-level numbers. So
  17641. 11:16:36when somebody is looking at your
  17642. 11:16:38dashboard, they can just really quickly
  17643. 11:16:40glance at this and know exactly what it
  17644. 11:16:42is instead of like some of these other
  17645. 11:16:44visualizations that we're about to
  17646. 11:16:45create. They don't really have to dig
  17647. 11:16:47into it, look at the x-axis, the y-axis,
  17648. 11:16:49the the different uh legend colors and
  17649. 11:16:52whatnot. They can just see these high
  17650. 11:16:54numbers and get a really quick glance of
  17651. 11:16:56the data. Now, let's create our first
  17652. 11:16:58visualization. And what we're going to
  17653. 11:17:00do for that one is a clustered bar
  17654. 11:17:02chart. So, let's go ahead and click on
  17655. 11:17:04the clustered bar chart. We can create
  17656. 11:17:06as small or as large as we'd like. And
  17657. 11:17:09for this one, we're going to be looking
  17658. 11:17:10at the job titles. Now remember we kind
  17659. 11:17:13of changed the job titles or you know u
  17660. 11:17:17transform those if you want to say that.
  17661. 11:17:19So we're going to look at job titles and
  17662. 11:17:21then we're going to look at their
  17663. 11:17:22average salary and if you remember we
  17664. 11:17:25transformed that one as well. We have
  17665. 11:17:27all average salary. Now this one is it
  17666. 11:17:30looks like a text right now so it may
  17667. 11:17:32not work properly. And what we're
  17668. 11:17:33actually going to do is go over here.
  17669. 11:17:36I want to see the average salary.
  17670. 11:17:41So, let's click on average salary and
  17671. 11:17:42see if we can change this data type from
  17672. 11:17:44a text to a decimal number. Let's click
  17673. 11:17:48yes. I forgot to do that when we were
  17674. 11:17:50transforming it. And there we go. This
  17675. 11:17:52is perfect. Um, so now we can go back
  17676. 11:17:55and we can select our average salary.
  17677. 11:17:59And as you can see, it has this um this
  17678. 11:18:01function symbol. And so now we can click
  17679. 11:18:03on it and it'll look a lot better. And
  17680. 11:18:06although this says average salary as the
  17681. 11:18:07title, it's actually doing a count or
  17682. 11:18:09the sum. So we can click average right
  17683. 11:18:12here. And what we want to do is actually
  17684. 11:18:15break this down by the job title. And so
  17685. 11:18:19now we can see data scientists are
  17686. 11:18:21making the most by far. They're making
  17687. 11:18:23average of 93,000 at least from the
  17688. 11:18:26survey takers that took it. Then we have
  17689. 11:18:28our data engineers making 65,000.
  17690. 11:18:31Data architects are making 63. And then
  17691. 11:18:34where are the data analysts? Data
  17692. 11:18:36analysts are right here making 55. So
  17693. 11:18:38again, we had 630 people take this
  17694. 11:18:41survey. And so the vast majority of them
  17695. 11:18:44were data analyst. So this one's
  17696. 11:18:46probably the most accurate out of all of
  17697. 11:18:47them. And I actually don't like how this
  17698. 11:18:50looks as the clustered bar chart. Let's
  17699. 11:18:52try the stacked bar chart and put this
  17700. 11:18:55as the legend. That's more what I was
  17701. 11:18:57going for. I don't know. I didn't want
  17702. 11:19:00as skinny because when you're doing this
  17703. 11:19:01one, it typically they have multiple
  17704. 11:19:03options per um
  17705. 11:19:06x-axis. And so I think that's why it was
  17706. 11:19:08that little skinny line. But this one is
  17707. 11:19:10more what I was looking for. But let's
  17708. 11:19:12make that smaller. And let's definitely
  17709. 11:19:14change that title cuz good night. Um
  17710. 11:19:17this is like incredibly long. So let's
  17711. 11:19:19go over here to this format visual.
  17712. 11:19:23We'll go to the general the title and
  17713. 11:19:27we're just going to say average
  17714. 11:19:30salary by job title. Just like that. And
  17715. 11:19:36this looks a lot better. Now, we're not
  17716. 11:19:38going to kind of format our whole
  17717. 11:19:41dashboard yet. We're going to create our
  17718. 11:19:42visualizations and then we're going to
  17719. 11:19:44kind of organize everything and kind of
  17720. 11:19:46play Tetris with it to make it look the
  17721. 11:19:48best. So, we're just going to minimize
  17722. 11:19:51this and put it right up here for now.
  17723. 11:19:55Um, but we will go back and kind of make
  17724. 11:19:57everything look better at the end. And
  17725. 11:19:59actually, while we're here, I also want
  17726. 11:20:01to change this as well. So, rename for
  17727. 11:20:05this, we're going to say job title.
  17728. 11:20:08Oops. Why did I do that? Job
  17729. 11:20:13title. And for this one, we're just
  17730. 11:20:16going to say
  17731. 11:20:19average salary.
  17732. 11:20:22There we go. Looks much better, much
  17733. 11:20:24cleaner. Uh, took away a lot of the
  17734. 11:20:27anxiety that I was feeling about 2
  17735. 11:20:29minutes ago when we first put that up
  17736. 11:20:30there. So, let's go on to our second
  17737. 11:20:32visualization. The next one that I'm
  17738. 11:20:34interested in is actually what
  17739. 11:20:36programming language people were using
  17740. 11:20:38the most. So, we have salary. There's a
  17741. 11:20:40thousand different things we can look at
  17742. 11:20:41in here, but I want to know, you know,
  17743. 11:20:43what is people's favorite programming
  17744. 11:20:45language? So, let's take a look at that.
  17745. 11:20:47So, we have favorite programming
  17746. 11:20:50language. Let's find that. So, we have
  17747. 11:20:51our favorite programming language and we
  17748. 11:20:53also have how many people actually took
  17749. 11:20:56it or the unique people. So, right now,
  17750. 11:20:58this is columns. We don't want that.
  17751. 11:21:01Let's um let's do a clustered column
  17752. 11:21:03chart. Click on this right here. And it
  17753. 11:21:07looks like
  17754. 11:21:09here we go. That is kind of what we're
  17755. 11:21:12looking for. And instead of count of
  17756. 11:21:13unique ID, we'll say count of
  17757. 11:21:17let's do count of voters.
  17758. 11:21:21And for favorite programming language,
  17759. 11:21:22we'll say
  17760. 11:21:25favorite oops favorite programming
  17761. 11:21:28language and get rid of that as well.
  17762. 11:21:31And then we're going to go into here
  17763. 11:21:32also and change the title and say
  17764. 11:21:37favorite programming
  17765. 11:21:40languages
  17766. 11:21:41or favorite pro programming language
  17767. 11:21:44just like this. Now let's make this a
  17768. 11:21:46lot bigger so you can see it. But really
  17769. 11:21:48[clears throat] quickly at a glance you
  17770. 11:21:50can see Python is by far the most
  17771. 11:21:52popular are other C++ JavaScript Java.
  17772. 11:21:54Now all we're seeing is the count. So
  17773. 11:21:56it's all the same. It's just blue. We
  17774. 11:21:58can see how many people voted for each
  17775. 11:22:00one. But if we wanted to break it out
  17776. 11:22:01similar to how we did with the job
  17777. 11:22:03titles, we could still do that. So all
  17778. 11:22:06we'd have to do is break it out uh or
  17779. 11:22:07bring this job title down to the legend.
  17780. 11:22:10And now it breaks it out like this. And
  17781. 11:22:12that's not exactly what I was going for.
  17782. 11:22:14I was going more for something like this
  17783. 11:22:17where we can see the still the whole
  17784. 11:22:18count. But now we can see who is
  17785. 11:22:21actually voting for these things. So,
  17786. 11:22:23I'm just not a huge fan of the colors
  17787. 11:22:24that are pre-selected here and kind of
  17788. 11:22:27the whole theme of this dashboard. At
  17789. 11:22:29the very end, we're going to completely
  17790. 11:22:32revamp this, change a bunch of colors,
  17791. 11:22:34the background, and make this look a lot
  17792. 11:22:36nicer rather than just the white
  17793. 11:22:37background like we have it. Um, and so
  17794. 11:22:40for now, let's just
  17795. 11:22:43make this a lot smaller and put it into
  17796. 11:22:46this corner. These will not be staying
  17797. 11:22:48there, but we need to we need room to
  17798. 11:22:50create our next visualizations. and just
  17799. 11:22:52a cleaner space to do things. Now, the
  17800. 11:22:54next thing that I really want to include
  17801. 11:22:56is a way to break down where they're
  17802. 11:22:58from, their country, because especially
  17803. 11:23:00something like salary is very dependent
  17804. 11:23:02on your country. Whereas the average
  17805. 11:23:04salary in the United States for a data
  17806. 11:23:05analyst may be like 60,000. In another
  17807. 11:23:09country, it could be 20,000. That could
  17808. 11:23:11bring down the average quite a bit. So,
  17809. 11:23:13we need a way to be able to break that
  17810. 11:23:15down. Now, we can do something like a
  17811. 11:23:18filled map, and there's no problem with
  17812. 11:23:20that at all. Um, but, you know, for what
  17813. 11:23:24we're building, what we're creating,
  17814. 11:23:26it's not probably going to work out the
  17815. 11:23:28best. I mean, this looks okay. We could
  17816. 11:23:31stick it in the corner or something. Um,
  17817. 11:23:33and you can do that and that's perfectly
  17818. 11:23:34fine. I think what I'm going to do is
  17819. 11:23:36something like a tree map, which I don't
  17820. 11:23:40use a lot, but I want something where
  17821. 11:23:42they can just click on it. They can look
  17822. 11:23:44at the values
  17823. 11:23:46distinct.
  17824. 11:23:48They can look at the values and just
  17825. 11:23:49click on it and it'll be right there for
  17826. 11:23:51them. So they don't have to filter it
  17827. 11:23:53out on their own or know geography and
  17828. 11:23:55look at this map. They can just read
  17829. 11:23:56Canada, other United Kingdom, India,
  17830. 11:23:58United States and click on that. And so
  17831. 11:24:00for example, let's click over here on
  17832. 11:24:02United States. The numbers change quite
  17833. 11:24:04a bit. Now the average salary for a data
  17834. 11:24:06scientist is 139,000. For a data
  17835. 11:24:09analyst, it's 80. And if we look at
  17836. 11:24:11India, you know, the average salary for
  17837. 11:24:14a data scientist is 68. The average
  17838. 11:24:16salary is 26 for a data analyst. That
  17839. 11:24:18doesn't mean that they make less money
  17840. 11:24:20in India. That just means that the cost
  17841. 11:24:22of living is probably lower in India.
  17842. 11:24:24Therefore, they don't need the higher US
  17843. 11:24:26dollars salary because again, this was
  17844. 11:24:28all done in US dollars. So, just
  17845. 11:24:30something to think about. Uh, let's
  17846. 11:24:31click out of that. So, we'll keep that
  17847. 11:24:33one as well. So, now let's create our
  17848. 11:24:35next visualization. This is one that I
  17849. 11:24:37do not get to use enough in my actual
  17850. 11:24:39job. So, we're going to use it in this
  17851. 11:24:40project. Um, and it's going to be this
  17852. 11:24:42gauge right here. So, let's add that
  17853. 11:24:44one. Put it right over here. We're going
  17854. 11:24:46to add two of those. Let's just go ahead
  17855. 11:24:49and add another one while we're at it
  17856. 11:24:52because we're going to have them kind of
  17857. 11:24:53like right here, right next to each
  17858. 11:24:54other. The first one, and these ones are
  17859. 11:24:56really good for kind of looking at these
  17860. 11:24:58kind of surveys, and I don't get to work
  17861. 11:25:00with surveys enough, but we can see, you
  17862. 11:25:02know, how happy are they in terms of
  17863. 11:25:04work life balance. So, we can add that.
  17864. 11:25:07We're going to add work life balance.
  17865. 11:25:08Um, and right now it's doing a count and
  17866. 11:25:11we don't have minimum or maximum values
  17867. 11:25:13in there yet. So, it's going to look
  17868. 11:25:14kind of weird, but we're going to look
  17869. 11:25:15at the average rate or the the average
  17870. 11:25:18score of these. Then, we're going to
  17871. 11:25:20pull this over to the minimum value. We
  17872. 11:25:22want to put that at the minimum and pull
  17873. 11:25:25this over and add the maximum value. So,
  17874. 11:25:28now it actually has 0 to 10. And it
  17875. 11:25:31shows that the average person is happy
  17876. 11:25:34with uh which one was this? The average
  17877. 11:25:36person is happy with their work life
  17878. 11:25:37balance. Uh they rate about a 5.74
  17879. 11:25:40overall. Now let's really quickly change
  17880. 11:25:45the title of this because this is
  17881. 11:25:46ridiculous. I want to say happy with
  17882. 11:25:50work life balance. So this is their
  17883. 11:25:53rating. Uh you know change it to
  17884. 11:25:54whatever title you want. That's what I'm
  17885. 11:25:56going to do. And we'll also do happy
  17886. 11:25:58with their salary. So let's click on
  17887. 11:26:01salary. We'll add that to minimum.
  17888. 11:26:05And we'll add the maximum value as well
  17889. 11:26:07to make sure that we know how to use
  17890. 11:26:09that.
  17891. 11:26:11And then we'll take [clears throat] the
  17892. 11:26:12average. So not many people are happy
  17893. 11:26:14with their salary. I'm just finding out.
  17894. 11:26:15I mean this is a real survey. This is
  17895. 11:26:17real data. So I mean it's uh pretty
  17896. 11:26:19interesting. Let's go to the title.
  17897. 11:26:22Let's go to happy with or maybe it's
  17898. 11:26:25happiness. Happiness with salary. Maybe
  17899. 11:26:29that's what we should make it. And I'm
  17900. 11:26:31going to change that over here as well.
  17901. 11:26:32I think it sounds better.
  17902. 11:26:34Some of this I've already planned out,
  17903. 11:26:36some I haven't. This is not something
  17904. 11:26:37I've planned out. So, uh, so we're going
  17905. 11:26:39to say happiness with work life balance,
  17906. 11:26:41happiness with salary. Really
  17907. 11:26:43interesting. Um, we may go back and
  17908. 11:26:45tweak these just a little bit in the
  17909. 11:26:46future, but the very last visualization
  17910. 11:26:48that we're going to do is male versus
  17911. 11:26:50female. Kind of got to have that in
  17912. 11:26:52there. Um, I don't typically like pie
  17913. 11:26:55charts and doughut charts, but uh, you
  17914. 11:26:57know, I'm feeling I'm just feeling it.
  17915. 11:26:59So, let's try it. Um, and we will do,
  17916. 11:27:04let's see, let's make this larger. So,
  17917. 11:27:06we have male, female,
  17918. 11:27:08and what do we want to look at? Like,
  17919. 11:27:10what do we want to measure? So, we have
  17920. 11:27:11male versus female. We can measure
  17921. 11:27:14anything. Um, but maybe what we'll do is
  17922. 11:27:17the average salary. Again, I mean, we've
  17923. 11:27:19kind of only looked at salary once in
  17924. 11:27:22this one right here. um and a little bit
  17925. 11:27:24of like how happy they are. But we'll
  17926. 11:27:26look at the average salary between males
  17927. 11:27:29and females. And then we'll look at not
  17928. 11:27:33the current age. Oops, I meant average
  17929. 11:27:36salary. And then we'll look at the
  17930. 11:27:39average.
  17931. 11:27:41And it looks like the average salary is
  17932. 11:27:43actually really close versus males
  17933. 11:27:45versus females. 55 for female versus 53
  17934. 11:27:49for males. So actually the females are a
  17935. 11:27:52little bit higher. Uh, congratulations.
  17936. 11:27:53So, they're just a little bit higher in
  17937. 11:27:56terms of pay. So, now we need to start
  17938. 11:27:58organizing all of this, cleaning it up,
  17939. 11:28:00making it look a lot better than it does
  17940. 11:28:02right now. It looks great. Uh, you know,
  17941. 11:28:06but we can do a lot more with this. So,
  17942. 11:28:07I'm going to we're we're going to keep
  17943. 11:28:09these or all these kind of over on this
  17944. 11:28:11left-hand side. I'm going to put this I
  17945. 11:28:14want this up here. We also need to
  17946. 11:28:15change that title. I want this up here.
  17947. 11:28:18Um, and again, we're going to kind of
  17948. 11:28:19change the theme as we go.
  17949. 11:28:23I just want to format it, right?
  17950. 11:28:26I'll have it just like this. Let's
  17951. 11:28:28change the title of this.
  17952. 11:28:32Let's go to title and we're going to say
  17953. 11:28:34country of survey takers.
  17954. 11:28:38Uh I'm not the the survey takers. I'm
  17955. 11:28:40not really stuck on that. If you find
  17956. 11:28:42something better, you think of something
  17957. 11:28:43better, I would go with that. But um you
  17958. 11:28:47know, it definitely doesn't look bad.
  17959. 11:28:48And where did this where did my other
  17960. 11:28:49visualization go? There it goes. Um, I
  17961. 11:28:52think this one I want to make kind of
  17962. 11:28:54more tall. Um, so I might move it this
  17963. 11:28:57way. Jeez, this is such a I hate I hate
  17964. 11:29:00having a lot of visualizations on here.
  17965. 11:29:01It just really uh is annoying to me. So,
  17966. 11:29:04what we're going to do, we're going to
  17967. 11:29:07step this to the side. Put this to the
  17968. 11:29:09side as well.
  17969. 11:29:12Make it to where it's just
  17970. 11:29:16Okay. I didn't want it to cut off.
  17971. 11:29:19We'll do that. Might make these
  17972. 11:29:25these a little bigger actually. So, I
  17973. 11:29:27want it to kind of match the size
  17974. 11:29:31like right there. I'll match this.
  17975. 11:29:34Perfect. This one I kind of want to
  17976. 11:29:36bring over here and bring it down a
  17977. 11:29:40little bit. Maybe something like this.
  17978. 11:29:44Maybe. I'm not sure. I'm not I'm not
  17979. 11:29:46sold on that. Um, I added a few
  17980. 11:29:48different visualizations that I didn't
  17981. 11:29:49have in my original. So, now I'm kind of
  17982. 11:29:51having to do this on the fly. So, um, I
  17983. 11:29:53might fast forward some of the parts
  17984. 11:29:55where I'm like really thinking about it
  17985. 11:29:56or taking too much time on it. But, I'm
  17986. 11:29:58going to bring this down a little bit
  17987. 11:30:00actually because I don't like how close
  17988. 11:30:01that is to, um, the the text above it.
  17989. 11:30:06But one thing we do need to do,
  17990. 11:30:12I'm going to put this up kind of like
  17991. 11:30:14this. I think that looks fine. I think
  17992. 11:30:17I'm going to put this at the very
  17993. 11:30:18bottom. So, let's make some room for it.
  17994. 11:30:22Right. Just like that. Stretch it to the
  17995. 11:30:24side. And we'll lower it.
  17996. 11:30:28And I think we'll keep that as is.
  17997. 11:30:32Kind of like this. Um, okay. There's a
  17998. 11:30:35lot going on in here. And there are some
  17999. 11:30:37things I'm just noticing as we're
  18000. 11:30:39walking through this that I kind of
  18001. 11:30:40missed. Um, like I need to change some
  18002. 11:30:43titles and stuff like that. So, let me
  18003. 11:30:44go ahead and change some of those
  18004. 11:30:46things. So, we're going to do title.
  18005. 11:30:49We're going to do average salary by
  18006. 11:30:54gender or by sex.
  18007. 11:30:58Do like that. Average salary by sex. I
  18008. 11:31:00also don't like that it's in the middle.
  18009. 11:31:03Um, I don't like that it's on the
  18010. 11:31:06outside. I want them on the inside for
  18011. 11:31:07this. So, let's go to the details. Let's
  18012. 11:31:11go to inside and see if that looks any
  18013. 11:31:13better. Oh, that looks terrible. Um, let
  18014. 11:31:16me see if I can change that. Maybe I
  18015. 11:31:18don't. No, I definitely want it. Um, I
  18016. 11:31:23guess we'll do outside. I You can't even
  18017. 11:31:25see the information. Oh, the decimal is
  18018. 11:31:28crazy long. Um, let me go and see if I
  18019. 11:31:30can change that decimal to just like a
  18020. 11:31:32whole number or like 1.1.
  18021. 11:31:35Uh, because that's a problem. So, maybe
  18022. 11:31:37I need to go over here to the value.
  18023. 11:31:42All right. All right. So, I think I want
  18024. 11:31:43to change this one. It's just not
  18025. 11:31:44working out exactly how I wanted. And
  18026. 11:31:47you guys know if I make mistakes, I'm
  18027. 11:31:48going to keep it in here so you guys can
  18028. 11:31:50see it. I I hope that this was going to
  18029. 11:31:52turn out better, but it didn't. Um, one
  18030. 11:31:54that I do want to add because this is
  18031. 11:31:56kind of a a breakdown and a nice
  18032. 11:31:59visualization. I want to add this
  18033. 11:32:00difficulty piece. So, I want to add
  18034. 11:32:02this. How difficult was it for you to
  18035. 11:32:04break into data science? So, let's get
  18036. 11:32:06rid of these. And I want to click on
  18037. 11:32:08this really quickly. See what it gives
  18038. 11:32:09us. Um, bum values. Okay. So now this
  18039. 11:32:15shows us percentages um of how easy it
  18040. 11:32:18was. Again, it's neither easy nor
  18041. 11:32:20difficult. Difficult, easy, very
  18042. 11:32:22difficult, very easy. These numbers make
  18043. 11:32:25absolutely no sense. We need to kind of
  18044. 11:32:27order them a little better. So I'm going
  18045. 11:32:29to come over here to slices. We have our
  18046. 11:32:31colors over here. We want very difficult
  18047. 11:32:34to be like the most difficult. Um so
  18048. 11:32:38we're going to make that red.
  18049. 11:32:41And then we want difficult to be maybe
  18050. 11:32:43like an orange.
  18051. 11:32:45Let's see if we can find an orange.
  18052. 11:32:46There we have an orange. This does not
  18053. 11:32:48look red enough. There we go. Oh, no,
  18054. 11:32:52no, no. Very difficult is red. Difficult
  18055. 11:32:54is orange. We have neither easy nor
  18056. 11:32:57difficult. And that's kind of a neutral.
  18057. 11:32:59Um, let's see if we have something
  18058. 11:33:00neutral in here.
  18059. 11:33:04Kind of like this yellow. I don't know.
  18060. 11:33:06Let's try it out. Then we have easy and
  18061. 11:33:09very easy. And these will be like our
  18062. 11:33:11blues. So, I'm going to keep that um I'm
  18063. 11:33:15going to keep that kind of like a dark
  18064. 11:33:18blueish.
  18065. 11:33:20And then our blue for super easy is just
  18066. 11:33:23going to be like really blue. Um and
  18067. 11:33:28that doesn't look bad. The I mean, look,
  18068. 11:33:29I'm I'm not a color person. I I'm not
  18069. 11:33:32great with colors, and we're going to
  18070. 11:33:34kind of organize this in just a little
  18071. 11:33:35bit, but this looks better to me. Um,
  18072. 11:33:38but we need to change up some stuff as
  18073. 11:33:40well, like the title. Need to do
  18074. 11:33:44difficulty to break into data.
  18075. 11:33:50There we go. And we're also going to
  18076. 11:33:53change
  18077. 11:33:54this title right here. We'll just say
  18078. 11:33:57difficulty.
  18079. 11:34:00Difficulty.
  18080. 11:34:02This looks better to me. Um, again, not
  18081. 11:34:05perfect and there's a thousand different
  18082. 11:34:07things you could have done, but that's
  18083. 11:34:08just what we're going to do. I need to
  18084. 11:34:09go through here and see what I need to
  18085. 11:34:11change. So, right off the bat, I can see
  18086. 11:34:12I need to change this um
  18087. 11:34:16to let's see right here. I'm going to
  18088. 11:34:19rename this job title just like we did
  18089. 11:34:23in this one right here. Uh, count of
  18090. 11:34:26voters. That's fine. Programming
  18091. 11:34:29language breaking into difficulty,
  18092. 11:34:31happiness, happiness, average count.
  18093. 11:34:33Okay. Okay. So, what we have here is
  18094. 11:34:38very close to a finished product. Now,
  18095. 11:34:41it's not 100% complete. I mean, I I do
  18096. 11:34:44want to make it look a little nicer
  18097. 11:34:46rather than just the typical white. So,
  18098. 11:34:48what we're going to do, we're going to
  18099. 11:34:50go up here. We'll go to uh what is it?
  18100. 11:34:53View. And we have all these different
  18101. 11:34:55filters. And we're just going to play
  18102. 11:34:56around with it. See if we can find
  18103. 11:34:58something that we like. Um,
  18104. 11:35:01this doesn't look too bad. It's uh not
  18105. 11:35:04really my style. Uh, we can do this one.
  18106. 11:35:07Frontier. This is pretty neat. I kind of
  18107. 11:35:10am digging this. We might come back to
  18108. 11:35:12it. I like the natural tones. I don't
  18109. 11:35:14know why I said tones like that, but I
  18110. 11:35:16did. Um, this one's [clears throat] not
  18111. 11:35:19bad, but I don't I don't It's not That's
  18112. 11:35:22not my I don't like how dark that is.
  18113. 11:35:24Um, and so maybe it's like, you know,
  18114. 11:35:28uh, we change like the background color
  18115. 11:35:30of all of these as well as match it with
  18116. 11:35:33um, match it with something else.
  18117. 11:35:36Whatever you want, genuinely, you
  18118. 11:35:38customize this however you want. I kind
  18119. 11:35:40of like this one. It's kind of groovy,
  18120. 11:35:42man. And, um, it's [clears throat] not
  18121. 11:35:44perfect by any means, but what we can
  18122. 11:35:48do, and we can customize this current
  18123. 11:35:49theme. We can come in here, customize
  18124. 11:35:51this theme however we'd like. I
  18125. 11:35:55personally [clears throat] don't want
  18126. 11:35:56color five, which is the data analyst
  18127. 11:35:58color. I don't like it to I don't want
  18128. 11:36:01to go go and change it because I don't
  18129. 11:36:03like it, but I don't really like that
  18130. 11:36:04color per se. You know, I might want to
  18131. 11:36:07choose a different color. Um, but it has
  18132. 11:36:09to be like this muted like that. It has
  18133. 11:36:11a style to it. So, you can come in here
  18134. 11:36:14and you can customize this and make it
  18135. 11:36:16however you'd like and and really mess
  18136. 11:36:19around with it. Play around with it. For
  18137. 11:36:21me, uh I'm just going to keep it how it
  18138. 11:36:23is because I don't really want to mess
  18139. 11:36:25with it and break it or anything like
  18140. 11:36:26that. So, let me just up just a tiny
  18141. 11:36:30bit. So, this is it. This is the
  18142. 11:36:33project. I hope that it was helpful. Um
  18143. 11:36:36I am not joking when I say that I'm
  18144. 11:36:39because I'm going to do a different
  18145. 11:36:40project. I'm gonna go really in depth in
  18146. 11:36:42another project. It's probably gonna be
  18147. 11:36:44like a two-hour project. It's gonna be
  18148. 11:36:45crazy long. Um well, for a YouTube
  18149. 11:36:47video, but I can see doing a thousand
  18150. 11:36:51different things with this data,
  18151. 11:36:52creating a really great dashboard,
  18152. 11:36:55really cleaning the data, which is a
  18153. 11:36:57large part of of actually doing this.
  18154. 11:36:59And we didn't do much data cleaning at
  18155. 11:37:01all. There's just so much you can do
  18156. 11:37:02with this. And so, really dig into this.
  18157. 11:37:04See what you like, see what you don't
  18158. 11:37:06like, see what you want to clean, what
  18159. 11:37:08you don't want to clean. You could put
  18160. 11:37:09it in SQL. You could put it in um Excel
  18161. 11:37:12and just and just standardize the data
  18162. 11:37:15to make it a lot more usable. Do
  18163. 11:37:17whatever you want with it. I mean, I I
  18164. 11:37:19took this survey for you guys that we
  18165. 11:37:20could use it. So, go out and use it and
  18166. 11:37:24make the best dashboard that you can
  18167. 11:37:26possibly do. So, I hope that this was
  18168. 11:37:28helpful. I hope that you enjoyed this.
  18169. 11:37:29Thank you so much for watching this
  18170. 11:37:32video. If you like this Thank you so
  18171. 11:37:35much for watching. If you like this
  18172. 11:37:36video, be sure to like and subscribe
  18173. 11:37:38below, and I'll see you in the next
  18174. 11:37:39video.
  18175. 11:37:41[music]
  18176. 11:37:52What's going on everybody? Welcome back
  18177. 11:37:53to another video. Today, we're going to
  18178. 11:37:55be starting our Python tutorial series.
  18179. 11:38:02Now, I am extremely excited for this
  18180. 11:38:04series. We're going to be walking
  18181. 11:38:06through all the things that you need to
  18182. 11:38:07know to get started in Python. We'll be
  18183. 11:38:09looking at variables, data types, for
  18184. 11:38:11loops, y loops, operators, and a ton
  18185. 11:38:14more. After this beginner series, we're
  18186. 11:38:15going to be going into another set of
  18187. 11:38:17series where we look at pandas, mapplot,
  18188. 11:38:19lib, seabor, web scraping, and more.
  18189. 11:38:21Now, in this video, we're just going to
  18190. 11:38:23be setting up our environment to where
  18191. 11:38:24we can learn Python in future videos. In
  18192. 11:38:26this series, we're going to be using
  18193. 11:38:27Jupyter Notebooks for all of our
  18194. 11:38:28tutorials because I feel like it's a
  18195. 11:38:30really great place to learn the basics.
  18196. 11:38:32But then in future videos, I'll show you
  18197. 11:38:33different IDEs that you can use for your
  18198. 11:38:35Python code. I genuinely cannot wait to
  18199. 11:38:37get started on this series. I absolutely
  18200. 11:38:38love Python. So without further ado,
  18201. 11:38:40let's jump on my screen. I'm going to
  18202. 11:38:42show you how to install Jupyter
  18203. 11:38:43Notebooks. All right, so let's get
  18204. 11:38:44started by downloading Anaconda.
  18205. 11:38:46Anaconda is an open- source distribution
  18206. 11:38:48of Python and our products. So within
  18207. 11:38:51Anaconda is our Jupyter notebooks as
  18208. 11:38:53well as a lot of other things, but we're
  18209. 11:38:54going to be using it for our Jupyter
  18210. 11:38:56notebooks. So let's go right down here.
  18211. 11:38:58And if I hit download, it's going to
  18212. 11:38:59download for me because I'm on Windows.
  18213. 11:39:02But if you want additional installers,
  18214. 11:39:03if you're running on Mac or Linux, then
  18215. 11:39:06you can get those all right here. Now,
  18216. 11:39:08if you are running on Windows, just make
  18217. 11:39:09sure to check your system to see if it's
  18218. 11:39:11a 32-bit or a 64. You can go into your
  18219. 11:39:14about in your system settings to find
  18220. 11:39:16that information. I'm going to click on
  18221. 11:39:18this 64-bit.
  18222. 11:39:20It's going to pop up on my screen right
  18223. 11:39:22here, and I'm going to click save.
  18224. 11:39:25Now, it's going to start downloading it.
  18225. 11:39:26It says it could take a little while,
  18226. 11:39:28but honestly, it's going to take
  18227. 11:39:29probably about 2 to 3 minutes, and then
  18228. 11:39:31it will get going. Now that it's done,
  18229. 11:39:33I'm just going to click on it, and it's
  18230. 11:39:35going to pull up this window right here.
  18231. 11:39:37We are just going to click next because
  18232. 11:39:38we want to install it. This is our
  18233. 11:39:40license agreement. You can read through
  18234. 11:39:42this if you would like. I will not. I'm
  18235. 11:39:44just going to click I agree. Now we can
  18236. 11:39:47select our installation type. And you
  18237. 11:39:49can either select it for just me or if
  18238. 11:39:50you have multiple admin or users on one
  18239. 11:39:53laptop, you can do that as well. For me,
  18240. 11:39:56it's just me, so I'm going to use this
  18241. 11:39:58one as it recommends. Now, it's going to
  18242. 11:40:00show you where it's installing it on
  18243. 11:40:01your computer. This is the actual file
  18244. 11:40:04path. It's going to take about 3.5 gigs
  18245. 11:40:07of space. I have plenty of space, but
  18246. 11:40:09make sure you have enough space. And
  18247. 11:40:10then once you do, you can come right
  18248. 11:40:12over here to next. And now we can do
  18249. 11:40:15some advanced options. We can add
  18250. 11:40:17Anaconda 3 to my path environment
  18251. 11:40:20variable. And when you're using Python,
  18252. 11:40:22you typically have a default path with
  18253. 11:40:25whatever Python IDE or notebook that
  18254. 11:40:28you're using. I use a lot of Visual
  18255. 11:40:30Studio Code. So if I do this, I'm
  18256. 11:40:32worried it might mess something up. So I
  18257. 11:40:34am not going to do this. It also says it
  18258. 11:40:36doesn't recommend it. Again, messing
  18259. 11:40:37with these paths is kind of something
  18260. 11:40:39that you might want to do once you know
  18261. 11:40:40more about Python. So, I don't really
  18262. 11:40:42recommend you having this checked. We
  18263. 11:40:44can also register Anaconda 3 as my
  18264. 11:40:46default Python 3.9. You can do this one.
  18265. 11:40:50And I'm going to keep it this way just
  18266. 11:40:51so I have the exact same settings as you
  18267. 11:40:53do. So, let's go ahead and click
  18268. 11:40:54install. And now, it is going to
  18269. 11:40:57actually install this on your computer.
  18270. 11:40:59Now, once that's complete, we can hit
  18271. 11:41:01next. And now, we're going to hit next
  18272. 11:41:03again. And finally, we're going to hit
  18273. 11:41:06finish. But if you want to, you can have
  18274. 11:41:08this tutorial and this getting started
  18275. 11:41:10with Anaconda. I don't want either of
  18276. 11:41:13them cuz I don't need them. But if you
  18277. 11:41:15would like to have those, keep those
  18278. 11:41:16checked and you can get those. Let's
  18279. 11:41:18click finish. Now, let's go down and
  18280. 11:41:20we're going to search for Anaconda and
  18281. 11:41:23it'll say Anaconda Navigator and we're
  18282. 11:41:26going to click on that and it should
  18283. 11:41:28open up for us. So, this is what you
  18284. 11:41:30should be seeing on your screen. This is
  18285. 11:41:31the Anaconda Navigator and this is where
  18286. 11:41:34that distribution of Python and R is
  18287. 11:41:37going to be. So we have a lot of
  18288. 11:41:38different options in here and some of
  18289. 11:41:40them may look familiar. We have things
  18290. 11:41:42like Visual Studio Code, Spider, R
  18291. 11:41:45Studio, and then right up here we have
  18292. 11:41:47our Jupyter notebooks and this is what
  18293. 11:41:50we're going to be using throughout our
  18294. 11:41:51tutorials. So let's go ahead and click
  18295. 11:41:53on launch. And this is what should kind
  18296. 11:41:55of pop up on your screen. Now I've been
  18297. 11:41:57using this a lot. Um, so I have a ton of
  18298. 11:41:59notebooks and files in here. But if you
  18299. 11:42:03are just now seeing this, it might be
  18300. 11:42:04completely blank or just have some, you
  18301. 11:42:07know, default folders in here. But this
  18302. 11:42:09is where we're going to open up a new
  18303. 11:42:11Jupyter notebook where we can write code
  18304. 11:42:13and all the things that we're going to
  18305. 11:42:14be learning in future tutorials. And you
  18306. 11:42:16can use this area to save things and
  18307. 11:42:19create folders and organize everything.
  18308. 11:42:21If you already have some notebooks from
  18309. 11:42:23previous projects or something, you can
  18310. 11:42:25upload them here. But what we're going
  18311. 11:42:26to do is go right to this new. We're
  18312. 11:42:29going to click on the dropdown and we're
  18313. 11:42:30going to open up a Python 3 kernel. And
  18314. 11:42:33so we're going to open this up right
  18315. 11:42:34here. Now, right here is where we're
  18316. 11:42:36going to be spending 99% of our time in
  18317. 11:42:39future videos. This is where we're going
  18318. 11:42:41to write all of our code. So right here
  18319. 11:42:43is a cell and this is where we can type
  18320. 11:42:45things. So I can say print. I can do the
  18321. 11:42:48famous hello world and then I'll run
  18322. 11:42:51that by clicking shift enter. And this
  18323. 11:42:53is where all of our code is going to go.
  18324. 11:42:55These are called cells. So each one of
  18325. 11:42:58these are a cell. And we have a ton of
  18326. 11:42:59stuff up here. And I'm going to get to
  18327. 11:43:01that in just a second. But one thing I
  18328. 11:43:03wanted to show you is that you don't
  18329. 11:43:04only have to write code here. You can
  18330. 11:43:06also do something called markdown. And
  18331. 11:43:08so markdown is its own kind of you could
  18332. 11:43:10say language, but um it's just a
  18333. 11:43:12different way of writing, especially
  18334. 11:43:13within a notebook. So all we're going to
  18335. 11:43:15do is do this little hashtag. And
  18336. 11:43:18actually I think it's a pound sign, but
  18337. 11:43:19I'm going to call it hashtag. We're
  18338. 11:43:20going to do that. We're going to say
  18339. 11:43:22first notebook. And then if I run that,
  18340. 11:43:25we have our first notebook. And we can
  18341. 11:43:26make little comments and little notes
  18342. 11:43:27like that that don't actually run any
  18343. 11:43:29code. They just kind of organize things
  18344. 11:43:31for us. And I'm going to do that in a
  18345. 11:43:33lot of our future videos. So, just
  18346. 11:43:34wanted to show you how to do that. Now,
  18347. 11:43:35let's look right up here. A lot of these
  18348. 11:43:37things are pretty important. Uh, one of
  18349. 11:43:40the first things that's really important
  18350. 11:43:41is actually saving this. So, let's say
  18351. 11:43:43we wanted to change the title to I'm
  18352. 11:43:45going to do a aaa because I want it to
  18353. 11:43:47be at the beginning. Um, so I can show
  18354. 11:43:49you this. I'm going do a aaa new
  18355. 11:43:51notebook and I'm going to rename it and
  18356. 11:43:54then I'm going to save that. So if I go
  18357. 11:43:56right back over here, you can see a aaa
  18358. 11:43:59new notebook. That green means that it's
  18359. 11:44:02currently running. And when I say
  18360. 11:44:04running, I mean right up here. And if we
  18361. 11:44:07wanted to, we go ahead and shut that
  18362. 11:44:08down, which means it wouldn't run the
  18363. 11:44:10code anymore. And then we'd have to run
  18364. 11:44:12up a new cluster. Uh so let's go ahead
  18365. 11:44:14and do that. I didn't plan on doing
  18366. 11:44:15that, but let's do it. So we have no
  18367. 11:44:17notebooks running. And right here it
  18368. 11:44:19says we have a dead kernel. So this was
  18369. 11:44:21our Python 3 kernel. And now since I
  18370. 11:44:24stopped it, it's no longer processing
  18371. 11:44:25anything. So let's go ahead and say try
  18372. 11:44:27restarting now.
  18373. 11:44:30And it says kernel is ready. So it's
  18374. 11:44:32back up and running and we're good to
  18375. 11:44:34go. The next thing is this button right
  18376. 11:44:36here. Now this is an insert cell below.
  18377. 11:44:38So if I have a lot of code I know I'm
  18378. 11:44:40going to be writing, I can click a lot
  18379. 11:44:42of that. And I often do that because I
  18380. 11:44:44just don't like having to do that all
  18381. 11:44:46the time. So I make a bunch of cells
  18382. 11:44:48just so I can use them. You can also
  18383. 11:44:50delete cells. So say we have some code
  18384. 11:44:52here. We'll say here and we have code
  18385. 11:44:56here. And then we have this empty cell
  18386. 11:44:58right here. We can just get rid of that
  18387. 11:44:59by doing this cut selected cells. We can
  18388. 11:45:02also copy selected cells. So if I hit
  18389. 11:45:04copy selected cells and I can go right
  18390. 11:45:07here and say paste selected cells. And
  18391. 11:45:10as you can see it pasted that exact same
  18392. 11:45:12cell. You can also move this up and
  18393. 11:45:14down. So, I can actually take this one
  18394. 11:45:16and say I wanted it in this location. I
  18395. 11:45:19can take this cell and move it up or I
  18396. 11:45:21can move it down. And that's just an
  18397. 11:45:23easy way to kind of organize it. Instead
  18398. 11:45:25of having to like copy this and moving
  18399. 11:45:27it right down here and pasting it, you
  18400. 11:45:28can just take this cell and move it up,
  18401. 11:45:30which is really nice. Now, earlier when
  18402. 11:45:32I ran this code right here, I hit shift
  18403. 11:45:35enter. You can also run and it'll run
  18404. 11:45:37the cell below. So, you can hit run and
  18405. 11:45:39it works properly. If you're running a
  18406. 11:45:41script and it's taking forever and it's
  18407. 11:45:43not working properly, at least it's you
  18408. 11:45:45don't think it's working properly, you
  18409. 11:45:47can stop that by doing this interrupt
  18410. 11:45:49the kernel right here and anything
  18411. 11:45:51you're trying to do within this kernel
  18412. 11:45:52if it's just not working properly, it'll
  18413. 11:45:54stop it. You can restart it. Then you
  18414. 11:45:56can try fixing your code. You can also
  18415. 11:45:58hit this button if you want to restart
  18416. 11:45:59your kernel and this button if you want
  18417. 11:46:01to restart the kernel and then rerun the
  18418. 11:46:03entire notebook. As we talked about just
  18419. 11:46:06a second ago, we have our code and our
  18420. 11:46:08markdown code. We're not going to talk
  18421. 11:46:10about either of these because we're not
  18422. 11:46:11going to use that throughout the entire
  18423. 11:46:13series. The next thing I want to show
  18424. 11:46:14you is right up here. If you open this
  18425. 11:46:17file, we can create a new notebook. We
  18426. 11:46:19can open an existing notebook. We can
  18427. 11:46:21copy it, save it, rename it, all that
  18428. 11:46:23good stuff. We can also edit it. So, a
  18429. 11:46:26lot of these things that we were talking
  18430. 11:46:27about, you can cut the cells and copy
  18431. 11:46:28the cells using these shortcuts if you
  18432. 11:46:30would like to. We also go to view and
  18433. 11:46:32you can toggle a lot of these things if
  18434. 11:46:34you would like to, which just means
  18435. 11:46:35it'll show it or not show it depending
  18436. 11:46:37on what you want. So, if we toggle this
  18437. 11:46:38toolbar, it'll take away the toolbar for
  18438. 11:46:41us. Or if we go back and we toggle the
  18439. 11:46:43toolbar, we can bring it back. We can
  18440. 11:46:45also insert a few different things like
  18441. 11:46:47inserting a cell above or a cell below.
  18442. 11:46:49So, instead of saying this plus button,
  18443. 11:46:51you can just say A or B, routing above
  18444. 11:46:54or below. We also have the cell in which
  18445. 11:46:56we can run our cells or run all of them
  18446. 11:46:58or all above or all below. And then we
  18447. 11:47:01have our kernels right here, which we
  18448. 11:47:03were talking about earlier where we can
  18449. 11:47:04interrupt it and restart those. There
  18450. 11:47:06are widgets. We're not going to be
  18451. 11:47:08looking at any widgets in this series,
  18452. 11:47:10but if it's something you're interested
  18453. 11:47:11in, you can definitely do that. Then we
  18454. 11:47:13have help. So, if you are looking for
  18455. 11:47:15some help on any of these things,
  18456. 11:47:16especially some of these references,
  18457. 11:47:17which are really nice, you can use
  18458. 11:47:19those. And you can also edit your own
  18459. 11:47:21keyboard shortcuts. And now that we
  18460. 11:47:23walked through all of that, you now have
  18461. 11:47:24Anaconda and Jupyter Notebooks installed
  18462. 11:47:26on your computer in future videos. This
  18463. 11:47:28is where we're going to be writing all
  18464. 11:47:29of our Python code. So, be sure to check
  18465. 11:47:31those out so we can learn Python
  18466. 11:47:32together. Thank you guys so much for
  18467. 11:47:33watching. I hope you were able to get
  18468. 11:47:34everything installed correctly. I am
  18469. 11:47:36super excited for this series ahead of
  18470. 11:47:38us. If you like this video, be sure to
  18471. 11:47:40like and subscribe below and I will see
  18472. 11:47:41you in the next video.
  18473. 11:47:44[music]
  18474. 11:47:53[snorts]
  18475. 11:47:54Hello everybody. Today we're going to be
  18476. 11:47:56learning about variables in Python. A
  18477. 11:47:58variable is basically just a container
  18478. 11:48:00for storing data values. So you'll take
  18479. 11:48:03a value like a number or a string and
  18480. 11:48:05you can assign it to a variable and then
  18481. 11:48:07the variable will carry and contain
  18482. 11:48:10whatever you put into it. So for
  18483. 11:48:12example, let's go right over here. We're
  18484. 11:48:14going to say x and this is going to be
  18485. 11:48:16our variable. We're going to say is
  18486. 11:48:17equal to. Now we can assign the value to
  18487. 11:48:20it. So let's say I want to put 22. X is
  18488. 11:48:25now equal to 22. So we won't have to
  18489. 11:48:28write out the number 22 in later scripts
  18490. 11:48:30that we write. we can just say x because
  18491. 11:48:32x is equal to 22. It now contains that
  18492. 11:48:36number. So now we can hit enter and say
  18493. 11:48:38print. We'll do an open parenthesis and
  18494. 11:48:41we'll say x. Now I'm going to hit shift
  18495. 11:48:43enter. And now it prints out that 22
  18496. 11:48:46because we are printing x and x is equal
  18497. 11:48:49to 22. This is our value and this is our
  18498. 11:48:52variable. One really great thing about
  18499. 11:48:54variables is that it assigns its own
  18500. 11:48:56data type. It's going to automatically
  18501. 11:48:58do this. So, we didn't have to go and
  18502. 11:49:00tell X that it's an integer. It just
  18503. 11:49:02automatically knew that 22 is a number.
  18504. 11:49:04So, we can check that by saying type and
  18505. 11:49:07then open parenthesis and writing X. And
  18506. 11:49:10we'll do shift enter again. And this
  18507. 11:49:13says that X is an integer type. Now, we
  18508. 11:49:15only assigned an integer to X. Let's try
  18509. 11:49:19assigning a string value or some text to
  18510. 11:49:21a variable. So, we'll say Y is equal to
  18511. 11:49:25uh let's say mint chocolate chip. I'm
  18512. 11:49:28feeling some ice cream today. So, we'll
  18513. 11:49:30say mint chocolate chip. Now, if we
  18514. 11:49:33print that again, we'll do print open
  18515. 11:49:36parenthesis y and do shift enter. It'll
  18516. 11:49:39print mint chocolate chip. And if we
  18517. 11:49:42look at the type, we can see that the
  18518. 11:49:44type is a string this time and not an
  18519. 11:49:47integer. Now, again, we did not tell it
  18520. 11:49:49that x was an integer and y was a
  18521. 11:49:51string. It just automatically knew this.
  18522. 11:49:54Let's go over here really quickly. We're
  18523. 11:49:56going to add several rows in here
  18524. 11:49:57because we're about to write a lot of
  18525. 11:50:00different variables and really learn
  18526. 11:50:02in-depth how to use variables. The next
  18527. 11:50:04thing to know about variables is that
  18528. 11:50:05you can overwrite previous variables.
  18529. 11:50:08Right now we have mint chocolate chip
  18530. 11:50:10and that is assigned to the variable y.
  18531. 11:50:12So if I go down here, I say print y, I
  18532. 11:50:16hit shift enter, it's going to print out
  18533. 11:50:18mint chocolate chip. But if I go right
  18534. 11:50:20above it, I say y is equal to and let's
  18535. 11:50:24say chocolate. If I print that out, it's
  18536. 11:50:28now going to say chocolate. Whereas up
  18537. 11:50:29here, I'm reassigning it to y, it's
  18538. 11:50:32still going to say mint chocolate chip.
  18539. 11:50:35So if I come right down here and I copy
  18540. 11:50:39this, and I'm going to paste this right
  18541. 11:50:41here. Initially, it is going to assign Y
  18542. 11:50:43to chocolate. But then right here it
  18543. 11:50:46will automatically overwrite Y as mint
  18544. 11:50:48chocolate chip. And when we hit shift
  18545. 11:50:50enter it's going to show mint chocolate
  18546. 11:50:52chip. Variables are also case sensitive.
  18547. 11:50:55So if I come up here and I say a capital
  18548. 11:50:58Y, this is a lowercase Y and this is a
  18549. 11:51:00capital Y. It is going to print out the
  18550. 11:51:03correct one instead of mint chocolate
  18551. 11:51:05chip. And then if I go down here to the
  18552. 11:51:07print and I type the capital Y, it will
  18553. 11:51:11give us the mint chocolate chip. Up till
  18554. 11:51:13now, we've only assigned one value to
  18555. 11:51:15one variable. But we can actually assign
  18556. 11:51:18multiple values to multiple variables.
  18557. 11:51:21So let's do x comma y comma z is equal
  18558. 11:51:26to and now we can assign multiple values
  18559. 11:51:29to all of those. So we can say chocolate
  18560. 11:51:34and then we'll do a comma. Oops, a
  18561. 11:51:37comma. Then we can say vanilla and then
  18562. 11:51:41we'll do another comma and we'll say
  18563. 11:51:44rocky road. Now this is going to assign
  18564. 11:51:48chocolate to x, vanilla to y and rocky
  18565. 11:51:51road to z. So what we can do is we'll
  18566. 11:51:54say print and we'll go print print.
  18567. 11:51:59We'll say x y and z. So it prints out
  18568. 11:52:04chocolate, vanilla, and rocky road. And
  18569. 11:52:06these are our three different values. We
  18570. 11:52:09can also assign multiple variables to
  18571. 11:52:11one value. And we can do this by saying
  18572. 11:52:14x is equal to y is equal to z is equal
  18573. 11:52:17to and we can put whatever we would
  18574. 11:52:19like. Let's do root beer bloat. Then
  18575. 11:52:23we'll come back up here. We'll copy this
  18576. 11:52:27and let's print off our x, our y, and z.
  18577. 11:52:30And they are all the exact same. Now, so
  18578. 11:52:33far we've really only looked at integers
  18579. 11:52:34and strings, but you can assign things
  18580. 11:52:37like lists, dictionaries, tupils, and
  18581. 11:52:39sets all to variables as well. So, let's
  18582. 11:52:42go right down here. So, let's create our
  18583. 11:52:44very first list. I'm going to say ice
  18584. 11:52:47cream is equal to, and that is our
  18585. 11:52:49variable right there. The ice cream is
  18586. 11:52:51our variable. So, now we're going to do
  18587. 11:52:53an open bracket like this. And we're
  18588. 11:52:56going to come up here and copy all of
  18589. 11:52:58these values and we're going to stick it
  18590. 11:53:00within our list. So now within ice cream
  18591. 11:53:04we have three string values chocolate
  18592. 11:53:06vanilla and rocky road all within this
  18593. 11:53:09list. So what we can do is we can say x
  18594. 11:53:13comma y comma z is equal to ice cream.
  18595. 11:53:19So now these three values chocolate
  18596. 11:53:21vanilla and rocky road will be assigned
  18597. 11:53:23to these three variables x y and z. And
  18598. 11:53:26we can copy this print up here and we'll
  18599. 11:53:30hit shift enter. And now the X, Y, and Z
  18600. 11:53:34all were assigned these values of
  18601. 11:53:36chocolate, vanilla, and rocky road. Now
  18602. 11:53:38something that we just did which is
  18603. 11:53:40really important or something that you
  18604. 11:53:41really need to consider is how you name
  18605. 11:53:43your variables. So right here we have
  18606. 11:53:46ice cream. Now this to me is exactly how
  18607. 11:53:49I usually write my variables. But there
  18608. 11:53:52are many different ways that you can
  18609. 11:53:53write your variables. So, let's take a
  18610. 11:53:54look at that really quickly and let's
  18611. 11:53:57add just a few more because I have a
  18612. 11:53:59feeling we're going to go a little bit
  18613. 11:54:00longer than what we have. So, there are
  18614. 11:54:02a few best practices for naming
  18615. 11:54:04variables. First, I'm going to show you
  18616. 11:54:05kind of what a lot of people will do.
  18617. 11:54:08I'll show you some good practices and
  18618. 11:54:09I'm going to show you some bad practices
  18619. 11:54:11as well that you should avoid doing. The
  18620. 11:54:14first thing that we're going to look at
  18621. 11:54:14is something called camel case. And
  18622. 11:54:17let's say we want to name it test
  18623. 11:54:20variable case. Oops. Case. Now if we
  18624. 11:54:24have a test variable case, the camel
  18625. 11:54:26case is going to look like this. We'll
  18626. 11:54:28have lowercase test and then we'll have
  18627. 11:54:30uppercase variable and uppercase case is
  18628. 11:54:34equal to. This is what this variable is
  18629. 11:54:37going to look like. And we can assign it
  18630. 11:54:39vanilla swirl.
  18631. 11:54:43And this is what your camel case will
  18632. 11:54:45look like. It's going to be lowercase.
  18633. 11:54:47And then all the rest of those uh
  18634. 11:54:49compound words or however you want to
  18635. 11:54:50say that, these letters are going to be
  18636. 11:54:52capitalized to kind of separate where
  18637. 11:54:54the words end and begin. Let's go right
  18638. 11:54:56down here. We're going to copy this. The
  18639. 11:54:59next one is called Pascal case. So
  18640. 11:55:02Pascal case is going to look just a
  18641. 11:55:04little bit different. Instead of the
  18642. 11:55:06lowercase at test, it's going to be a
  18643. 11:55:08capital T in test. So test variable
  18644. 11:55:11case. Again, this is a very similar way
  18645. 11:55:14of writing it. Very similar to camel
  18646. 11:55:15case. um but just a capital at the
  18647. 11:55:18beginning. Now, let's look at the last
  18648. 11:55:20one. And this one is my personal
  18649. 11:55:22favorite. This one is going to be the
  18650. 11:55:24snake case. Now, this one is quite a bit
  18651. 11:55:27different in the fact that you don't use
  18652. 11:55:29any capital letters and you separate
  18653. 11:55:32everything using underscore. So, we're
  18654. 11:55:34going to write test
  18655. 11:55:36variable_case.
  18656. 11:55:39Now, typically, let me have them all in
  18657. 11:55:41there. Typically, these are the best
  18658. 11:55:43practices. These are what you typically
  18659. 11:55:46want to do, but probably the best one to
  18660. 11:55:49use is this snake case right here. What
  18661. 11:55:52a lot of people say is that it improves
  18662. 11:55:54readability. If you take a look at
  18663. 11:55:56either the camel case or the Pascal
  18664. 11:55:58case, which you will see people do, it's
  18665. 11:56:01not as easy to distinguish exactly what
  18666. 11:56:03it says. And the name of a variable is
  18667. 11:56:06important because you can gain
  18668. 11:56:07information from it if people name them
  18669. 11:56:09appropriately. So when I'm naming
  18670. 11:56:11variables, I usually write it in snake
  18671. 11:56:13case because I just find it a lot easier
  18672. 11:56:15to read because each word is broken up
  18673. 11:56:18by this underscore. So now let's look at
  18674. 11:56:20some good variable names. These are all
  18675. 11:56:22ones that you can use or could use. So
  18676. 11:56:24let's do something like test var. So
  18677. 11:56:27test var is completely appropriate. We
  18678. 11:56:30can also do something like test_var
  18679. 11:56:33oops underscore. We could do underscore
  18680. 11:56:37test_var.
  18681. 11:56:39You'll see that often as well where
  18682. 11:56:41people will start it with an underscore.
  18683. 11:56:44You can do test var
  18684. 11:56:49capital T oops capital T capital V in
  18685. 11:56:54test var or you could even do something
  18686. 11:56:56like test
  18687. 11:56:58var 2. Now adding a number to your
  18688. 11:57:01variable is not inherently a bad thing.
  18689. 11:57:03Usually it's semifowned upon but there
  18690. 11:57:06are definitely some use cases where you
  18691. 11:57:07can use it. But one thing that you
  18692. 11:57:10cannot do is do something like
  18693. 11:57:14putting the two at the front. If you put
  18694. 11:57:16the two at the front, it no longer
  18695. 11:57:17works. It won't run properly at all. So,
  18696. 11:57:20we're going to take that out. So, we
  18697. 11:57:22can't do that. So, I'm going to use this
  18698. 11:57:23as an example of what you should not do.
  18699. 11:57:25You also can't use a dash. So, something
  18700. 11:57:28like test dash var 2. That doesn't work
  18701. 11:57:32either. And you also can't use something
  18702. 11:57:35like a space
  18703. 11:57:38or a comma or really any kind of symbol
  18704. 11:57:41like a period or a backslash or equal
  18705. 11:57:44sign. None of those things will work
  18706. 11:57:46within your variable. Now, another thing
  18707. 11:57:48that you can do within your variable is
  18708. 11:57:50use the plus sign. So, let's assign
  18709. 11:57:52this. We'll say x is equal to and we'll
  18710. 11:57:56do a string. We'll say ice cream
  18711. 11:57:59is my favorite.
  18712. 11:58:02and then we'll do a plus sign and we'll
  18713. 11:58:05say period. Now what this will do is it
  18714. 11:58:08will literally add these two strings
  18715. 11:58:11together. So let's do print and we'll do
  18716. 11:58:14x. So now it says ice cream is my
  18717. 11:58:18favorite. One thing that we cannot do in
  18718. 11:58:21a variable is we cannot add a string and
  18719. 11:58:24a number or an integer. So we can't do
  18720. 11:58:26ice cream is my favorite too. If we try
  18721. 11:58:29to do that it will give us this error
  18722. 11:58:30right here. So in this error it's saying
  18723. 11:58:32you can only concatenate a string not an
  18724. 11:58:35integer to a string. So only a string
  18725. 11:58:37plus a string for this example. You can
  18726. 11:58:40also do and we'll say x is equal to or
  18727. 11:58:43we'll say y
  18728. 11:58:45we'll say y is equal to
  18729. 11:58:493 + 2 and it should output five because
  18730. 11:58:52you can also do an integer and an
  18731. 11:58:54integer. Now, so far we've only been
  18732. 11:58:56outputting one variable in the print
  18733. 11:58:58statement, but you can actually add
  18734. 11:59:00multiple variables within a print
  18735. 11:59:02statement. So, let's go right down here.
  18736. 11:59:05We're going to say, let's get some more
  18737. 11:59:07right there. So, we'll say x is equal to
  18738. 11:59:11ice cream and we'll say y is equal to
  18739. 11:59:17is. And then the last one, z is equal to
  18740. 11:59:22my favorite. and we'll do a period at
  18741. 11:59:25the end. Now we can go to the bottom and
  18742. 11:59:27we can say print x + y + c. And when we
  18743. 11:59:33enter that
  18744. 11:59:35and when we run and when we run that we
  18745. 11:59:37get ice cream is my favorite. Now we can
  18746. 11:59:39actually add a space before is a space
  18747. 11:59:42before my and when we hit shift enter it
  18748. 11:59:45says ice cream is my favorite. You can
  18749. 11:59:47also do this exact same thing with
  18750. 11:59:49numbers as well. So we'll say x is equal
  18751. 11:59:53to 1 2 and y z is equal to 3. So this
  18752. 11:59:57should equal six. Now one thing that we
  18753. 12:00:00tried to do was assign to one variable a
  18754. 12:00:02string plus an integer and that did not
  18755. 12:00:04work. But what you can do is you can
  18756. 12:00:07take something like this and you can say
  18757. 12:00:09ice cream
  18758. 12:00:11and we'll get rid of this one and we'll
  18759. 12:00:14get rid of the z. Now saying plus is
  18760. 12:00:16actually not going to work. Let's try
  18761. 12:00:18running this. So again, we can't
  18762. 12:00:20concatenate these, but what we can do in
  18763. 12:00:22the print statement is we can separate
  18764. 12:00:24it by a comma. So when we add this
  18765. 12:00:26comma, it should work properly. Let's
  18766. 12:00:28hit enter. And it says ice cream 2.
  18767. 12:00:31Again, this makes no sense, but you are
  18768. 12:00:33able to combine a string and an integer
  18769. 12:00:36separating by a comma. Now, this is the
  18770. 12:00:37meat and potatoes of variables. There
  18771. 12:00:40are some other things as well, but some
  18772. 12:00:41of those things are a little bit more
  18773. 12:00:42advanced and not something I wanted to
  18774. 12:00:44cover in this tutorial. Although, we may
  18775. 12:00:46be looking at some of those things in
  18776. 12:00:47future tutorials. But this is definitely
  18777. 12:00:50the basics, what you really, really need
  18778. 12:00:52to know about variables. I hope that
  18779. 12:00:54this video was helpful. If it was, be
  18780. 12:00:56sure to like and subscribe below. And I
  18781. 12:00:58will see you in the next video.
  18782. 12:01:01[music]
  18783. 12:01:08>> [music]
  18784. 12:01:11>> Hello everybody. Today we're going to be
  18785. 12:01:13talking about data types in Python. Data
  18786. 12:01:15types are the classification of the data
  18787. 12:01:17that you are storing. These
  18788. 12:01:19classifications tell you what operations
  18789. 12:01:20can be performed on your data. We're
  18790. 12:01:22going to be looking at the main data
  18791. 12:01:24types within Python, including numeric,
  18792. 12:01:26sequence type, set, boolean, and
  18793. 12:01:29dictionary. So, let's get started
  18794. 12:01:30actually writing some of this out. And
  18795. 12:01:32first let's look at numeric. There are
  18796. 12:01:34three different types of numeric data
  18797. 12:01:36types. We have integers, float, and
  18798. 12:01:38complex numbers. Let's take a look at
  18799. 12:01:40integers. An integer is basically just a
  18800. 12:01:43whole number whether it's positive or
  18801. 12:01:44negative. So an integer could be a 12.
  18802. 12:01:47And we can check that by saying type.
  18803. 12:01:50We'll do an open parenthesis and a
  18804. 12:01:52closed parenthesis. And if we say the
  18805. 12:01:54type of 12, it's going to give us an
  18806. 12:01:56integer. Or if we say a -12, that is
  18807. 12:01:59also an integer. We can also perform
  18808. 12:02:01basic calculations like -12 + 100 and
  18809. 12:02:04that'll tell us it is also an integer.
  18810. 12:02:06So whether it's just a static value or
  18811. 12:02:09you're performing an operation on it,
  18812. 12:02:10it's still going to be that data type if
  18813. 12:02:12those numbers are whole numbers whether
  18814. 12:02:14negative or positive. Now let's take
  18815. 12:02:16this exact one and let's say 12 and
  18816. 12:02:20we'll do plus 10.25.
  18817. 12:02:23When we run this, it's no longer going
  18818. 12:02:24to be a whole number. It'll now be a
  18819. 12:02:26float. So let's check this. And now this
  18820. 12:02:29is a float type because it is no longer
  18821. 12:02:31a whole number. It's now a decimal
  18822. 12:02:32number. And the last data type within
  18823. 12:02:34the numeric data type is called complex.
  18824. 12:02:37Let's copy this right down here. Now
  18825. 12:02:39personally this is not one that I've
  18826. 12:02:40used almost ever, but it is one just
  18827. 12:02:43worth noting. So you can do 12 plus and
  18828. 12:02:46let's say 3 J. And if we do this, it's
  18829. 12:02:50going to give us a complex. The complex
  18830. 12:02:52data type is used for imaginary numbers.
  18831. 12:02:55For me, it's not often used, but if you
  18832. 12:02:57do use it, J is used as that imaginary
  18833. 12:03:00number. If you use something like C or
  18834. 12:03:04any other number, it's going to give you
  18835. 12:03:06an error. J is the only one that will
  18836. 12:03:08work with it. Now, let's take a look at
  18837. 12:03:10boolean values. So, we'll say boolean.
  18838. 12:03:13The boolean data type only has two
  18839. 12:03:16built-in values, either true or false.
  18840. 12:03:18So, let's go right down here and say
  18841. 12:03:20type true.
  18842. 12:03:23And when we run this, it'll say bool,
  18843. 12:03:25which stands for boolean. We can do the
  18844. 12:03:27exact same thing with false, and that is
  18845. 12:03:30also boolean. And this can be used with
  18846. 12:03:32something like a comparison operator. So
  18847. 12:03:34let's say one is greater than five. And
  18848. 12:03:38let's check this. This is giving us a
  18849. 12:03:40boolean because it's telling us whether
  18850. 12:03:42one is greater than five. Let's bring
  18851. 12:03:44that right down here. This will give us
  18852. 12:03:46a false. So it's telling us that one is
  18853. 12:03:49not greater than five. And just as we
  18854. 12:03:51got a false, we can say one is equal to
  18855. 12:03:53one. And this should give us a true. So
  18856. 12:03:56now let's take a look at our sequence
  18857. 12:03:57type data types. And that includes
  18858. 12:03:59strings, lists, and tupils. We'll start
  18859. 12:04:02off by looking at strings. In Python,
  18860. 12:04:05strings are arrays of bytes representing
  18861. 12:04:07Unicode characters. When you're using
  18862. 12:04:09strings, you put them either in a single
  18863. 12:04:11quote, a double quote, or a triple
  18864. 12:04:12quote. I call them apostrophes. It's
  18865. 12:04:14just what I was raised to call them, but
  18866. 12:04:16most people who use Python call them
  18867. 12:04:18quotes. So right here we have a single
  18868. 12:04:20quote and that works well. We can do a
  18869. 12:04:24double quote and that works also. And as
  18870. 12:04:28you can see they are the exact same
  18871. 12:04:29output. And then we have a triple quote
  18872. 12:04:32just like this. And this is called a
  18873. 12:04:34multi-line. So we can write on multiple
  18874. 12:04:36lines here. So let's write a nice little
  18875. 12:04:39poem. So, we'll say the ice cream
  18876. 12:04:42vanquished my longing for sweets upon
  18877. 12:04:47this diet. I look away.
  18878. 12:04:50It no longer exists
  18879. 12:04:54on this day. And then if we run that,
  18880. 12:04:56it's going to look a little bit weird.
  18881. 12:04:59It's basically giving us the raw text,
  18882. 12:05:01which is completely fine. But let's call
  18883. 12:05:03this a multi-line.
  18884. 12:05:06And we're going to call this a variable
  18885. 12:05:08multi-line. And we're going to come down
  18886. 12:05:10here and say print.
  18887. 12:05:13And before I run this, I have to make
  18888. 12:05:15sure that this is ran. So now let's
  18889. 12:05:18print out our multi-line. And now we
  18890. 12:05:20have our nice little poem right down
  18891. 12:05:22here. Now something to know about these
  18892. 12:05:24single and double quotes is how they're
  18893. 12:05:25actually used. So if we use a single
  18894. 12:05:28quote and we say, "I've always wanted to
  18895. 12:05:33eat a gallon of ice cream." and then we
  18896. 12:05:36do an apostrophe at the end. Obviously,
  18897. 12:05:38something went wrong here. What went
  18898. 12:05:40wrong is when you use a single quote and
  18899. 12:05:43then within your text, within your
  18900. 12:05:45sentence, you have another apostrophe,
  18901. 12:05:47it's going to give you an error. So,
  18902. 12:05:49what we want to do is whenever we have a
  18903. 12:05:52quote within it, we need to use a double
  18904. 12:05:55quote. These double quotes will negate
  18905. 12:05:57any single quotes that you have within
  18906. 12:05:59your statement. They won't, however,
  18907. 12:06:01negate another double quote. So you need
  18908. 12:06:03to make sure you aren't using double
  18909. 12:06:05quotes within your sentence. If you want
  18910. 12:06:07to do something like that, you need to
  18911. 12:06:08use the triple quotes like we did above.
  18912. 12:06:11So we can do double double and then
  18913. 12:06:15let's paste this within it.
  18914. 12:06:19And anything you do within these triple
  18915. 12:06:21quotes will be completely fine as long
  18916. 12:06:23as you don't do triple quotes within
  18917. 12:06:25your triple quotes. We'll say this is
  18918. 12:06:27wrong. So even though it's between these
  18919. 12:06:29two triple quotes, it doesn't work
  18920. 12:06:31exactly. Again, you just have to
  18921. 12:06:33understand how that works. You have to
  18922. 12:06:34use the proper apostrophes or quotes
  18923. 12:06:36within your string. And just to check
  18924. 12:06:38this, we can always say, here's our
  18925. 12:06:40multi-line. We can always say type of
  18926. 12:06:45multi-line.
  18927. 12:06:47And that is still a string. One really
  18928. 12:06:50important thing to know about strings is
  18929. 12:06:52that they can be indexed. Indexing means
  18930. 12:06:54that you can search within it. And that
  18931. 12:06:56index starts at zero. So, let's go ahead
  18932. 12:06:58and create a variable. And we'll just
  18933. 12:07:00say a is equal to and let's do the all
  18934. 12:07:04popular hello world. Let's run this. And
  18935. 12:07:08now when we print this string, we can
  18936. 12:07:10say a and we're going to do a bracket.
  18937. 12:07:13And now we can search throughout our
  18938. 12:07:14string using the index. So all you have
  18939. 12:07:17to do is do a colon. We can say five.
  18940. 12:07:21What this is going to do is it's going
  18941. 12:07:22to say zero position zero all the way up
  18942. 12:07:24to five, which should give us the whole
  18943. 12:07:26hello, I believe. Let's run this. and
  18944. 12:07:29it's giving us the first five positions
  18945. 12:07:30of this string. We can also get rid of
  18946. 12:07:33the colon and just say something like
  18947. 12:07:35five. And then when we run this, it's
  18948. 12:07:38actually going to give us position five.
  18949. 12:07:41So this is 0 1 2 3 4 and then five is
  18950. 12:07:45the space. Let's do six so we can see
  18951. 12:07:47the actual letter. And that is our W. We
  18952. 12:07:50can also use a negative when we're
  18953. 12:07:52indexing through our string. So we could
  18954. 12:07:54say -3 and it'll give us the L because
  18955. 12:07:57it's -1 2 and 3. We can also specify a
  18956. 12:08:01range if we don't want to use the
  18957. 12:08:02default of zero. So before we did 0 to 5
  18958. 12:08:05and it started at zero because that was
  18959. 12:08:07our default but we could also do 2 to 5.
  18960. 12:08:10Let's run this. And now we go position 0
  18961. 12:08:131 and then we start at two l. Now we can
  18962. 12:08:17also multiply strings and we have this a
  18963. 12:08:20hello world. So we can do a * 3 and if
  18964. 12:08:24we run this it'll give us hello world
  18965. 12:08:26three times and we can also do a + a and
  18966. 12:08:31that is hello world hello world. Now
  18967. 12:08:34let's go down here and take a look at
  18968. 12:08:35lists. Lists are really fantastic
  18969. 12:08:37because they store multiple values. The
  18970. 12:08:40string was stored as one value multiple
  18971. 12:08:42characters but a list can store multiple
  18972. 12:08:45separate values. So let's create our
  18973. 12:08:47very first list. We'll say list really
  18974. 12:08:50quickly and then we'll put a bracket and
  18975. 12:08:53a bracket means this is going to be a
  18976. 12:08:55list. There are other ones like a
  18977. 12:08:57squiggly bracket and a parenthesis.
  18978. 12:09:00These denote that they are different
  18979. 12:09:01types of data types. The bracket is what
  18980. 12:09:03makes a list a list. So to keep it super
  18981. 12:09:06simple, we'll say 1 2 3 and we'll run
  18982. 12:09:09this. And now we have a list that has
  18983. 12:09:10three separate values in it. The comma
  18984. 12:09:13in our list denotes that they are
  18985. 12:09:14separate values. And a list is indexed
  18986. 12:09:17just like a string is indexed. So
  18987. 12:09:19position zero is this one. Position one
  18988. 12:09:21is the two and position two is the
  18989. 12:09:24three. Now when we made this list, we
  18990. 12:09:26didn't have to use any quotes because
  18991. 12:09:27these are numbers. But if we wanted to
  18992. 12:09:30create a list and we wanted to add
  18993. 12:09:32string values, we have to do it with our
  18994. 12:09:34quotes. So we'll say quote cookie dough.
  18995. 12:09:38Then we'll do a comma to separate the
  18996. 12:09:40value. And then we'll say strawberry.
  18997. 12:09:44And then we'll do one more and this will
  18998. 12:09:46just be chocolate. And when we run this,
  18999. 12:09:48we have all three of these values stored
  19000. 12:09:50in our list. Now, one of the best things
  19001. 12:09:52about list is you can have any data type
  19002. 12:09:54within them. They don't just have to be
  19003. 12:09:56numbers or strings. You can basically
  19004. 12:09:59put anything you want in there. So,
  19005. 12:10:01let's create a new list. And let's say
  19006. 12:10:04vanilla.
  19007. 12:10:05And then we'll do three. And then we'll
  19008. 12:10:08add a list within a list. And we'll say
  19009. 12:10:11scoops.
  19010. 12:10:13comma spoon. And then we'll get out of
  19011. 12:10:17that list. And then we'll add another
  19012. 12:10:19value of true for boolean. And now we
  19013. 12:10:22can hit shift enter. And we just created
  19014. 12:10:25a list with several different data types
  19015. 12:10:28within one list. Now let's take this one
  19016. 12:10:31list right here with all of our
  19017. 12:10:32different ice cream flavors. We'll say
  19018. 12:10:34ice cream is equal to this list. Now one
  19019. 12:10:38thing that's really great about lists is
  19020. 12:10:40that they are changeable. That means we
  19021. 12:10:42can change the data in here. We can also
  19022. 12:10:44add and remove items from the list after
  19023. 12:10:47we've already created it. So let's go
  19024. 12:10:49and take ice cream and we'll say ice
  19025. 12:10:51cream.append.
  19026. 12:10:53And this is going to append it to the
  19027. 12:10:54very end of the list. We'll do an open
  19028. 12:10:57parenthesis. Let's say salted caramel.
  19029. 12:11:01Now when we run this and we call it just
  19030. 12:11:04like this, it's going to take this list
  19031. 12:11:07add salted caramel to the end and we'll
  19032. 12:11:10print it off. And as you can see, it was
  19033. 12:11:12added to the list. And just like I said
  19034. 12:11:14before, let me go down here. We can also
  19035. 12:11:17change things from this list. So let's
  19036. 12:11:19say ice cream. And then we need to look
  19037. 12:11:21at the indexed position. So we're going
  19038. 12:11:23to say zero. And that's going to be this
  19039. 12:11:25cookie dough right here. We can say that
  19040. 12:11:27is equal to. So we can now change that
  19041. 12:11:30value. So let's call that butter pecan.
  19042. 12:11:34And now when we call it,
  19043. 12:11:37we can now see that the cookie dough was
  19044. 12:11:39changed to butter pecan. Another thing
  19045. 12:11:41that you saw just a little bit ago is
  19046. 12:11:43something called a list within a list.
  19047. 12:11:45Basically a nested list. So we had
  19048. 12:11:48scoops spoon true. Let's give this and
  19049. 12:11:51we'll say nested
  19050. 12:11:54list is equal to. Now when we run this,
  19051. 12:11:57we now have this nested list. So if we
  19052. 12:12:00look at the index and we say zero, we'll
  19053. 12:12:03get vanilla. If we say two, we'll get
  19054. 12:12:06scoops and spoons. Now since we have a
  19055. 12:12:08list within a list, we can also look at
  19056. 12:12:10the index of that nested list. So let's
  19057. 12:12:13now say one. And that should give us
  19058. 12:12:16just spoon. And you can go on and on and
  19059. 12:12:19on with this. You can do lists within
  19060. 12:12:20lists within lists. And all of them will
  19061. 12:12:23have indexing that you can call. Now
  19062. 12:12:25let's go down here and start taking a
  19063. 12:12:26look at tupils. So a list and a tupil
  19064. 12:12:29are actually quite similar, but the
  19065. 12:12:31biggest difference between a list and a
  19066. 12:12:33tupil is that a tupil is something
  19067. 12:12:35called immutable. It means it cannot be
  19068. 12:12:37modified or changed after it's created.
  19069. 12:12:39So let's go right up here. We're going
  19070. 12:12:41to say tupil and let's write our very
  19071. 12:12:45first tupil. So we'll say tupil
  19072. 12:12:48scoops
  19073. 12:12:50is equal to and then we'll do an open
  19074. 12:12:52parenthesis. Now these open parenthesis
  19075. 12:12:54you've seen if you do like a print
  19076. 12:12:55statement but that's different because
  19077. 12:12:57that's executing a function. This is
  19078. 12:13:00actually creating a tupil which is going
  19079. 12:13:01to store data for us. So we'll say 1 2 3
  19080. 12:13:052 and 1. Let's go ahead and create that
  19081. 12:13:09tupil. And we can just check the data
  19082. 12:13:11type really quickly. And it's a tupole.
  19083. 12:13:14And just like we saw before a tupil is
  19084. 12:13:17also indexed. So if we go at the very
  19085. 12:13:19first position which is a one, we will
  19086. 12:13:22get the output of a one. But we can't do
  19087. 12:13:25something like append and then add a
  19088. 12:13:28value like three. If we do that, it's
  19089. 12:13:30going to say tupil object has no
  19090. 12:13:32attribute append. It's just because you
  19091. 12:13:34cannot change or add anything to a
  19092. 12:13:37tupil. Just like we were talking about
  19093. 12:13:38before, typically people will use tupils
  19094. 12:13:41for when data is never going to change.
  19095. 12:13:43An example for this might be something
  19096. 12:13:45like a city name, a country, a location,
  19097. 12:13:48something that won't change. They
  19098. 12:13:49definitely have their use cases, but I
  19099. 12:13:51don't think they're as popular as just
  19100. 12:13:52using a list. So, now let's scroll down
  19101. 12:13:54and start taking a look at sets. But
  19102. 12:13:57really quickly, let me add a few more
  19103. 12:14:00cells for us. And let's say sets.
  19104. 12:14:05Now a set is somewhat similar to a list
  19105. 12:14:08and a tupil, but they are a little bit
  19106. 12:14:11different in the fact that they don't
  19107. 12:14:12have any duplicate elements. Another big
  19108. 12:14:15difference is that the values within a
  19109. 12:14:17set cannot be accessed using an index
  19110. 12:14:19because it doesn't have an index because
  19111. 12:14:21it's actually unordered. We can still
  19112. 12:14:23loop through the items in a set with
  19113. 12:14:25something like a for loop, but we can't
  19114. 12:14:26access it using the bracket and then
  19115. 12:14:28accessing its index point. So let's go
  19116. 12:14:31ahead and create our very first set. So,
  19117. 12:14:33we're going to say daily_pints.
  19118. 12:14:36Then, we're going to say equal to. And
  19119. 12:14:38to create a set, we're going to use
  19120. 12:14:40these squiggly brackets. I don't know if
  19121. 12:14:42there's an actual name for those, if I'm
  19122. 12:14:43being honest. I call them squiggly
  19123. 12:14:45brackets, and that's what we're going to
  19124. 12:14:46go with. We're going to put in a one, a
  19125. 12:14:48two, and a three. So, let's go ahead and
  19126. 12:14:50run this.
  19127. 12:14:52And let's look at the type. And as you
  19128. 12:14:55can see, it is a set. Now, when we print
  19129. 12:14:57this out, it's going to show us one, a
  19130. 12:15:00two, and a three. And those are all the
  19131. 12:15:02values within our set. But if we copy
  19132. 12:15:04this and we'll say daily pints log, this
  19133. 12:15:07is going to be every single day. Maybe I
  19134. 12:15:11had different values.
  19135. 12:15:13Now when we run this and we do the exact
  19136. 12:15:15same thing. Now when we print this,
  19137. 12:15:20it's going to have just the unique
  19138. 12:15:21values within that set. Now a use case
  19139. 12:15:23for set and this is something that I've
  19140. 12:15:25done in the past is comparing two
  19141. 12:15:27separate sets. Maybe you have a list or
  19142. 12:15:29a tupil and you convert that into a set
  19143. 12:15:31and that will narrow it down to its
  19144. 12:15:33unique values. Then you can compare the
  19145. 12:15:35unique values of one set to the unique
  19146. 12:15:37values in another set. And then we can
  19147. 12:15:39see what's the same and what's
  19148. 12:15:40different. So let's go down here and
  19149. 12:15:42let's say wife's
  19150. 12:15:45daily and we'll just copy this right
  19151. 12:15:48here. We'll say is equal to let's do our
  19152. 12:15:51squiggly lines. Let's do one two. Let's
  19153. 12:15:54do just random numbers.
  19154. 12:15:57So now this is my daily log and this is
  19155. 12:16:00my wife's daily log. And now we can
  19156. 12:16:02compare these values. So let's go right
  19157. 12:16:04down here. Let's say print. We'll do my
  19158. 12:16:09daily logs and then we'll do this bar
  19159. 12:16:12right here. And this is going to show us
  19160. 12:16:13the combined unique values. It's
  19161. 12:16:15basically like putting them all in one
  19162. 12:16:17set and then trimming it down to just
  19163. 12:16:19the unique values. So we'll take wife's
  19164. 12:16:21daily pints log. And when we run this,
  19165. 12:16:24we actually need to run this first. When
  19166. 12:16:26we run this, we should see all the
  19167. 12:16:27unique values between these two sets.
  19168. 12:16:30And so, as you can see, 0 1 2 3 4 5 6 7
  19169. 12:16:3324 31. So, these are all the unique
  19170. 12:16:36values between these two sets.
  19171. 12:16:39We can also do another one. And instead
  19172. 12:16:42of this bar, we're going to do this
  19173. 12:16:44symbol right here, which I believe is
  19174. 12:16:46called an amperand. Don't quote me on
  19175. 12:16:48that. But when we run this, it's going
  19176. 12:16:50to show what matches. That means which
  19177. 12:16:53ones show up in both sets. So the only
  19178. 12:16:56ones that show up in both sets are 1 2 3
  19179. 12:16:59and five. We can also do the opposite of
  19180. 12:17:01that by doing a minus sign. And this is
  19181. 12:17:04going to show us what doesn't match. And
  19182. 12:17:06so we have 4 6 and 31. Now where is our
  19183. 12:17:1024 that was in our wife's daily pints
  19184. 12:17:12log? It's in this one, but we're
  19185. 12:17:14subtracting the values on this one. So
  19186. 12:17:16let's reverse this and we'll say daily
  19187. 12:17:19pints log
  19188. 12:17:21and let's run it. Now those are our
  19189. 12:17:23other values. So, we're taking the
  19190. 12:17:24values of this and then we're
  19191. 12:17:26subtracting all the ones that are the
  19192. 12:17:28same and getting the remaining values.
  19193. 12:17:31And then for our last one, we can get
  19194. 12:17:33rid of this and we'll do this symbol
  19195. 12:17:36right here. And this is going to show if
  19196. 12:17:38a value is either in one or the other,
  19197. 12:17:41but not in both. So, let's run this. So,
  19198. 12:17:44these values are completely unique only
  19199. 12:17:47to each of those sets. Now, the very
  19200. 12:17:50last one that we are going to look at in
  19201. 12:17:51this video is dictionaries. So, let's go
  19202. 12:17:54right down here. Let's add a few cells
  19203. 12:17:57and let's say dictionaries.
  19204. 12:18:00Now, I saved dictionary for last because
  19205. 12:18:02this one is probably the most different
  19206. 12:18:04out of all the previous data types that
  19207. 12:18:06we've looked at. Within a data type, we
  19208. 12:18:08have something called a key
  19209. 12:18:11value pair. That means when we use a
  19210. 12:18:14dictionary, it's not like a list where
  19211. 12:18:16you just have a value, value, comma,
  19212. 12:18:18value. we have a key that indicates what
  19213. 12:18:21that value is attributed to. So let's
  19214. 12:18:24write out a dictionary to see how this
  19215. 12:18:26looks. So we're going to say dictionary
  19216. 12:18:29cream. And just like a set, we use a
  19217. 12:18:32squiggly line. But the thing that
  19218. 12:18:34differentiates it is that in a
  19219. 12:18:36dictionary, we'll have that key value
  19220. 12:18:37pair. Whereas in a set, each value is
  19221. 12:18:40just separated by a comma. So let's
  19222. 12:18:42write name. And this is our key. And
  19223. 12:18:45then we do a colon. And this is then
  19224. 12:18:47where we input our value. So we're going
  19225. 12:18:49to say Alex freeberg. And then we
  19226. 12:18:53separate that key value pair by a comma.
  19227. 12:18:56And now we can do another key value
  19228. 12:18:57pair. So we'll say weekly intake and a
  19229. 12:19:03colon. And we'll say five pints of ice
  19230. 12:19:06cream. Do a comma. And then we'll do
  19231. 12:19:09favorite ice creams. And now what we're
  19232. 12:19:12going to do is we're going to put in
  19233. 12:19:13here a list. So within this dictionary,
  19234. 12:19:16we can also add a list. We'll do MCC for
  19235. 12:19:19mint chocolate chip. And then we'll add
  19236. 12:19:21chocolate, another one of my favorites.
  19237. 12:19:23So now we have our very first
  19238. 12:19:25dictionary. Let's copy this and run it.
  19239. 12:19:29And let's just look at the type. And as
  19240. 12:19:32you can see, it says that this is a
  19241. 12:19:34dictionary. Let's also print it out.
  19242. 12:19:37Now, if we want to, we can take our
  19243. 12:19:39dictionary cream and say values with an
  19244. 12:19:43open parenthesis. And when we execute
  19245. 12:19:45this, we'll see all of the values within
  19246. 12:19:47this dictionary. So, here's our values
  19247. 12:19:49of Alex Freeberg, five, mint chocolate
  19248. 12:19:51chip, and chocolate. We can also say
  19249. 12:19:54keys, and when we run this, all of the
  19250. 12:19:56keys, the name, weekly intake, and
  19251. 12:19:58favorite ice creams. And we can also say
  19252. 12:20:03items. So, this key value pair is one
  19253. 12:20:06item. And this key value pair is another
  19254. 12:20:08item. Now one difference between
  19255. 12:20:11something like a list and a dictionary
  19256. 12:20:13is how you call the index. But you can't
  19257. 12:20:15call it by doing something like this
  19258. 12:20:17where you just do a bracket oops and say
  19259. 12:20:20zero. So this would in theory take this
  19260. 12:20:24very first one, right? Our very first
  19261. 12:20:26key value pair. That's going to give us
  19262. 12:20:28an error. How you call a dictionary is
  19263. 12:20:29actually by the key. So it doesn't
  19264. 12:20:31technically have an index, but you can
  19265. 12:20:33specify what you want to call and take
  19266. 12:20:35it out. So we're going to say name and
  19267. 12:20:38this is going to call that key right
  19268. 12:20:40here. And when we run this we'll get the
  19269. 12:20:43value which is Alex Freeberg. One other
  19270. 12:20:46thing that you can do is you can also
  19271. 12:20:48update information in a dictionary which
  19272. 12:20:50we can't with some other data types. So
  19273. 12:20:52for this for the name it was Alex
  19274. 12:20:54Freeberg. Now let's say Freeberg and
  19275. 12:20:59when we update that I'm also going to
  19276. 12:21:01print the dictionary. get rid of this.
  19277. 12:21:06So, it's going to update Christine
  19278. 12:21:08Freeberg in that value of the name. So,
  19279. 12:21:11let's go ahead and run this. And now, it
  19280. 12:21:14changed the name from Alex Freeberg to
  19281. 12:21:15Christine Freeberg. We can also update
  19282. 12:21:18all of these values at one time. So,
  19283. 12:21:21let's copy this
  19284. 12:21:24and I'm going to put it right down here.
  19285. 12:21:26I'm going to say
  19286. 12:21:27dictionary.cream.update.
  19287. 12:21:29Then we're going to put a bracket or not
  19288. 12:21:32a bracket but a parenthesis around
  19289. 12:21:33these. So now what we're going to do is
  19290. 12:21:36update this entire thing. Let me take
  19291. 12:21:38this say print this dictionary. Now we
  19292. 12:21:43can update this to anything we want. So
  19293. 12:21:46instead of here I can say
  19294. 12:21:49I'll say weight
  19295. 12:21:51and because of all that ice cream I now
  19296. 12:21:53weigh 300 lb. So let's run this. And as
  19297. 12:21:58you can see, it did not delete our key
  19298. 12:22:00value pair right here. Instead, it just
  19299. 12:22:02added to it. When you're using the
  19300. 12:22:04update, we can't actually delete. That's
  19301. 12:22:06the delete statement, and I'll show you
  19302. 12:22:08that in just a second. But all we did
  19303. 12:22:10was added this new value. It also is
  19304. 12:22:12going to check and see if you changed
  19305. 12:22:14anything with your key value pair. So,
  19306. 12:22:16we can go in here and change this value.
  19307. 12:22:18And we'll say 10. So, now when we run
  19308. 12:22:20this, the value of this key value pair
  19309. 12:22:23was changed. But let's say we do want to
  19310. 12:22:25delete it. We'll say deel. that stands
  19311. 12:22:27for delete part of this dictionary
  19312. 12:22:30cream. And now let's specify the key
  19313. 12:22:32which will also delete the value with
  19314. 12:22:34it. Well, let's specify the key that we
  19315. 12:22:36want to get rid of. And let's say wait.
  19316. 12:22:39And then let's print that again.
  19317. 12:22:43And as you can see, the weight was
  19318. 12:22:46deleted from that dictionary. So that is
  19319. 12:22:48all we're going to cover in this data
  19320. 12:22:49types video. Thank you guys so much for
  19321. 12:22:51watching. I really appreciate it. If you
  19322. 12:22:53like this video, be sure to like and
  19323. 12:22:54subscribe below, and I'll see you in the
  19324. 12:22:56next video.
  19325. 12:23:09Hello everybody. Today we're going to be
  19326. 12:23:11taking a look at comparison, logical,
  19327. 12:23:12and membership operators in Python.
  19328. 12:23:14Operators are used to perform operations
  19329. 12:23:16on variables and values. For example,
  19330. 12:23:19you're often going to want to compare
  19331. 12:23:20two separate values to see if they are
  19332. 12:23:22the same or if they're different within
  19333. 12:23:24Python. And that's where the comparison
  19334. 12:23:26operator comes in. Right here, you can
  19335. 12:23:27see our operators. You can also see what
  19336. 12:23:29they do. So, this equal sign, equal sign
  19337. 12:23:32stands for equal. We have the does not
  19338. 12:23:34equal, the greater than, less than,
  19339. 12:23:36greater than or equal to, and less than
  19340. 12:23:38or equal to. And honestly, I use these
  19341. 12:23:40almost every single time I use Python.
  19342. 12:23:42So, these are very important to know and
  19343. 12:23:44know how to use. So, let's get rid of
  19344. 12:23:45that really quickly and actually start
  19345. 12:23:47writing it out and see how these
  19346. 12:23:48comparison operators work in Python. The
  19347. 12:23:50very first one that we're going to look
  19348. 12:23:51at is equal to. Now, you can't just say
  19349. 12:23:5310 is equal to 10. Let's try running
  19350. 12:23:56that really quickly by clicking shift
  19351. 12:23:58enter. It's going to say cannot assign
  19352. 12:24:00to literal. That's because this is like
  19353. 12:24:02assigning a variable. We're trying to
  19354. 12:24:03say 10 is equal to 10 and then we can
  19355. 12:24:06call that 10 later. But that's not how
  19356. 12:24:08this actually works. What we're trying
  19357. 12:24:09to do is to determine whether 10 is
  19358. 12:24:11equal to 10. So, we're going to say
  19359. 12:24:13equal sign equal sign. And then if we
  19360. 12:24:15run that by clicking shift enter again,
  19361. 12:24:17it's going to say true. Now, if we put
  19362. 12:24:19something else like 50 in there and we
  19363. 12:24:21try to run this, it's going to say
  19364. 12:24:23false. So, really what you're going to
  19365. 12:24:25get when you use these comparison
  19366. 12:24:26operators is either a true or a false.
  19367. 12:24:29If we take this right down here, we can
  19368. 12:24:31also say does not equal. And we're going
  19369. 12:24:33to use an exclamation point equal sign.
  19370. 12:24:35And that says 10 is not equal to 50. And
  19371. 12:24:37that should be true. You can also
  19372. 12:24:39compare strings and variables. So, let's
  19373. 12:24:41go right down here and we're going to
  19374. 12:24:43say vanilla is not equal
  19375. 12:24:48to chocolate. And when we run this,
  19376. 12:24:50it'll say false. Now, if it was the
  19377. 12:24:53same, just like when we did our numbers,
  19378. 12:24:54it should say true. And we can also
  19379. 12:24:56compare variables. So, we'll say x is
  19380. 12:24:59equal to vanilla and y is equal to
  19381. 12:25:03chocolate. And then when we come down
  19382. 12:25:05here, we can say x is equal to y. And
  19383. 12:25:08it'll give us a false. and we say x is
  19384. 12:25:12not equal to y and it'll give us a true.
  19385. 12:25:15The next one that we're going to take a
  19386. 12:25:16look at is the less than. So let's copy
  19387. 12:25:18this one right up here. Let's scroll
  19388. 12:25:20down and let's say 10 is less than 50.
  19389. 12:25:26Now this will come out as true. Now
  19390. 12:25:28let's say we put a 10 in here. Before 10
  19391. 12:25:31was of course less than 50. But is 10
  19392. 12:25:34less than 10? No. That's false because
  19393. 12:25:37they are the same. So if we want an
  19394. 12:25:38output that is true, all we would have
  19395. 12:25:40to add is an equal sign right here. And
  19396. 12:25:42this would say 10 is less than or it is
  19397. 12:25:45equal to 10. And now it's true. Of
  19398. 12:25:49course, we can say the exact same thing
  19399. 12:25:50by saying greater than. So 10 is equal
  19400. 12:25:53or greater than 10. That'll be true
  19401. 12:25:55because 10 is equal to 10. But we can
  19402. 12:25:58also say 50 is greater or equal to 10
  19403. 12:26:01because 50 is obviously greater than 10.
  19404. 12:26:03Now let's look at logical operators that
  19405. 12:26:05are often combined with comparison
  19406. 12:26:07operators. So our operators are and or
  19407. 12:26:10and not. So if you have an and that
  19408. 12:26:12returns true if both statements are
  19409. 12:26:14true. If it's or only one of the
  19410. 12:26:17statements has to be true. And the not
  19411. 12:26:19basically reverses the result. So if it
  19412. 12:26:21was going to return true, it would
  19413. 12:26:23return false. I don't use this not one a
  19414. 12:26:26lot, but I will show you how it works.
  19415. 12:26:28So let's actually test that out. So
  19416. 12:26:30before we were saying 10 is greater than
  19417. 12:26:3250 and of course this returned false. So
  19418. 12:26:35now let's add a parentheses around this.
  19419. 12:26:3810 is greater than 50 and we're going to
  19420. 12:26:39say and we'll do an open parenthesis. 50
  19421. 12:26:43is greater than 10. Now this statement
  19422. 12:26:45right here is true. 50 is greater than
  19423. 12:26:4710. So we have a true statement and a
  19424. 12:26:50false statement. But this and is going
  19425. 12:26:52to look at both of them. It's going to
  19426. 12:26:53say they both need to be true in order
  19427. 12:26:56to return a true. So let's try running
  19428. 12:26:58this. and we still have a false. If we
  19429. 12:27:01want it to return true, we're going to
  19430. 12:27:02have to change this to make it a true
  19431. 12:27:04statement. So 70 is greater than 50 and
  19432. 12:27:0650 is greater than 10. When we run this,
  19433. 12:27:09it should return true. Now let's look at
  19434. 12:27:11the or. So let's copy this and we'll say
  19435. 12:27:1510 is greater than 50 or 50 is greater
  19436. 12:27:19than 10. Now this is a false statement
  19437. 12:27:21and this is a true statement. So if even
  19438. 12:27:23one of them is a true statement, the
  19439. 12:27:25output should be true. And again we can
  19440. 12:27:27do this even with strings. So we can do
  19441. 12:27:30vanilla
  19442. 12:27:32and chocolate.
  19443. 12:27:35There we go. And vanilla is actually
  19444. 12:27:38greater than chocolate because v is a
  19445. 12:27:40higher number in the alphabetical order.
  19446. 12:27:42So v is like 20some whereas chocolate is
  19447. 12:27:45three. Right? So it actually looks at
  19448. 12:27:46the spelling for this. So if we say or
  19449. 12:27:49here it will come out true. And if we
  19450. 12:27:52say and here, it should also be true
  19451. 12:27:54because V is greater than C and 50 is
  19452. 12:27:57greater than 10. So this should also be
  19453. 12:27:59true. Now let's copy this right here.
  19454. 12:28:02And we're going to say not. So what we
  19455. 12:28:05had before is 50 is greater than 10.
  19456. 12:28:08That returned true. But now all we're
  19457. 12:28:10doing is putting not in front of it. So
  19458. 12:28:12instead of returning true, it's going to
  19459. 12:28:13return false. So now let's take a look
  19460. 12:28:15at membership operators. And we use this
  19461. 12:28:17to check if something whether it's a
  19462. 12:28:19value or a string or something like that
  19463. 12:28:21is within another value or string or
  19464. 12:28:24sequence. Our operators are in and not
  19465. 12:28:26in. So it's pretty simple. If it's in,
  19466. 12:28:28it's going to return true if the
  19467. 12:28:30sequence with a specified value is
  19468. 12:28:31present in the object just like we were
  19469. 12:28:33talking about. And for not in, it's
  19470. 12:28:35basically the exact same thing if it's
  19471. 12:28:37not in that object. So let's start out
  19472. 12:28:38by taking a look at a string. We're
  19473. 12:28:40going to say ice cream is equal to I
  19474. 12:28:44love chocolate ice cream.
  19475. 12:28:48And then we're going to say love in ice
  19476. 12:28:52cream. And that will return true. So all
  19477. 12:28:55we're doing is searching if the word
  19478. 12:28:56love or that string is in this larger
  19479. 12:28:59string. We could also just do that by
  19480. 12:29:01literally copying this and putting this
  19481. 12:29:03where this is. So we can check is this
  19482. 12:29:05string part of this string and it'll say
  19483. 12:29:08true. We can also make a list. So we'll
  19484. 12:29:10say scoops is equal to and then we'll do
  19485. 12:29:13a bracket and we'll say 1 2 3 4 5. Then
  19486. 12:29:17we'll say two in scoops. So all we're
  19487. 12:29:21doing is searching to see if two is
  19488. 12:29:22within this list. And that should return
  19489. 12:29:25true. Now if we put a six here and we
  19490. 12:29:28said not in, it will also return true
  19491. 12:29:32because six is not in scoops and that is
  19492. 12:29:34true. And just like we did, we could
  19493. 12:29:36also say wanted scoops and we'll say
  19494. 12:29:40eight. So I wanted eight scoops. So we
  19495. 12:29:43can say wanted scoops in scoops. And
  19496. 12:29:46this should return true because there's
  19497. 12:29:48not an eight within the scoops that we
  19498. 12:29:50wanted. And if we said in and we said we
  19499. 12:29:54wanted eight, is that within our list
  19500. 12:29:56that we created? And that's going to
  19501. 12:29:58return a false. So that is a quick
  19502. 12:30:00breakdown of comparison, logical, and
  19503. 12:30:02membership operators. I hope that this
  19504. 12:30:04was helpful. Thank you guys so much for
  19505. 12:30:06watching. If you like this video, be
  19506. 12:30:08sure to like and subscribe and I will
  19507. 12:30:10see you in the next video.
  19508. 12:30:16[music]
  19509. 12:30:23Hello everybody. Today we're going to be
  19510. 12:30:25taking a look at the if statement within
  19511. 12:30:27Python. Now, it's actually the if l if
  19512. 12:30:29else statement, but that's a mouthful,
  19513. 12:30:30so I'm just going to call it the if else
  19514. 12:30:32statement. Now, we have this flowchart,
  19515. 12:30:34and I apologize for it being blurry, but
  19516. 12:30:36this is the absolute best one that I
  19517. 12:30:37could find. Right up top, we have our if
  19518. 12:30:39condition. Now, if this if condition is
  19519. 12:30:42true, we're going to run a body of code.
  19520. 12:30:44But if that condition is false, we're
  19521. 12:30:46going to go over here and go to the LF
  19522. 12:30:48condition. The LF condition or statement
  19523. 12:30:50is basically saying if the first if
  19524. 12:30:52statement doesn't work, let's try this
  19525. 12:30:54if statement. If this LF statement is
  19526. 12:30:56true, it goes to this body of code. If
  19527. 12:30:58it's false, it'll come over here to the
  19528. 12:31:00else. And the else is basically if all
  19529. 12:31:02of these things don't work then run this
  19530. 12:31:05body of code. Now you can have as many
  19531. 12:31:07ill if statements as you want but you
  19532. 12:31:08can only have one if statement and one
  19533. 12:31:10else statement. So let's write out some
  19534. 12:31:12code and see how this actually looks.
  19535. 12:31:14Let's first start off by writing if.
  19536. 12:31:15That is our if statement. And now we
  19537. 12:31:17have to write our condition which is
  19538. 12:31:19about to be either met or not met. So
  19539. 12:31:21we'll say if 25 is greater than 10 which
  19540. 12:31:24is true. We'll say colon and then we're
  19541. 12:31:27going to hit enter and it's going to
  19542. 12:31:29automatically indent that line of code
  19543. 12:31:30for us. And this is our body of code. So
  19544. 12:31:33if 25 is greater than 10, our body of
  19545. 12:31:35code will execute. So for us, we're just
  19546. 12:31:38going to write print and we'll say it
  19547. 12:31:40worked. Now if we run this, it's going
  19548. 12:31:42to check is 25 greater than 10. If that
  19549. 12:31:45is true, print this. So let's hit shift
  19550. 12:31:49enter. And it worked. Now let's take
  19551. 12:31:52this exact code. We'll paste it right
  19552. 12:31:54down here. And we'll say is less than.
  19553. 12:31:57And right now, this if statement is not
  19554. 12:31:59true. So, it's not actually going to
  19555. 12:32:01work. As you can see, there's no output.
  19556. 12:32:04There's nothing that happened really.
  19557. 12:32:05But it did check to see if 25 was less
  19558. 12:32:07than 10, but it just wasn't true. Now,
  19559. 12:32:10we can use our else statement. So, we're
  19560. 12:32:12going to come right down here, and we're
  19561. 12:32:13going to say else, and we'll do a colon,
  19562. 12:32:16and we'll hit enter. Again,
  19563. 12:32:17automatically indenting. And we're going
  19564. 12:32:18to say print. and we're going to say it
  19565. 12:32:22did not work dot dot dot. So what it's
  19566. 12:32:25going to do is it's going to come up
  19567. 12:32:26here and check is 25 less than 10. No,
  19568. 12:32:30it's not. So this body of code is not
  19569. 12:32:32going to be executed. It's going to go
  19570. 12:32:33right down to this else statement. Now
  19571. 12:32:35this else statement is going to be
  19572. 12:32:36printed. There's no condition on this.
  19573. 12:32:38So the if statement has a condition. 25
  19574. 12:32:40is less than 10. This has no condition.
  19575. 12:32:42So if this doesn't work, if this is
  19576. 12:32:44false, it's going to come down here and
  19577. 12:32:46it will run this body of code. Let's run
  19578. 12:32:48this by clicking shift enter. And as you
  19579. 12:32:51can see, our output is it did not work.
  19580. 12:32:54Now, let's go back up here and put
  19581. 12:32:56greater than because this is now true.
  19582. 12:32:58It's going to say if 25 is greater than
  19583. 12:33:0010, print it worked. And then it's going
  19584. 12:33:02to stop. It's not going to go to this
  19585. 12:33:04else statement at all. So, let's run
  19586. 12:33:06this. And our output is it worked. So,
  19587. 12:33:09what if we have a lot of different
  19588. 12:33:10conditions that we want to try? Let's
  19589. 12:33:12come right down here. This is where the
  19590. 12:33:14lf comes in. So really quickly, let's
  19591. 12:33:16change this to a not true, a false
  19592. 12:33:19statement. We're going to go down and
  19593. 12:33:20say l if and we're going to say if it
  19594. 12:33:24is, and let's say 30, we'll say l if
  19595. 12:33:30worked.
  19596. 12:33:32So now it's going to check is 25 less
  19597. 12:33:35than 10. No, it's not. Let's look at the
  19598. 12:33:37next condition. Is 25 less than 30? And
  19599. 12:33:40if it is, we'll print l if worked. So
  19600. 12:33:43let's try running this. and lf worked.
  19601. 12:33:46Now, we can do as many of these LF
  19602. 12:33:48statements as we want. We can do let's
  19603. 12:33:51just try a few of them right here. So,
  19604. 12:33:53we'll say if 25 is less than 20 is less
  19605. 12:33:58than 21 and let's do 40 and let's do 50.
  19606. 12:34:03So, we'll say LF, LF2, LF3, and LF4.
  19607. 12:34:08Now, if you look at this, the first one
  19608. 12:34:10that is actually going to work is this
  19609. 12:34:1325 to 40 right here. Once this one is
  19610. 12:34:16checked and it comes out as true, none
  19611. 12:34:18of the other LF or else statements will
  19612. 12:34:20work. So, let's try this one. It should
  19613. 12:34:21be LF3.
  19614. 12:34:23And this one ran properly. Now, within
  19615. 12:34:26our condition so far, we've only used a
  19616. 12:34:27comparison operator. We can also use a
  19617. 12:34:30logical operator like and or or. So, we
  19618. 12:34:33can say if 25 is less than 10, which
  19619. 12:34:36it's not. and let's say or actually and
  19620. 12:34:39we'll say or one is less than three
  19621. 12:34:43which is true. If we run this now it
  19622. 12:34:46will actually work. So we can use
  19623. 12:34:47several different types of operators
  19624. 12:34:49within our if statement to see if a
  19625. 12:34:51condition is true or not or several
  19626. 12:34:53conditions are true. There's also a way
  19627. 12:34:55to write an if else statement in one
  19628. 12:34:57line if you want to do that. So we can
  19629. 12:34:59write print. We'll say it worked
  19630. 12:35:03and then we'll come over here and say if
  19631. 12:35:0510 is greater than 30 and then we'll
  19632. 12:35:08write else print and we'll say it did
  19633. 12:35:13not work just like we had before except
  19634. 12:35:16now it's all occurring on one line. So
  19635. 12:35:18let's just try this and see if it works.
  19636. 12:35:21So it's saying print it worked if 10 is
  19637. 12:35:24greater than 30 which it wasn't. So, it
  19638. 12:35:25went to the else statement and then it
  19639. 12:35:27printed out our body right here.
  19640. 12:35:29Although we didn't have any indentation
  19641. 12:35:30or multiple lines, it was all done in
  19642. 12:35:32one line. Now, there's one other thing
  19643. 12:35:34that we haven't looked at yet. Uh, and
  19644. 12:35:36I'm going to show it to you really
  19645. 12:35:37quickly. And that's a nested if
  19646. 12:35:39statement. So, when we run this, it's
  19647. 12:35:41going to say it worked. It works because
  19648. 12:35:43it says 25 is less than 10 or 1 is less
  19649. 12:35:46than three. Since this is true, it's
  19650. 12:35:49going to print out it worked. But we can
  19651. 12:35:51also do a nested if statement. So we can
  19652. 12:35:53do multiple if statements as well. So
  19653. 12:35:56we're going to hit enter and we'll say
  19654. 12:35:57if and we'll do a true statement here.
  19655. 12:35:59So we'll say if 10 is greater than five.
  19656. 12:36:03Let's do a colon hit enter and then
  19657. 12:36:06we'll say print and then we'll type a
  19658. 12:36:07string saying this nested if statement
  19659. 12:36:12oops worked.
  19660. 12:36:14Now let's try this out and see what we
  19661. 12:36:16get. So it went through the first if
  19662. 12:36:18statement. It said it was true and it
  19663. 12:36:20prints out it worked. This is still the
  19664. 12:36:22body of code. So it goes down to this
  19665. 12:36:24next if statement and it says if 10 is
  19666. 12:36:26greater than five, we're going to print
  19667. 12:36:28this out. And you could do this on and
  19668. 12:36:30on and on. It can basically go on
  19669. 12:36:32forever and you can create a really
  19670. 12:36:34in-depth logic. And that actually
  19671. 12:36:36happens a lot when you start writing
  19672. 12:36:37more advanced code. So I hope that this
  19673. 12:36:39was helpful. I hope that you understand
  19674. 12:36:40the if else statement better. I hope
  19675. 12:36:42that you understand how nested if
  19676. 12:36:43statements work as well. Thank you guys
  19677. 12:36:46so much for watching. If you like this
  19678. 12:36:47video, be sure to like and subscribe
  19679. 12:36:49below, and I'll see you in the next
  19680. 12:36:50video.
  19681. 12:37:03Hello everybody. Today we're going to be
  19682. 12:37:05learning about for loops in Python. The
  19683. 12:37:07for loop is used to iterate over a
  19684. 12:37:09sequence, which could be a list, a
  19685. 12:37:11tupil, an array, a string, or even a
  19686. 12:37:13dictionary. Here's the list that we'll
  19687. 12:37:15be working with throughout this video.
  19688. 12:37:16And I have this little diagram right
  19689. 12:37:18here which kind of explains how a for
  19690. 12:37:20loop works. The for loop is going to
  19691. 12:37:22start by looking at the very first item
  19692. 12:37:24in our sequence or our list. And that's
  19693. 12:37:26going to be our one right here. It's
  19694. 12:37:28going to ask is this the last element in
  19695. 12:37:31our list? And it is not. So it's going
  19696. 12:37:34to go down to this body of the for loop.
  19697. 12:37:36Now we can have a thousand different
  19698. 12:37:38things that can happen in the body of
  19699. 12:37:39the for loop as we're about to look at
  19700. 12:37:41in just a second. Then it's going to go
  19701. 12:37:43up to the next element and ask is this
  19702. 12:37:45the last element reached. So it'll be no
  19703. 12:37:48again because it'll be going to the two
  19704. 12:37:50and then the three and then the four and
  19705. 12:37:51the five. Once it reaches the five,
  19706. 12:37:54it'll go to the body of the for loop and
  19707. 12:37:56then when it asks if that's the last
  19708. 12:37:58element, the answer would be yes because
  19709. 12:38:00it's iterated through all the items
  19710. 12:38:02within the list and then we would exit
  19711. 12:38:04the loop and the for loop would be over.
  19712. 12:38:06Now, that may not have made perfect
  19713. 12:38:07sense, but let's actually start writing
  19714. 12:38:09out the syntax of a for loop so we can
  19715. 12:38:11understand this better. To start our for
  19716. 12:38:13loop, we're going to say four. And then
  19717. 12:38:15we're going to give it a temporary
  19718. 12:38:17variable for this for loop. So, it's a
  19719. 12:38:19variable. As it iterates through these
  19720. 12:38:21numbers, it's going to assign the
  19721. 12:38:23variable to that number. So, for this
  19722. 12:38:25one, we're just going to say number
  19723. 12:38:26because it's pretty appropriate because
  19724. 12:38:28these are all numbers. And then we're
  19725. 12:38:30going to say in integers. Now, right
  19726. 12:38:34here, you can put just about anything.
  19727. 12:38:35This could be the list. This could be a
  19728. 12:38:37tupole. This could be a string even. But
  19729. 12:38:40that is what we're going to iterate
  19730. 12:38:41through. So we're saying for the
  19731. 12:38:43variables, each of these numbers within
  19732. 12:38:45this list of integers. And then we're
  19733. 12:38:48going to write a colon. This is the body
  19734. 12:38:50of code that's going to actually be
  19735. 12:38:52executed when we run through and iterate
  19736. 12:38:54through our list. So for our first
  19737. 12:38:56example, we're going to start off super
  19738. 12:38:58simple. And all we're going to do is say
  19739. 12:39:00print open parenthesis and say number.
  19740. 12:39:03as it iterates through the 1 2 3 4 and
  19741. 12:39:06five number becomes our variable that is
  19742. 12:39:09going to be printed. So during that
  19743. 12:39:11first loop our one will be printed
  19744. 12:39:13because that will be assigned right
  19745. 12:39:15here. Then through the next iteration
  19746. 12:39:17the two will be assigned and it'll be
  19747. 12:39:19put right here in each loop until the
  19748. 12:39:22very end. So let's hit shift enter. And
  19749. 12:39:26as you can see it did exactly that. Now
  19750. 12:39:28in this body and I'll copy and paste
  19751. 12:39:30this down here. In this body, we really
  19752. 12:39:32can do just about anything we want. We
  19753. 12:39:34don't even have to use this variable
  19754. 12:39:36number right here. We can just print yep
  19755. 12:39:40if we wanted to. And what it's going to
  19756. 12:39:42do is for each iteration, all five of
  19757. 12:39:44those, every time it loops through, it's
  19758. 12:39:46going to print off yep. So, let's hit
  19759. 12:39:49shift enter. And it printed it off for
  19760. 12:39:52us. So, really, we weren't even using
  19761. 12:39:54the numbers within the list. We were
  19762. 12:39:56really just using it as almost a
  19763. 12:39:58counter. Now let's copy this integers
  19764. 12:40:00once again. Let's go right up here and
  19765. 12:40:02let's go copy this for loop that we
  19766. 12:40:05wrote. Now we do not have to call this
  19767. 12:40:09number. This can be anything you want.
  19768. 12:40:11Any variable name that you'd like to
  19769. 12:40:13name it. We could call it jelly and we
  19770. 12:40:17can do
  19771. 12:40:18jelly plus jelly.
  19772. 12:40:22I think you're getting the picture,
  19773. 12:40:23right? When it loops through that one,
  19774. 12:40:25it's doing 1 plus one. when it loops
  19775. 12:40:27through the two, it's doing 2 + 2. That
  19776. 12:40:30is basically how a for loop works. Now,
  19777. 12:40:32for a dictionary, it's going to handle
  19778. 12:40:33it a little bit differently. So, let's
  19779. 12:40:35create a dictionary really quickly. So,
  19780. 12:40:38we'll say ice cream
  19781. 12:40:41dictionary is equal to we're going to do
  19782. 12:40:43a squiggly brackets. So, we're going to
  19783. 12:40:45say name and we're going to say colon.
  19784. 12:40:48We need to assign our value for that
  19785. 12:40:50item. So, we're going to say Alex
  19786. 12:40:53freeberg. We'll do our next one
  19787. 12:40:54separated by a comma and we'll say
  19788. 12:40:57weekly intake and I'll say five scoops
  19789. 12:41:01per week. The next one we will do is
  19790. 12:41:04favorite ice creams. And for this one,
  19791. 12:41:08we're going to do something a little bit
  19792. 12:41:09different. For this, we're going to have
  19793. 12:41:10a list within this dictionary. So, we'll
  19794. 12:41:13say within our list of my favorite ice
  19795. 12:41:16creams, we'll say mint chocolate chip.
  19796. 12:41:18And I'll just do MCC for that. and we'll
  19797. 12:41:21separate that out by a comma and we'll
  19798. 12:41:24say chocolate. So now we have this
  19799. 12:41:26dictionary ice cream dict. And within it
  19800. 12:41:28we have my name, my weekly intake, and
  19801. 12:41:30my favorite ice creams with a list in
  19802. 12:41:34there as well. Let's hit shift enter.
  19803. 12:41:36And now we're going to start writing our
  19804. 12:41:37for loop. Now the for loop is going to
  19805. 12:41:39look very similar, but to call a
  19806. 12:41:41dictionary, it's just a little bit
  19807. 12:41:43different. So, we're going to say for
  19808. 12:41:45the cream in ice cream
  19809. 12:41:50dictionary dot values and then we're
  19810. 12:41:53going to do parentheses and then a
  19811. 12:41:54colon. Now, we're going to print the
  19812. 12:41:58cream. So, in order to indicate what we
  19813. 12:42:01actually want to pull, we have to
  19814. 12:42:02specify within the dictionary what we
  19815. 12:42:05want. Are we pulling the item? Are we
  19816. 12:42:07pulling the value? We need to specify
  19817. 12:42:09this. So, that's why we have this dot
  19818. 12:42:11values right here. So let's run this and
  19819. 12:42:13see what we get. So as you can see, we
  19820. 12:42:15are pulling in the values right here.
  19821. 12:42:17That's why we're pulling in Alex
  19822. 12:42:18Freeberg five and mint chocolate chip/
  19823. 12:42:21chocolate. Now we are able to call both
  19824. 12:42:24of those, both the key and the value. So
  19825. 12:42:27let's go right down here and we can do
  19826. 12:42:29both the key and the value. So we can
  19827. 12:42:32pull two things at one time. And we're
  19828. 12:42:35going to do this by saying dot items. So
  19829. 12:42:38we could also do key if we just wanted
  19830. 12:42:40to do a key, but we want to do items. So
  19831. 12:42:43we want to do both of them. So we're
  19832. 12:42:45going to go right down here and say for
  19833. 12:42:47key and value in ice cream dictionary
  19834. 12:42:50items print and let's write key and then
  19835. 12:42:53we'll do a comma and then let's give it
  19836. 12:42:56a little arrow or something like that.
  19837. 12:42:58Uh something like this and then we'll do
  19838. 12:43:00a comma and we'll say value. And let's
  19839. 12:43:03print this off and see what we get.
  19840. 12:43:06So it's looping through and for each key
  19841. 12:43:08and value it's saying here is the key.
  19842. 12:43:11So that's the name. Then we have weekly
  19843. 12:43:13intake. Then we have favorite ice
  19844. 12:43:14creams. It's giving us a little arrow
  19845. 12:43:16and then we're also printing off the
  19846. 12:43:18value. So we have name Alex Freeberg.
  19847. 12:43:20Weekly intake five. Favorite ice creams
  19848. 12:43:23mint chocolate chip and chocolate. So
  19849. 12:43:25now let's talk about nested for loops.
  19850. 12:43:27We've looked at for loops. We understand
  19851. 12:43:28how they work and why they do what they
  19852. 12:43:30do. But what about a nested for loop? a
  19853. 12:43:33for loop within a for loop. For this
  19854. 12:43:35example, let's create two separate list.
  19855. 12:43:38Let's create flavors.
  19856. 12:43:40And let's make that a list by making it
  19857. 12:43:43a bracket. We'll do vanilla, the
  19858. 12:43:47classic, chocolate,
  19859. 12:43:51and then cookie dough, all great
  19860. 12:43:54flavors. So, that's our first list. And
  19861. 12:43:57then we're going to say toppings. And
  19862. 12:43:59we'll do a bracket for that as well. And
  19863. 12:44:01we'll say hot fudge.
  19864. 12:44:05And then we'll do Oreos.
  19865. 12:44:09And then we'll do marshmallows.
  19866. 12:44:12Is that how you spell marshmallows?
  19867. 12:44:15I think it's an E. That looks wrong. I
  19868. 12:44:18might be spelling it wrong, but that's
  19869. 12:44:19okay. So, let's save this by clicking
  19870. 12:44:22shift enter. And now we have our flavors
  19871. 12:44:24and our toppings. So, now let's write
  19872. 12:44:27our first for loop. So we're going to
  19873. 12:44:28say 41 as in our number one for loop.
  19874. 12:44:32We're going to say in flavors and we'll
  19875. 12:44:34do a colon. We'll click enter. Now we
  19876. 12:44:37can write our second for loop. So we're
  19877. 12:44:39going to say for two in toppings and
  19878. 12:44:43we'll do a colon and enter. And then
  19879. 12:44:45we're going to say print and we'll do an
  19880. 12:44:47open parenthesis. And then we're going
  19881. 12:44:49to say one. So we're printing the one in
  19882. 12:44:52flavors. And then we're going to say
  19883. 12:44:54one, comma, we're going to say top
  19884. 12:44:57topped with comm, two. So what this is
  19885. 12:45:02essentially going to do is we're going
  19886. 12:45:04to say for one, we're going to take the
  19887. 12:45:06very first one in flavors and then we're
  19888. 12:45:09going to loop through all of two as
  19889. 12:45:11well. So we're going to loop through hot
  19890. 12:45:13fudge, Oreos, and marshmallows. And once
  19891. 12:45:17we print that off, then we will loop all
  19892. 12:45:19the way back to flavors and look at the
  19893. 12:45:22next iteration or the next sequence
  19894. 12:45:24within the first for loop. So let's run
  19895. 12:45:26this really quickly and see what we get.
  19896. 12:45:29So as you can see, it goes vanilla,
  19897. 12:45:32vanilla, vanilla, and vanilla is topped
  19898. 12:45:34with the hot fudge, the Oreos, and the
  19899. 12:45:36marshmallows. And then we start
  19900. 12:45:38iterating through our second one in our
  19901. 12:45:40first for loop. So there's that
  19902. 12:45:41hierarchy. So we're iterating completely
  19903. 12:45:43through this one before we actually go
  19904. 12:45:45to the very first for loop and start
  19905. 12:45:47iterating through that one again. Now
  19906. 12:45:48that is essentially how a nested for
  19907. 12:45:50loop works. These nested for loops can
  19908. 12:45:52get very complicated. In fact, for loops
  19909. 12:45:55in general can get very complicated the
  19910. 12:45:57more you add to it and the more you're
  19911. 12:45:59wanting to do with it. But that is
  19912. 12:46:00basically how a for loop and a nested
  19913. 12:46:02for loop works. Thank you guys so much
  19914. 12:46:04for watching. Be sure to like and
  19915. 12:46:06subscribe below and I'll see you in the
  19916. 12:46:07next video.
  19917. 12:46:12>> [music]
  19918. 12:46:20>> Hello everybody. Today we're going to be
  19919. 12:46:21taking a look at while loops in Python.
  19920. 12:46:23The while loop in Python is used to
  19921. 12:46:25iterate over a block of code as long as
  19922. 12:46:27the test condition is true. Now the
  19923. 12:46:29difference between a for loop and a
  19924. 12:46:31while loop is that a for loop is going
  19925. 12:46:32to iterate over the entire sequence
  19926. 12:46:34regardless of a condition. But the while
  19927. 12:46:36loop is only going to iterate over that
  19928. 12:46:38sequence as long as a specific condition
  19929. 12:46:40is met. Once that condition is not met,
  19930. 12:46:42the code is going to stop and it's not
  19931. 12:46:44going to iterate through the rest of the
  19932. 12:46:45sequence. So if we take a look at this
  19933. 12:46:46flowchart right here, we're going to
  19934. 12:46:48enter this while loop and we have a test
  19935. 12:46:50condition right here. The first time
  19936. 12:46:52that this test condition comes back
  19937. 12:46:53false, it's going to exit the while
  19938. 12:46:55loop. So let's start actually writing
  19939. 12:46:56out the code and see how this while loop
  19940. 12:46:58works. So let's create a variable. We're
  19941. 12:47:00just going to say number is equal to
  19942. 12:47:02one. And then we'll say while. And now
  19943. 12:47:04we need to write our condition that
  19944. 12:47:05needs to be met in order for our block
  19945. 12:47:07of code beneath this to run. So we're
  19946. 12:47:09going to say while number is less than
  19947. 12:47:12five. And then we'll do colon enter. And
  19948. 12:47:15now this is our block of code. We're
  19949. 12:47:17going to say print and then we'll say
  19950. 12:47:18number. Now what we need to do is
  19951. 12:47:20basically create a counter. We're going
  19952. 12:47:22to say number equals number plus one. If
  19953. 12:47:26you've never done something like this,
  19954. 12:47:27it's kind of like a counter. Most people
  19955. 12:47:28will start it at zero. In fact, let's
  19956. 12:47:30start it at zero. And then each time it
  19957. 12:47:32runs through this while loop, it's going
  19958. 12:47:34to add one to this number up here. And
  19959. 12:47:36then it's going to become a 1, a 2, a
  19960. 12:47:38three each time it iterates through this
  19961. 12:47:40while loop. Now once this number is no
  19962. 12:47:42longer less than five, it'll break out
  19963. 12:47:45of the while loop and it will no longer
  19964. 12:47:47run. So let's run this really quick by
  19965. 12:47:49hitting shift enter. So it starts at
  19966. 12:47:51zero and it's going to say while the
  19967. 12:47:53number is less than five, print number.
  19968. 12:47:55So the first time that it runs through
  19969. 12:47:57it is zero and so it prints zero and
  19970. 12:48:00then it adds one to number and then it
  19971. 12:48:03continues that y loop right here and it
  19972. 12:48:05keeps looping through this portion. It
  19973. 12:48:06never goes back up here to this line of
  19974. 12:48:08code. This is just our variable that we
  19975. 12:48:10start with. And then once this condition
  19976. 12:48:12is no longer met once it is false then
  19977. 12:48:15it's going to break out of that code.
  19978. 12:48:17Now that we basically know how a while
  19979. 12:48:18loop works let's look at something
  19980. 12:48:20called a break statement. So let's copy
  19981. 12:48:22this right down here. And what we're
  19982. 12:48:24going to say is if number is equal to
  19983. 12:48:28three, we're going to break. Now with
  19984. 12:48:30the break statement, we can basically
  19985. 12:48:32stop the loop even if the while
  19986. 12:48:34condition is true. So while this number
  19987. 12:48:36is less than five, it's going to
  19988. 12:48:37continue to loop through. But now we
  19989. 12:48:40have this break statement. So it's going
  19990. 12:48:41to say if the number equals three, we're
  19991. 12:48:43going to break out of this while loop.
  19992. 12:48:45But if this is false, we're going to
  19993. 12:48:47continue adding to that number just like
  19994. 12:48:49normal. So let's execute this. So, as
  19995. 12:48:51you can see, it only went to three
  19996. 12:48:52instead of four like before because each
  19997. 12:48:55time it was running through this while
  19998. 12:48:57loop, it was checking if the number was
  19999. 12:48:58equal to three. And once it got to
  20000. 12:49:00three, this became true. And then we
  20001. 12:49:02broke out of this while loop. The next
  20002. 12:49:04thing that I want to look at, and we'll
  20003. 12:49:05copy this right down here, is an else
  20004. 12:49:08statement, much like an if statement.
  20005. 12:49:10But we can use the else statement with a
  20006. 12:49:11while loop, which runs the block of
  20007. 12:49:13code, and when that condition is no
  20008. 12:49:15longer true, then it activates the else
  20009. 12:49:17statement. So, we'll go right down here
  20010. 12:49:19and we'll say else and we'll do a colon
  20011. 12:49:22and enter. And then we'll say print and
  20012. 12:49:25we'll say no longer
  20013. 12:49:29less than five. Now, because this if
  20014. 12:49:31statement is still in there, it will
  20015. 12:49:32break. So, let's say six. And then we'll
  20016. 12:49:36run this. And so, it's going to iterate
  20017. 12:49:37through this block of code. And once
  20018. 12:49:39this statement is no longer true, once
  20019. 12:49:41we break out of it, we're going to go to
  20020. 12:49:43our else statement. Now, as long as this
  20021. 12:49:45statement is true, it's going to
  20022. 12:49:46continue to iterate through. But once
  20023. 12:49:48this condition is not met, then it will
  20024. 12:49:50go to our else statement and we'll run
  20025. 12:49:52that line of code. Now, the else
  20026. 12:49:53statement is only going to trigger if
  20027. 12:49:55the while loop no longer is true. If we
  20028. 12:49:58have something like this if statement
  20029. 12:49:59that causes it to break out of the while
  20030. 12:50:01loop, the else statement will no longer
  20031. 12:50:03work. So, let's say if the number is
  20032. 12:50:05three and we run this, the else
  20033. 12:50:07statement is no longer going to trigger.
  20034. 12:50:09So, this body of code will not be run.
  20035. 12:50:11Now, the next thing that I want to look
  20036. 12:50:12at is the continue statement. If the
  20037. 12:50:13continue statement is triggered, it
  20038. 12:50:15basically rejects all remaining
  20039. 12:50:17statements in the current iteration of
  20040. 12:50:18the loop and then we'll go to the next
  20041. 12:50:20iteration. Now to demonstrate this, I'm
  20042. 12:50:22going to change this break into a
  20043. 12:50:24continue. So before when we had the
  20044. 12:50:26break, if the number was equal to three,
  20045. 12:50:28it would stop all the code completely.
  20046. 12:50:31But when we change this to continue,
  20047. 12:50:33which we'll do right now, what it's
  20048. 12:50:35going to do is it's no longer going to
  20049. 12:50:36run through any of the subsequent code
  20050. 12:50:38in this block of code. It's just going
  20051. 12:50:40to go straight up to the beginning and
  20052. 12:50:42restart our while loop. So, what's going
  20053. 12:50:44to happen when we run this is it's going
  20054. 12:50:46to come to three. It's going to become
  20055. 12:50:48three and it's going to continue back
  20056. 12:50:49into the while loop, but it's never
  20057. 12:50:51going to have that number change to be
  20058. 12:50:53added to one to continue with the while
  20059. 12:50:55loop. This will basically create an
  20060. 12:50:57infinite loop. Let's try this really
  20061. 12:50:59quickly. And as you can see, it's going
  20062. 12:51:01to stay three forever. Eventually, this
  20063. 12:51:03would time out, but I'm just going to
  20064. 12:51:05stop the code really quick. So if we
  20065. 12:51:06just change up the order of which we're
  20066. 12:51:09doing things, we're going to say there
  20067. 12:51:12and we're going to put this down here.
  20068. 12:51:14So what it's going to do now, instead of
  20069. 12:51:16printing the number immediately and then
  20070. 12:51:18adding the number later, we're going to
  20071. 12:51:20add the number right away and then we're
  20072. 12:51:22going to say if it is three, we're going
  20073. 12:51:24to continue and it's going to print the
  20074. 12:51:25number. So let's try executing this and
  20075. 12:51:27see what happens. So as you can see, we
  20076. 12:51:29no longer have the three in our output.
  20077. 12:51:31What it did was when we got to the
  20078. 12:51:33number three, it continued and didn't
  20079. 12:51:35execute this right here, which prints
  20080. 12:51:37off that number. So, that really is the
  20081. 12:51:39basics of the while loop. I hope that
  20082. 12:51:41this was helpful. I hope that you
  20083. 12:51:42learned something in this video. If you
  20084. 12:51:44did, be sure to like and subscribe
  20085. 12:51:45below, and I'll see you in the next
  20086. 12:51:47video.
  20087. 12:51:59Hello everybody. Today we're going to be
  20088. 12:52:01taking a look at functions in Python. A
  20089. 12:52:03function is a block of code which is
  20090. 12:52:05only run when you call it. So right here
  20091. 12:52:07we're defining our function and then
  20092. 12:52:09this is our body of code that when we
  20093. 12:52:11actually call it is going to be ran. So
  20094. 12:52:14right here we have our function call and
  20095. 12:52:15all we're doing is putting the function
  20096. 12:52:17with the parenthesis. That is basically
  20097. 12:52:19us calling that function and then we
  20098. 12:52:21have our output. Throughout this video,
  20099. 12:52:23I'm going to show you how to write a
  20100. 12:52:24function as well as pass arguments to
  20101. 12:52:26that function and then a few other
  20102. 12:52:27things like arbitrary arguments, keyword
  20103. 12:52:30arguments, and arbitrary keyword
  20104. 12:52:32arguments. All of these things are
  20105. 12:52:33really important to know when you are
  20106. 12:52:34using functions. So, let's get started
  20107. 12:52:36by writing our very first function
  20108. 12:52:38together. We're going to start off by
  20109. 12:52:39saying def. That is the keyword for
  20110. 12:52:41defining a function. Then, we can
  20111. 12:52:44actually name our function. And for this
  20112. 12:52:45one, we're just going to do first
  20113. 12:52:48function. And then, we do an open
  20114. 12:52:50parenthesis. and then we'll put a colon.
  20115. 12:52:52We'll hit enter and it'll automatically
  20116. 12:52:54indent for us. And this is where our
  20117. 12:52:56body of code is going to go. Now, within
  20118. 12:52:57our body of code, we can write just
  20119. 12:52:59about anything. And in this video, I'm
  20120. 12:53:00not going to get super advanced. We're
  20121. 12:53:02just going to walk through the basics to
  20122. 12:53:03make sure that you understand how to use
  20123. 12:53:05functions. So, for right now, all we're
  20124. 12:53:07going to say is print. We'll do an open
  20125. 12:53:09parenthesis. We'll do an apostrophe, and
  20126. 12:53:11we'll say we did it. And now, we're
  20127. 12:53:14going to hit shift enter. And this is
  20128. 12:53:16not going to do anything. At least you
  20129. 12:53:18won't see any output from this. If we
  20130. 12:53:20want to see the output or we actually
  20131. 12:53:21want to run that function and some
  20132. 12:53:23functions don't have outputs, but if we
  20133. 12:53:25want to run that function, what we have
  20134. 12:53:27to do is just copy this and put it right
  20135. 12:53:29down here. And now we're going to
  20136. 12:53:31actually call our function. So let's go
  20137. 12:53:33ahead and click shift enter. And now
  20138. 12:53:35we've successfully called our first
  20139. 12:53:37function. This function is about as
  20140. 12:53:38simple as it could possibly be. But now
  20141. 12:53:40let's take it up a notch and start
  20142. 12:53:42looking at arguments. So, let's go right
  20143. 12:53:44down here and we're going to say define
  20144. 12:53:47number
  20145. 12:53:49squared. We'll do a parenthesis and our
  20146. 12:53:52colon as well. Now, really quickly, when
  20147. 12:53:54you're naming your function, it's kind
  20148. 12:53:55of like naming a variable. You can use
  20149. 12:53:57something like x or y, but I tend to
  20150. 12:53:59like to be a little bit more
  20151. 12:54:00descriptive. But now, let's take a look
  20152. 12:54:02at passing an argument into a function.
  20153. 12:54:04The argument is going to be passed right
  20154. 12:54:06here in the parenthesis. So, for us, I'm
  20155. 12:54:09just going to call it a number. And
  20156. 12:54:11then, we're going to hit enter. And now
  20157. 12:54:13we'll write our body of code. And all
  20158. 12:54:14we're going to do for this is type print
  20159. 12:54:16and open parenthesis. And we'll say
  20160. 12:54:18number and we'll do two stars. At least
  20161. 12:54:21that's what I call it, a star. And a
  20162. 12:54:23two. And what this is going to do is
  20163. 12:54:24it's going to take the number that we
  20164. 12:54:26pass into our function. It's going to
  20165. 12:54:28put it right here in our body of code.
  20166. 12:54:30And then for what we're doing, it's
  20167. 12:54:32going to put it to the power of two. And
  20168. 12:54:33so when the user or you run this and
  20169. 12:54:36call this function, this number is
  20170. 12:54:38something that you can specify. It's an
  20171. 12:54:40argument that you can input that will
  20172. 12:54:42then be run in this body of code. So
  20173. 12:54:44let's copy this right here and then
  20174. 12:54:47we'll put it right down here into this
  20175. 12:54:49next cell and we'll say five. And so
  20176. 12:54:52this five is going to be passed through
  20177. 12:54:53into this function and be called right
  20178. 12:54:56here for this print statement. Let's run
  20179. 12:54:58it and it should come out as I believe
  20180. 12:55:0025. That is my fault. I forgot to
  20181. 12:55:02actually run this block of code. So I'm
  20182. 12:55:04going to hit shift enter. So now we've
  20183. 12:55:06defined our function up here. And now we
  20184. 12:55:08can actually call it. So now we'll hit
  20185. 12:55:10shift enter and we got our output of 25.
  20186. 12:55:13Now in this function we only called one
  20187. 12:55:15argument but you can basically call as
  20188. 12:55:17many arguments as you want. You just
  20189. 12:55:19have to separate them by commas. So
  20190. 12:55:21let's copy this and we'll put it right
  20191. 12:55:24down here. Now we'll say number squared
  20192. 12:55:28custom and then we'll do number and then
  20193. 12:55:31we'll do power. So now we can specify
  20194. 12:55:35our number as well as the power that we
  20195. 12:55:37want to raise it to. So instead of
  20196. 12:55:38having two, which is what you call
  20197. 12:55:40hard-coded, we can now customize that
  20198. 12:55:42and we'll have power. And now when we
  20199. 12:55:45call this function, we can specify the
  20200. 12:55:47number and the power and both of those
  20201. 12:55:49will go into this body of code and be
  20202. 12:55:51run. And we can customize those numbers.
  20203. 12:55:53So let's copy this
  20204. 12:55:56and we'll say
  20205. 12:55:585 to the power of three. And let's make
  20206. 12:56:02sure I ran this. So let's do shift
  20207. 12:56:04enter. And now we will call our
  20208. 12:56:06function. And let's hit shift enter. And
  20209. 12:56:08we got 5 to the power of three, which is
  20210. 12:56:11125. And just one last thing to mention
  20211. 12:56:13is if you have two arguments within your
  20212. 12:56:16function and you are calling it right
  20213. 12:56:18here, you have to pass in two arguments.
  20214. 12:56:20You can't just have one. So if we have a
  20215. 12:56:22five right here, it's going to error
  20216. 12:56:23out. We have to specify both arguments
  20217. 12:56:27for it to work. Now let's take a look at
  20218. 12:56:30arbitrary arguments. Now, arbitrary
  20219. 12:56:33arguments are really interesting because
  20220. 12:56:35if you don't know how many arguments you
  20221. 12:56:37want to pass through, if you don't know
  20222. 12:56:38if it's a one, a two, or a three, you
  20223. 12:56:40can specify that later when you're
  20224. 12:56:42calling the argument. So, you don't have
  20225. 12:56:44to do it up front and know that
  20226. 12:56:45information ahead of time. So, let's
  20227. 12:56:47define our function. So, we're going to
  20228. 12:56:48say define and then we're going to say
  20229. 12:56:50number_s
  20230. 12:56:53and we'll do an open parenthesis and a
  20231. 12:56:55colon. Now within our argument right
  20232. 12:56:58here, typically we would just specify
  20233. 12:57:00here's what our argument will be. It
  20234. 12:57:02will be number or it will be a word,
  20235. 12:57:04right? But what we're going to do is
  20236. 12:57:05something called an arbitrary argument.
  20237. 12:57:07So it's unknown. So we're going to put
  20238. 12:57:09star and we'll say args. Now you will
  20239. 12:57:12see something exactly like this.
  20240. 12:57:14Typically if you're looking at tutorials
  20241. 12:57:15that'll have star args in there or if
  20242. 12:57:17you're looking at just a generic piece
  20243. 12:57:19of code, this is what it will look like.
  20244. 12:57:21But for us, we're going to actually put
  20245. 12:57:23number. So again, we have the star and
  20246. 12:57:25then we have our arbitrary argument
  20247. 12:57:28right here. And then we'll hit enter and
  20248. 12:57:30we're going to say print open
  20249. 12:57:32parenthesis. And this is where it's
  20250. 12:57:34going to get a little bit different. So
  20251. 12:57:35we're going to say number and then we're
  20252. 12:57:37going to do an open bracket and let's
  20253. 12:57:38say zero and then we'll do that times
  20254. 12:57:42and then we'll say number again with a
  20255. 12:57:45bracket of one. So in a little bit once
  20256. 12:57:47we run this and then we call this number
  20257. 12:57:49args function right here we're going to
  20258. 12:57:51need to specify the number zero and the
  20259. 12:57:54number one that's going to be called. So
  20260. 12:57:56let's go ahead and run this and then we
  20261. 12:57:58are going to call it and let's say 5a 6
  20262. 12:58:04comma 1 2 8. So right up here we did not
  20263. 12:58:08know how many arguments we were going to
  20264. 12:58:10pass through. It could be five it could
  20265. 12:58:12be a thousand. We could also call in a
  20266. 12:58:15tupole and that's what this is right
  20267. 12:58:16here. We're calling in a tupole. So what
  20268. 12:58:19it's going to do now is when it calls
  20269. 12:58:20this number, it's going to call the very
  20270. 12:58:22first within that tupole which will be
  20271. 12:58:23that five. And then it'll also call in
  20272. 12:58:25this number which will be the first
  20273. 12:58:27position which is the six. So let's hit
  20274. 12:58:30shift enter and it's going to multiply
  20275. 12:58:32these numbers together. So 5 * 6 is
  20276. 12:58:34equal to 30. Now like I just said this
  20277. 12:58:37is a tupole. So we don't actually have
  20278. 12:58:38to write out these numbers like we just
  20279. 12:58:40did. we can pass through a tupil when we
  20280. 12:58:43are actually calling this function.
  20281. 12:58:45Let's do that right up here. Let's just
  20282. 12:58:47create um let's call it args tupil and
  20283. 12:58:51we'll do open parentheses and we'll do
  20284. 12:58:54the same numbers. Let's just copy it to
  20285. 12:58:57make it easier.
  20286. 12:58:59And now we've created this tupil right
  20287. 12:59:01here which we can then pass in. And this
  20288. 12:59:03is a lot more handy, a lot more
  20289. 12:59:05specific. And this is most likely how
  20290. 12:59:07someone would do something like this.
  20291. 12:59:09But let's now create this.
  20292. 12:59:12And now we can copy args tupole and pass
  20293. 12:59:15it through. Now, really quickly, this is
  20294. 12:59:18going to fail. And I'm doing that on
  20295. 12:59:19purpose, but I want to show you what you
  20296. 12:59:20need to do in order to pass through this
  20297. 12:59:22tupole. So, right now, it's going to say
  20298. 12:59:25tupil index is out of range. All you
  20299. 12:59:28have to do in order to use this is you
  20300. 12:59:30have to specify a star before it just
  20301. 12:59:32like you did when you were creating your
  20302. 12:59:34argument up here. we have to put a star
  20303. 12:59:36in front of our tupil that we just
  20304. 12:59:38passed through. And now let's try
  20305. 12:59:39running this. And now it works properly.
  20306. 12:59:42Now the last two things that we're going
  20307. 12:59:43to look at are keyword arguments and
  20308. 12:59:45arbitrary keyword arguments. There are
  20309. 12:59:47more things that you can learn and do
  20310. 12:59:49within functions, but again I'm just
  20311. 12:59:51trying to teach you the basics to make
  20312. 12:59:52sure that you understand how they work.
  20313. 12:59:54So let's go right up here. And a keyword
  20314. 12:59:56argument is kind of similar to this
  20315. 12:59:58right here. And let's actually copy this
  20316. 13:00:01and put it right down here. Now, a
  20317. 13:00:04keyword argument is very similar in that
  20318. 13:00:06you're going to specify your arguments
  20319. 13:00:08right here. But what we did up here, let
  20320. 13:00:11me bring this down. When we actually
  20321. 13:00:14called the function, what we did was we
  20322. 13:00:17just put in a five and a three. And when
  20323. 13:00:19we did that, it automatically assigned
  20324. 13:00:21number to five and power to three. And
  20325. 13:00:24that's totally fine and you can do that.
  20326. 13:00:26But if you want a little bit more
  20327. 13:00:28control, you can use a keyword argument.
  20328. 13:00:30So right here we could say power is
  20329. 13:00:34equal to five and number is equal to
  20330. 13:00:39three. So I just switched it around,
  20331. 13:00:40right? Number was assigned to five and
  20332. 13:00:42power was assigned to three, but I just
  20333. 13:00:44switched it to show you how this might
  20334. 13:00:46work. So let's run both of these. And
  20335. 13:00:49now it's 3 to the power of five, which
  20336. 13:00:51is 243.
  20337. 13:00:53So that essentially is a keyword
  20338. 13:00:54argument. Again, it just gives you a
  20339. 13:00:56little bit more control. you don't have
  20340. 13:00:58to put them in specific positions like
  20341. 13:01:00if you're just calling multiple
  20342. 13:01:01arguments. Now let's come right down
  20343. 13:01:03here. We're going to create basically
  20344. 13:01:04another custom function. Uh so for this
  20345. 13:01:07one we're going to write define number_g
  20346. 13:01:12and then we'll do an open parenthesis a
  20347. 13:01:14colon and enter. And what this one is is
  20348. 13:01:17this one is a keyword argument or an
  20349. 13:01:20arbitrary keyword argument. Now, to
  20350. 13:01:22specify an arbitrary argument, all we
  20351. 13:01:24did was a star and then we input number.
  20352. 13:01:28But if we're doing a keyword argument,
  20353. 13:01:30we actually have to have two stars right
  20354. 13:01:32here. So, let's start taking a look. And
  20355. 13:01:34again, if you're doing arbitrary, it
  20356. 13:01:36means we don't really know how many
  20357. 13:01:38keyword arguments we want to pass into
  20358. 13:01:40our function. So, we're just going to
  20359. 13:01:42put starst star number. And then later
  20360. 13:01:44within our body of code, and when we're
  20361. 13:01:45calling it, we'll be able to specify it.
  20362. 13:01:48And just like the arbitrary argument
  20363. 13:01:50before, the arbitrary keyword argument
  20364. 13:01:52means we really just don't know how many
  20365. 13:01:54keyword arguments we're going to need to
  20366. 13:01:55pass into our function. So to
  20367. 13:01:57demonstrate this, let's write print do
  20368. 13:02:00an open parenthesis and we'll say my
  20369. 13:02:02oops need to do an apostrophe.
  20370. 13:02:05My number is we'll do just like that
  20371. 13:02:10little space and we'll say plus. And
  20372. 13:02:11this is kind of where it gets a little
  20373. 13:02:13interesting or a little bit more tricky.
  20374. 13:02:15So we're going to say is number. So this
  20375. 13:02:17is us calling our number and then we're
  20376. 13:02:19going to do a bracket and then I'm
  20377. 13:02:22actually going to go to calling the
  20378. 13:02:24function. It's a little bit backward or
  20379. 13:02:26a little bit different than what you
  20380. 13:02:28might think. But when we're calling it,
  20381. 13:02:29what I'm going to do is I'm going to say
  20382. 13:02:31integer
  20383. 13:02:33is equal to let's just do some random
  20384. 13:02:35number. Now when we're calling that
  20385. 13:02:37keyword within our body of code, what
  20386. 13:02:39we're going to do is we're going to
  20387. 13:02:40actually type out integer just like
  20388. 13:02:43this. And this looks a little bit
  20389. 13:02:46different, but what this allows us to do
  20390. 13:02:48is we can put as many keyword arguments
  20391. 13:02:50in here as we want later, and I'll show
  20392. 13:02:52you in just a second. But for us, we're
  20393. 13:02:53just creating this key and this value
  20394. 13:02:56when we are calling it within the
  20395. 13:02:58function. So now when we create this and
  20396. 13:03:00we run this,
  20397. 13:03:02oh, whoops, I forgot this has to be a
  20398. 13:03:04string. Um, so let's run this again.
  20399. 13:03:08Now we'll say my number is 2309.
  20400. 13:03:12Then we're going to add, we'll say plus,
  20401. 13:03:15and this isn't going to look great, but
  20402. 13:03:16we'll say my other number because this
  20403. 13:03:19will all be in the same line. That's
  20404. 13:03:20okay. My other number. And then we'll
  20405. 13:03:23say number. And we can specify again
  20406. 13:03:26what we want in there. So now we can go
  20407. 13:03:29down here to where we're calling it.
  20408. 13:03:31We'll just put a comma. And we'll say
  20409. 13:03:34integer oops, integer
  20410. 13:03:382 is equal to, and we'll do a random
  20411. 13:03:40number. And then we'll put integer two
  20412. 13:03:43right here. And then we'll add plus
  20413. 13:03:46right here so we don't error out. We'll
  20414. 13:03:48create this. We'll run this. And as you
  20415. 13:03:51can see, both numbers were passed
  20416. 13:03:53through. Again, the syntax is terrible.
  20417. 13:03:55But now you can see that you have this
  20418. 13:03:56arbitrary keyword argument right here.
  20419. 13:03:59And all we have to do is put number
  20420. 13:04:02number. And we can pass through as many
  20421. 13:04:03of these arbitrary keyword arguments as
  20422. 13:04:05we want as long as we just specify it
  20423. 13:04:08within our function when we're calling
  20424. 13:04:09it. So, that's all we're going to look
  20425. 13:04:11at in today's video on functions. There
  20426. 13:04:13are, of course, other things that you
  20427. 13:04:14can do within functions, and it can get
  20428. 13:04:15a little bit more advanced, but I wanted
  20429. 13:04:17to show you the basics, the meat and
  20430. 13:04:19potatoes of things that I definitely
  20431. 13:04:20think you should know in order to get
  20432. 13:04:22started using functions. I hope that you
  20433. 13:04:24were able to understand functions better
  20434. 13:04:25because of this video. If you did, be
  20435. 13:04:27sure to like and subscribe below,
  20436. 13:04:28[music] and I will see you in the next
  20437. 13:04:30video.
  20438. 13:04:42Hello everybody. Today we're going to be
  20439. 13:04:44talking about converting data types in
  20440. 13:04:46Python. In this video I'm going to show
  20441. 13:04:47you how to convert several different
  20442. 13:04:49data types including strings, numbers,
  20443. 13:04:51sets, tupils, and even dictionaries. So
  20444. 13:04:54let's start off by creating a variable.
  20445. 13:04:55We'll say num_int is equal to 7. And we
  20446. 13:04:59can check that data type by saying type
  20447. 13:05:02and then inserting our variable num int.
  20448. 13:05:06And that will tell us that our data type
  20449. 13:05:08for this variable is an integer. Let's
  20450. 13:05:10go ahead and create another one. We're
  20451. 13:05:12going to say num string is equal to. And
  20452. 13:05:15for this one, we'll also do a seven. But
  20453. 13:05:18let's check the type. And we'll do an
  20454. 13:05:20open parenthesis. We'll say the type of
  20455. 13:05:22num string. And that one is a string.
  20456. 13:05:25Now let's say we wanted to add those.
  20457. 13:05:27We'll say num
  20458. 13:05:29sum. So the sum of num intint plus num
  20459. 13:05:35string. Now when we're adding these two
  20460. 13:05:37values, it is not going to work. It's
  20461. 13:05:39going to give us an error and it's going
  20462. 13:05:41to say unsupported operand for int and
  20463. 13:05:44string. So it cannot add both an integer
  20464. 13:05:46and a string. What we need to do in
  20465. 13:05:48order to add these two numbers is to
  20466. 13:05:50convert that string into an integer. So
  20467. 13:05:53let's go right up here. Let's add
  20468. 13:05:55another cell and let's say
  20469. 13:05:58num_string_converted [clears throat]
  20470. 13:06:02is equal to and we want to convert it
  20471. 13:06:04into an integer. So all we have to do to
  20472. 13:06:07convert it into an integer is type int
  20473. 13:06:10and then we're going to say num
  20474. 13:06:13string. And that is as easy as it's
  20475. 13:06:16going to get. All we have to do is say
  20476. 13:06:18integer with our num string inside of
  20477. 13:06:21it. And then it's going to convert it.
  20478. 13:06:23And we can even check it right after by
  20479. 13:06:25saying type numstring converted. And
  20480. 13:06:28let's run this. And now we can see that
  20481. 13:06:30it was converted into an integer. So now
  20482. 13:06:32let's add that numstring converted right
  20483. 13:06:35here.
  20484. 13:06:37Let's copy and replace that string with
  20485. 13:06:39the string converted.
  20486. 13:06:41And let's actually print out that num
  20487. 13:06:45sum. And it worked properly. Now, we did
  20488. 13:06:49not specify what type of value this
  20489. 13:06:51numsum was going to be. But because
  20490. 13:06:55it was two integers in here, it's going
  20491. 13:06:57to automatically apply that data type of
  20492. 13:06:59integer to that num sum. Let's go right
  20493. 13:07:01down here. And now let's look at how we
  20494. 13:07:04can convert lists, sets, and tupils. So
  20495. 13:07:07now let's say we have a list type, and
  20496. 13:07:10that's equal to 1 2 3. And we can check
  20497. 13:07:14it again by saying type
  20498. 13:07:17and that is a list. Let's say we want to
  20499. 13:07:20convert it to a tupil. It's fairly easy.
  20500. 13:07:23All we're going to do is write tupil say
  20501. 13:07:26list type. That list type is now going
  20502. 13:07:29to be a tupil. And we can check that by
  20503. 13:07:32saying type and wrapping it around this
  20504. 13:07:35tupil. And it shows us that it is
  20505. 13:07:38converting that list into a tupole. Now
  20506. 13:07:41we can also convert a list into a set.
  20507. 13:07:43But it may change the actual values
  20508. 13:07:47within it. Let's check that out really
  20509. 13:07:49quickly. So let's say we have this list
  20510. 13:07:51and let's add a few more values to this.
  20511. 13:07:55Just like that. Now let's say we want to
  20512. 13:07:57convert it to a set. So we're going to
  20513. 13:07:59run this and we'll say set
  20514. 13:08:03of list type. And let's try running this
  20515. 13:08:06and see what the output is. So this is
  20516. 13:08:08something that you really need to be
  20517. 13:08:10aware of when you are converting data
  20518. 13:08:12types because set does not act the same
  20519. 13:08:14as a list. A set is basically going to
  20520. 13:08:16take the unique values in the list and
  20521. 13:08:18convert it to a set and it fundamentally
  20522. 13:08:20changes the data that was in that
  20523. 13:08:22original list. And just to check the
  20524. 13:08:24data type, we can say type.
  20525. 13:08:27I'm just doing this for all of them. And
  20526. 13:08:29as you can see, that is now a set. Now
  20527. 13:08:31let's go down here and take a look at
  20528. 13:08:32dictionaries. Now, let's say we have a
  20529. 13:08:36dictionary called dictionary type and
  20530. 13:08:39we'll do a squiggly bracket and we'll
  20531. 13:08:42say name and we'll do a colon and we'll
  20532. 13:08:45say Alex. Then we'll do age and a colon
  20533. 13:08:50and we'll say 28
  20534. 13:08:53and then we'll do hair
  20535. 13:08:57colon.
  20536. 13:08:59And so really quickly, let's take that
  20537. 13:09:01dictionary type and just confirm that it
  20538. 13:09:04is a dictionary. And it is. And now what
  20539. 13:09:07we're going to do is take a look at all
  20540. 13:09:09of the items within that dictionary. So
  20541. 13:09:12we're going to do dictionary type do
  20542. 13:09:14items open parenthesis. And this is
  20543. 13:09:17going to show us all the items within
  20544. 13:09:19it. Now we can also take this and look
  20545. 13:09:21at something like the values.
  20546. 13:09:25And when we run that, these are our
  20547. 13:09:27values. So within our dictionary we have
  20548. 13:09:29items and that's what this is right
  20549. 13:09:31here. This is one item. And then within
  20550. 13:09:34that we have our values which are right
  20551. 13:09:36here. So Alex, 28 and NA. And then we
  20552. 13:09:39have something called a key. And this is
  20553. 13:09:42the key. The name, age, and hair are all
  20554. 13:09:45keys. And we can look at that by saying
  20555. 13:09:49keys. So let's say we want to take all
  20556. 13:09:51of the keys and put that into a list.
  20557. 13:09:54What we're going to do is we're going to
  20558. 13:09:55take this right here. say list.
  20559. 13:09:58We'll do an open parenthesis. We'll type
  20560. 13:10:00that in right there. So, it says a list
  20561. 13:10:02and we're converting these keys into a
  20562. 13:10:04list. And let's run that. And now this
  20563. 13:10:07is a list. And let's just check the type
  20564. 13:10:10as well just to confirm.
  20565. 13:10:13And as you can see, it was converted
  20566. 13:10:14properly into a list. And we can do the
  20567. 13:10:17exact same thing with values.
  20568. 13:10:22And the values can also be converted
  20569. 13:10:24into a list. Now, we can also convert
  20570. 13:10:26longer strings that aren't just numbers
  20571. 13:10:28like we did above in our very first
  20572. 13:10:29example. So, let's do long string and
  20573. 13:10:33we'll say I like to party. Now, we're
  20574. 13:10:37going to take this string and we're
  20575. 13:10:39going to say list long string. So, we're
  20576. 13:10:43going to convert this string into a
  20577. 13:10:45list. And let's see what happens. So, it
  20578. 13:10:47took every single character in that
  20579. 13:10:49string and put it into a list. And we
  20580. 13:10:51could also do a set as well. That one's
  20581. 13:10:54a lot shorter because it's only looking
  20582. 13:10:55at unique values. So, that is how you
  20583. 13:10:58convert data types in Python. Thank you
  20584. 13:11:00guys so much for watching. I really
  20585. 13:11:01appreciate it. If you like this video,
  20586. 13:11:03be sure to like and subscribe below and
  20587. 13:11:04I'll see you in the next video.
  20588. 13:11:07[music]
  20589. 13:11:18Hello everybody. Today we're going to be
  20590. 13:11:20working on building a BMI calculator in
  20591. 13:11:22Python. Now, before we get started, I
  20592. 13:11:24want to show you this BMI calculator
  20593. 13:11:25that I found online. And it shows you
  20594. 13:11:27the basic calculation that they use. And
  20595. 13:11:29that's the one we're going to use in
  20596. 13:11:30this video. And they also have this
  20597. 13:11:32calculator right down here. And some
  20598. 13:11:34ranges that we can use for our
  20599. 13:11:36calculator as well. So, for reference, I
  20600. 13:11:38weigh about 170.
  20601. 13:11:41I'm about 5'9. Let's calculate this. So,
  20602. 13:11:44I'm about a 25.1 BMI, which falls into
  20603. 13:11:48the overweight category. That's
  20604. 13:11:50unfortunate, but we can see exactly how
  20605. 13:11:53this works and how ours should work when
  20606. 13:11:55we actually build it. So, we're going to
  20607. 13:11:57kind of reference this throughout the
  20608. 13:11:58video. So, let's go right over here to
  20609. 13:12:01our BMI calculator. We need to calculate
  20610. 13:12:03weight and height and then run this
  20611. 13:12:06calculation right here. So, let's go
  20612. 13:12:07ahead and copy this
  20613. 13:12:10and we're going to put it right down
  20614. 13:12:11here.
  20615. 13:12:14And so, now we have our calculation. So
  20616. 13:12:17what we need is we need input from a
  20617. 13:12:20user and there is an input function
  20618. 13:12:22within Python that we're going to be
  20619. 13:12:24using. So let's actually give me a few
  20620. 13:12:26more cells. So the first thing that we
  20621. 13:12:28need to calculate is their weight. So
  20622. 13:12:30let's type out weight right here. We'll
  20623. 13:12:32say weight is equal to and this is where
  20624. 13:12:33we'll use our input function. So we'll
  20625. 13:12:35say input and when we actually run this
  20626. 13:12:38it's just going to give us this blank
  20627. 13:12:39square or a user can input something.
  20628. 13:12:42We'll say Alex. So this is our output is
  20629. 13:12:45what the actual user input and it does
  20630. 13:12:47save it to this variable. So if we say
  20631. 13:12:50print weight, it will still print out
  20632. 13:12:53Alex. Now this is where we want the user
  20633. 13:12:55to just like we did before where they'll
  20634. 13:12:58input their weight. So we want to kind
  20635. 13:13:00of give them a prompt for this. We'll
  20636. 13:13:02put a string in here. So I'll do a
  20637. 13:13:04double quote and then I'll say enter
  20638. 13:13:08your weight in and we're using pounds.
  20639. 13:13:12Let's say pounds
  20640. 13:13:14colon space. So now when we do this,
  20641. 13:13:17it'll say enter your weight in pounds.
  20642. 13:13:19I'll say 170. And then when we run this,
  20643. 13:13:22it does store that. Now let's do print.
  20644. 13:13:24I should have saved it. Wait again.
  20645. 13:13:27Oops. Now it's only storing the value of
  20646. 13:13:30170. It's not actually storing this
  20647. 13:13:32string right here. So that's really
  20648. 13:13:33important for when we do our
  20649. 13:13:34calculations later. Um I'm going to I'm
  20650. 13:13:38going to save this right down here
  20651. 13:13:39because I'm sure I'm going to use that
  20652. 13:13:40later. Um, so we have that as working.
  20653. 13:13:44Now, we need to also do our height. So,
  20654. 13:13:46let's copy this. And we'll put it right
  20655. 13:13:49here. And we'll do height
  20656. 13:13:53and enter your height in inches. So, now
  20657. 13:13:56for this one, if we hit enter,
  20658. 13:14:00it's actually running. Let's stop it
  20659. 13:14:01really quick and interrupt it. Let's try
  20660. 13:14:04running this. So, it's going to say,
  20661. 13:14:06enter your weight in pounds. That's the
  20662. 13:14:07first input. Say 170.
  20663. 13:14:11And then when I hit enter, it's going to
  20664. 13:14:13prompt me for that second input. And so
  20665. 13:14:15in inches, 59 is 69 in. And then I can
  20666. 13:14:20hit enter again. And now we have both of
  20667. 13:14:24our inputs. Now we need this calculation
  20668. 13:14:26right down here. And just like that. So
  20669. 13:14:31now we have weight in pounds* 703
  20670. 13:14:34divided by height in inches by height in
  20671. 13:14:37inches. So we actually have weight and
  20672. 13:14:39it's already written in there but I'm
  20673. 13:14:41just going to do it like this. We'll do
  20674. 13:14:42weight time 703. So that's pounds there.
  20675. 13:14:46Our weight in pounds time 703 divided by
  20676. 13:14:49now we have our height in inches
  20677. 13:14:52times the height in inches. So this is
  20678. 13:14:55our calculation right here. So let's do
  20679. 13:14:58this exact same thing. Let's run this.
  20680. 13:15:01And this times of course is not going to
  20681. 13:15:03work. Whoops. We need to do our star for
  20682. 13:15:06both of these. All right. Now, this is
  20683. 13:15:08our calculation. So, let's run this. So,
  20684. 13:15:11we have 170 and that's pounds and inches
  20685. 13:15:15was 69. Hit enter.
  20686. 13:15:19And it says cannot multiply the sequence
  20687. 13:15:21of non- integer type of string. Ah,
  20688. 13:15:23that's because these are being stored in
  20689. 13:15:25strings. So, if right down here I do and
  20690. 13:15:28we'll do type of height and we run that.
  20691. 13:15:33This is actually a string. So, we want
  20692. 13:15:36to change that because we don't need
  20693. 13:15:37that anymore. Get rid of that.
  20694. 13:15:40So, we don't want it to be a string. We
  20695. 13:15:42need those to be integers or floats or
  20696. 13:15:45really anything besides a string. It
  20697. 13:15:47just needs to be numerical. Uh, so
  20698. 13:15:49integer float really. So, let's do
  20699. 13:15:50integer. And then we'll wrap that input
  20700. 13:15:52in it. And we'll do the same thing for
  20701. 13:15:55this one.
  20702. 13:15:57Now, we have an integer for our weight,
  20703. 13:15:59an integer for our height. So now when
  20704. 13:16:01we're running this calculation, it
  20705. 13:16:03should work properly. Let's run this
  20706. 13:16:05again. Our pounds are 70.
  20707. 13:16:08Our height is 69 in.
  20708. 13:16:13And it's not giving us our output
  20709. 13:16:15because we're not printing anything.
  20710. 13:16:16Okay. So I just need to do
  20711. 13:16:19print
  20712. 13:16:21BMI. So let's try this again. 170 69.
  20713. 13:16:26And there is our BMI 25.1. So it worked
  20714. 13:16:29the exact same as this one. So they
  20715. 13:16:32input well we input our height, we
  20716. 13:16:35inputed our or we inputed our weight, we
  20717. 13:16:36inputed our height, and then it
  20718. 13:16:38calculated our BMI. The next thing that
  20719. 13:16:40we need to do is we need to kind of give
  20720. 13:16:43the user some context. Is that good? Is
  20721. 13:16:46there BMI in within a good range? A bad
  20722. 13:16:48range? We don't know. Uh so let's go
  20723. 13:16:50ahead and I'm going to see if I can copy
  20724. 13:16:53this. Know if this will work or not.
  20725. 13:16:56Let's go ahead and copy this right down
  20726. 13:16:57here. Perfect. So what we now need to do
  20727. 13:17:00is we need to say okay if the user has
  20728. 13:17:04given us this input we want to give them
  20729. 13:17:06or tell them if they are a normal
  20730. 13:17:09weight, overweight, obese, severely
  20731. 13:17:12obese, anything like that. And we have
  20732. 13:17:13these ranges. So that should help us out
  20733. 13:17:16quite a bit. So let's just write our if
  20734. 13:17:18statement and then we'll include it up
  20735. 13:17:20here. But let's go down here and we'll
  20736. 13:17:23say if and then we'll do BMI and let's
  20737. 13:17:26just say BMI is greater than zero. So if
  20738. 13:17:31it's greater than zero if they had any
  20739. 13:17:33input where the BMI was not zero which
  20740. 13:17:36should be every time if they do it
  20741. 13:17:37properly and they don't you know put a
  20742. 13:17:39string in there or something or type out
  20743. 13:17:4140 which maybe we should make a prompt
  20744. 13:17:43for that if that happens. Then we can
  20745. 13:17:45say if we'll do BMI
  20746. 13:17:49and now we need to give that first
  20747. 13:17:50range. So this range right here. So if
  20748. 13:17:52it's under 18.5 so we need to do a less
  20749. 13:17:56than. So if it's less than 18.5
  20750. 13:18:00and it just says under it doesn't say
  20751. 13:18:02under or equal to. So I'll keep it at
  20752. 13:18:0418.5. So if it's under 18.5
  20753. 13:18:08then let's give kind of the output.
  20754. 13:18:10We'll say print
  20755. 13:18:12and the output or the basically the
  20756. 13:18:15prompt is underweight. So we'll just say
  20757. 13:18:18you are under
  20758. 13:18:22under case underweight and just like
  20759. 13:18:25that. Um
  20760. 13:18:27then we're going to pass several LF
  20761. 13:18:30statements through here. But let's just
  20762. 13:18:32say else. So I guess this would be like
  20763. 13:18:36if they are if they don't input
  20764. 13:18:39something properly or something messes
  20765. 13:18:41up maybe we could write something like
  20766. 13:18:44um print oops
  20767. 13:18:47I'm thinking all this through. We can
  20768. 13:18:49write print enter valid inputs
  20769. 13:18:54or something like this or we can always
  20770. 13:18:57change that. But let's really quickly
  20771. 13:19:00let's run this.
  20772. 13:19:02Okay. So, I'm not in that range. Uh,
  20773. 13:19:04let's make the next one. So, then I can
  20774. 13:19:07be within a certain range. Oops.
  20775. 13:19:10And we need we should need one more
  20776. 13:19:12minimum. So, we'll say LF
  20777. 13:19:15and LF.
  20778. 13:19:18These next two are this 24.9. So, it's
  20779. 13:19:22going to check this one first. So, if
  20780. 13:19:23it's 18.5 or below 18.5, it's
  20781. 13:19:27automatically going to print this one.
  20782. 13:19:29So this next one, we don't have to do
  20783. 13:19:30like a range or anything. We can just
  20784. 13:19:33say if it's below if it's between 25 and
  20785. 13:19:3729.9. So this one actually should be
  20786. 13:19:40less than or equal to. Um, this one is
  20787. 13:19:44normal. Oh, whoops. 24.9.
  20788. 13:19:47So this one is 24.9.
  20789. 13:19:50This one is going to say you are normal
  20790. 13:19:53weight. So let's run this now.
  20791. 13:19:58Let's see. BMI was 25.1.
  20792. 13:20:02Oh, guys, I'm just messing up here. I
  20793. 13:20:04apologize. All right, this is the one
  20794. 13:20:06that I was part of. So, now it's going
  20795. 13:20:08to be I'm part of the overweight crowd.
  20796. 13:20:11Now, let's run this. And now our prompt
  20797. 13:20:13is you are overweight because remember
  20798. 13:20:14the BMI was saved right here as 25.1
  20799. 13:20:19down here. If we run through this, it's
  20800. 13:20:22saying no, you're not in Oops.
  20801. 13:20:26Get rid of that. No, you're not in under
  20802. 13:20:2818.5. You're not under 24.9. If you're
  20803. 13:20:32under 29.9,
  20804. 13:20:34you are overweight. So, that did work
  20805. 13:20:36properly. So, that's really good. And I
  20806. 13:20:38don't think I want this to be our output
  20807. 13:20:41for the person because we're going to
  20808. 13:20:42add this up here. It's just going to
  20809. 13:20:43give us the BMI. And then the output is
  20810. 13:20:46going to say you are overweight. Uh
  20811. 13:20:48let's make it a little bit more
  20812. 13:20:49customized. Um I'm going to say name is
  20813. 13:20:53equal to input. And then we'll say enter
  20814. 13:20:57your name.
  20815. 13:21:00Um, so it'll be enter your name. We'll
  20816. 13:21:02do Alex 70
  20817. 13:21:0569. There's our BMI. Now it's going to
  20818. 13:21:09run through this logic or it will run
  20819. 13:21:10through this logic in just a second.
  20820. 13:21:12When
  20821. 13:21:14we actually finish this, so then we have
  20822. 13:21:1734.9.
  20823. 13:21:21And let's do one more.
  20824. 13:21:25Oops. And then this one's going to be
  20825. 13:21:27for 39.9.
  20826. 13:21:31So this one was overweight. This one is
  20827. 13:21:34obese.
  20828. 13:21:36Severely obese. So we'll say severely is
  20829. 13:21:40that how you spell it? Severely obese.
  20830. 13:21:41And then anything that's over that 40
  20831. 13:21:44and over. So if it's not this one,
  20832. 13:21:46anything else should be se morbidly
  20833. 13:21:50obese. So actually this else statement
  20834. 13:21:52right here should say
  20835. 13:21:55uh you are
  20836. 13:21:59you are severely obese. This is going to
  20837. 13:22:01say morbidly morbidly obese. Now I added
  20838. 13:22:06that name up here because I wanted to
  20839. 13:22:08add that down below actually. So, we're
  20840. 13:22:11going to say uh name plus and then we'll
  20841. 13:22:16do like comma
  20842. 13:22:20you are underweight. So, it'll be a
  20843. 13:22:22little bit more personalized. Uh I think
  20844. 13:22:24it'll I think it'll be a nice touch. I
  20845. 13:22:27really do. We'll do it like this. And
  20846. 13:22:29we'll say you and let's go back and do
  20847. 13:22:31that to all of them.
  20848. 13:22:33And let me see how quickly I can do
  20849. 13:22:35this.
  20850. 13:22:38Oh, whoops. What' I do? Get rid of that.
  20851. 13:22:42Name plus you. Like that. Jeez, you guys
  20852. 13:22:48are seeing me mess up a ton. Name plus
  20853. 13:22:51you. And then
  20854. 13:22:55name plus you. So now let's run this.
  20855. 13:22:58And now it's a little more personalized.
  20856. 13:23:00It says Alex, you are overweight. So
  20857. 13:23:03this is all really good. Now this is an
  20858. 13:23:06if statement. Um, what we had done
  20859. 13:23:08before I think is actually what we
  20860. 13:23:09should put right down here. So, we'll
  20861. 13:23:10say else and then if that doesn't work,
  20862. 13:23:13we'll say, what do we say? Enter valid
  20863. 13:23:16input. We'll just put that. Um, and let
  20864. 13:23:19let me see if I can test this out. Don't
  20865. 13:23:23I don't know if this will error out or
  20866. 13:23:25if this will even work.
  20867. 13:23:27Let me just see if I can mess with it
  20868. 13:23:29and see if I can get it to work.
  20869. 13:23:30Actually, let's copy this. We're going
  20870. 13:23:34to copy this whole thing. We're going to
  20871. 13:23:36include it right here.
  20872. 13:23:38And now we have basically our entire
  20873. 13:23:41calculator. So, um, let's run this.
  20874. 13:23:45Enter your name. We'll say Alex.
  20875. 13:23:48Enter your pounds, 170. Enter your
  20876. 13:23:51inches, 69. And then it's going to say
  20877. 13:23:5425.1.
  20878. 13:23:56Alex, you are overweight. And that's
  20879. 13:23:58perfect. We could even go as far as
  20880. 13:24:00adding like some feedback. We say you
  20881. 13:24:03are overweight. And then it would be a
  20882. 13:24:05period and we could say um you need to
  20883. 13:24:09exercise more stop sitting and writing
  20884. 13:24:14so many Python tutorials. So now if we
  20885. 13:24:18run this we'll do Alex
  20886. 13:24:2117069.
  20887. 13:24:23It says Alex you are overweight. You
  20888. 13:24:25need to exercise more and stop sitting
  20889. 13:24:26and writing so many Python tutorials.
  20890. 13:24:30Period. And that's it. This is the
  20891. 13:24:34entire project. Um, you can go a ton
  20892. 13:24:38farther. You can include much more
  20893. 13:24:40complex logic. You could even build out
  20894. 13:24:42a UI to create your own, you know, app
  20895. 13:24:45just like this where it has this input
  20896. 13:24:47and this UI. You can build that out
  20897. 13:24:49within Jupyter Notebooks with Python.
  20898. 13:24:52Um, but that's not really what this
  20899. 13:24:54tutorial is for. This is just to kind of
  20900. 13:24:56help you um, think through some of the
  20901. 13:24:58logic of creating something like this.
  20902. 13:25:00So, you know, I hope that this was
  20903. 13:25:02helpful. I hope that this was fun. I
  20904. 13:25:03like creating stuff like this. We have
  20905. 13:25:05two other projects that we're going to
  20906. 13:25:06do and maybe I'll include more, but we
  20907. 13:25:08have two right now that I have planned.
  20908. 13:25:10Um, and I hope those are helpful. This
  20909. 13:25:12is probably our easiest one and they'll
  20910. 13:25:14get a little bit more difficult in the
  20911. 13:25:16next projects. So, I hope that this was
  20912. 13:25:18fun. I hope that this was helpful and
  20913. 13:25:20that you can now kind of utilize those
  20914. 13:25:22Python skills that you've been working
  20915. 13:25:23on. If you like this video, be sure to
  20916. 13:25:25like and subscribe below and I'll see
  20917. 13:25:27you in the next video.
  20918. 13:25:29[music]
  20919. 13:25:40Hello everybody. Today we're going to be
  20920. 13:25:42creating an automatic file sorter for
  20921. 13:25:43your files in File Explorer. Now, out of
  20922. 13:25:46all the projects that we've done in this
  20923. 13:25:47series so far, I think this one might be
  20924. 13:25:48the most difficult, but I also think
  20925. 13:25:50this one is the most cool because it has
  20926. 13:25:52some real life applications. So, without
  20927. 13:25:54further ado, let's take a look at some
  20928. 13:25:56files that we have right down here in my
  20929. 13:25:58file explorer. So, I have this beautiful
  20930. 13:26:00picture of Rosie uh right here. This is
  20931. 13:26:03a PNG file. I have a CSV file and a text
  20932. 13:26:06file. And I want to sort all of them
  20933. 13:26:09into their own folders depending on what
  20934. 13:26:11kind of file it is. So, if I go right in
  20935. 13:26:14here and I click on this one, I go to
  20936. 13:26:16properties, I can see that this is a PNG
  20937. 13:26:19file. Um, if I go into this one, I don't
  20938. 13:26:21need to, but if I go into this one, it's
  20939. 13:26:22a CSV file. And of course, this one is a
  20940. 13:26:25text file. So, I want three separate
  20941. 13:26:28folders in here, and I want them to
  20942. 13:26:31automatically go into those folders
  20943. 13:26:33without me having to drag and drop and
  20944. 13:26:35going and clicking. Now, we only have
  20945. 13:26:37four files here, but imagine if we have
  20946. 13:26:40thousands of files, how much time that
  20947. 13:26:42could save us. So, let's get out of here
  20948. 13:26:45and let's start writing our code. So
  20949. 13:26:48we're going to say import OS,
  20950. 13:26:52and then we're going to say shutil.
  20951. 13:26:55Now OS obviously stands for operating
  20952. 13:26:57system. Shutil, uh, I don't know what it
  20953. 13:27:00actually supposed to stand for, but what
  20954. 13:27:02it will allow us to do is do some
  20955. 13:27:03high-level operations on our files in
  20956. 13:27:06file explorer. So we're going to go
  20957. 13:27:07ahead and import those. And now that we
  20958. 13:27:10have those imported, uh, something
  20959. 13:27:11that's going to be very important for us
  20960. 13:27:13to have throughout this whole thing, and
  20961. 13:27:15this is anytime I'm working with like
  20962. 13:27:16directories or something like this, we
  20963. 13:27:18want to get this path down. So, I'm
  20964. 13:27:20going to go ahead and copy this path.
  20965. 13:27:23And we're just going to say path is
  20966. 13:27:25equal to, and we'll do this right here.
  20967. 13:27:28So, let's run this. And I need to put an
  20968. 13:27:31R right here to make this a raw text.
  20969. 13:27:34Um, so when you don't have the R, uh,
  20970. 13:27:36it's going to read in these, you know,
  20971. 13:27:38these backslashes and these colons and
  20972. 13:27:40different stuff. If we do R, it's just
  20973. 13:27:41going to read it in as the raw string
  20974. 13:27:43and that's what we want. So, here's what
  20975. 13:27:45we need to do there. There's a few
  20976. 13:27:47different things that have to happen
  20977. 13:27:48when we are writing this out. One thing
  20978. 13:27:50is is we need to go in here and we need
  20979. 13:27:52to see this path and we need to see are
  20980. 13:27:54there folders in here already? Um, if
  20981. 13:27:56not, we need to create a folder. So,
  20982. 13:27:59that's one of the first things that we
  20983. 13:28:01need to do. The next thing that we need
  20984. 13:28:03is it needs to check each of these files
  20985. 13:28:05individually, identify what kind of file
  20986. 13:28:08it is, and then put it into the correct
  20987. 13:28:11folder. So, we have to create the
  20988. 13:28:12folder, then check these, and then place
  20989. 13:28:15it into the correct folder. So, let's go
  20990. 13:28:18right out of here. So, what we're going
  20991. 13:28:20to start doing is we're going to start
  20992. 13:28:22working with these paths and these
  20993. 13:28:24directories. And some of these things
  20994. 13:28:25you may never have seen before, but
  20995. 13:28:27that's okay. I'll try to explain it as I
  20996. 13:28:28go through. So the first thing that
  20997. 13:28:30we're going to write is os.list
  20998. 13:28:33directories. Uh and what this is
  20999. 13:28:35actually going to do is show us all the
  21000. 13:28:36files in there. So we're going to say
  21001. 13:28:38path. So it should show us all the files
  21002. 13:28:41within path. And so here are our
  21003. 13:28:43results. So we have the data
  21004. 13:28:45professional results, fake text file,
  21005. 13:28:48our image, and our other image. So this
  21006. 13:28:50is actually showing us what files are in
  21007. 13:28:52that path. And that's super important
  21008. 13:28:54because we're probably going to have to
  21009. 13:28:56loop through this in some way later. Um,
  21010. 13:28:58I wrote this all out before, so I kind
  21011. 13:29:01of remember, but I'm doing this all off
  21012. 13:29:02the top of my head. So, I guarantee you
  21013. 13:29:04throughout this I'll make some mistakes.
  21014. 13:29:06But what we now need to do is we need to
  21015. 13:29:09create folders or check if there's a
  21016. 13:29:11folder and create it if it isn't there.
  21017. 13:29:12That's um the next step that we need to
  21018. 13:29:14take. So, let's go right down here and
  21019. 13:29:17we want to check if this path exists
  21020. 13:29:19already. So, if that folder already
  21021. 13:29:21exists. So, we're going to say
  21022. 13:29:22os.path.exists.
  21023. 13:29:26So this is going to check does this path
  21024. 13:29:28just like this path up here does it
  21025. 13:29:30already exist and then we're going to do
  21026. 13:29:32an open parenthesis. We'll say path. So
  21027. 13:29:34that's our path. Now we need to add a
  21028. 13:29:37folder name to this. Um we could
  21029. 13:29:40hardcode it. So we could do plus we
  21030. 13:29:43could say CSV files and that could work.
  21031. 13:29:46So it would say does this path already
  21032. 13:29:48exist? And we can try running this. And
  21033. 13:29:50it's going to say false. So this doesn't
  21034. 13:29:52already exist. But the thing is is we
  21035. 13:29:55need to create three separate paths. So
  21036. 13:29:56we could do this by just hard coding it
  21037. 13:30:00in by saying CSV files, image files, um,
  21038. 13:30:03and text files. Or we can just put this
  21039. 13:30:06all in a list and loop through it. I
  21040. 13:30:08think it's just going to be easier to do
  21041. 13:30:10that or I don't know, visually it's
  21042. 13:30:12going to be easier. So we'll do uh
  21043. 13:30:14folder_names
  21044. 13:30:17and we'll say is equal to and we'll
  21045. 13:30:19create a list. So I think I want to call
  21046. 13:30:21it CSV files. comma um image files or
  21047. 13:30:26PNG files, whatever you want to write.
  21048. 13:30:28And then we'll do text files.
  21049. 13:30:33Do text files. And then we can go right
  21050. 13:30:36down here. Um a little for loop. Uh I
  21051. 13:30:39think what we'll do, well actually let's
  21052. 13:30:41write folder
  21053. 13:30:44names. Um then we can put something like
  21054. 13:30:48uh let's write loop. Why not? Um, so a
  21055. 13:30:52little trick for the for loop is going
  21056. 13:30:54to say for and we'll say loop in and
  21057. 13:30:57we'll just do a range because we want it
  21058. 13:30:59to basically go through here. We don't
  21059. 13:31:01want it to actually give us these file
  21060. 13:31:02names. We just want it to count 0 1 and
  21061. 13:31:05two. So if we do range from 0 to two 0
  21062. 13:31:10uh 0 1 2 that should work. If we do um
  21063. 13:31:13this then when it loops through it's
  21064. 13:31:15going to call folder name and say zero
  21065. 13:31:17which would be CSV files, image files
  21066. 13:31:19and text files. Um, so let's
  21067. 13:31:24uh yeah, I need a colon. Let's run
  21068. 13:31:26through this really quickly. Uh,
  21069. 13:31:28shouldn't do anything.
  21070. 13:31:30But what we can do now is we can say,
  21071. 13:31:33okay, if this does not exist, what we
  21072. 13:31:37can do is actually create it. So we'll
  21073. 13:31:40say if not. So if this does not exist
  21074. 13:31:44then what we're going to do is take this
  21075. 13:31:49and we'll say osmake
  21076. 13:31:54directory and then we'll do just like
  21077. 13:31:57that. Um I think it's make directory s I
  21078. 13:32:02think that's correct. Um so let's test
  21079. 13:32:04this out really quickly. Let's see if
  21080. 13:32:06this works.
  21081. 13:32:08and invalid syntax. I need a colon.
  21082. 13:32:11Okay, so I just ran this. Let's see if
  21083. 13:32:14it did actually make those folders.
  21084. 13:32:17Let's refresh it. And it didn't. So,
  21085. 13:32:21let's just print this off. Um, so if
  21086. 13:32:24not, let's just print. Let's see. Does
  21087. 13:32:27this actually work?
  21088. 13:32:29Let's do if.
  21089. 13:32:33Okay.
  21090. 13:32:34Ah. Okay. So, I think I know what might
  21091. 13:32:38be happening. I think it's giving us It
  21092. 13:32:40may actually be Let Let's check this
  21093. 13:32:41really quick. Go to Python tutorials.
  21094. 13:32:44Oh, no.
  21095. 13:32:46I think it's creating
  21096. 13:32:49Yeah, it's creating these Python
  21097. 13:32:50tutorial images right here. Whoops.
  21098. 13:32:52Okay, so I just figured it out. Um,
  21099. 13:32:55let's go back into Python tutorials.
  21100. 13:32:57Don't take a look at any of those
  21101. 13:32:58notebooks. Those are secret. Um, we were
  21102. 13:33:01creating them in the wrong place. Um,
  21103. 13:33:04and that's because of this right here.
  21104. 13:33:05We need a backslash. So, we need to
  21105. 13:33:07actually include a backslash right here
  21106. 13:33:10in this path. We didn't have that. Um,
  21107. 13:33:15uly scanning string literal.
  21108. 13:33:18Okay. So, this backslash could cause an
  21109. 13:33:21issue. Let's see if I can do forward
  21110. 13:33:22slashes on all these. Just stick with
  21111. 13:33:25me, guys. I might cut this out. I might
  21112. 13:33:26not. We'll see if this is important.
  21113. 13:33:29Just going to keep talking while we're
  21114. 13:33:30doing it. Um, let's run this.
  21115. 13:33:35Okay. So, now that we're doing these
  21116. 13:33:36forward slashes, we're still checking.
  21117. 13:33:39Let's make sure we can still check those
  21118. 13:33:40files. Good. Now, when we loop through
  21119. 13:33:43this, I'm not going to Well, yeah, I can
  21120. 13:33:45print it off. Doesn't matter. I'm going
  21121. 13:33:47to print it and we'll see if that name
  21122. 13:33:48works. And then we're also going to um
  21123. 13:33:53uh well, I said if so, if it exists,
  21124. 13:33:56then make it. No, no, no. So, if not, I
  21125. 13:33:59think the not did make sense. We just
  21126. 13:34:00weren't sure. We had to do some um
  21127. 13:34:02checking. So, if it exists, then we're
  21128. 13:34:05going to create it. And we'll keep the
  21129. 13:34:06print in there because it doesn't really
  21130. 13:34:07matter. So, it's going to create the CSV
  21131. 13:34:10and image, but it didn't create the
  21132. 13:34:12text. Let's see. Okay, let's uh I don't
  21133. 13:34:17know why this would work, but let's run
  21134. 13:34:19it. Okay, so I think I just had the
  21135. 13:34:21wrong range. So, now we have our images
  21136. 13:34:24all right, we have our folders, all
  21137. 13:34:26three folders. Now, we need to write a
  21138. 13:34:28script that will read in these and check
  21139. 13:34:32and see what kind of file it is and
  21140. 13:34:34place it into the correct folder.
  21141. 13:34:36So, let's come right down here and let's
  21142. 13:34:39see what we need to do. So, now I think
  21143. 13:34:42we need to use this right here. Um, I
  21144. 13:34:45think we need to loop through this to be
  21145. 13:34:47able to check each one. So, we need to
  21146. 13:34:49name this. So, we'll just do um file_ame
  21147. 13:34:53is equal to run that. So now we have
  21148. 13:34:55this file name um and what we can do is
  21149. 13:34:59loop through this. So let's say
  21150. 13:35:03let's say for file in file name. So
  21151. 13:35:07we're going to loop through this. Now
  21152. 13:35:09when it goes through it needs to check
  21153. 13:35:12the it's going to check the file path
  21154. 13:35:14and in the file path it'll say txt.csv.
  21155. 13:35:18So let's say um if I think it should be
  21156. 13:35:22CSV. Let's test it on this one. But if
  21157. 13:35:26CSV is in
  21158. 13:35:28file name or actually it's file. So if
  21159. 13:35:33if it's in file
  21160. 13:35:35and not in and oh not not in but if it's
  21161. 13:35:40also not in this I believe because we're
  21162. 13:35:44going to check we're going to check each
  21163. 13:35:45of those folders. So, we're going to
  21164. 13:35:48loop through and it's going to check and
  21165. 13:35:50see if the CSV. So, if that string is in
  21166. 13:35:54the file,
  21167. 13:35:56then what we want to do is check that
  21168. 13:36:00it's also not in here. That's actually
  21169. 13:36:03just the folder. We also need um also
  21170. 13:36:07we're not doing that for loop anymore.
  21171. 13:36:09Um,
  21172. 13:36:11okay. I'm sorry. I'm talking this
  21173. 13:36:13through. I'm figuring it out as I go
  21174. 13:36:15because I may have forgotten some of
  21175. 13:36:17this. So, we're going to say this.
  21176. 13:36:19That's the CSV files. So, we need to
  21177. 13:36:22check this one. Um, let's do it like
  21178. 13:36:26this. Oops. Okay. So, it's going to
  21179. 13:36:30check to see if CSV files and I think it
  21180. 13:36:33needs that in between it. So, it's going
  21181. 13:36:34to say the path. So, there's our path
  21182. 13:36:37plus
  21183. 13:36:39slash CSV files. Um, actually, no. It
  21184. 13:36:43needs to be like this cuz we're going to
  21185. 13:36:44check that. Then I got it. All right, I
  21186. 13:36:46figured it out now. Then we're going to
  21187. 13:36:48check if this file is in there. Yeah.
  21188. 13:36:51So, that's right. So, it says if the CSV
  21189. 13:36:55is in the file, um, which is right where
  21190. 13:37:00am I looking?
  21191. 13:37:02Oh, file name. So, if it's in that list
  21192. 13:37:04of the actual files, which is all of
  21193. 13:37:06these. if we find CSV in any of these
  21194. 13:37:09files and it's not already in here. So,
  21195. 13:37:13it's going to say path plus CSV files.
  21196. 13:37:16Did I say files? Yeah, CSV files plus
  21197. 13:37:20file. Okay, that all looks correct. So,
  21198. 13:37:23if it's not in there, we're going to use
  21199. 13:37:25shuttle.move. Now, this is how we
  21200. 13:37:27actually move the file. It gives us the
  21201. 13:37:29ability to move what we want. Then,
  21202. 13:37:31we'll say move. We need to take it from
  21203. 13:37:33our initial path to our new path. So,
  21204. 13:37:36we're going to specify we'll separate by
  21205. 13:37:38a comma. We need to specify its original
  21206. 13:37:41path, which it should just be this
  21207. 13:37:46without this.
  21208. 13:37:48I think it should be file path because
  21209. 13:37:51this is where it is now. It's in the fi
  21210. 13:37:53this path with that file name. Then, we
  21211. 13:37:56need to say we want to move it to here.
  21212. 13:37:59That is what we want to do. Um,
  21213. 13:38:03yeah. So, let's check it with just this
  21214. 13:38:05one. and see if it works. Okay, it ran
  21215. 13:38:08through it. Let's go check. Aha, now
  21216. 13:38:10that CSV file is gone. Perfect. That is
  21217. 13:38:13exactly what we wanted to happen. Now we
  21218. 13:38:15can just recreate this for
  21219. 13:38:19um
  21220. 13:38:21for both our PNG files or our image
  21221. 13:38:23files and our text files. So we'll say
  21222. 13:38:25LF and LF
  21223. 13:38:29and let's do PNG.
  21224. 13:38:33Then we'll do image files
  21225. 13:38:36and image files because again we're just
  21226. 13:38:39doing the exact same thing. I can do
  21227. 13:38:40text files. The next one's going to be
  21228. 13:38:43text files. Text files. So this one's
  21229. 13:38:46going to check for txt.
  21230. 13:38:48Now do we need anything else? Um, we'll
  21231. 13:38:52just say else and we'll print off print
  21232. 13:38:57this file type is not included or or if
  21233. 13:39:02there's multiple files, we'll say there
  21234. 13:39:04are files in this path
  21235. 13:39:10that were not moved.
  21236. 13:39:12Okay. So, if we run through this, it's
  21237. 13:39:17going to catch our CSV, catch our PNG,
  21238. 13:39:19catch our text, and if not, it'll say
  21239. 13:39:21there are files in this path that were
  21240. 13:39:23not moved. Exclamation point. All right.
  21241. 13:39:25Now, let's run through this.
  21242. 13:39:28Uh,
  21243. 13:39:30uh, that's because if LF l
  21244. 13:39:35and then it's going to this else
  21245. 13:39:37statement. Uh, I don't know. Let's let's
  21246. 13:39:40circle back around to that in a second.
  21247. 13:39:42All of them were moved properly. That's
  21248. 13:39:46really good
  21249. 13:39:49really quickly. I I'll I'll check and
  21250. 13:39:51see. I just don't I'm going to take that
  21251. 13:39:52out for now. So, I'm just going to run
  21252. 13:39:54it. Um I we may or may not go back to
  21253. 13:39:56that, but let's check and see if
  21254. 13:39:58everything worked properly. So, let's go
  21255. 13:40:00into the CSV file. And we have our CSV
  21256. 13:40:03file. Let's go into our image files. And
  21257. 13:40:05we have our images. And let's go into
  21258. 13:40:08our text file. And there are our text
  21259. 13:40:12files. Now, is there anything else that
  21260. 13:40:15we need to do? I don't believe so. But
  21261. 13:40:18what I can do is I can take all this.
  21262. 13:40:23I can include it in here.
  21263. 13:40:26And I'm going to
  21264. 13:40:30basically restart it
  21265. 13:40:34just to see if it works properly from
  21266. 13:40:36scratch. Right. I just want to make sure
  21267. 13:40:38that I didn't miss anything. Um, and
  21268. 13:40:40we'll delete these.
  21269. 13:40:42So, we have our I'm just going to rerun
  21270. 13:40:45everything. We We imported,
  21271. 13:40:48we created our path. These are our file
  21272. 13:40:50names. And then when we run this, it
  21273. 13:40:52should take our folder names, check
  21274. 13:40:54through them. If they aren't already
  21275. 13:40:56created, it's going to create it. Don't
  21276. 13:40:59need it to print. So, let's get rid of
  21277. 13:41:00that. Then for the file within our file
  21278. 13:41:04names, and it check it checks each one.
  21279. 13:41:06We check if there's a CSV and if it's
  21280. 13:41:09already in that file, if it's already in
  21281. 13:41:12that folder, I mean, if it's in that
  21282. 13:41:14folder, then it doesn't do anything. But
  21283. 13:41:15if it isn't, so and not it's not in
  21284. 13:41:18there, it is going to move it to that
  21285. 13:41:20location. So, it's going to check CSV,
  21286. 13:41:22PNG, and text. I think everything should
  21287. 13:41:25work properly. Let's run this.
  21288. 13:41:29And it looks like it's working. Good,
  21289. 13:41:31good, good. And perfect. It worked
  21290. 13:41:35exactly how I had hoped. Um,
  21291. 13:41:38that's great. So, this is the automatic
  21292. 13:41:41file sorter in file explorer project.
  21293. 13:41:45Uh, you can go even a step further. So,
  21294. 13:41:47I had to come in here and manually run
  21295. 13:41:49this. You can go a step further and put
  21296. 13:41:51a timer on this where it automatically
  21297. 13:41:53does this maybe every hour, every day,
  21298. 13:41:57every 30 minutes. You can run this in
  21299. 13:41:59your background, especially if you
  21300. 13:42:00create um like an execution for this.
  21301. 13:42:04You can run this in your background. Um
  21302. 13:42:06if you are curious on how to do that, I
  21303. 13:42:08think I did something similar to that in
  21304. 13:42:10my web scraping project. Um my Amazon
  21305. 13:42:14web scraping project if you want to go
  21306. 13:42:15check that one out. But we're not going
  21307. 13:42:16to do it in this project. This is all I
  21308. 13:42:18wanted to show you how to do. So, I hope
  21309. 13:42:20that this was helpful. I hope that this
  21310. 13:42:21project was, you know, interesting and
  21311. 13:42:24that you liked it. And I hope that you
  21312. 13:42:25learned something. And so if you did, be
  21313. 13:42:27sure to like and subscribe below and I
  21314. 13:42:29will see you in the next video. What's
  21315. 13:42:31going on everybody? Welcome back to
  21316. 13:42:32another video. Today we're going to be
  21317. 13:42:34starting our Python web scraping
  21318. 13:42:35tutorial series. Now, this is more of a
  21319. 13:42:37continuation of the Python tutorial
  21320. 13:42:39series, but because we're going to be
  21321. 13:42:40focusing on web scraping for three or
  21322. 13:42:42four videos, I wanted to just make it
  21323. 13:42:44its own little minieries. In this
  21324. 13:42:46series, I'm going to show you the basics
  21325. 13:42:47of web scraping. how to actually look at
  21326. 13:42:49HTML, how to inspect a web page, how to
  21327. 13:42:51pull that data in, and then even put it
  21328. 13:42:53into a CSV file so you can save it and
  21329. 13:42:55use it. Now, in this series, we're just
  21330. 13:42:56covering the basics, which is a
  21331. 13:42:58fantastic place to start, but in future
  21332. 13:42:59series, I'll be going into some of the
  21333. 13:43:01more advanced web scraping topics as
  21334. 13:43:03well. So, without further ado, let's
  21335. 13:43:04jump on my screen and get started with
  21336. 13:43:05web scraping. Now, the first thing that
  21337. 13:43:07we need to learn is HTML. HTML stands
  21338. 13:43:10for hypertext markup language, and it's
  21339. 13:43:12used to describe all of the elements on
  21340. 13:43:15a web page. Now, when we actually go to
  21341. 13:43:17a website and start pulling data and
  21342. 13:43:19information, we need to know HTML so we
  21343. 13:43:21can specify exactly what we want to take
  21344. 13:43:24off of that website. So, that's where
  21345. 13:43:26HTML comes in. And we're going to look
  21346. 13:43:27at the basics, understanding just the
  21347. 13:43:29basic structure of HTML. Then, we'll go
  21348. 13:43:31look at a real website. And you'll kind
  21349. 13:43:33of see that it's a little bit more
  21350. 13:43:34difficult than what we just have right
  21351. 13:43:36here. But, this is the basic building
  21352. 13:43:38blocks to get to what the HTML actually
  21353. 13:43:40looks like on a website. Now, this is
  21354. 13:43:43basically what HTML looks like. We have
  21355. 13:43:45these angle brackets with things like
  21356. 13:43:47HTML, head, title, body, and then you'll
  21357. 13:43:51notice that at the end we'll have a body
  21358. 13:43:54and then we'll have a body at the
  21359. 13:43:56bottom. This forward/body denotes that
  21360. 13:43:59this is the end of the body section in
  21361. 13:44:02HTML. So everything inside of this is
  21362. 13:44:05within this body. So there is this
  21363. 13:44:07hierarchy within HTML. We have HTML and
  21364. 13:44:11HTML at the bottom which encapsulates
  21365. 13:44:13all the HTML on the website. Then we
  21366. 13:44:15have things like head and head, body and
  21367. 13:44:18body. Now within these sections, we
  21368. 13:44:20usually have things like classes, tags,
  21369. 13:44:22attributes, text, and all these other
  21370. 13:44:24things. Things that we'll get to in
  21371. 13:44:25different lessons, but one of the
  21372. 13:44:27easiest ones to notice and look at are
  21373. 13:44:29tags. Things like a P tag or a title
  21374. 13:44:32tag. Now, within these tags, because
  21375. 13:44:34this is a super simple example, we have
  21376. 13:44:37these strings here. my first web page.
  21377. 13:44:39And this is what's called a variable
  21378. 13:44:41string. And this is actual text that we
  21379. 13:44:43could take out of this web page. Now
  21380. 13:44:45that you understand the super basics of
  21381. 13:44:47HTML, let's actually go to our website.
  21382. 13:44:49And I'm going to have a link down below,
  21383. 13:44:51but it's going to be this one right
  21384. 13:44:52here. This is basically just a website
  21385. 13:44:54that you can, you know, practice web
  21386. 13:44:56scraping on. It's called
  21387. 13:44:57scrapethesite.com.
  21388. 13:44:59And what we're going to do is look at
  21389. 13:45:01the HTML behind this web page. And you
  21390. 13:45:03can do this on any website that you go
  21391. 13:45:05on. So we're going to rightclick. We're
  21392. 13:45:07going to go down to inspect.
  21393. 13:45:10Now, right off the bat, this looks a lot
  21394. 13:45:13more complicated and a lot more complex
  21395. 13:45:15than the very simple illustration that
  21396. 13:45:17we were looking at. But let's kind of
  21397. 13:45:20roll this up just a little bit. You'll
  21398. 13:45:22notice we have HTML and HTML at the
  21399. 13:45:24bottom. We have a head and there is the
  21400. 13:45:26end of the head and then a body and the
  21401. 13:45:28end of the body. So in a super simple
  21402. 13:45:31sense it is similar but just the
  21403. 13:45:34information that's within it is a lot
  21404. 13:45:36more difficult. Now if we look at this
  21405. 13:45:38title right here, this is our title tag.
  21406. 13:45:40If we click this little arrow, this is
  21407. 13:45:43our drop down. You'll notice that here
  21408. 13:45:45we have this string hockey teams forms
  21409. 13:45:47searching and pageionation. Now let's
  21410. 13:45:50say we didn't know we didn't want to
  21411. 13:45:52click on that and go find it. There is
  21412. 13:45:54something that's super helpful within
  21413. 13:45:55this inspection page that you can click
  21414. 13:45:57on right here. It says select an element
  21415. 13:45:59in the page to inspect it. So, we're
  21416. 13:46:01going to click on that. And as we go
  21417. 13:46:03through our page and let's click on this
  21418. 13:46:05title. It's going to take us to exactly
  21419. 13:46:07where this is in our HTML. This is
  21420. 13:46:10extremely helpful, extremely useful. For
  21421. 13:46:13example, let's say the data I want is
  21422. 13:46:15down here. I want to take in the Boston
  21423. 13:46:17Bruins. I can click on it and it's going
  21424. 13:46:19to take me to where that is exactly in
  21425. 13:46:21the HTML. This is where we can start
  21426. 13:46:23writing our web scraping script to
  21427. 13:46:25specify, okay, I'm looking for a TR tag.
  21428. 13:46:27I'm looking for a TD tag. I'm looking
  21429. 13:46:29for the class called team. This is all
  21430. 13:46:32information and things that we can use
  21431. 13:46:33to specify exactly what we want to pull
  21432. 13:46:36out of our web page. Now, there are
  21433. 13:46:38other things that we didn't really look
  21434. 13:46:40at as well in just our simple
  21435. 13:46:42illustration. Let's come right over
  21436. 13:46:44here. There's things like hrefs. Now,
  21437. 13:46:46these are hyperlinks. So, if we went and
  21438. 13:46:49then clicked on this, this is just
  21439. 13:46:51regular text, but inside of it is this
  21440. 13:46:53hyperlink where if we clicked on it, it
  21441. 13:46:55would take us to another website. And
  21442. 13:46:57typically that's denoted by this href
  21443. 13:46:59right here. Then you'll typically see
  21444. 13:47:01things like a P tag which usually stands
  21445. 13:47:03for a paragraph. Now the last thing that
  21446. 13:47:05I want to show you while we're here and
  21447. 13:47:07we're going to learn a lot more in the
  21448. 13:47:08next several lessons. But if we come
  21449. 13:47:10right down here there is this actual
  21450. 13:47:12entire table here. And let's try to find
  21451. 13:47:15this table. And I'm having trouble
  21452. 13:47:17selecting the entire thing. But let's
  21453. 13:47:18select this team name. And if we look at
  21454. 13:47:20this team name you can see that this is
  21455. 13:47:22encapsulating the table. So this table
  21456. 13:47:24tag. Now, these are super helpful
  21457. 13:47:26because it takes in the entire table.
  21458. 13:47:28Now, if we wrap this up and we look just
  21459. 13:47:30at this, it says class table and then we
  21460. 13:47:33have the end of this table tag. Now,
  21461. 13:47:35when we open it, it's going to have all
  21462. 13:47:38of this information. So, as you can see,
  21463. 13:47:39as I'm highlighting over it, we have
  21464. 13:47:41these TH tags. Then, we have these TD
  21465. 13:47:44tags and even these TR tags, which is
  21466. 13:47:48the individual data. And this is
  21467. 13:47:49something that we'll look at when we're
  21468. 13:47:51actually scraping all of the data from
  21469. 13:47:52this table in a future lesson. So this
  21470. 13:47:55is how we can use HTML, how we can
  21471. 13:47:57inspect the web page and see exactly
  21472. 13:47:59what's going on kind of under the hood.
  21473. 13:48:00And then in future lessons, we'll see
  21474. 13:48:02how we can use this HTML to specify
  21475. 13:48:04exactly what data we want to pull out.
  21476. 13:48:06Thank you guys so much for watching. If
  21477. 13:48:08you like this video, be sure to like and
  21478. 13:48:10subscribe below. I will see you in the
  21479. 13:48:11next lesson.
  21480. 13:48:24Hello everybody. In this lesson, we're
  21481. 13:48:26going to be taking a look at beautiful
  21482. 13:48:28soup and requests. Now, these packages
  21483. 13:48:30in Python are really useful. These are
  21484. 13:48:32the two main ones that I used when I was
  21485. 13:48:34first starting out with web scraping. It
  21486. 13:48:36can get a lot of what you want done in
  21487. 13:48:38order to get that information out. Now,
  21488. 13:48:39of course, there are other packages that
  21489. 13:48:41you can use that may be a little bit
  21490. 13:48:42more advanced, but again, this is just
  21491. 13:48:44the beginner series. In a future series,
  21492. 13:48:46we'll look at other packages as well
  21493. 13:48:48that have some more advanced
  21494. 13:48:49functionality. So, what we're going to
  21495. 13:48:50be doing is we're going to import these
  21496. 13:48:52packages. And then we're going to get
  21497. 13:48:53all of the HTML from our website and
  21498. 13:48:56make sure that it's in a usable state.
  21499. 13:48:58And then in the next lesson, we're going
  21500. 13:49:00to kind of query around in the HTML,
  21501. 13:49:02kind of pick and choose exactly what we
  21502. 13:49:04want. We'll look at things like tags,
  21503. 13:49:06variable strings, classes, attributes,
  21504. 13:49:08and more. So let's get started by
  21505. 13:49:10importing our packages. What we're going
  21506. 13:49:12to say is from BS4, this is the module
  21507. 13:49:16that we're taking it from. We're going
  21508. 13:49:17to say import. Then we'll do beautiful
  21509. 13:49:22soup. Then we're going to come down and
  21510. 13:49:24we're going to say import requests. Now
  21511. 13:49:27let's go ahead and run this. I'm going
  21512. 13:49:28to hit shift enter. And it works well
  21513. 13:49:30for me. Now if this does not work for
  21514. 13:49:32you, you may potentially need to
  21515. 13:49:34actually install BS4. So, you may have
  21516. 13:49:36to go to your terminal window and say
  21517. 13:49:38pip install bs4. I'll just let you
  21518. 13:49:40Google how to do that if you need to do
  21519. 13:49:41that because it's pretty easy. But if
  21520. 13:49:43you're using Jupyter Notebooks through
  21521. 13:49:44Anaconda, like how we set it up at the
  21522. 13:49:46beginning of this Python series, then
  21523. 13:49:48you should be totally fine. It should be
  21524. 13:49:50there for you. The next thing that we
  21525. 13:49:51need to do is specify where we're taking
  21526. 13:49:53this HTML from. So, what we need to
  21527. 13:49:56actually do is come right over here to
  21528. 13:49:57our web page and we need to get the URL.
  21529. 13:50:00So, we're going to go here. We're going
  21530. 13:50:01to copy this URL. And I'm just going to
  21531. 13:50:03put it right here for a second. And what
  21532. 13:50:06we're going to do is we're going to be
  21533. 13:50:07using this URL quite a bit. So we just
  21534. 13:50:09want to assign it to a variable. So
  21535. 13:50:11we'll just say URL is equal to and then
  21536. 13:50:13we'll put it right in here. Now we can
  21537. 13:50:16get rid of that. So now this is our URL
  21538. 13:50:18going forward. This is where we're going
  21539. 13:50:19be pulling data from. Let's go ahead and
  21540. 13:50:22run this. Now we're going to use
  21541. 13:50:23requests and what we're going to do is
  21542. 13:50:25we're going to say requests.get
  21543. 13:50:28and then we're going to put in URL. Now
  21544. 13:50:31this get function is going to use the
  21545. 13:50:33request library. It's going to send a
  21546. 13:50:34get request to that URL and it's going
  21547. 13:50:37to return a response object. Let's go
  21548. 13:50:39ahead and run this.
  21549. 13:50:41As you can see here, I got a response of
  21550. 13:50:43200. If you got something like a 204 or
  21551. 13:50:46a 400 or 401 or 404, all of these things
  21552. 13:50:50are potentially bad. Something like a
  21553. 13:50:52204 would mean there was no content in
  21554. 13:50:54the actual web page. 400 means a bad
  21555. 13:50:57request. So, it was invalid. The server
  21556. 13:50:59couldn't process it and you don't get
  21557. 13:51:00any response. If you got a 404, that
  21558. 13:51:03might be one that you're familiar with.
  21559. 13:51:04That's an error that means the server
  21560. 13:51:05cannot be found. The next thing that
  21561. 13:51:07we're going to do is take the HTML. Now,
  21562. 13:51:09if you remember, we come right back here
  21563. 13:51:12and we inspect this. We have all of this
  21564. 13:51:14HTML right here. Now, on this web page
  21565. 13:51:16specifically, right now, it's completely
  21566. 13:51:19static. It's not a bunch of moving stuff
  21567. 13:51:21or anything like that. usually when
  21568. 13:51:23you're looking at HTML if you're looking
  21569. 13:51:24at something like Amazon and those web
  21570. 13:51:26pages can update. But when you actually
  21571. 13:51:28pull that into Python, you're basically
  21572. 13:51:29getting a snapshot of the HTML at that
  21573. 13:51:32time. So what we're going to do is bring
  21574. 13:51:34in all of this HTML which is our
  21575. 13:51:36snapshot of our website and then we can
  21576. 13:51:39take a look at it. So we're going to
  21577. 13:51:41come right down here and now we're going
  21578. 13:51:42to say beautiful soup. So now we'll use
  21579. 13:51:45the beautiful soup package library. So
  21580. 13:51:47we need to say beautiful soup and we're
  21581. 13:51:49going to do an open parenthesis. We're
  21582. 13:51:50going to do two things. There's two
  21583. 13:51:52parameters that we need to put in here.
  21584. 13:51:53First, we need to put in this get
  21585. 13:51:55request. So, we actually need to name
  21586. 13:51:57this and we'll call this page. We'll say
  21587. 13:52:00page is equal to. And let's run this.
  21588. 13:52:02And now, we're going to put that page in
  21589. 13:52:04here. And what we're going to say is
  21590. 13:52:06text. So, the page is what's sending
  21591. 13:52:08that request. And then the text is
  21592. 13:52:10what's retrieving the actual raw HTML
  21593. 13:52:12that we're going to be using. Then,
  21594. 13:52:14we're going to put a comma here. And
  21595. 13:52:16what we need to specify is how we're
  21596. 13:52:18going to parse this information. Now,
  21597. 13:52:19this is an HTML. So what we're going to
  21598. 13:52:21do is HTML just like this. This is a
  21599. 13:52:25standard. This is already built in to
  21600. 13:52:26this library. So we don't need to go any
  21601. 13:52:28further. But it's basically going to
  21602. 13:52:29parse the information in an HTML format.
  21603. 13:52:32Let's go ahead and run this. Let's see
  21604. 13:52:34what we get. And as you can see, we have
  21605. 13:52:37a lot of information. And as we scroll
  21606. 13:52:40down, I'll try to point out some things
  21607. 13:52:41that we've already looked at in previous
  21608. 13:52:43lessons. Um
  21609. 13:52:47something like this th tag that should
  21610. 13:52:49be very similar. That's the title. Then
  21611. 13:52:51we have these TD tags. And then of
  21612. 13:52:53course, if we scroll down even further,
  21613. 13:52:55we'll have things like a TR tag. So
  21614. 13:52:57these are all things that we looked at
  21615. 13:52:58in that first lesson when learning about
  21616. 13:53:00HTML. Now again, we want to assign this
  21617. 13:53:02to a variable. So we're going to say
  21618. 13:53:05soup. That's going to say equal to this
  21619. 13:53:08information right here. Now I'm not
  21620. 13:53:10going to go into all the history behind
  21621. 13:53:11beautiful soup. But what I will say is
  21622. 13:53:13the guy who created this beautiful soup
  21623. 13:53:15library, uh, what he said was is that it
  21624. 13:53:17takes this really messy HTML or XML,
  21625. 13:53:20which you can also use it for. Uh, and
  21626. 13:53:22it makes it into this kind of beautiful
  21627. 13:53:24soup. So, I just thought that was kind
  21628. 13:53:25of funny. Uh, but that's why we're
  21629. 13:53:26calling it soup right here. And we're
  21630. 13:53:28going to go ahead and run this. And
  21631. 13:53:30we'll come right down here and we'll say
  21632. 13:53:32print soup. And let's run it. And now we
  21633. 13:53:36have everything in here. So, we have our
  21634. 13:53:38HTML, our head, we have some href and
  21635. 13:53:42some links in here. Let's scroll down a
  21636. 13:53:44little bit more. And then we have our
  21637. 13:53:46body right there. And of course, we have
  21638. 13:53:48a bunch of information in here. Now, in
  21639. 13:53:50the next lesson, what we're going to be
  21640. 13:53:52doing is learning how to kind of query
  21641. 13:53:54all of this to take specific information
  21642. 13:53:56out and basically understand a lot of
  21643. 13:53:58what's going on in this HTML to make
  21644. 13:54:00sure we can actually get what we need.
  21645. 13:54:01Now, if this looks really kind of messy
  21646. 13:54:04to you and it just doesn't make a lot of
  21647. 13:54:06sense, there is one more thing that I'm
  21648. 13:54:08going to show you and we'll come right
  21649. 13:54:09down here. So, we'll say soup.pritify.
  21650. 13:54:13And if you've ever used a different type
  21651. 13:54:15of programming languages, uh, Pritify is
  21652. 13:54:17very common in a lot of them where it'll
  21653. 13:54:19just make it a little bit more easy to
  21654. 13:54:21visualize and see. Uh, you'll notice
  21655. 13:54:22that it kind of has this hierarchy built
  21656. 13:54:24in. Whereas, if we scroll up, there's no
  21657. 13:54:27hierarchy built in. It's all just down
  21658. 13:54:28this lefth hand side. So if you kind of
  21659. 13:54:31want to view it and just kind of
  21660. 13:54:32visually see the differences, this does
  21661. 13:54:34help a lot. But it doesn't actually help
  21662. 13:54:37a lot when you're, you know, querying it
  21663. 13:54:39or using, you know, find and find all,
  21664. 13:54:41which is what we're going to look at in
  21665. 13:54:43the next lesson. So that is our lesson
  21666. 13:54:44on beautiful soup and requests. In the
  21667. 13:54:47next two lessons, we're going to be
  21668. 13:54:48looking at find and find all as well as
  21669. 13:54:50really diving into things like variable
  21670. 13:54:52strings and tags and classes and all
  21671. 13:54:53those things. And then in the last
  21672. 13:54:55lesson, we're going to do kind of this
  21673. 13:54:56mini project where we try to get all the
  21674. 13:54:57data from this web page that we've been
  21675. 13:54:59using from that table and put it into a
  21676. 13:55:02pandas dataf frame. So, thank you guys
  21677. 13:55:04so much for watching. I really
  21678. 13:55:05appreciate it. If you like this video,
  21679. 13:55:07be sure to like and subscribe below and
  21680. 13:55:09I will see [music] you in the next
  21681. 13:55:10lesson.
  21682. 13:55:22Hello everybody. In this lesson, we're
  21683. 13:55:24going to be taking a look at find and
  21684. 13:55:26find all. Really, we're going to be
  21685. 13:55:28looking at a ton of different things in
  21686. 13:55:30this lesson. This is where we really
  21687. 13:55:31start digging in, seeing how we can
  21688. 13:55:33extract specific information from our
  21689. 13:55:36web page. But in order to do that, let's
  21690. 13:55:38set everything up where we actually
  21691. 13:55:39bring in the HTML like we did in the
  21692. 13:55:41last lesson. And we're just going to
  21693. 13:55:43write all this out one more time just
  21694. 13:55:44for practice if nothing else. And then
  21695. 13:55:47we'll get into actually getting that
  21696. 13:55:49information from the HTML. So, we're
  21697. 13:55:51going to start by saying from BS4 import
  21698. 13:55:55beautiful
  21699. 13:55:57soup. There we go. And import requests.
  21700. 13:56:01We'll go ahead and run this. Then we're
  21701. 13:56:03going to come up here, grab our HTML or
  21702. 13:56:07sorry, our URL. So, we'll say URL is
  21703. 13:56:09equal to and we'll have that right here.
  21704. 13:56:13Now, we need to say page is equal to and
  21705. 13:56:16then we'll do requests.get get and then
  21706. 13:56:19we'll put in our URL right here. And
  21707. 13:56:21we're going to come over here and run
  21708. 13:56:22this. And lastly, we need to say soup.
  21709. 13:56:25So we'll say soup is equal to beautiful
  21710. 13:56:29soup. There we go. And then within our
  21711. 13:56:31parenthesis, we need to specify the
  21712. 13:56:33page.ext because we need that. And our
  21713. 13:56:35parser, which is HTML.
  21714. 13:56:39And there we go. And let's go ahead and
  21715. 13:56:41run this. Let's print it out. Make sure
  21716. 13:56:43it's working.
  21717. 13:56:45And there we go. So, we have our soup
  21718. 13:56:48right here. All this should look really
  21719. 13:56:50similar to uh our last lesson. And so,
  21720. 13:56:54now we've brought in our HTML from our
  21721. 13:56:56page. We have a lot a lot a lot of
  21722. 13:56:58information in here. Now, really
  21723. 13:57:00quickly, let's come over and let's
  21724. 13:57:02inspect our web page.
  21725. 13:57:05Now, in here, we have a ton of
  21726. 13:57:08information, right? We have bunch of
  21727. 13:57:10different tags and classes and all these
  21728. 13:57:11other things. But how do we actually use
  21729. 13:57:14these? Well, that's where the find and
  21730. 13:57:16find all is going to come into play. And
  21731. 13:57:18they're pretty similar, and you'll see
  21732. 13:57:20that in just a little bit. But let's say
  21733. 13:57:22we want to take uh one of these tags.
  21734. 13:57:24And let's come down. Let's say we just
  21735. 13:57:27want to take this div tag. Now, there's
  21736. 13:57:30going to be a lot of different div tags
  21737. 13:57:33in our HTML, but let's just come right
  21738. 13:57:36here. Let's go down and let's say we're
  21739. 13:57:39going to call soup. We're going to say
  21740. 13:57:40soup. That's all of our information. and
  21741. 13:57:41we're going to sayfind.
  21742. 13:57:43Now, within our parentheses, we can
  21743. 13:57:45specify a lot of different things, but
  21744. 13:57:47we're going to keep it really simple
  21745. 13:57:48right now. We're just going to say div.
  21746. 13:57:51Let's go ahead and run this. What this
  21747. 13:57:52is going to bring up is the very first
  21748. 13:57:55div tag in our HTML. And that's going to
  21749. 13:57:57be this information right here. Now,
  21750. 13:58:00let's copy this. And we're going to do
  21751. 13:58:02the exact same thing except we're going
  21752. 13:58:05to say find_all.
  21753. 13:58:08Now, let's run this. Now we're going to
  21754. 13:58:10have a ton more information. Really all
  21755. 13:58:13find and find all do is that they find
  21756. 13:58:16the information. Now find is only going
  21757. 13:58:19to find the first response in our HTML
  21758. 13:58:22list. That's the div class container.
  21759. 13:58:24Let's go back up to the top. That's our
  21760. 13:58:27div class container. But find all is
  21761. 13:58:29going to find all of them. So it'll put
  21762. 13:58:31it in this list for you. So it's going
  21763. 13:58:33to have this first one and it goes down
  21764. 13:58:34to uh this for slashd, which should be
  21765. 13:58:38right here. And then we have a comma
  21766. 13:58:40which separates our next div tag. So
  21767. 13:58:43that is how we can use it. Now what if
  21768. 13:58:45we want to specify one of these div
  21769. 13:58:47tags? We pulled in a ton of them, but we
  21770. 13:58:49want to just look for one of them. Well,
  21771. 13:58:51this is something where the class comes
  21772. 13:58:53in handy because right now we have class
  21773. 13:58:55is equal to container. Class is equal to
  21774. 13:58:57co MD-12.
  21775. 13:59:00I don't know what these are at the off
  21776. 13:59:01the top of my head, but um usually
  21777. 13:59:04they'll be somewhat unique and we can
  21778. 13:59:06use these to help us specify what we're
  21779. 13:59:08looking for. For example, just kind of
  21780. 13:59:10glancing at this, we can also use this a
  21781. 13:59:12tag if we wanted to look at this. So, we
  21782. 13:59:14could say, oh, we're looking for uh
  21783. 13:59:16these hrefs. So, we have an href here
  21784. 13:59:19and this right down here, we have this
  21785. 13:59:20href as well, which again u if you
  21786. 13:59:23remember from a previous lesson, that
  21787. 13:59:25stands for a hyperlink. Now something
  21788. 13:59:27like the class or the href um or these
  21789. 13:59:31ids these are all attributes. So we can
  21790. 13:59:34specify or kind of filter down based off
  21791. 13:59:36of these. Now let's try it. So what we
  21792. 13:59:38can do is we can do class first and this
  21793. 13:59:39is kind of the default uh within
  21794. 13:59:42something like find all is you can even
  21795. 13:59:44do class underscore. We can come right
  21796. 13:59:46back up. We have this div and then
  21797. 13:59:48here's our class. So again we have to
  21798. 13:59:50have the div and the class. So if we
  21799. 13:59:52took this a tag, this is an a tag which
  21800. 13:59:55would go right here with the class of
  21801. 13:59:57something like navl link or something
  21802. 13:59:59like nav link again down here. We need
  21803. 14:00:01to specify that more but we have our
  21804. 14:00:03div. So we'll say cl co md12 right here.
  21805. 14:00:08And let's go ahead and run this. And now
  21806. 14:00:10it's going to pull in just that
  21807. 14:00:11information. Now we're still getting a
  21808. 14:00:13list because we have multiple of these.
  21809. 14:00:15So this div class uh col md-12 doesn't
  21810. 14:00:19just happen once. If we scroll down,
  21811. 14:00:22we'll see it multiple times. Something
  21812. 14:00:24like right here. Uh or actually, let me
  21813. 14:00:27see, right here. So, here's this comma.
  21814. 14:00:29Then here's our next one. So, we have
  21815. 14:00:31two of these uh div tags with a class of
  21816. 14:00:34coal- md-12. And in each of these, we
  21817. 14:00:38have different information. This looks
  21818. 14:00:40like a paragraph with this p tag right
  21819. 14:00:42here. And let's scroll back up. Uh, so I
  21820. 14:00:46also think we should try out doing
  21821. 14:00:48something like this P tag. Typically
  21822. 14:00:50these P tags stand for paragraphs or
  21823. 14:00:52they have text information in them.
  21824. 14:00:54Let's try a P tag really quickly. Let's
  21825. 14:00:56just see what we get. And let's run
  21826. 14:00:59this. And it looks like we get multiple
  21827. 14:01:01P tags. Now, if we come back here, you
  21828. 14:01:04can see that there's this information
  21829. 14:01:06and it's this information that we're
  21830. 14:01:07pulling in. And I'm just, you know,
  21831. 14:01:09noticing that from right here. And then
  21832. 14:01:12we have this information right here. And
  21833. 14:01:14it looks like there's one more which is
  21834. 14:01:16this href which looks like this open
  21835. 14:01:18source. So data via and then that uh
  21836. 14:01:21hyperlink or that link right there. So
  21837. 14:01:24we have three different P tags. Now just
  21838. 14:01:26to verify and make sure that that's
  21839. 14:01:28correct, what we could do is come over
  21840. 14:01:30here. We're going to click on this
  21841. 14:01:32paragraph. It's going to take us to that
  21842. 14:01:34P tag where the class is equal to lead.
  21843. 14:01:37Let's come over here and look at this
  21844. 14:01:39paragraph. Now we have another P tag
  21845. 14:01:42right over here where the class is equal
  21846. 14:01:44to glyphicon glyphicon/education.
  21847. 14:01:48I have no idea what that means. Um and
  21848. 14:01:50then we'll go to our last one which is
  21849. 14:01:52right here where the P tag is equal to
  21850. 14:01:56uh we have a tag href class uh and a
  21851. 14:01:59bunch of other information. So let's say
  21852. 14:02:01we just wanted to pull in this paragraph
  21853. 14:02:04right here. Let's go here and see how we
  21854. 14:02:06can specify this information. So it
  21855. 14:02:08looks like P where the class is equal to
  21856. 14:02:10lead. That looks like it's going to be
  21857. 14:02:13unique to just that one. So if we come
  21858. 14:02:15down here, we're going to say comma and
  21859. 14:02:18it was class. So you can do uh class
  21860. 14:02:21underscore is equal to and then we're
  21861. 14:02:24going to say lead. Let's try running
  21862. 14:02:26this. And we're just pulling in that
  21863. 14:02:29information. Now let's say we actually
  21864. 14:02:31want to pull in this paragraph. We
  21865. 14:02:33actually want this text right here. And
  21866. 14:02:36this is a very real use case. You know,
  21867. 14:02:38let's say I'm trying to pull in some
  21868. 14:02:39information or or a paragraph of text.
  21869. 14:02:42Well, let's copy this. And what we're
  21870. 14:02:44going to then do is say text. And let's
  21871. 14:02:48run this. Now, we're going to get an
  21872. 14:02:49error right here. And this is a very
  21873. 14:02:51common error because we're trying to use
  21874. 14:02:54find all. Unfortunately, find all does
  21875. 14:02:57not have a text attribute. We actually
  21876. 14:03:00need to change this to find. Typically,
  21877. 14:03:03when I'm working with these find and
  21878. 14:03:05find alls, I'm using find all most of
  21879. 14:03:07the time until I want to start
  21880. 14:03:09extracting text. Then when I specify it,
  21881. 14:03:12I'll change this back to find, just like
  21882. 14:03:14this. Now, let's try this. And now we're
  21883. 14:03:17getting in parentheses this information.
  21884. 14:03:20Now, this is all wonky. It needs to
  21885. 14:03:22definitely be cleaned up a little bit.
  21886. 14:03:24But if we code back up, it's no longer
  21887. 14:03:26in a list. And we no longer have things
  21888. 14:03:29like these P tags in here or this class
  21889. 14:03:33attribute. So we're really just trying
  21890. 14:03:34to pull out this information. Now again,
  21891. 14:03:37this does not look perfect. We could
  21892. 14:03:39even try to do something like strip.
  21893. 14:03:42Look like there's some white space. That
  21894. 14:03:44cleans it up a little bit. This
  21895. 14:03:46definitely looks a little better. Um and
  21896. 14:03:48we could definitely go in here and clean
  21897. 14:03:50this up more. But just for you know an
  21898. 14:03:52example, this is how we can then extract
  21899. 14:03:54that information. Now, let's look at one
  21900. 14:03:56more example. This is some information,
  21901. 14:03:58and this is what we're going to do kind
  21902. 14:04:00of our little mini project in the next
  21903. 14:04:01lesson on. Let's say we wanted to take
  21904. 14:04:03all this information. Well, what if we
  21905. 14:04:05wanted to pull in something like the
  21906. 14:04:06team name? That's going to be in right
  21907. 14:04:09here in this TR tag. And each of these
  21908. 14:04:12TR tags have TH tags underneath them.
  21909. 14:04:15So, if we scroll down, you'll notice
  21910. 14:04:17that each row is this TR tag. So, let's
  21911. 14:04:22go ahead and search for let's do th.
  21912. 14:04:25Let's just search for that first. So,
  21913. 14:04:27let's come right back up here. Let's use
  21914. 14:04:29this find all.
  21915. 14:04:32And we'll get rid of this text for right
  21916. 14:04:35now. And let's just say we want to look
  21917. 14:04:38for
  21918. 14:04:39the TR. Is that what we said we were
  21919. 14:04:41looking for? No, TH. So, let's say we're
  21920. 14:04:43looking for TH. Let's go ahead and run
  21921. 14:04:46this. So, we're going to have underneath
  21922. 14:04:47this th we have team name, year, wins,
  21923. 14:04:50losses, and notice these are all the
  21924. 14:04:53titles. So, these titles are the only
  21925. 14:04:56ones with these TH tags. If we go down,
  21926. 14:04:59you'll notice that the date is actually
  21927. 14:05:01TD tags. So, now let's go back and look
  21928. 14:05:05for TD. We'll say D. And this is going
  21929. 14:05:09to be a lot longer. We have a lot of
  21930. 14:05:11information, but these are all the rows
  21931. 14:05:13of data. Let's see if we can just get
  21932. 14:05:15one piece of this data. We're going to
  21933. 14:05:17get back. We want just this team name.
  21934. 14:05:19That's all we're trying to pull in for
  21935. 14:05:21now. Um, and then we'll try to get this
  21936. 14:05:24row. And then in the next lesson, we're
  21937. 14:05:26going to try to get all of this
  21938. 14:05:27information, make it look really nice,
  21939. 14:05:29and then we'll put it into a Pandanda's
  21940. 14:05:31data frame. So, let's just get this team
  21941. 14:05:33name right now. Let's go ahead. We're
  21942. 14:05:36going to say th. Let's run this. And we
  21943. 14:05:39have this th. And now that we know we're
  21944. 14:05:42getting this information in, we can do
  21945. 14:05:47find. Let's run this. So there's our
  21946. 14:05:50team name. We're just going to say text.
  21947. 14:05:54And again, we can do dot strip just like
  21948. 14:05:57that. And bam, we have our team name. So
  21949. 14:06:00you can kind of start getting the idea
  21950. 14:06:02of how we're pulling this information
  21951. 14:06:04out. We're really just specifying
  21952. 14:06:06exactly what we're seeing in this HTML.
  21953. 14:06:09And what's really, really helpful. And
  21954. 14:06:10you know something that I do all the
  21955. 14:06:12time is I'm inspecting it. I'm just kind
  21956. 14:06:15of searching like how what do I want?
  21957. 14:06:17What piece of information do I want?
  21958. 14:06:18Then I go ahead and click on it and then
  21959. 14:06:20I'm looking you know where is this
  21960. 14:06:22sitting in the hierarchy. It's within
  21961. 14:06:23the body. It's within this table with
  21962. 14:06:26the class of table. Then it's down here
  21963. 14:06:28where this TR tag and then this TD tag.
  21964. 14:06:31So I'm looking kind of at the hierarchy
  21965. 14:06:33and I'm specifying exactly what I'm
  21966. 14:06:35looking for. So that is what we're going
  21967. 14:06:36to look at in today's lesson. And that's
  21968. 14:06:38how we can use find and find all. We
  21969. 14:06:40were able to look at classes and tags
  21970. 14:06:43and attributes and variable strings,
  21971. 14:06:45which is this right here, getting that
  21972. 14:06:47text uh and variable strings. And we
  21973. 14:06:50were look at find and find all and how
  21974. 14:06:52it's pulling that information in and how
  21975. 14:06:54we can specify exactly what we're
  21976. 14:06:55looking for. Now, in the next lesson,
  21977. 14:06:57which is definitely going to be the most
  21978. 14:06:58exciting one, we're going to try to pull
  21979. 14:07:00in all of this information. So every
  21980. 14:07:03single thing because we'll be able to
  21981. 14:07:05put all this information into a dataf
  21982. 14:07:07frame which then we can use pandas to
  21983. 14:07:09really search and manipulate that data
  21984. 14:07:12within that data frame. So with that
  21985. 14:07:13being said that is the end of this
  21986. 14:07:15lesson. If you like this video be sure
  21987. 14:07:17to like and subscribe. I will see you in
  21988. 14:07:19the next lesson.
  21989. 14:07:22[music]
  21990. 14:07:27>> [music]
  21991. 14:07:32>> Hello everybody. In this lesson, we are
  21992. 14:07:34going to be scraping data from a real
  21993. 14:07:35website and putting it into a Pandanda's
  21994. 14:07:37dataf frame and maybe even exporting it
  21995. 14:07:39to CSV if we're feeling a bit spicy.
  21996. 14:07:41Now, in the last several lessons, we've
  21997. 14:07:44been looking at this page right here.
  21998. 14:07:46And I even promised that we were going
  21999. 14:07:48to be pulling this data, but as I was
  22000. 14:07:50building out the project, I just I
  22001. 14:07:52honestly thought it was a little bit too
  22002. 14:07:53easy since in the last lesson, we kind
  22003. 14:07:55of already pulled out some information
  22004. 14:07:57from this table and I want to kind of
  22005. 14:07:59throw you guys off. So, we're going to
  22006. 14:08:00be pulling from a different table. We're
  22007. 14:08:02going to be going on to Wikipedia and
  22008. 14:08:04looking at the list of the largest
  22009. 14:08:05companies in the United States by
  22010. 14:08:06revenue and we're going to be pulling
  22011. 14:08:08all of this information. So, if you
  22012. 14:08:10thought this was going to be easy in a
  22013. 14:08:11little mini project, uh it's now a full
  22014. 14:08:13project because why not? So, let's get
  22015. 14:08:17started. Uh, what we're going to do is
  22016. 14:08:19we're going to import beautiful soup and
  22017. 14:08:20requests. We're going to get this
  22018. 14:08:22information and we're going to see how
  22019. 14:08:24we can do this and it's going to get a
  22020. 14:08:26little bit more complicated, a little
  22021. 14:08:28bit more tricky. We're going to have to,
  22022. 14:08:29you know, format things properly to get
  22023. 14:08:31it into our pandas data frame to make it
  22024. 14:08:33looking good and making it more usable.
  22025. 14:08:36So, let's go ahead and get rid of this
  22026. 14:08:37easy table. We don't want that one. Uh,
  22027. 14:08:39and we're going to come in here and
  22028. 14:08:41we're just going to start off. This
  22029. 14:08:42should look uh really familiar by now.
  22030. 14:08:44We're going to say from BS4 import
  22031. 14:08:49beautiful
  22032. 14:08:50soup. I don't know if you've noticed,
  22033. 14:08:52but I've messed up spelling beautiful
  22034. 14:08:53soup in every single uh video I've
  22035. 14:08:56noticed. Uh let's run this. And now we
  22036. 14:08:59need to go ahead and get our URL. So
  22037. 14:09:01let's come up here. Let's get our URL.
  22038. 14:09:05Say URL is equal to. And we'll just keep
  22039. 14:09:08it all in the same thing really quickly
  22040. 14:09:10because we know this by heart by now,
  22041. 14:09:12right? Uh we'll say request.get
  22042. 14:09:15and then URL to make sure that we're
  22043. 14:09:17getting that information. It give us a
  22044. 14:09:19response object. Um hopefully it'll be
  22045. 14:09:21200. That'll mean a good response. And
  22046. 14:09:24then we'll say soup is equal to and then
  22047. 14:09:26we'll say beautiful soup. And we'll do
  22048. 14:09:29our page.ext.
  22049. 14:09:30Now we're pulling in the information
  22050. 14:09:32from this URL. And then we use our
  22051. 14:09:34parser which will be oops html.
  22052. 14:09:38And let's go ahead and run this. Looks
  22053. 14:09:41like everything went well. Let's print
  22054. 14:09:42our soup. Now, this is completely new to
  22055. 14:09:45you. It's completely new to me. I don't
  22056. 14:09:47know what I'm doing. Uh but it looks
  22057. 14:09:49like we're pulling in the information.
  22058. 14:09:50Am I right? So, we got a lot of things
  22059. 14:09:53going for us. Uh the uh stuff was
  22060. 14:09:56imported properly. We got our URL. We
  22061. 14:09:58got our soup, which is uh not beautiful
  22062. 14:10:01in my opinion. But let's keep on
  22063. 14:10:04rolling. Let's come right down here.
  22064. 14:10:05Now, what we need to do is we need to
  22065. 14:10:07specify what data we're looking for. So,
  22066. 14:10:10let's come and let's inspect this web
  22067. 14:10:12page. Now, the only information that
  22068. 14:10:14we're going to want is right in here.
  22069. 14:10:16We're going to want these uh titles or
  22070. 14:10:18these headers. Whoops. So, we're going
  22071. 14:10:21to want rank name, industry, etc. And
  22072. 14:10:23then we are for sure going to want all
  22073. 14:10:25of this information. Let's just scroll
  22074. 14:10:27down, see if there's anything tricky in
  22075. 14:10:28here.
  22076. 14:10:31All right, that looks pretty good. Uh,
  22077. 14:10:33and there is another table. So, there's
  22078. 14:10:35not just one table in here. There are
  22079. 14:10:37two tables in this page. So that might
  22080. 14:10:41change things for us. But let's come
  22081. 14:10:43right back and let's inspect our page by
  22082. 14:10:46using this little button right here. And
  22083. 14:10:49let's specify in let's see if I can
  22084. 14:10:51highlight just this page. Oh, it's not
  22085. 14:10:54going. Oh, let's do that right there. So
  22086. 14:10:57now we have this uh wiki table sorter.
  22087. 14:11:00Now I'm going to actually come right
  22088. 14:11:02here. I'm going to copy and I'm just
  22089. 14:11:04going to say copy the outer HTML. I'm
  22090. 14:11:07just going to paste in here real quick.
  22091. 14:11:09And that's a ton of information. I
  22092. 14:11:11didn't think it was going to copy all of
  22093. 14:11:12it. And we're just going to delete that.
  22094. 14:11:13I just wanted to keep that class uh
  22095. 14:11:15because I wanted to then come right down
  22096. 14:11:19here at the bottom and just see what
  22097. 14:11:21this table uh looks like. I don't know
  22098. 14:11:24if it's part of it or if it's a if it's
  22099. 14:11:26its own table.
  22100. 14:11:28Um I can't tell. Let's look at this rank
  22101. 14:11:31and let's come up. So it says uh it's
  22102. 14:11:34under this table
  22103. 14:11:36and it looks like it's its own table but
  22104. 14:11:38it says wiki table sort sortable jQuery
  22105. 14:11:41table sortter wikip sortable jQuery
  22106. 14:11:44table sortter. So, it looks like there
  22107. 14:11:47are two tables with the same class,
  22108. 14:11:50which shouldn't be a problem if we're
  22109. 14:11:53using find to get our text because we
  22110. 14:11:55should be taking the first one, which
  22111. 14:11:56will be this table. And this is the
  22112. 14:11:58table we want. Um, and if we wanted this
  22113. 14:12:02one, we could just use find all and
  22114. 14:12:04since it's a list, we could use indexing
  22115. 14:12:07to pull this table, right? Um, but I
  22116. 14:12:10think we're going to be okay with just
  22117. 14:12:12pulling in this one.
  22118. 14:12:14So, let's go ahead and let's do our
  22119. 14:12:16find. So, we'll do soup.find.
  22120. 14:12:20And we could find all or we could just
  22121. 14:12:22do find uh table. Let's just try this
  22122. 14:12:25and see what we get. And if it pulls in
  22123. 14:12:28the right one that we're looking for,
  22124. 14:12:29that would be great. Now, this does not
  22125. 14:12:32look correct at all. Um I don't know
  22126. 14:12:35what table it's pulling in. Oh, maybe
  22127. 14:12:37it's this right here. This might be a
  22128. 14:12:40table. Yeah, it is. So we have this uh
  22129. 14:12:43box more citations. So actually we are
  22130. 14:12:45going to have to do exactly like what I
  22131. 14:12:47was talking about. Uh let's pull this
  22132. 14:12:51and we well we could do comma class uh
  22133. 14:12:54right here. And let's do both. You know
  22134. 14:12:56what? This is a learning opportunity.
  22135. 14:12:58Let's do both. So let me go back up to
  22136. 14:13:01the top because I need these. Um and
  22137. 14:13:04what we're going to do is come right
  22138. 14:13:07down here. I want to add in uh another
  22139. 14:13:10thing. Actually, I'll just push this one
  22140. 14:13:12up. There we go. So, we're going to say
  22141. 14:13:15find_all.
  22142. 14:13:17Let's run this. So, now we have
  22143. 14:13:19multiple. And again, we got that weird
  22144. 14:13:21one first, but if we scroll down, here's
  22145. 14:13:23our comma. And then here's our wik wiki
  22146. 14:13:27table sortable. And then we have rank,
  22147. 14:13:30name, industry, all the ones that we
  22148. 14:13:32were hoping to see. And I guarantee you
  22149. 14:13:34if you scroll all the way to the bottom,
  22150. 14:13:37um, we're going to see
  22151. 14:13:40potentially Wells Fargo, Goldman Sachs.
  22152. 14:13:43I'm pretty sure those are, um,
  22153. 14:13:46let's see. Yeah, here we go. Like Ford
  22154. 14:13:48Motor, Wells Fargo, Goldman Sachs.
  22155. 14:13:50That's this table right here. So now
  22156. 14:13:52we're looking at the third table, but
  22157. 14:13:54again, this is a list, so we can use
  22158. 14:13:56indexing on this. And we'll just choose
  22159. 14:13:58not position zero because that's this
  22160. 14:14:00one right here, which we did not like.
  22161. 14:14:03Well, now we'll take position one. Let's
  22162. 14:14:05run this.
  22163. 14:14:07Let's go back up to the top. And this is
  22164. 14:14:09our table right here. Rank, name,
  22165. 14:14:12industry. This is the information that
  22166. 14:14:14we were actually wanting just to
  22167. 14:14:16confirm. Rank name, industry, etc. So,
  22168. 14:14:20this is the information we're wanting
  22169. 14:14:22and we're able to specify that with our
  22170. 14:14:23find all. And this is the information we
  22171. 14:14:26want. So, we now want to make this the
  22172. 14:14:28only information that we're looking at.
  22173. 14:14:30So, I'm just going to copy this. We
  22174. 14:14:32didn't need to use our class for this
  22175. 14:14:33one. You could, probably could have. Um,
  22176. 14:14:35but we could. So, let's actually um put
  22177. 14:14:37this right down here. This will be our
  22178. 14:14:38table. We'll say equal to, but then I'll
  22179. 14:14:41come right here and I'm going to say
  22180. 14:14:44soup.find.
  22181. 14:14:46And this is just for demonstration
  22182. 14:14:48purposes. We'll do table,
  22183. 14:14:50blast is equal to, and then we'll look
  22184. 14:14:54at this right here. Whoops. Me do this.
  22185. 14:14:58And let's see if we get the correct
  22186. 14:15:00output.
  22187. 14:15:01And let's run this. And looks like we're
  22188. 14:15:03getting a none type object. Uh, if I
  22189. 14:15:06remember, it looks like the actual class
  22190. 14:15:08is this right here. So, let's run this
  22191. 14:15:12instead. And I got to get rid of the
  22192. 14:15:14index. There we go. Okay. So, we were
  22193. 14:15:17able to pull it in just using the find.
  22194. 14:15:19So, the find table class. And it says
  22195. 14:15:21wiki table sortable. At least that's the
  22196. 14:15:24HTML that we're pulling in right here.
  22197. 14:15:27Let me go back because I don't I don't
  22198. 14:15:31know if that's what I was seeing
  22199. 14:15:32earlier.
  22200. 14:15:34Let's just get this rank. Let's go back
  22201. 14:15:36up. Oh, where's the rank?
  22202. 14:15:39Go. Rank. There we go. So, here's our
  22203. 14:15:41rank. And let's go up to the table and
  22204. 14:15:45there's our class.
  22205. 14:15:47Yeah. And and that's just uh to me
  22206. 14:15:49that's a little bit odd. So, it says
  22207. 14:15:50wiki table sortable jQuery-t
  22208. 14:15:58um in our actual Python script that
  22209. 14:16:00we're running, it was only pulling in
  22210. 14:16:03the wiki table sortable. So, it wasn't
  22211. 14:16:06pulling in the jQuery-t
  22212. 14:16:09uh I'm not 100% sure, but all things
  22213. 14:16:12that we're working through and we were
  22214. 14:16:14able to uh we were able to figure out.
  22215. 14:16:17So, we're going to make this our table.
  22216. 14:16:20We're going to say tables equal to uh
  22217. 14:16:22soup.findall.
  22218. 14:16:24And let's run this. And if we print out
  22219. 14:16:26our table, we have this table. Now, this
  22220. 14:16:29is our only data that we are looking at.
  22221. 14:16:31Now, the first thing that I want to get
  22222. 14:16:33is I want to get these titles or these
  22223. 14:16:36headers right here. That's what we're
  22224. 14:16:37going to get first. So, let's go in
  22225. 14:16:40here. We can just look in this
  22226. 14:16:41information. You can see that these are
  22227. 14:16:42with these TH tags. And we can pull out
  22228. 14:16:46those TH tags really easily. Let's come
  22229. 14:16:49right down here. We're just going to say
  22230. 14:16:52TH. And we can get rid of this. Let's
  22231. 14:16:55run this. Now, these are our only TH
  22232. 14:16:58tags because everything else is a TR tag
  22233. 14:17:00for these rows of data. So, these TH
  22234. 14:17:03tags are pretty unique, which makes it
  22235. 14:17:05really easy, which is really great
  22236. 14:17:07because then we can just do world_titles
  22237. 14:17:10is equal to. So, now we have these
  22238. 14:17:12titles, but uh they're not perfect, but
  22239. 14:17:15what we're going to do is we're going to
  22240. 14:17:17loop through it. So, I'm going to say
  22241. 14:17:18world titles and I'll kind of walk
  22242. 14:17:20through what I'm talking about. This is
  22243. 14:17:22in a list and each one is within these
  22244. 14:17:25th tags. So, th and then there's our um
  22245. 14:17:28string that we're trying to get. So, we
  22246. 14:17:30can easily take this list and use list
  22247. 14:17:34comprehension and we can do that right
  22248. 14:17:36down here. So, I'm going to keep this to
  22249. 14:17:38where we can see it. Um we'll do world
  22250. 14:17:41table titles. That's equal to. Now we'll
  22251. 14:17:46do our list comprehension. Should be
  22252. 14:17:47super easy. Uh we'll just say for title
  22253. 14:17:51in world_titles. And then what do we
  22254. 14:17:54want? We want title.ext.
  22255. 14:17:57That's it. Um because we're just taking
  22256. 14:17:59the text from each of these. We're just
  22257. 14:18:01looping through and we're getting rank.
  22258. 14:18:03Then we're looping through getting name.
  22259. 14:18:04Looping through getting industry. That's
  22260. 14:18:06it. So let's go and print our world
  22261. 14:18:10table titles and see if it worked.
  22262. 14:18:14And it did. Uh, this looks like it needs
  22263. 14:18:16to be cleaned up just a little bit. So,
  22264. 14:18:19let's go ahead and do that while we're
  22265. 14:18:21here before we actually put it into the
  22266. 14:18:23uh, Pandas dataf frame. Oops. I just
  22267. 14:18:26wanted uh, I just wanted this actually.
  22268. 14:18:30So, what we're going to do is try to get
  22269. 14:18:31rid of those backslash ends. If we do
  22270. 14:18:34strip, that may actually not work. Yeah.
  22271. 14:18:36Uh, because this is a list. What we need
  22272. 14:18:38to do is we can actually do it
  22273. 14:18:40dot.ext.strip,
  22274. 14:18:42strip right here. Let's try to do it in
  22275. 14:18:44there. There we go. So, now we have uh
  22276. 14:18:46this and now this world tables is good
  22277. 14:18:50to go. Now, I'm actually noticing one
  22278. 14:18:52thing that may be odd. Yeah. So, we have
  22279. 14:18:56rank name, industry, it goes to
  22280. 14:18:58headquarters, but then in here we're
  22281. 14:19:00getting rank name, industry, and then
  22282. 14:19:02the profits,
  22283. 14:19:04which is from
  22284. 14:19:06this table right here, which we don't
  22285. 14:19:10want. Uh let's scroll back up. Let's
  22286. 14:19:13kind of backtrack this and see where
  22287. 14:19:15this happened. We did find all table.
  22288. 14:19:18We're looking at the first one, right?
  22289. 14:19:21And then we're doing headquarters.
  22290. 14:19:26Uh so we're doing print table. Ah, okay.
  22291. 14:19:28I think I found the issue here. And
  22292. 14:19:30let's backtrack again. This is we're
  22293. 14:19:32working through this together. We're
  22294. 14:19:33going to make mistakes. Uh the table is
  22295. 14:19:35what we actually wanted to do. We just
  22296. 14:19:37did soup.allTth, find all th which is
  22297. 14:19:39going to pull in that secondary table. U
  22298. 14:19:42gez we were not thinking here. Um so now
  22299. 14:19:45we need to do find all on the table not
  22300. 14:19:49the soup because now we were looking at
  22301. 14:19:50all of them. Oh what a rookie mistake.
  22302. 14:19:52Okay. Uh let's go back. Now let's look
  22303. 14:19:55at this. Now it's just down to
  22304. 14:19:57headquarters. Okay. Okay. Let's go ahead
  22305. 14:20:00and run this. Let's run this. Now we
  22306. 14:20:03just have headquarters. Now let's run
  22307. 14:20:05this.
  22308. 14:20:06Now we are sitting pretty. Okay, excuse
  22309. 14:20:09my mistakes. Hey, listen. You know, if
  22310. 14:20:11it happens to me, it happens to you. I
  22311. 14:20:13promise you. This is, you know, this is
  22312. 14:20:14a project. This is a little project
  22313. 14:20:16we're creating here. So, we're going to
  22314. 14:20:17run into issues, and that's okay. We're
  22315. 14:20:19figuring it out as we go. Now, what I
  22316. 14:20:21want to do before we start pulling in
  22317. 14:20:22all the data is I want to put this into
  22318. 14:20:25our pandas data frame. We'll have the
  22319. 14:20:27uh, you know, headers there for us to
  22320. 14:20:29go, so we won't have to get that later,
  22321. 14:20:31and it just makes it easier uh, in
  22322. 14:20:32general, trust me. So, we're going to
  22323. 14:20:34import pandas as pd. Let's go ahead and
  22324. 14:20:37run this. And now we're going to create
  22325. 14:20:38our data frame. So, we'll say pd dot.
  22326. 14:20:42Now, we have these world uh table
  22327. 14:20:44titles. So, what we're going to do is
  22328. 14:20:46pd.data
  22329. 14:20:47frame. And then in here for our columns,
  22330. 14:20:50we'll say that's equal to the world
  22331. 14:20:52table titles. And let's just go ahead
  22332. 14:20:55and say that's our data frame and call
  22333. 14:20:57our data frame right here. Let's run it.
  22334. 14:20:59There we go. So, we were able to pull
  22335. 14:21:02out and extract those headers and those
  22336. 14:21:04titles of these columns. We're able to
  22337. 14:21:06put it into our data frame. So, we're
  22338. 14:21:08set up and we're ready to go. We're
  22339. 14:21:09rocking and rolling. The next thing we
  22340. 14:21:11need, let's go back up. Next thing we
  22341. 14:21:14need is to start pulling in this data
  22342. 14:21:16right here. So, we have to see how we
  22343. 14:21:18can pull this data in. Now, if you
  22344. 14:21:20remember
  22345. 14:21:22that we had those TH tags, those were
  22346. 14:21:24our titles. As you can see, I'm
  22347. 14:21:26highlighting over it. But down here now
  22348. 14:21:28we have these TD tags and those are all
  22349. 14:21:31encapsulated within a TR tag. So these
  22350. 14:21:34TR represent the rows, right? Then the D
  22351. 14:21:39represents the data within those rows.
  22352. 14:21:41So R for rows, D for data. So let's see
  22353. 14:21:44how we can use that in order to get the
  22354. 14:21:46information that we want. So let's go
  22355. 14:21:48back up here. Just going to take this
  22356. 14:21:50because again we're only pulling from
  22357. 14:21:52table, not soup. Not soup. What were we
  22358. 14:21:56thinking? Um, and let's go ahead and
  22359. 14:21:58let's look at TR. Let's run this. Now,
  22360. 14:22:01when we're doing this TR, these do come
  22361. 14:22:04in with the headers. So, we're going to
  22362. 14:22:07have to later on, we're going to have to
  22363. 14:22:08get rid of these. We don't want to pull
  22364. 14:22:09those in um and have that as part of our
  22365. 14:22:12data. But, if we scroll down, there's
  22366. 14:22:14our Walmart.
  22367. 14:22:16Um, we have the location. These are all
  22368. 14:22:19with these TD tags. And then, of course,
  22369. 14:22:23it's separated by a comma. And then we
  22370. 14:22:25have our TD2. So above we had our TD1.
  22371. 14:22:29So row one, row two, row three, all the
  22372. 14:22:31way down. Now we will easily be able to
  22373. 14:22:34use this, right? Because this is our
  22374. 14:22:36column data. And we can even call it
  22375. 14:22:38that column
  22376. 14:22:40data is equal to we'll run that. Um, and
  22377. 14:22:44what we're going to do is we're going to
  22378. 14:22:45loop through that because it was all in
  22379. 14:22:46a list. So we're going to loop through
  22380. 14:22:48that information, but instead of looking
  22381. 14:22:49at the TR tag, we're going to look at
  22382. 14:22:51the TD tag. So let's come right down
  22383. 14:22:54here. We'll say for the row in column
  22384. 14:22:57row
  22385. 14:22:59and we'll do a colon. Now we need to
  22386. 14:23:01loop through this. We'll do something
  22387. 14:23:03like row.find_all.
  22388. 14:23:06And then what are we looking for? We're
  22389. 14:23:08not looking for the tr looking for the
  22390. 14:23:10TD. And just for now, let's print this
  22391. 14:23:14off.
  22392. 14:23:15See what this looks like. Apparently, I
  22393. 14:23:18didn't run this uh column data, that's
  22394. 14:23:21why.
  22395. 14:23:24And let's run this. And what we actually
  22396. 14:23:27need to do is something almost exactly
  22397. 14:23:30like this.
  22398. 14:23:32And I'm going to put it right below it.
  22399. 14:23:35Um, instead of printing this off because
  22400. 14:23:38again, this is all in a list. We're
  22401. 14:23:40using find all. So we're we're printing
  22402. 14:23:42off another list which isn't actually
  22403. 14:23:44super helpful. um for each of all these
  22404. 14:23:48data that we're pulling in. What we can
  22405. 14:23:50do is we can call this uh the row data
  22406. 14:23:54and then we'll put the row data in here.
  22407. 14:23:56So we'll say for and we'll say in row
  22408. 14:24:00data. So we'll just say for the data in
  22409. 14:24:02row data and we'll take the data we'll
  22410. 14:24:05exchange that and now instead of uh
  22411. 14:24:08world table titles we can change this
  22412. 14:24:11into uh individual
  22413. 14:24:14row data right and now let's print off
  22414. 14:24:18the individual row data. So it's the
  22415. 14:24:20exact same process that we were doing up
  22416. 14:24:23here and that's how we cleaned it up and
  22417. 14:24:25got this. And we may not need to strip
  22418. 14:24:27but let's just run this and see what we
  22419. 14:24:29get. There we go. Um, and strip I'm sure
  22420. 14:24:31was helpful. Let's actually get rid of
  22421. 14:24:33this.
  22422. 14:24:34Yeah, strip was helpful. It's the exact
  22423. 14:24:37same thing that happened on the last
  22424. 14:24:38one. So, let's keep that actually. Let's
  22425. 14:24:41run this. And now, let's just kind of
  22426. 14:24:43glance at this information. Let's look
  22427. 14:24:45through it. This looks exactly like the
  22428. 14:24:48information that's in the table. Let's
  22429. 14:24:50just confirm with this first one. Uh, 25
  22430. 14:24:53uh two, what am I saying? 572754
  22431. 14:24:562.4 4 2300
  22432. 14:24:59572752.4
  22433. 14:25:002300. So this looks exactly correct. Now
  22434. 14:25:04we have to figure out a way to get this
  22435. 14:25:07into our table because again these are
  22436. 14:25:09all individual lists. It's not like
  22437. 14:25:12we're just, you know, putting all this
  22438. 14:25:14in at one time. We can't just take the
  22439. 14:25:16entire table and plop it into um into
  22440. 14:25:19the data frame. We need a way to kind of
  22441. 14:25:21put this in one at a time. Now, if
  22442. 14:25:23you're just here for web scraping and
  22443. 14:25:24you haven't taken like my Panda series,
  22444. 14:25:26that's totally fine. That's not what
  22445. 14:25:28we're here for anyways. Um, but what we
  22446. 14:25:30can do, we'll have our individual row
  22447. 14:25:32data and we're going to put it in kind
  22448. 14:25:35of one at a time. Now, the reason we
  22449. 14:25:37have to do that is because when we had
  22450. 14:25:39it like this, and let's go back. When we
  22451. 14:25:41had it like this, it's printing out all
  22452. 14:25:43of it. But what it's really doing, and
  22453. 14:25:45let's get rid of it. Um, what it's
  22454. 14:25:47really doing is it's kind of doing it
  22455. 14:25:48like this. It's printing it off one at a
  22456. 14:25:51time and it's only going to save that
  22457. 14:25:53current row of data. This last one, it's
  22458. 14:25:57only going to save that as it's looping
  22459. 14:25:59through. So, what we actually want to do
  22460. 14:26:01is every time it loops through, we
  22461. 14:26:03append this information onto the data
  22462. 14:26:06frame. So, as it goes through, and
  22463. 14:26:08eventually it's going to end up with
  22464. 14:26:09this one, but as it goes through, let's
  22465. 14:26:11run this. As it goes through, it puts
  22466. 14:26:14this one in. And then the next time it
  22467. 14:26:15loops through, it puts this one in. And
  22468. 14:26:17the next time it loops through, etc.,
  22469. 14:26:19all the way down. Um, so let's see how
  22470. 14:26:22we can do this. So we have our data
  22471. 14:26:23frame right here. Let's get rid of this.
  22472. 14:26:27Let's bring our data frame in. Now
  22473. 14:26:29again, like I just mentioned, if you
  22474. 14:26:30don't know pandas and you haven't
  22475. 14:26:32learned that, uh, you know, go take my,
  22476. 14:26:34uh, series on that. It's really good.
  22477. 14:26:36And we do something very similar to this
  22478. 14:26:37in that series. So I'm not going to kind
  22479. 14:26:39of walk through the entire logic. Um,
  22480. 14:26:41but there is something called LOC, which
  22481. 14:26:44stands for location when you're looking
  22482. 14:26:45at the index on a dataf frame. And we're
  22483. 14:26:48going to use that to our advantage. So,
  22484. 14:26:50we're going to say the length of the
  22485. 14:26:52data frame. So, we're looking at how
  22486. 14:26:54many rows are in this data frame. And
  22487. 14:26:56then, we're going to say that's our
  22488. 14:26:57length. Then, we're going to take that
  22489. 14:27:00length and use it when we're actually
  22490. 14:27:03putting in this new information. Pretty
  22491. 14:27:05um pretty cool. So, we're going to say
  22492. 14:27:07df.loc loc and then a bracket and we're
  22493. 14:27:10putting in that length. So we're
  22494. 14:27:12checking the length of our data frame
  22495. 14:27:14each time it's looping through and then
  22496. 14:27:16we're going to put the information in
  22497. 14:27:18the next position. That's exactly what
  22498. 14:27:20we're doing. So let's go ahead and put
  22499. 14:27:22in the individual row data. Um so let's
  22500. 14:27:26just recap. We're looping through this
  22501. 14:27:29TR. This is our column data. So these TR
  22502. 14:27:32that's our row of data. Then we're as
  22503. 14:27:35we're as we're looping through it, we're
  22504. 14:27:37doing find all and looking for TD tags.
  22505. 14:27:39That's our individual data. So that's
  22506. 14:27:42our row data. Then we're taking that
  22507. 14:27:43data, each piece of data, and we're
  22508. 14:27:46getting out the text and we're stripping
  22509. 14:27:48it to kind of clean it. And now it's in
  22510. 14:27:50a list for each individual row. Then
  22511. 14:27:53we're looking at our current data frame,
  22512. 14:27:55which has nothing in it right now. We're
  22513. 14:27:57looking at the length of it. And we're
  22514. 14:27:59appending each row of this information
  22515. 14:28:02into the next position. So, let's go
  22516. 14:28:04ahead and run this. It's working. It's
  22517. 14:28:07thinking. And it looks like we got an
  22518. 14:28:09issue. And not set a row with mismatched
  22519. 14:28:12columns. Now, we're encountering an
  22520. 14:28:14issue. Not one that I got earlier, but
  22521. 14:28:16we're going to cancel this out. We're
  22522. 14:28:19going to figure this out together. So,
  22523. 14:28:20let's print off our individual row data.
  22524. 14:28:24Let's look at this. This one is empty.
  22525. 14:28:26Uh this is I'm almost certain is
  22526. 14:28:29probably the issue. Um I didn't
  22527. 14:28:31encounter this issue when I wrote these
  22528. 14:28:33uh when I wrote this lesson. Um but I'm
  22529. 14:28:35almost certain that this is the issue
  22530. 14:28:37right here. So let's do the column data,
  22531. 14:28:39but let's start at position. Um let's
  22532. 14:28:42try one and not parentheses. I need
  22533. 14:28:46brackets because this is a list, right?
  22534. 14:28:48So it should work. And there we go. So
  22535. 14:28:51now that first one's gone. So now we
  22536. 14:28:53just have the information. I didn't even
  22537. 14:28:55think about that um just a second ago,
  22538. 14:28:57but I'm glad we're running into it in
  22539. 14:28:59case you ran into that uh issue. Let's
  22540. 14:29:02go ahead and try this again.
  22541. 14:29:04And it looked like it worked. So, let's
  22542. 14:29:06pull our data frame down. I could have
  22543. 14:29:08just wrote DF. Let's pull our data frame
  22544. 14:29:10down. And now this is looking fantastic.
  22545. 14:29:14Now, um these three dots just mean
  22546. 14:29:16there's information in there, just
  22547. 14:29:17doesn't want to display it. But it looks
  22548. 14:29:19like we have our rank, we have our name,
  22549. 14:29:22we have the industry, revenue, revenue
  22550. 14:29:24growth, employees and headquarters for
  22551. 14:29:26every single one. So this is perfect.
  22552. 14:29:29Now this is exactly what I was hoping to
  22553. 14:29:31get. Now you can go in and use pandas
  22554. 14:29:33and manipulate this and change it and
  22555. 14:29:35you know dive into all the information
  22556. 14:29:36in there. But we can also export this
  22557. 14:29:40into a CSV if that's what you're
  22558. 14:29:42wanting. So we could easily do that by
  22559. 14:29:44saying we'll do df.2 2 CSV and then
  22560. 14:29:49within here we're just going to do R and
  22561. 14:29:51specify our file path. So let's come
  22562. 14:29:53down here to our file path and we'll go
  22563. 14:29:55to our folder for our output. So we're
  22564. 14:29:58just going to take this path and let me
  22565. 14:30:01do it like that. So I have this path in
  22566. 14:30:02my one drive documents Python web
  22567. 14:30:05scraping folder for output. So you know
  22568. 14:30:07I already made this um and I'm just
  22569. 14:30:08going to put this right down here. Now I
  22570. 14:30:11do have to specify what we're going to
  22571. 14:30:12call this. Um we'll just call this
  22572. 14:30:15companies. And then we have to say CSV.
  22573. 14:30:18That is very important. Now if we run
  22574. 14:30:20this, I already know just because uh we
  22575. 14:30:23have this rank and this index here.
  22576. 14:30:25We're going to keep this index in the
  22577. 14:30:26output. Not great. Uh but let's run it.
  22578. 14:30:30Let's look at our output.
  22579. 14:30:33There's our companies. And when we pull
  22580. 14:30:34this up, as you can see, this is not
  22581. 14:30:37what we want because we have this extra
  22582. 14:30:38thing right here. Now, if we were
  22583. 14:30:40automating this, this would get super
  22584. 14:30:41annoying. So, what we're going to do is
  22585. 14:30:43go back and just say index equals false.
  22586. 14:30:45Let's go out of here. And now we're just
  22587. 14:30:47going to come right down here. We're
  22588. 14:30:48going to say, comma, index equals false.
  22589. 14:30:52And so, it's going to take this index,
  22590. 14:30:53and it's not going to import or actually
  22591. 14:30:55export it into the CSV. Now, let's go
  22592. 14:30:58ahead and run this.
  22593. 14:31:01Let's pull up our folder one more time.
  22594. 14:31:05And let's refresh just to make sure.
  22595. 14:31:07Should be good. And now this looks a lot
  22596. 14:31:10better. So, we're able to take all of
  22597. 14:31:12that information and put it into a CSV
  22598. 14:31:15and it's all there. So, this is the
  22599. 14:31:17whole project. So, if we scroll all the
  22600. 14:31:19way back up, let's just kind of glance
  22601. 14:31:21at what we did here. Scroll down. We
  22602. 14:31:24brought in our libraries and packages.
  22603. 14:31:26We specified our URL. We brought in our
  22604. 14:31:29soup. Um, and then we tried to find our
  22605. 14:31:32table. Now, that took a little bit of uh
  22606. 14:31:35testing out, but we knew that the table
  22607. 14:31:37was the second one. So, in position one.
  22608. 14:31:40So we took that table. We were also able
  22609. 14:31:42to specify it using find but then we
  22610. 14:31:45used the class and of course we just
  22611. 14:31:47wanted to work with that table. That's
  22612. 14:31:48all the data we wanted. So we specified
  22613. 14:31:51this is our table and we worked with
  22614. 14:31:53just our table going forward. Of course
  22615. 14:31:55uh we encountered some small issues user
  22616. 14:31:58errors on my end but we were able to get
  22617. 14:32:00our world titles and we put those into
  22618. 14:32:03our data frame right here using pandas.
  22619. 14:32:06Then next we went back and we got all
  22620. 14:32:08the row data and the individual data
  22621. 14:32:10from those rows and we put it into our
  22622. 14:32:13pandas dataf frame. Then we came below
  22623. 14:32:16and we exported this into an actual CSV
  22624. 14:32:19file. So that is how we can use web
  22625. 14:32:21scraping to get data from something like
  22626. 14:32:23a table and put it into a pandas dataf
  22627. 14:32:26frame. I hope that this lesson was
  22628. 14:32:27helpful. I know we encountered some
  22629. 14:32:28issues. That's on my end and I
  22630. 14:32:30apologize. But if you run into the same
  22631. 14:32:32issues, hopefully that helped. Uh, but I
  22632. 14:32:34hope this was helpful and if you like
  22633. 14:32:36this, be sure to like and subscribe
  22634. 14:32:37below. I appreciate you. I love you and
  22635. 14:32:40I will see you in the next lesson.
  22636. 14:32:43[music]
  22637. 14:32:54So, the first thing that we need to do
  22638. 14:32:55is import our pandas library. So, we're
  22639. 14:32:58going to say import and we're going to
  22640. 14:32:59say pandas. Now, this will import the
  22641. 14:33:01pandas library, but it's pretty common
  22642. 14:33:04place to give it an alias and as a
  22643. 14:33:07standard when using pandas. People will
  22644. 14:33:09say as pd. So, this is just a quick
  22645. 14:33:12alias that you can use. Uh, that's what
  22646. 14:33:13I always use and I've always used it cuz
  22647. 14:33:15that's how I learned it and I want to
  22648. 14:33:17teach it to you the right way. So,
  22649. 14:33:18that's how we're going to do it in this
  22650. 14:33:19video. So, let's hit shift enter. Now
  22651. 14:33:22that that is imported, we can start
  22652. 14:33:24reading in our files. Now, right down
  22653. 14:33:26here, I'm going to open up my file
  22654. 14:33:27explorer. And we have several different
  22655. 14:33:30types of files in here. We have CSV
  22656. 14:33:33files, text files, JSON files, and an
  22657. 14:33:36Excel worksheet, which is a little bit
  22658. 14:33:38different than a CSV. So, we're going to
  22659. 14:33:41import all of those. I'm going to show
  22660. 14:33:42you how to import it, as well as some of
  22661. 14:33:45the different things that you need to be
  22662. 14:33:46aware of when you're importing. So,
  22663. 14:33:48we're going to import some of those
  22664. 14:33:49different file types, and I'll show you
  22665. 14:33:51how to do that within pandas. So, the
  22666. 14:33:53first thing that we need to say is PD
  22667. 14:33:55dot and let's read in a CSV because
  22668. 14:33:58that's a pretty common one. We'll say
  22669. 14:34:00read
  22670. 14:34:02CSV. And this is literally all you have
  22671. 14:34:05to write in order to call that in. Now,
  22672. 14:34:08it's not going to call it in as a string
  22673. 14:34:10like it would in one of our previous
  22674. 14:34:11videos if you're just using the regular
  22675. 14:34:14operating system of Python. When you're
  22676. 14:34:16using pandas, it calls it in as a data
  22677. 14:34:18frame. And I'll talk about some of the
  22678. 14:34:19nuances of that. So, let's go down to
  22679. 14:34:21our file explorer. We have this
  22680. 14:34:23countries of the world CSV. You just
  22681. 14:34:25need to click on it and rightclick
  22682. 14:34:28and copy as path. And that's literally
  22683. 14:34:31going to copy that file path for us. You
  22684. 14:34:33don't have to type it out manually. You
  22685. 14:34:34can if you'd like. And we're just going
  22686. 14:34:36to paste it in between these
  22687. 14:34:38parentheses. Now, if we run it right
  22688. 14:34:40now, it will not work. I'll do that for
  22689. 14:34:42you. It's saying we have this Unicode
  22690. 14:34:44error. Uh, basically what's happening is
  22691. 14:34:46is it's reading in these backslashes and
  22692. 14:34:49this colon and all those backslashes in
  22693. 14:34:51there and this period at the end. What
  22694. 14:34:53we need to do is read this in as a raw
  22695. 14:34:55text. So, we're just going to say R. And
  22696. 14:34:57now it's going to read this as a literal
  22697. 14:35:00string or a literal value and not as you
  22698. 14:35:03know with all these backslashes which
  22699. 14:35:05does make a big difference. When we run
  22700. 14:35:07this, it's going to populate our very
  22701. 14:35:09first data frame. So, let's go ahead and
  22702. 14:35:10run it. And now we have this CSV in here
  22703. 14:35:14with our country and our region. Now if
  22704. 14:35:17we go and pull up this file and let's do
  22705. 14:35:18that really quickly. Let's bring up this
  22706. 14:35:20countries of the world. It automatically
  22707. 14:35:22populated those headers for us in the
  22708. 14:35:24data frame. But we don't have any column
  22709. 14:35:27for those 0 1 2 3. So if we go back, as
  22710. 14:35:30you can see right here, there's this
  22711. 14:35:32index. And that's really important in a
  22712. 14:35:34dataf frame. It's really what makes a
  22713. 14:35:35dataf frame a dataf frame. And we use
  22714. 14:35:37index a lot in pandas. We're able to
  22715. 14:35:39filter on the index, search on the
  22716. 14:35:41index, and a lot of other things which
  22717. 14:35:42I'll show you in future videos. But this
  22718. 14:35:45is basically how you read in a file.
  22719. 14:35:48Now, if we go right up here in between
  22720. 14:35:49these parentheses and we hit shift tab,
  22721. 14:35:52this is going to come up for us. Let's
  22722. 14:35:54hit this plus button. And what this is
  22723. 14:35:57is these are all the arguments or all
  22724. 14:35:59the things that we can specify when
  22725. 14:36:02we're reading in a file. And there are a
  22726. 14:36:04lot of different options. So, let's go
  22727. 14:36:05ahead and take a look really quickly.
  22728. 14:36:07Really quickly, I wanted to give a huge
  22729. 14:36:08shout out to the sponsor of this entire
  22730. 14:36:10Panda series, and that is Udemy. Udemy
  22731. 14:36:12has some of the best courses at the best
  22732. 14:36:14prices, and it is no exception when it
  22733. 14:36:16comes to pandas courses. If you want to
  22734. 14:36:18master pandas, this is the course that I
  22735. 14:36:19would recommend. It's going to teach you
  22736. 14:36:20just about everything you need to know
  22737. 14:36:22about pandas. So, huge shout out to
  22738. 14:36:24Udemy for sponsoring this Pandanda
  22739. 14:36:25series. And let's get back to the video.
  22740. 14:36:27The first thing is obviously the file
  22741. 14:36:28path. We can specify a separator, which
  22742. 14:36:32there is no default. So when we're
  22743. 14:36:34pulling in this CSV, when we're reading
  22744. 14:36:36in the CSV, it's automatically going to
  22745. 14:36:38assume it's a comma because it's a
  22746. 14:36:39commaepparated uh file. You can choose
  22747. 14:36:42delimters, headers, names, index
  22748. 14:36:45columns, and a lot of other things as
  22749. 14:36:47you can see right here. Now, I will say
  22750. 14:36:49that I don't use almost any of these. Uh
  22751. 14:36:53the few that I'm going to show you
  22752. 14:36:54really quickly in just a second are up
  22753. 14:36:56the very top, but you can do a ton of
  22754. 14:36:59different things, and I'm just going to
  22755. 14:37:00slowly go through them. So that's what
  22756. 14:37:02those are. You can also go down here.
  22757. 14:37:04This is our doc string and you can see
  22758. 14:37:07exactly how these parameters work. It'll
  22759. 14:37:10show you and give you a text and walk
  22760. 14:37:12you through how to do this. Again, most
  22761. 14:37:14of these you'll probably never use, but
  22762. 14:37:17things like a separator could actually
  22763. 14:37:18be useful and things like a header could
  22764. 14:37:20be useful because it is possible that
  22765. 14:37:23you want to either rename your headers
  22766. 14:37:25or you don't have a header in your CSV
  22767. 14:37:28and you don't want it to autopop
  22768. 14:37:30populate that header. So that is
  22769. 14:37:31something that you can specify. So for
  22770. 14:37:33example, this header one and I'll show
  22771. 14:37:35you how to do this. Uh the default
  22772. 14:37:36behavior is to infer that there are
  22773. 14:37:38column names. If no names are passed,
  22774. 14:37:41this behavior is identical to header
  22775. 14:37:42equals zero. So it's saying that first
  22776. 14:37:45row or that first index, which is like
  22777. 14:37:47right here, that zero is going to be
  22778. 14:37:50read in as a header. But we can come
  22779. 14:37:53right over here and we'll do comma
  22780. 14:37:55header is equal to and we could say
  22781. 14:37:58none. And as you can see, there are no
  22782. 14:38:01headers now. Instead, it's another
  22783. 14:38:03index. So, we have indexes on both the
  22784. 14:38:05x-axis and the y-axis. And so, right
  22785. 14:38:08now, we have this zero and one index
  22786. 14:38:10indicating the first column and the
  22787. 14:38:12second column. If we want to specify
  22788. 14:38:14those names, we can say the header
  22789. 14:38:16equals none. Then we can say names is
  22790. 14:38:19equal to and we'll give it a list. And
  22791. 14:38:22so, the first one was country and what's
  22792. 14:38:25that second one? Oh, region. So, they're
  22793. 14:38:28right here. That's the first um the
  22794. 14:38:30first row, but we'll rename it and we'll
  22795. 14:38:32just say country and region. And when we
  22796. 14:38:36run that, we've now populated the
  22797. 14:38:37country and the region. Uh we're just
  22798. 14:38:39pretending that our CSV does not have
  22799. 14:38:41these values in it and we have to name
  22800. 14:38:42it ourselves. That's how you do it. But
  22801. 14:38:45let's get rid of all that because we
  22802. 14:38:47actually do want those in there. So,
  22803. 14:38:48we're just going to get rid of those and
  22804. 14:38:50read it in as normal. And there we go.
  22805. 14:38:54Now, typically when you're reading in a
  22806. 14:38:55file, what you need to do is you want to
  22807. 14:38:58assign that to a variable. Almost always
  22808. 14:39:00when you see any tutorial or anybody
  22809. 14:39:03online or even when you're actually
  22810. 14:39:05working, people will say DF is equal to.
  22811. 14:39:08DF stands for dataf frame. Again, this
  22812. 14:39:10is a dataf frame. In the next video in
  22813. 14:39:13this series, I'm going to walk through
  22814. 14:39:14what a series is as well as what a dataf
  22815. 14:39:17frame is because that's pretty important
  22816. 14:39:18to know when you're working with these
  22817. 14:39:20data frames. But we'll assign it to this
  22818. 14:39:22value and then we'll say we'll call it
  22819. 14:39:24by saying df and we'll run it. And
  22820. 14:39:27that's typically how you'll do things
  22821. 14:39:28because [clears throat] you want to save
  22822. 14:39:29this data frame. So later on you can do
  22823. 14:39:31things like dataf frame dot and you can
  22824. 14:39:34uh you know pass in different modules
  22825. 14:39:36but you can't really do that. It's not
  22826. 14:39:38as easy to do it if you're calling this
  22827. 14:39:39entire CSV and importing it every time.
  22828. 14:39:42So let's copy this because now we're
  22829. 14:39:45going to import a different type of
  22830. 14:39:47file. So now we've been doing read CSV,
  22831. 14:39:50but we can also import text files. Now
  22832. 14:39:53you can do that with the read CSV. We
  22833. 14:39:55can import text files. Let's look at
  22834. 14:39:57this one. We have the same one. It's
  22835. 14:39:59countries of the world except now it's a
  22836. 14:40:00text file cuz I just converted it for
  22837. 14:40:02this video. I'll copy that as a path.
  22838. 14:40:05And so now when we do this, oops, let me
  22839. 14:40:07get those
  22840. 14:40:09quotes in there. It'll say world.txt.
  22841. 14:40:12It will still work. As you can see, this
  22842. 14:40:15did not import properly. Um, we have
  22843. 14:40:17this country back slasht region and then
  22844. 14:40:20all of our values are the exact same
  22845. 14:40:21with this backslash t. That's because we
  22846. 14:40:23need to use a separator. And I'll show
  22847. 14:40:26you in just a little bit how we can do
  22848. 14:40:27this in a different way. But with that
  22849. 14:40:29read cvv, this is how we can do it.
  22850. 14:40:31We'll just say is equal to we need to do
  22851. 14:40:35back slasht. Now let's try running this.
  22852. 14:40:38And as you can see, it now has it broken
  22853. 14:40:40out into country and region. We could
  22854. 14:40:43also do it the more proper way. Okay.
  22855. 14:40:45And this is the way you should do it.
  22856. 14:40:46And I'll get rid of these really
  22857. 14:40:48quickly. But just want to keep them
  22858. 14:40:50there in case you want to see that. But
  22859. 14:40:52you can also do read table. And let's
  22860. 14:40:57get rid of this separator. And now we
  22861. 14:40:59have no separator. It's just reading it
  22862. 14:41:01in as a table. Let's run this. And it
  22863. 14:41:03reads it in properly the first time.
  22864. 14:41:05This read table can be used for tons of
  22865. 14:41:08different data types, but typically I've
  22866. 14:41:09been using it for like text files. Um,
  22867. 14:41:11we can also read in that CSV. So, let's
  22868. 14:41:14change this right here to CSV. We can
  22869. 14:41:16read it in as a CSV, but just like we
  22870. 14:41:19did in the last one when we read in the
  22871. 14:41:20text file using read CSV, this read
  22872. 14:41:23table, you're going to need to specify
  22873. 14:41:24the separator. So, I'll just copy this
  22874. 14:41:28and we'll say comma. And now it reads it
  22875. 14:41:32in properly. Again, you can use that for
  22876. 14:41:34a ton of different file types, but you
  22877. 14:41:35just need to specify a few more things
  22878. 14:41:37if you don't want to use the more
  22879. 14:41:38specific readers function when you're
  22880. 14:41:41using pandas. Now, let's copy this
  22881. 14:41:43again. We're going to go right down
  22882. 14:41:45here. And now, let's do JSON files. JSON
  22883. 14:41:49files usually hold semistructured data,
  22884. 14:41:51um, which is definitely different than
  22885. 14:41:53very structured data like a CSV where it
  22886. 14:41:55has columns and rows. So, let's go to
  22887. 14:41:58our file explorer. We have this JSON
  22888. 14:42:01sample. We will copy this in as path.
  22889. 14:42:07Let's paste it right here. And we'll do
  22890. 14:42:09read_json.
  22891. 14:42:11Again, these different functions were
  22892. 14:42:12built out specifically for these file
  22893. 14:42:15types. That's why, you know, each one
  22894. 14:42:17has a different name. So, now we're
  22895. 14:42:18reading this in as the JSON.
  22896. 14:42:21Let's read it in. And it read it in
  22897. 14:42:24properly.
  22898. 14:42:27Now, let's go ahead and copy this and
  22899. 14:42:29take a look at Excel files because Excel
  22900. 14:42:31files are a little bit different than
  22901. 14:42:32other ones that we've looked at. Um, so
  22902. 14:42:35let's just do readers
  22903. 14:42:37cell
  22904. 14:42:39and let's go down to our file explorer
  22905. 14:42:41and let's actually open up this
  22906. 14:42:43workbook. As you can see, we have sheet
  22907. 14:42:46one right here, but we also have this
  22908. 14:42:48world population which has a lot more
  22909. 14:42:50data. Let's say we just wanted to read
  22910. 14:42:52in sheet one. We can do that or by
  22911. 14:42:55default it's going to read in this world
  22912. 14:42:57population because it's the first sheet
  22913. 14:42:58in the Excel file. Well, let's go ahead
  22914. 14:43:01and take a look at that. Let's get out
  22915. 14:43:03of here. And let's say, oops, I forgot
  22916. 14:43:06to copy the file path. Let's go ahead
  22917. 14:43:09and copy as path.
  22918. 14:43:12And we'll put it right here.
  22919. 14:43:15And let's just read it in with no
  22920. 14:43:17arguments or anything in there or no
  22921. 14:43:19parameters. When we read it in, it's
  22922. 14:43:21reading in that very first sheet. So,
  22923. 14:43:24this is the one that has all of the
  22924. 14:43:25data. Now, let's say we wanted to read
  22925. 14:43:27in that extra sheet name or the second
  22926. 14:43:29sheet name. We'll just go comma
  22927. 14:43:31sheet_name
  22928. 14:43:34says equal to and then we can specify
  22929. 14:43:36sheet was it sheet one like this. Yes it
  22930. 14:43:39was. So we just had to specify the sheet
  22931. 14:43:41name right here and then it brought in
  22932. 14:43:44that sheet instead of the default which
  22933. 14:43:46is the very first sheet in that Excel.
  22934. 14:43:48Now that definitely covers a lot of how
  22935. 14:43:50you read in those files. Again you can
  22936. 14:43:52come in here and hit shift tab and this
  22937. 14:43:54plus sign and take a look at all the
  22938. 14:43:56documentation and you can specify a lot
  22939. 14:43:58of different things. things that I
  22940. 14:44:00didn't think were very important for you
  22941. 14:44:02guys to know, especially if you're just
  22942. 14:44:03starting out. The ones that we looked at
  22943. 14:44:05today are what I would say are like the
  22944. 14:44:07ones that I use almost all the time. So,
  22945. 14:44:09I wanted to show you those, but if
  22946. 14:44:11you're interested in any of these other
  22947. 14:44:12ones or you have very unique data and
  22948. 14:44:14you need to do that. Um, you know, it's
  22949. 14:44:16worth really getting in here and
  22950. 14:44:18figuring things out. A few other things
  22951. 14:44:20that I wanted to show you just in this
  22952. 14:44:21kind of first video or this intro video
  22953. 14:44:23on how to read in files. Um, one thing
  22954. 14:44:26that you may have noticed, especially in
  22955. 14:44:27this file right here, is we're only
  22956. 14:44:30looking at the first five and then the
  22957. 14:44:33last five. So, if we wanted to see all
  22958. 14:44:35the data, all the data is in these like
  22959. 14:44:37little three dots right here, right? We
  22960. 14:44:39want to be able to see that data. But
  22961. 14:44:43right now, we can't. And that's because
  22962. 14:44:44of some settings that are already within
  22963. 14:44:46pandas. And all we need to do is change
  22964. 14:44:49that. So, this one has 234 rows and four
  22965. 14:44:52columns. So, obviously, we can see all
  22966. 14:44:53the columns. Well, let's just change the
  22967. 14:44:55rows. All we'll say is PD set
  22968. 14:45:00option. Now, what we need to do is we're
  22969. 14:45:02going to change the rows. We're not
  22970. 14:45:04going to change the columns, at least
  22971. 14:45:06not on this one. So, we'll say quote
  22972. 14:45:09display
  22973. 14:45:13rows. Now, if we just run this for
  22974. 14:45:16whatever data we bring in, it's going to
  22975. 14:45:18be able to show the max rows. And then
  22976. 14:45:19we'll say 235.
  22977. 14:45:22Although there's 234 rows. I'm just
  22978. 14:45:24going to be safe. Let's run this.
  22979. 14:45:27And now it has changed it. So let's read
  22980. 14:45:29in this file again. And you'll see how
  22981. 14:45:31it's changed. Now we have all of the
  22982. 14:45:34numbers. And we have this little bar on
  22983. 14:45:37the right that allows us to go down all
  22984. 14:45:39the way to the bottom and all the way to
  22985. 14:45:41the top. So now we can actually look and
  22986. 14:45:43kind of skim and see our values. I like
  22987. 14:45:45that better than just having that, you
  22988. 14:45:47know, shorter version. Um, we can do the
  22989. 14:45:50exact same thing on columns as well. So,
  22990. 14:45:52if we look at this one, this is our JSON
  22991. 14:45:54file. It has the same thing right here.
  22992. 14:45:56We have what was it 38 columns, but we
  22993. 14:45:59can only see I think it's maybe it's 20
  22994. 14:46:02or something like that. I can't
  22995. 14:46:03remember. Um, but we have 38. We can
  22996. 14:46:05only see like let's say 15 of them or 20
  22997. 14:46:07of them. We'll do the exact same thing
  22998. 14:46:10and we'll just say PD set options
  22999. 14:46:15doc columns and we'll set that to 40 for
  23000. 14:46:20that one. When we run this, oops, let's
  23001. 14:46:23get over here. When we run this one
  23002. 14:46:26again, we can now scroll over and see
  23003. 14:46:29every single one of our columns. Now,
  23004. 14:46:31that one is a, in my opinion, a lot more
  23005. 14:46:33useful. I like being able to see every
  23006. 14:46:35single column. So definitely something
  23007. 14:46:37that you should be using, especially
  23008. 14:46:39when you have these really large files.
  23009. 14:46:41You want to be able to see a lot of the
  23010. 14:46:42data and a lot of the columns. So when
  23011. 14:46:44you're slicing and dicing and doing all
  23012. 14:46:46the things we're about to learn in this
  23013. 14:46:47panda series, you know, you know what
  23014. 14:46:49you're looking at. I also want to show
  23015. 14:46:51you just how to kind of look at your
  23016. 14:46:53data in these data frames as well.
  23017. 14:46:55That's also pretty important. So let's
  23018. 14:46:56go right down here. And the very last
  23019. 14:46:58one that we imported was this one right
  23020. 14:47:01here, this read Excel. So this data
  23021. 14:47:02frame is the only one that's going to
  23022. 14:47:04read in. Let's run it. Um, this is the
  23023. 14:47:07last one to be run. So, this variable
  23024. 14:47:09right here, DF, uh, it won't be applied
  23025. 14:47:11to all these other ones. Um, which we
  23026. 14:47:13can always go back and change those.
  23027. 14:47:15Typically, you'll do something like
  23028. 14:47:16dataf frame 2. You want to do something
  23029. 14:47:18like that. Um, so let's keep dataf frame
  23030. 14:47:202. Oops. So, what we're going to do is
  23031. 14:47:23we're going to bring dataf frame 2 right
  23032. 14:47:25down here. And we want to take a look at
  23033. 14:47:27some of this data. We want to know a
  23034. 14:47:28little bit more about it. Something that
  23035. 14:47:30you can do is dataf frame 2.info.
  23036. 14:47:33And we'll do an open parenthesis. And
  23037. 14:47:35when we run this, it's going to give us
  23038. 14:47:37a really quick breakdown of a little bit
  23039. 14:47:39of our data. So we have our columns
  23040. 14:47:41right here. Rank, CCA3, country, and
  23041. 14:47:44capital. It's saying we have 234 values
  23042. 14:47:48in those columns. Because there's 234
  23043. 14:47:52scroll up here. Because there's 234
  23044. 14:47:55uh rows, that tells me that there's no
  23045. 14:47:58missing data in here, at least not, you
  23046. 14:48:00know, completely missing like null
  23047. 14:48:02values. there is something in each of
  23048. 14:48:04those rows. The count tells me it's
  23049. 14:48:06non-null, so there's no null values. And
  23050. 14:48:08it tells me the data type. So, it's
  23051. 14:48:09reading in as an integer, an object, an
  23052. 14:48:11object, and an object. And it also tells
  23053. 14:48:14us how much memory it's using, which is
  23054. 14:48:16also pretty neat because when you get
  23055. 14:48:17really really large data types, memory
  23056. 14:48:20usage and and knowing how to work around
  23057. 14:48:21that stuff does become more important
  23058. 14:48:23than when you're working at these really
  23059. 14:48:25small, you know, sample sizes that we're
  23060. 14:48:27looking at. We can also do oops, let me
  23061. 14:48:30get rid of that. can also do dataf frame
  23062. 14:48:322 and we'll do shape. And for this one,
  23063. 14:48:36we do not need the parenthesis.
  23064. 14:48:39And all this is going to tell us is we
  23065. 14:48:40have 234 rows and four columns. We're
  23066. 14:48:44also able to look at uh the first few
  23067. 14:48:47values or rows in each of these data
  23068. 14:48:50frames. So we can just say dataf frame 2
  23069. 14:48:52head. And if we do that, it's going to
  23070. 14:48:54give us the first five values. But we
  23071. 14:48:56can specify how many we want. We can say
  23072. 14:48:59head 10. It'll give us the first 10 rows
  23073. 14:49:01right here. We can do the exact same
  23074. 14:49:04thing. And let's go right down here and
  23075. 14:49:06we'll say tail. So they'll give us the
  23076. 14:49:08last 10 rows within our data frame. Now
  23077. 14:49:12let's copy this. And let's say we don't
  23078. 14:49:14want to actually look at all of these
  23079. 14:49:16values or all these columns. We can
  23080. 14:49:18specify that by saying df2 and oops,
  23081. 14:49:21let's get rid of all of this.
  23082. 14:49:24And we'll say with a quote we'll say
  23083. 14:49:27rank. And now we can take just a look
  23084. 14:49:30the rank data. Now we can't do that by
  23085. 14:49:33doing the index or at least not like
  23086. 14:49:35this. If we want to use this index that
  23087. 14:49:38is right here, we can. But there's a
  23088. 14:49:40very special function called LO and I
  23089. 14:49:42look for that. And I'm going to have an
  23090. 14:49:44entire video on this because it does get
  23091. 14:49:45a little bit more complex. But there's
  23092. 14:49:48DF2. Loc. And there's lo and stands for
  23093. 14:49:52location and eyelocation. That's only
  23094. 14:49:54for the indexes. Whether it's the xaxis
  23095. 14:49:57or the y-axis, those are the indexes.
  23096. 14:49:59And for location, it's looking for the
  23097. 14:50:02actual text, the actual string of the
  23098. 14:50:04index. So if we come up here, that dataf
  23099. 14:50:07frame 2, we can specify 224 and it'll
  23100. 14:50:10give us this information right here in a
  23101. 14:50:12little different format. So let's go
  23102. 14:50:15bracket and we'll say 224. And when we
  23103. 14:50:18run this, it gives us our rank CCA
  23104. 14:50:21country capital with our values over
  23105. 14:50:23here. Kind of like a dictionary almost.
  23106. 14:50:26Now let's copy this and we'll say
  23107. 14:50:28df2.lo.
  23108. 14:50:31And right now these look the exact same,
  23109. 14:50:34but we haven't really talked a lot about
  23110. 14:50:36changing the index. And you can change
  23111. 14:50:38the index to a string or a different
  23112. 14:50:40column or something like that. And we'll
  23113. 14:50:42look at that in future videos. The
  23114. 14:50:43eyelock looks at the integer location.
  23115. 14:50:45So even if these um let's go right up
  23116. 14:50:48here even if this index had changed to
  23117. 14:50:51let's say this rank or the CCA3 or
  23118. 14:50:53country or whatever you make this index
  23119. 14:50:55the look will still look at the integer
  23120. 14:50:58location. So that 224 would still be 224
  23121. 14:51:01even if it was Usuzbekistan.
  23122. 14:51:03So then when we look at this, it's going
  23123. 14:51:05to be the exact same. But if we had
  23124. 14:51:08changed that index, this loc is the one
  23125. 14:51:10that we could search on and we could
  23126. 14:51:12search.
  23127. 14:51:16Is that how you spellistan?
  23128. 14:51:19Hey, I nailed it. So that is how you use
  23129. 14:51:22LO and I look. Again, I just wanted to
  23130. 14:51:24show you a little bit about how you can
  23131. 14:51:25look at your data frame or search within
  23132. 14:51:27your dataf frame. Now, in future videos,
  23133. 14:51:28I'm going to dive a lot deeper into a
  23134. 14:51:30lot of the concepts that we just looked
  23135. 14:51:32at because I just kind of touched on
  23136. 14:51:33them. I wanted you to have a brief
  23137. 14:51:35introduction to them so that in future
  23138. 14:51:37videos, I'm not just dropping everything
  23139. 14:51:39on you all at once. So, hopefully this
  23140. 14:51:40was a good quick introduction to those
  23141. 14:51:42topics. Uh, you should be able to read
  23142. 14:51:44in a file now, see your data frame, and
  23143. 14:51:46kind of look at it in a few different
  23144. 14:51:48ways that we just looked at. And I hope
  23145. 14:51:49that that was helpful. And if it was, be
  23146. 14:51:51sure to check out all my other videos on
  23147. 14:51:53Python and pandas. And if you like this
  23148. 14:51:55video, be sure to like and subscribe
  23149. 14:51:56below. and I will see you in the next
  23150. 14:51:58video.
  23151. 14:52:00[music]
  23152. 14:52:10Hello everybody. Today we're going to be
  23153. 14:52:12looking at filtering and ordering dataf
  23154. 14:52:13frames in pandas. There are a lot of
  23155. 14:52:15different ways you can filter and order
  23156. 14:52:17your data in pandas and I'm going to try
  23157. 14:52:19to show you all of the main ways that
  23158. 14:52:21you can do that. So let's kick it off by
  23159. 14:52:23importing our data set. So we're going
  23160. 14:52:24to say dataf frame is equal to and we'll
  23161. 14:52:26say pandas and I need to import my
  23162. 14:52:30pandas. So we'll say import p andas as
  23163. 14:52:33pd. That's pretty important I think. Um
  23164. 14:52:35so pdread
  23165. 14:52:37csv and we'll do r and then we'll say
  23166. 14:52:42the world population cv. So let's run
  23167. 14:52:44this all our data frame right here. And
  23168. 14:52:48this is the data frame that we're going
  23169. 14:52:50to be filtering through and ordering in
  23170. 14:52:52pandas. So, let's kick it off. The first
  23171. 14:52:55thing that we can do is filter based off
  23172. 14:52:57of the columns. So, the data within our
  23173. 14:53:00columns. So, Asia, Europe, Africa, or
  23174. 14:53:02whatever data we may have in that
  23175. 14:53:04column. Let's go right down here. We're
  23176. 14:53:06going to say DF. And then within it,
  23177. 14:53:09we're going to specify what column we're
  23178. 14:53:11going to be filtering on. So, we're
  23179. 14:53:12going to say DF with another bracket,
  23180. 14:53:14and we'll say rank. So, we're going to
  23181. 14:53:16be looking at this rank column right
  23182. 14:53:18here. And then we'll say in that rank
  23183. 14:53:21column we want to do greater than 10.
  23184. 14:53:24And that's actually going to be a lot of
  23185. 14:53:25them. Let's do less than. So when we run
  23186. 14:53:27this, it's only going to return these
  23187. 14:53:30values that are less than 10. We can
  23188. 14:53:32also do less than or equal to, you know,
  23189. 14:53:34all of these um comparison operators. So
  23190. 14:53:37less than or equal to. So now we have
  23191. 14:53:39all of the ranks 1 through 10. Now if we
  23192. 14:53:42look at these countries, we can specify
  23193. 14:53:44by specific values almost exactly like
  23194. 14:53:46we did here. But instead of doing a
  23195. 14:53:48comparison operator like we did right
  23196. 14:53:50here and including those names, let's
  23197. 14:53:52say Bangladesh and Brazil, we can use
  23198. 14:53:55the isin function almost like an in
  23199. 14:53:57function in SQL if you know SQL. So
  23200. 14:53:59let's go right down here and we're going
  23201. 14:54:01to say specific
  23202. 14:54:04countries. So right now we're just going
  23203. 14:54:06to make a list of the countries that we
  23204. 14:54:08want and then we'll say Bangladesh
  23205. 14:54:14and Brazil.
  23206. 14:54:17So let's go right down here and we'll
  23207. 14:54:20say okay for these specific countries
  23208. 14:54:22from the data frame let's do our bracket
  23209. 14:54:25we'll say in this country column so
  23210. 14:54:28we'll do data frame and then another
  23211. 14:54:30bracket for country. So in this country
  23212. 14:54:34column we can do is in and then an open
  23213. 14:54:38parenthesis and then look for our
  23214. 14:54:40specific countries. So, we're looking at
  23215. 14:54:43just this column and we're saying is in.
  23216. 14:54:45So, we're looking at are these values
  23217. 14:54:47within this column and we're getting
  23218. 14:54:50this error and this looks very very odd.
  23219. 14:54:53Let me um this doesn't look right. There
  23220. 14:54:56we go. I just had some syntax errors. I
  23221. 14:54:59apologize. Made it way more complicated
  23222. 14:55:01than it needed to be. But here's how you
  23223. 14:55:03use this is in function. So, we're
  23224. 14:55:06looking at Bangladesh and Brazil. And we
  23225. 14:55:08return those rows with Bangladesh and
  23226. 14:55:10Brazil. Really quickly, I wanted to give
  23227. 14:55:12a huge shout out to the sponsor of this
  23228. 14:55:14entire Pandanda series, and that is
  23229. 14:55:15Udemy. Udemy has some of the best
  23230. 14:55:17courses at the best prices, and it is no
  23231. 14:55:19exception when it comes to pandas
  23232. 14:55:21courses. If you want to master pandas,
  23233. 14:55:22this is the course that I would
  23234. 14:55:24recommend. It's going to teach you just
  23235. 14:55:25about everything you need to know about
  23236. 14:55:26pandas. So, huge shout out to Udemy for
  23237. 14:55:28sponsoring this Panda series. And let's
  23238. 14:55:30get back to the video. We can also do a
  23239. 14:55:32contains function kind of similar to is
  23240. 14:55:35in, except it's more like the like in
  23241. 14:55:38SQL as well. I'm comparing a lot of this
  23242. 14:55:40to SQL because when you're filtering
  23243. 14:55:41things, I always my brain always goes to
  23244. 14:55:43SQL. But in pandas, it's called the
  23245. 14:55:46contains. So let's do let's actually
  23246. 14:55:49copy this because I don't want to make
  23247. 14:55:50the same mistake again. Let's do that.
  23248. 14:55:53And we'll do the bracket, but instead of
  23249. 14:55:57in we're going to docontains
  23250. 14:56:00and then an open parenthesis. So we're
  23251. 14:56:03going to be looking for a string. If it
  23252. 14:56:05contain if it contains let's do United
  23253. 14:56:09almost like United States or or any
  23254. 14:56:11other United. So let's run this and as
  23255. 14:56:14you can see we have United Arab
  23256. 14:56:16Emirates, United Kingdom, United States,
  23257. 14:56:18United States Virgin Islands. So we can
  23258. 14:56:20kind of search for a specific string or
  23259. 14:56:23a number or a value within our data or
  23260. 14:56:26within that column of country. Now so
  23261. 14:56:28far we've only been looking at how you
  23262. 14:56:30can filter on these columns. We can also
  23263. 14:56:32filter based off of the index as well.
  23264. 14:56:35And there's two different ways you can
  23265. 14:56:37do it or two of the main ways. There's
  23266. 14:56:39filter and then there's lo and lo stands
  23267. 14:56:42for location and i look stands for
  23268. 14:56:44integer location. And if you've seen
  23269. 14:56:46other previous videos, I've kind of
  23270. 14:56:48mentioned those so we can take a quick
  23271. 14:56:49look at all of those. So really quickly,
  23272. 14:56:52we need to set an index because the
  23273. 14:56:54index right now is uh not the best.
  23274. 14:56:56We'll set our index to country.
  23275. 14:57:00So let's say df2
  23276. 14:57:03is equal to df set_index
  23277. 14:57:08and we'll say country. I'm just doing
  23278. 14:57:10df2 because later on I want to use that
  23279. 14:57:13data frame again. So I'm just going to
  23280. 14:57:14assign it to another data frame so we
  23281. 14:57:17can just easily switch back and forth.
  23282. 14:57:19So now we have this index as the country
  23283. 14:57:22and what we can do is use the filter
  23284. 14:57:24function. So let's go down here. We'll
  23285. 14:57:26say df2.filter
  23286. 14:57:31and we'll do an open parenthesis. And
  23287. 14:57:32now we can specify our items. So these
  23288. 14:57:35are actually going to be specifying
  23289. 14:57:36which columns we want to keep. So we're
  23290. 14:57:38going to say items is equal to then
  23291. 14:57:41we'll make a list. We'll say continent.
  23292. 14:57:44Hope that's how we spell continent. I'm
  23293. 14:57:46always messing up with my uh
  23294. 14:57:48my stuff here, my spelling. Then we'll
  23295. 14:57:50do CCA3 because why not? You can specify
  23296. 14:57:53whichever ones you want. When we run
  23297. 14:57:56this, it's going to only bring in those
  23298. 14:57:58two columns. Now, by default, it's
  23299. 14:58:01choosing the axis for us. But we can
  23300. 14:58:03also specify which axis we want to
  23301. 14:58:05search on. So, if we say axis is equal
  23302. 14:58:08to zero, it's actually going to search
  23303. 14:58:10this axis. This is the zero axis. This
  23304. 14:58:12is the one axis. So, where our columns
  23305. 14:58:15are is one. So, if we go back and do
  23306. 14:58:17one, we're searching on that one axis or
  23307. 14:58:20those header axises again. And this is
  23308. 14:58:22the default, but you can specify that.
  23309. 14:58:24So, if you just want to search on, you
  23310. 14:58:27know, filtering right here, you can do
  23311. 14:58:29that. And let's actually copy this and
  23312. 14:58:32do that right down here, just so you can
  23313. 14:58:33see what it looks like. But let's search
  23314. 14:58:35for Zimbabwe. And we'll do Zimbabwe. And
  23315. 14:58:39we'll be looking at the zero axis, which
  23316. 14:58:42is the up and down on the left hand
  23317. 14:58:44side. And when we filter on that, we can
  23318. 14:58:46filter by Zimbabwe by looking just at
  23319. 14:58:49the country index. We can also use the
  23320. 14:58:52like just like we did before. And I'll
  23321. 14:58:54show you the exact same demonstration
  23322. 14:58:56that we did, which you can say like is
  23323. 14:58:59equal to and instead of having to put in
  23324. 14:59:01a concrete um text, you can just say
  23325. 14:59:04United just like we did before and we're
  23326. 14:59:06searching where the access is equal to
  23327. 14:59:07zero, which again is this left-handed
  23328. 14:59:10access. So now we're looking for United
  23329. 14:59:12and it's going to give us all of the
  23330. 14:59:14countries or all the indexed values that
  23331. 14:59:16have United in it. Like we were talking
  23332. 14:59:18about before, we also have LO and I
  23333. 14:59:20look. So we can say dataf frame 2.lo.
  23334. 14:59:26Now this is a specific value. So we'll
  23335. 14:59:29do United States. So location is just
  23336. 14:59:32looking at the actual name or the value
  23337. 14:59:35of it, not its position. So if we search
  23338. 14:59:37for United States, it's going to give us
  23339. 14:59:39this right here where it gives us all of
  23340. 14:59:41the columns for United States and then
  23341. 14:59:43all of the uh values for United States.
  23342. 14:59:47Or we can do
  23343. 14:59:49the eyel which is the integer location
  23344. 14:59:52which is not the exact same because
  23345. 14:59:55we're looking at the string for the lo.
  23346. 14:59:58We're looking at this string but
  23347. 15:00:00underneath it there still is a position
  23348. 15:00:02that's that integer location. Let's do a
  23349. 15:00:04completely random one. Let's just say
  23350. 15:00:07three. If we look at the third position,
  23351. 15:00:09it's going to give us ASM, which I'm not
  23352. 15:00:12exactly sure what it is, but it still
  23353. 15:00:14gives us basically the same kind of
  23354. 15:00:15output, which is the columns and the
  23355. 15:00:18values. So, that's another way that you
  23356. 15:00:19can search within your index when you're
  23357. 15:00:21actually trying to filter down that
  23358. 15:00:23data. Now, let's go look at the order
  23359. 15:00:26by, and let's start with the very first
  23360. 15:00:28one that we looked at. Let's do data
  23361. 15:00:29frame. That's why I kept it because I
  23362. 15:00:31wanted to use it later. Now we can sort
  23363. 15:00:33and order these values instead of it
  23364. 15:00:35just being kind of a a jumbled mess in
  23365. 15:00:37here. We can sort these columns however
  23366. 15:00:40we would like. Ascending, descending,
  23367. 15:00:42multiple columns, single columns. And
  23368. 15:00:44let's look at how to do that. So we'll
  23369. 15:00:45say data frame and then we'll do dataf
  23370. 15:00:47frame. Look at rank again just like we
  23371. 15:00:50were doing above. And let's do dataf
  23372. 15:00:53frame where it's less than 10. I should
  23373. 15:00:55have just gone and copied this. I
  23374. 15:00:57apologize. So now we have this data
  23375. 15:00:59frame that is greater than 10. Now we
  23376. 15:01:02can do dots sort
  23377. 15:01:06values and this is the function that's
  23378. 15:01:08going to allow us to sort everything
  23379. 15:01:10that we want to sort. So we can do by is
  23380. 15:01:13equal to and we'll just order it by the
  23381. 15:01:16exact same thing that we were doing uh
  23382. 15:01:17or calling it on. So we'll do rank. So
  23383. 15:01:20now what this is going to do, it's going
  23384. 15:01:22to order our rank column. And as you can
  23385. 15:01:25see, it did that 1 2 3 4 5. We can also
  23386. 15:01:28do it with ascending or descending. So
  23387. 15:01:31if you want to, you can look in here and
  23388. 15:01:33see what you can do. So we'll do
  23389. 15:01:34ascending. We'll say that's equal to
  23390. 15:01:37true.
  23391. 15:01:39And so that's the automatic default. So
  23392. 15:01:41that didn't change anything. But if we
  23393. 15:01:43say false, it's going to be descending
  23394. 15:01:45from highest to lowest. So now we have
  23395. 15:01:47it in the opposite direction. Now we
  23396. 15:01:49don't have to just order or sort this on
  23397. 15:01:52one single column. We can do multiple
  23398. 15:01:54columns and we can do that by making a
  23399. 15:01:56list right here. Whoops. Make a list
  23400. 15:02:01just like that. And we'll input
  23401. 15:02:03different ones as well. So now let's
  23402. 15:02:05input our country.
  23403. 15:02:08And when we run this, it will give us
  23404. 15:02:10rank of 9876
  23405. 15:02:12as well as the country of Russia,
  23406. 15:02:15Bangladesh, Brazil. Now, if you noticed,
  23407. 15:02:18the country really didn't change because
  23408. 15:02:19the rank stayed the exact same. That's
  23409. 15:02:22because there's an order of importance
  23410. 15:02:23here and it starts with the very first
  23411. 15:02:25one. If we change this around and we
  23412. 15:02:29look at this one and put a comma right
  23413. 15:02:32here. Now the country is going to be
  23414. 15:02:34descended and the rank would come
  23415. 15:02:36second. So it's not going the rank isn't
  23416. 15:02:38going to really have any effect here. So
  23417. 15:02:41now we have the country United States,
  23418. 15:02:42Russia, Pakistan and the rank really
  23419. 15:02:45didn't get ordered at all. Now, if we
  23420. 15:02:47want to see how that can actually work,
  23421. 15:02:49let's do continent right here. And let's
  23422. 15:02:52actually put it right here and do
  23423. 15:02:54country here. So, if we run this, it's
  23424. 15:02:57first going to come and it's going to
  23425. 15:02:58organize or sort the continent. Then,
  23426. 15:03:02it's going to come back and go to the
  23427. 15:03:03country and then it's going to sort the
  23428. 15:03:05country. So, keep So, keep your eye
  23429. 15:03:08right here in this Asia area because
  23430. 15:03:10we're going to sort this differently
  23431. 15:03:12than ascending. So we have ascending
  23432. 15:03:14false and that applies to both of these.
  23433. 15:03:16It's false and false. But we can specify
  23434. 15:03:19which one we want to do. We can do a
  23435. 15:03:21false here and a true here. So we'll do
  23436. 15:03:23false, true. And what this is going to
  23437. 15:03:26do is it's going to say false for the
  23438. 15:03:28continent. So the continent right here
  23439. 15:03:30is going to stay the exact same. And so
  23440. 15:03:32that is a lot of how you can filter and
  23441. 15:03:35order your data within pandas. I hope
  23442. 15:03:37that this was helpful. I hope that you
  23443. 15:03:38enjoyed this video. If you liked it, be
  23444. 15:03:40sure to like and subscribe below. Check
  23445. 15:03:42out all my other videos on Python and
  23446. 15:03:44pandas and I will see you in the next
  23447. 15:03:45video.
  23448. 15:03:48[music]
  23449. 15:03:58Hello everybody. Today we're going to be
  23450. 15:04:00looking at indexing in pandas. If you
  23451. 15:04:02remember from previous videos, the index
  23452. 15:04:04is an object that stores the access
  23453. 15:04:06labels for all pandas objects. The index
  23454. 15:04:08in a dataf frame is extremely useful
  23455. 15:04:10because it's customizable and you can
  23456. 15:04:12also search and filter based off of that
  23457. 15:04:14index. In this video, we're going to
  23458. 15:04:16talk all about indexing, how you can
  23459. 15:04:17change the index and customize that, as
  23460. 15:04:19well as how you can search and filter on
  23461. 15:04:21that index. And then we're also going to
  23462. 15:04:23be looking at something a little bit
  23463. 15:04:24more advanced called multi-indexing. And
  23464. 15:04:27you won't always use it, but it's really
  23465. 15:04:29good to know in case you come across a
  23466. 15:04:31data frame that has that in it. So,
  23467. 15:04:33let's get started by importing pandas.
  23468. 15:04:36import pandas as pd. Now we'll get our
  23469. 15:04:39first data frame. We'll say df is equal
  23470. 15:04:41to pdread_csv.
  23471. 15:04:44And I've already copied this, but we're
  23472. 15:04:47going to do r and we're going to put
  23473. 15:04:49this file path. So I have this world
  23474. 15:04:51population cv. I will have that in the
  23475. 15:04:54description just like I do in all of my
  23476. 15:04:56other videos. Let's run df and let's
  23477. 15:04:59take a look at this data frame. So we
  23478. 15:05:01have a lot of information here. We have
  23479. 15:05:03rank, country, continent, population, as
  23480. 15:05:07well as the default index from zero all
  23481. 15:05:09the way up to 233. Now, if you haven't
  23482. 15:05:11watched any of my previous videos on
  23483. 15:05:13pandas, the index is pretty important,
  23484. 15:05:15and it's basically just a number or a
  23485. 15:05:17label for each row. It doesn't even
  23486. 15:05:19necessarily have to be a unique number.
  23487. 15:05:22Um, you can create or add an index
  23488. 15:05:24yourself if you want to, and it doesn't
  23489. 15:05:26have to be unique, but it it really
  23490. 15:05:28should be unique, especially if I want
  23491. 15:05:30to use it appropriately for what we're
  23492. 15:05:32doing. the country is actually going to
  23493. 15:05:33be a pretty great index because the
  23494. 15:05:36country, you know, is going to be all
  23495. 15:05:38unique because we're looking at every
  23496. 15:05:39single row as a different um country as
  23497. 15:05:42well as the population. So, let's go
  23498. 15:05:44ahead and create this country or add
  23499. 15:05:45this country as our index. Now, we can
  23500. 15:05:48do this in a lot of different ways, but
  23501. 15:05:50the first way that you can do this if
  23502. 15:05:52you already know what you are going to
  23503. 15:05:54create that index on is we can just go
  23504. 15:05:56right in here when we're reading in this
  23505. 15:05:57file and we'll say comma index
  23506. 15:06:01oops I spelled that completely wrong
  23507. 15:06:03index column and we'll say that is equal
  23508. 15:06:06to and then we're going to say quote
  23509. 15:06:09country. So, we're taking this country
  23510. 15:06:12and we're going to assign it as the
  23511. 15:06:13index. Now, let's read this in. And as
  23512. 15:06:16you can see, this is our index. Now, it
  23513. 15:06:19looks a little bit different. We didn't
  23514. 15:06:21have this country header right here,
  23515. 15:06:23which is specifying that this is still
  23516. 15:06:24the country. But you can tell that this
  23517. 15:06:26is the index based off the um bold
  23518. 15:06:29letters, as well as it being on the far
  23519. 15:06:30left. And all the regular columns for
  23520. 15:06:33the data is over here, while the country
  23521. 15:06:35header is right here, and it's lower
  23522. 15:06:37than all the others. Just a quick way
  23523. 15:06:39that you can see that that is the index.
  23524. 15:06:41Now before we move on, I want to show
  23525. 15:06:42you some other ways that you can do this
  23526. 15:06:44as well. But I'm going to show you how
  23527. 15:06:46to reverse this index before we move on.
  23528. 15:06:49And we'll say dataf frame. So we had our
  23529. 15:06:52dataf frame right here. So we have dataf
  23530. 15:06:54frame dot we'll say reset_index.
  23531. 15:06:58And then we'll say in place is equal to
  23532. 15:07:00true, which means we don't have to
  23533. 15:07:02assign this to another variable and all
  23534. 15:07:04that stuff. It'll just be true. So now
  23535. 15:07:06when we run that data frame again, the
  23536. 15:07:08index was reset to the default numbers.
  23537. 15:07:11So now let's go down here and I'll show
  23538. 15:07:13you how to do this in a different way.
  23539. 15:07:14You can do df do we'll say set index and
  23540. 15:07:18then we'll just say country. So very
  23541. 15:07:21similar to when we were reading in that
  23542. 15:07:22file and we said set the index or that
  23543. 15:07:24index column, we set index column equals
  23544. 15:07:27country. If we do this and we run it in,
  23545. 15:07:30it works. But if we say dataf frame
  23546. 15:07:33right down here, it's not going to save
  23547. 15:07:35that. If we want to save it just like we
  23548. 15:07:37did above, we're going to say in place
  23549. 15:07:40is equal to true. That is going to save
  23550. 15:07:43it to where we don't have to assign it
  23551. 15:07:45another variable. So now when we run
  23552. 15:07:47this, the data frame right here, which
  23553. 15:07:49is going to populate this, the data
  23554. 15:07:50frame is going to say in place is equal
  23555. 15:07:52to true. So that country will now be our
  23556. 15:07:54index again. Let's run this. And there
  23557. 15:07:57we go. Really quickly, I wanted to give
  23558. 15:07:59a huge shout out to the sponsor of this
  23559. 15:08:01entire Panda series, and that is Udemy.
  23560. 15:08:03Udemy has some of the best courses at
  23561. 15:08:05the best prices and it is no exception
  23562. 15:08:07when it comes to pandas courses. If you
  23563. 15:08:09want to master pandas, this is the
  23564. 15:08:10course that I would recommend. It's
  23565. 15:08:11going to teach you just about everything
  23566. 15:08:13you need to know about pandas. So, huge
  23567. 15:08:15shout out to Udemy for sponsoring this
  23568. 15:08:16pandas series. And let's get back to the
  23569. 15:08:18video. Now, what's really great about
  23570. 15:08:19this index is we're able to search based
  23571. 15:08:21off just this index. And so, we can
  23572. 15:08:23filter on it and basically look through
  23573. 15:08:25our data with it. And there are two
  23574. 15:08:27different ways that you can do that. At
  23575. 15:08:28least this is a very common way that
  23576. 15:08:30people who use pandas will do to kind of
  23577. 15:08:32search through that index. The first one
  23578. 15:08:34is called lock and there's lock and
  23579. 15:08:36eyelock. That stands for location or
  23580. 15:08:38integer location. Let's look at lock
  23581. 15:08:41first. Let's say df.lock
  23582. 15:08:44and then we'll do a bracket. Now we're
  23583. 15:08:46able to specify the actual string, the
  23584. 15:08:48label. So let's go right up here and
  23585. 15:08:50let's say Albania.
  23586. 15:08:52So we'll say Albania. So again, this is
  23587. 15:08:55just looking at the location. Let's run
  23588. 15:08:57this.
  23589. 15:08:58Now it's going to bring up all the
  23590. 15:09:00Albania data just like here where it's
  23591. 15:09:02kind of looks like a column in a column
  23592. 15:09:05and we can get this exact same data but
  23593. 15:09:08using eyelock right here. And when we
  23594. 15:09:12ran lock we're searching based off
  23595. 15:09:14Albania which is in the 01 position. So
  23596. 15:09:17if we actually pull the one position for
  23597. 15:09:19that integer
  23598. 15:09:21the eyelock we can look at the one
  23599. 15:09:25position and this should give us the
  23600. 15:09:27exact same data. Now let's take a look
  23601. 15:09:29at multi-indexing and we'll come back to
  23602. 15:09:32a little bit of this in a second. So
  23603. 15:09:35multi-indexing is creating multiple
  23604. 15:09:37indexes. We're not just going to create
  23605. 15:09:39the country as the index. Now we're
  23606. 15:09:41going to add an additional index on top
  23607. 15:09:43of that. So let's pull up our data
  23608. 15:09:45frame. Right now we have the country but
  23609. 15:09:47let's do dotreset
  23610. 15:09:50index
  23611. 15:09:51and we'll say in place equals true.
  23612. 15:09:55Oops. Let's run it. So now we have our
  23613. 15:09:58data frame. Now let's set our index. But
  23614. 15:10:01this time when we set our index we're
  23615. 15:10:03going to add the country as the index as
  23616. 15:10:05well as the continent as an index. So
  23617. 15:10:08we'll say dataf frame set_index.
  23618. 15:10:12Then we'll do a parenthesis and instead
  23619. 15:10:14of just doing country like we did
  23620. 15:10:16before, we're going to create a list.
  23621. 15:10:19Oops. And we'll do it like that. And
  23622. 15:10:22then we'll say
  23623. 15:10:24oops continent
  23624. 15:10:26and separated by a comma. So we have
  23625. 15:10:29continent and country. Let's just say in
  23626. 15:10:33place is equal to true. Now when we run
  23627. 15:10:36this, we're going to have two indexes.
  23628. 15:10:38Let's see what this looks like.
  23629. 15:10:42And let's run this. So now we have
  23630. 15:10:45country as well as continent as our
  23631. 15:10:48index. Now you may notice that these
  23632. 15:10:50indexes are repeating themselves on this
  23633. 15:10:53continent index. We have Europe right
  23634. 15:10:55here and Europe right here as well as
  23635. 15:10:58Asia and Asia. And it looks a little bit
  23636. 15:11:01funky, but we are able to sort these
  23637. 15:11:04values and make it look a lot better. So
  23638. 15:11:06let's go ahead and try this. We'll do df
  23639. 15:11:09do. sort_index.
  23640. 15:11:12And when we run this, it should sort our
  23641. 15:11:14index alphabetically. And we can also
  23642. 15:11:16look in here and see what kind of things
  23643. 15:11:19we can, you know, specify. We can
  23644. 15:11:21specify the axis, but it's automatically
  23645. 15:11:23going to be looking at the zero. This is
  23646. 15:11:25zero and this is one. So we have two
  23647. 15:11:27axes within our data frame. You can
  23648. 15:11:29choose the level, whether it's ascending
  23649. 15:11:31or not ascending, in place, kind,
  23650. 15:11:34string, sort, remaining, all of these
  23651. 15:11:36different things. The only one that I
  23652. 15:11:38really, you know, think is worth looking
  23653. 15:11:40at is the ascending. We already know
  23654. 15:11:41some of these other ones. But if we look
  23655. 15:11:43at ascending,
  23656. 15:11:45let's run it. Now, it's sorted these.
  23657. 15:11:47And so now it's kind of grouped
  23658. 15:11:49together. So we have Africa and all the
  23659. 15:11:51African ones as well as South America
  23660. 15:11:53and all the South American ones. Let's
  23661. 15:11:56really quickly say PD do
  23662. 15:12:00set option
  23663. 15:12:03and we'll say display.mmax
  23664. 15:12:07doc columns and just like this let's run
  23665. 15:12:10it and I need to specify whoops specify
  23666. 15:12:14right here let's see how many rows we
  23667. 15:12:16have
  23668. 15:12:18235 so let's do 235
  23669. 15:12:21let's run this and now when we run this
  23670. 15:12:24you can see that Africa is all grouped
  23671. 15:12:26together and all the countries are in
  23672. 15:12:28alphabetical order under it. And then we
  23673. 15:12:30go all the way down to Asia and again
  23674. 15:12:33just all in alphabetical order. If we
  23675. 15:12:35wanted to we could say ascending
  23676. 15:12:38equals true
  23677. 15:12:40and then when we run this oh meant say
  23678. 15:12:43false and then when we run this it's the
  23679. 15:12:46exact opposite. So it starts with South
  23680. 15:12:47America the last one and then goes in
  23681. 15:12:49reverse alphabetical order. We could
  23682. 15:12:51also say false make it a list and do
  23683. 15:12:54comma true
  23684. 15:12:57and just like this and then it would
  23685. 15:12:59sort this first column as false and this
  23686. 15:13:02next column as true. So you can really
  23687. 15:13:04customize it but you know for what we're
  23688. 15:13:06doing we don't need any of that. We just
  23689. 15:13:08need to be able to see this right here.
  23690. 15:13:09So now when we try to search by our
  23691. 15:13:11index like we did before we did dataf
  23692. 15:13:14frame.lo.
  23693. 15:13:16Now when we did that and we said you
  23694. 15:13:18know let's say Angola when we specified
  23695. 15:13:21Angola it's not going to work properly
  23696. 15:13:24because it's searching in this first
  23697. 15:13:26index for the first string that we have
  23698. 15:13:29we can search Africa
  23699. 15:13:32let's search for Africa
  23700. 15:13:35and now we have all of the African
  23701. 15:13:37countries and if we want to specify to
  23702. 15:13:40Angola we can also go down another level
  23703. 15:13:43oops by doing angola
  23704. 15:13:46And now we have what we were looking at
  23705. 15:13:48before where we're calling all of the
  23706. 15:13:50data within those. But we couldn't do it
  23707. 15:13:52just based off Africa because we had an
  23708. 15:13:54additional index right here. So once we
  23709. 15:13:56called both indexes, now we get this
  23710. 15:13:58view. But let's look at that eyel.
  23711. 15:14:13So, you think it may pull up Angola.
  23712. 15:14:16Let's go ahead and run this. And it's
  23713. 15:14:18still pulling up Albania. Let's go right
  23714. 15:14:21up here. If you remember when we didn't
  23715. 15:14:24have the multiple indexes, it was
  23716. 15:14:26pulling up Albania. The difference when
  23717. 15:14:28you're doing these multi-indexes is that
  23718. 15:14:31the LO is able to specify this, whereas
  23719. 15:14:35this one does not go based off that
  23720. 15:14:37multi-indexing. it's going to go based
  23721. 15:14:39off the initial index or the
  23722. 15:14:41integerbased index. So that's a lot
  23723. 15:14:44about indexing in pandas. We'll cover
  23724. 15:14:46even a few more things in future videos
  23725. 15:14:48as we get more and more into pandas. But
  23726. 15:14:51this is a lot of what indexing looks
  23727. 15:14:53like within pandas. And again, super
  23728. 15:14:55important to learn how to do and know
  23729. 15:14:56how to do because it's a pretty
  23730. 15:14:57important building block as we go
  23731. 15:14:59through this pandas series. So I hope
  23732. 15:15:02you enjoyed this video on indexing. If
  23733. 15:15:04you did, be sure to like and subscribe
  23734. 15:15:06below and I will see you in the next
  23735. 15:15:07video.
  23736. 15:15:09>> [music]
  23737. 15:15:20>> Hello everybody. Today we're going to be
  23738. 15:15:22taking a look at the group by function
  23739. 15:15:23and aggregating within pandas. Group by
  23740. 15:15:26is going to group together the values in
  23741. 15:15:28a column and display them all on the
  23742. 15:15:30same row. And this allows you to perform
  23743. 15:15:32aggregate functions on those groupings.
  23744. 15:15:35So let's start reading in our data and
  23745. 15:15:37take a look. So we're going to do import
  23746. 15:15:39pandas as pd.
  23747. 15:15:42And then we're going to say our data
  23748. 15:15:43frame is equal to and we'll say pd read
  23749. 15:15:48csv.
  23750. 15:15:49We'll do an open parenthesis r and our
  23751. 15:15:52file path. And we're going to be looking
  23752. 15:15:54at the flavors CSV right here. So right
  23753. 15:15:57here we have our flavor of ice cream. We
  23754. 15:16:00have our base flavor, whether it was
  23755. 15:16:01vanilla or chocolate, whether I liked it
  23756. 15:16:04or not, the flavor rating, texture
  23757. 15:16:06rating, and its overall or its total
  23758. 15:16:08rating. Now, these are all my own
  23759. 15:16:10personal scores. So, you know, I've
  23760. 15:16:12spent years researching this, so these
  23761. 15:16:13are all very accurate, but this should
  23762. 15:16:15be a low stress environment to learn
  23763. 15:16:17group by and the aggregate functions.
  23764. 15:16:19So, the first thing that we can do is
  23765. 15:16:21look at our group by. Now, you can't
  23766. 15:16:24group by well, you can you can group by
  23767. 15:16:26flavor, but as you can see, these are
  23768. 15:16:28all unique values. What we need is
  23769. 15:16:30something that has duplicate values or
  23770. 15:16:32or similar values on different rows that
  23771. 15:16:35I'll group together. So, this base
  23772. 15:16:37flavor is actually a perfect one to
  23773. 15:16:39group it on. And we'll do that by saying
  23774. 15:16:42df.group
  23775. 15:16:44by do an open parenthesis. And we'll
  23776. 15:16:46just specify base flavor. And this will
  23777. 15:16:50then group together those values. And I
  23778. 15:16:52need to make sure I can spell properly.
  23779. 15:16:55This will group those flavors together.
  23780. 15:16:57So let's run this. And as you can see,
  23781. 15:17:00it actually is its own object. So it has
  23782. 15:17:02a group by dataf frame group by object.
  23783. 15:17:05So now that we've grouped them, let's
  23784. 15:17:07give it a variable. So we'll say group
  23785. 15:17:10by
  23786. 15:17:12frame. Let's say that's equal to. Let's
  23787. 15:17:15copy this. We'll run it. And now what we
  23788. 15:17:19need to do is run our aggregations in
  23789. 15:17:21order to get an output. So we're going
  23790. 15:17:23to say mean and that's all we're going
  23791. 15:17:27to put just for now just to get an
  23792. 15:17:29output that we can take a look off and
  23793. 15:17:30then we'll build from there. So let's go
  23794. 15:17:32ahead and run this. And right here we
  23795. 15:17:36have our base flavor which is now saying
  23796. 15:17:38is the index of chocolate or vanilla.
  23797. 15:17:41And then it's taking the mean or the
  23798. 15:17:42average of all the columns that have
  23799. 15:17:44integers. Notice that it did not take
  23800. 15:17:47the liked column and it did not take the
  23801. 15:17:49flavor column because those are strings
  23802. 15:17:51and they cannot aggregate those and
  23803. 15:17:52we'll take a look at that later. But it
  23804. 15:17:54took all the values that have integers
  23805. 15:17:56and then it gave us the average of those
  23806. 15:17:58ratings. Really quickly, I wanted to
  23807. 15:18:00give a huge shout out to the sponsor of
  23808. 15:18:02this entire Pandanda series and that is
  23809. 15:18:04Udemy. Udemy has some of the best
  23810. 15:18:05courses at the best prices and it is no
  23811. 15:18:07exception when it comes to pandas
  23812. 15:18:09courses. If you want to master pandas,
  23813. 15:18:11this is the course that I would
  23814. 15:18:12recommend. and it's going to teach you
  23815. 15:18:13just about everything you need to know
  23816. 15:18:14about pandas. So, huge shout out to
  23817. 15:18:16Udemy for sponsoring this Panda series
  23818. 15:18:18and let's get back to the video. So,
  23819. 15:18:19right off the bat, as averages with
  23820. 15:18:22chocolate, I have a much higher rating
  23821. 15:18:23overall than the ones with vanilla
  23822. 15:18:25bases. Now, we can actually combine all
  23823. 15:18:28of this together into one line. And we
  23824. 15:18:30can do something like this. So, we'll
  23825. 15:18:32say
  23826. 15:18:34df.group by we'll say mean just like
  23827. 15:18:39this. And this will actually run it.
  23828. 15:18:41Before we didn't have any aggregating
  23829. 15:18:43function on there, so it didn't run. But
  23830. 15:18:45now that we combine it all into one, it
  23831. 15:18:47will run properly. Now there are a lot
  23832. 15:18:49of different aggregate functions, but
  23833. 15:18:51I'm going to show you some of the most
  23834. 15:18:52popular ones or the most common ones
  23835. 15:18:54that you will see. So let's copy this
  23836. 15:18:56right here. So we can do
  23837. 15:19:00count. And when we run this, we can look
  23838. 15:19:02at the count. And this will show us the
  23839. 15:19:04actual count of the rows that were
  23840. 15:19:06aggregated. So for chocolate, we had
  23841. 15:19:08three. So there's going to be three all
  23842. 15:19:09the way across. And for vanilla, we had
  23843. 15:19:11six. So, we're looking at a higher count
  23844. 15:19:14of vanilla, which if you're comparing it
  23845. 15:19:16to this mean up here, that could be a
  23846. 15:19:19big skew towards the chocolate because
  23847. 15:19:21if you have one or two good chocolates,
  23848. 15:19:23it could really pull the numbers up.
  23849. 15:19:24Whereas, if you had two good vanillaas,
  23850. 15:19:26but all the other ones were bad, it
  23851. 15:19:28pulls that average down. So, knowing the
  23852. 15:19:30count of something is really good.
  23853. 15:19:33Let's take a look at the next one. And
  23854. 15:19:35we can do min and max. And I'll just run
  23855. 15:19:37these really quickly. We can do min. And
  23856. 15:19:40when we run this, the first thing that
  23857. 15:19:42you should notice is that it now has a
  23858. 15:19:44flavor and a liked column. And that's
  23859. 15:19:46because min and max will actually look
  23860. 15:19:48at the first letter in the string or the
  23861. 15:19:50first set of letters if there are um you
  23862. 15:19:52know chocolate something. It'll look at
  23863. 15:19:54the first and then it'll actually
  23864. 15:19:56populate it. So chocolate with the ch
  23865. 15:19:59chocolate is the very first or the
  23866. 15:20:02minimum value for that string. And for a
  23867. 15:20:05cake batter, that is the minimum value
  23868. 15:20:07in vanilla as well. Now, with the liked,
  23869. 15:20:09it's interesting because apparently I
  23870. 15:20:11liked all the chocolate ones. I'm going
  23871. 15:20:12to go take a look. So, chocolate I
  23872. 15:20:14liked. Chocolate I like. Chocolate I
  23873. 15:20:16like. So, there is no no option in this
  23874. 15:20:18liked column. So, yes, was the only
  23875. 15:20:20option. And now, let's look at max.
  23876. 15:20:22Whoops.
  23877. 15:20:24And it should do the exact opposite,
  23878. 15:20:26which is going to take the highest value
  23879. 15:20:28even if it's a string. So, Rocky Road,
  23880. 15:20:30the letter R comes later in the
  23881. 15:20:31alphabet. So, that's what it's looking
  23882. 15:20:33at. and so does vanilla. And then we
  23883. 15:20:35have yes as well. And then of course
  23884. 15:20:38right here it's taking the max value. So
  23885. 15:20:41before when we were looking at min, I
  23886. 15:20:42just focused on those, but it still does
  23887. 15:20:44the exact same thing to these integer um
  23888. 15:20:47columns as well. So for the max value
  23889. 15:20:50for vanilla, it was mint chocolate chip.
  23890. 15:20:52That was our base. So I had a rating of
  23891. 15:20:5410 for this vanilla row or grouping. And
  23892. 15:20:58then we can also look at the sum.
  23893. 15:21:01And there are all the sums for these.
  23894. 15:21:03And again, it only does integer because
  23895. 15:21:05we can't add the strings. Here are the
  23896. 15:21:07sum or the total values for all of them.
  23897. 15:21:10And for the total values, since we had,
  23898. 15:21:11you know, six rows that were grouping
  23899. 15:21:13into this vanilla, we now have a lot or
  23900. 15:21:16a much higher score for vanilla. Now,
  23901. 15:21:19that's a really simple way to do your
  23902. 15:21:20aggregations. But there is actually an
  23903. 15:21:22aggregation function. And let's take a
  23904. 15:21:25look at this because this is um a little
  23905. 15:21:27bit more complex. Although when I write
  23906. 15:21:29it out or show you hopefully it makes a
  23907. 15:21:31lot of sense. We can do agg. So this is
  23908. 15:21:35our aggregate function and what we need
  23909. 15:21:36to pass into our aggregate function is
  23910. 15:21:39actually a dictionary. So let's do an
  23911. 15:21:41open parenthesis and we're going to do a
  23912. 15:21:43squiggly bracket and then we need to
  23913. 15:21:46specify what we're going to be
  23914. 15:21:47aggregating on or what column. So let's
  23915. 15:21:49do this flavor rating. Let's copy this.
  23916. 15:21:53We'll do flavor rating and I need to put
  23917. 15:21:55that as a string. And then we'll do a
  23918. 15:21:58colon. And now we can specify what
  23919. 15:22:00aggregate functions we want. So we've
  23920. 15:22:02done sum, count, mean, min, and max, all
  23921. 15:22:05of those. And we can actually put all of
  23922. 15:22:07those into here and perform all of those
  23923. 15:22:09aggregations on just one column. So
  23924. 15:22:12let's make a list. And then let's say
  23925. 15:22:15mean,
  23926. 15:22:17max,
  23927. 15:22:19count, and uh what's another one? Sum.
  23928. 15:22:23So let's do all four of those only on
  23929. 15:22:26this flavor rating column.
  23930. 15:22:29And when we run this, we have our base
  23931. 15:22:31flavor right here, chocolate and
  23932. 15:22:33vanilla. But now we don't have multiple
  23933. 15:22:35columns. We have one column with
  23934. 15:22:38multiple columns of our aggregations.
  23935. 15:22:40And it is possible to pass in multiple
  23936. 15:22:43columns like that. So we'll do texture
  23937. 15:22:46rating.
  23938. 15:22:47And we'll just come right here and do a
  23939. 15:22:49comma. Then we'll say uh uh texture
  23940. 15:22:53rating
  23941. 15:22:54and then a colon. I don't know why I
  23942. 15:22:58spelled it out when I copied it, but I
  23943. 15:23:00did. And then we'll do the exact same
  23944. 15:23:02ones. And now when we run it, we're
  23945. 15:23:04getting the exact same columns. Mean,
  23946. 15:23:06max, count, and sum for flavor rating.
  23947. 15:23:09Then mean, max, count, and sum for our
  23948. 15:23:11texture rating. Now, so far, we've only
  23949. 15:23:13grouped on one column, but we can
  23950. 15:23:16actually group on multiple columns.
  23951. 15:23:18Let's go back up here to our data. And I
  23952. 15:23:20should have just copied this down here.
  23953. 15:23:22Let's go back down and just look at
  23954. 15:23:24this. So really, we only grouped it on
  23955. 15:23:27this base flavor, but you can do
  23956. 15:23:30multiple groupings or group by multiple
  23957. 15:23:32columns. So let's do our base flavor,
  23958. 15:23:34which we did already, as well as the
  23959. 15:23:37liked column. So we're going to say
  23960. 15:23:39df.group group by then we'll do an open
  23961. 15:23:43parenthesis and then instead of just
  23962. 15:23:45passing through one string we're going
  23963. 15:23:48to do a list and we'll say base flavor
  23964. 15:23:53oops comma and then we'll do liked. So
  23965. 15:23:57now when it groups this, it should put
  23966. 15:24:00two groupings. And let's run this and
  23967. 15:24:02just see. Oops, I got to say, let's just
  23968. 15:24:05do mean.
  23969. 15:24:07So now we have our chocolate and a
  23970. 15:24:10vanilla. And remember, chocolate only
  23971. 15:24:12had yes. So that's the only one that
  23972. 15:24:14it's going to group on. But vanilla had
  23973. 15:24:17a no and a yes. So if we look at the
  23974. 15:24:20vanilla, we have our base flavor
  23975. 15:24:21vanilla. And then within liked, we have
  23976. 15:24:24no and a yes, which can show us that
  23977. 15:24:27within our vanilla, when we group on
  23978. 15:24:28these, our nos were really low. But our
  23979. 15:24:31yeses were really high. We actually had
  23980. 15:24:33a pretty similar rating or very close to
  23981. 15:24:35the same rating as the ones we really
  23982. 15:24:37liked in chocolate. And just like we did
  23983. 15:24:39above, we can take this
  23984. 15:24:42and I'm going to copy this and it'll
  23985. 15:24:44perform it on each of those rows. Let me
  23986. 15:24:47close that. And what did I do wrong? Oh,
  23987. 15:24:50I need the squiggly bracket.
  23988. 15:24:53And it'll show us each of those. So, the
  23989. 15:24:55mean, max, count, and sum for all of the
  23990. 15:24:58chocolate, and vanilla, as well as the
  23991. 15:25:00groupings of liked, yes, and no. Now,
  23992. 15:25:03after we've looked at all that, and
  23993. 15:25:04that's how I usually do it, there is one
  23994. 15:25:07uh shortcut function that can give you
  23995. 15:25:09some of these things just really
  23996. 15:25:10quickly. And so, let's go back up here
  23997. 15:25:13and take this. It's just called
  23998. 15:25:16describe. Um, and if you've ever done
  23999. 15:25:17it, it's just going to give you some
  24000. 15:25:19highlevel overview of some of those
  24001. 15:25:21different aggregations. So, let's run
  24002. 15:25:23this. And it's going to give us our
  24003. 15:25:25chocolate and vanilla. And within each
  24004. 15:25:27column, it's going to give us our count,
  24005. 15:25:29our mean, our standard deviation, I
  24006. 15:25:31believe is what that is. Our minimum,
  24007. 15:25:3325%, 50, 75, and 100, which is our max.
  24008. 15:25:37Then our count, and our mean. So, a lot
  24009. 15:25:39of those aggregate functions. But the
  24010. 15:25:41describe is, you know, a very
  24011. 15:25:43generalized um function. We can't get as
  24012. 15:25:46specific as we were with the previous
  24013. 15:25:48ones that we were looking at, but I just
  24014. 15:25:50wanted to throw this out there in case
  24015. 15:25:51this is something that you'd be
  24016. 15:25:52interested in because it, you know,
  24017. 15:25:54technically is showing a lot of those
  24018. 15:25:56aggregate functions just, you know, all
  24019. 15:25:58at one time. So, that is our group by
  24020. 15:26:00and aggregate functions within pandas. I
  24021. 15:26:02hope that that was helpful. I hope that
  24022. 15:26:03you understood, you know, everything
  24023. 15:26:04that we were working on. If you like
  24024. 15:26:06this video, be sure to like and
  24025. 15:26:08subscribe and check out all my other
  24026. 15:26:09videos on Python as well as pandas. And
  24027. 15:26:11I will see you in the next video.
  24028. 15:26:15>> [music]
  24029. 15:26:25>> Hello everybody. Today we're going to be
  24030. 15:26:27talking about merging, joining, and
  24031. 15:26:28concatenating data frames in pandas.
  24032. 15:26:30This whole video is basically around
  24033. 15:26:32being able to combine two separate data
  24034. 15:26:34frames together into one dataf frame.
  24035. 15:26:36These are really important to understand
  24036. 15:26:38when we're actually using the merge and
  24037. 15:26:40the join. Right here we have what's
  24038. 15:26:42called an inner join. And the
  24039. 15:26:44[clears throat] shaded part is what's
  24040. 15:26:45going to be returned. It's only the
  24041. 15:26:46things that are in both the left and the
  24042. 15:26:49right dataf frames. Then we have an
  24043. 15:26:51outer join or a full outer join. And
  24044. 15:26:54this will take all the data from the
  24045. 15:26:56left data frame and the right data frame
  24046. 15:26:58and everything that is similar. So
  24047. 15:26:59basically it just takes everything. We
  24048. 15:27:01also have a left join which is going to
  24049. 15:27:03take everything from the left and then
  24050. 15:27:05if there's anything that's similar,
  24051. 15:27:07it'll also include that. And then the
  24052. 15:27:09exact opposite of that is the right join
  24053. 15:27:11which is going to give us everything
  24054. 15:27:12from the right dataf frame and it's
  24055. 15:27:14going to give us everything that is
  24056. 15:27:15similar but it's not going to give us
  24057. 15:27:17anything that is just unique to the left
  24058. 15:27:19dataf frame. So this is just for
  24059. 15:27:21reference because in a little bit when
  24060. 15:27:22we start merging these these become very
  24061. 15:27:24important. So I just wanted to kind of
  24062. 15:27:26show you how that works visually. So
  24063. 15:27:28let's get started by pulling in our
  24064. 15:27:29files. So first we're going to say
  24065. 15:27:31import and as pd. We'll run this and
  24066. 15:27:36then we'll say dataf frame one and we'll
  24067. 15:27:38also have a dataf frame two and these
  24068. 15:27:39are the different data frames the left
  24069. 15:27:41and [clears throat] the right dataf
  24070. 15:27:42frame that we'll be using to join merge
  24071. 15:27:45and concatenate. So we'll say dataf
  24072. 15:27:47frame one is equal to [clears throat]
  24073. 15:27:48pd.csv
  24074. 15:27:50read and we'll do r and here is our file
  24075. 15:27:55path. So we have this lo csv that's our
  24076. 15:27:58Lord of the Rings CSV and let's call
  24077. 15:28:00that really quickly so we can see what's
  24078. 15:28:02in there. And I'm having a dyslexic
  24079. 15:28:05moment uh because it's supposed to be
  24080. 15:28:06read_csv.
  24081. 15:28:08Uh I apologize for that. But this is our
  24082. 15:28:11dataf frame. This is our dataf frame
  24083. 15:28:12one. We have three columns. It's their
  24084. 15:28:14fellowship ID 101 2 3 and four. Their
  24085. 15:28:18first name Froto Sam Wise Gandalf and
  24086. 15:28:20Pippen and their skills hiding gardening
  24087. 15:28:22spells and fireworks. So this is our
  24088. 15:28:24very first dataf frame that we're going
  24089. 15:28:26to be working with. Let's go down a
  24090. 15:28:27little bit. Let's pull this down here.
  24091. 15:28:31And we're just going to say dataf frame
  24092. 15:28:32two. Dataf frame two. And this is the
  24093. 15:28:35Lord of the Rings 2. So let's pull this
  24094. 15:28:38one in. Now, as you can see, it's very
  24095. 15:28:40similar. We have fellowship ID 1 2 6 78.
  24096. 15:28:44So we have three different IDs here. We
  24097. 15:28:47don't have 67 and 8 in this upper this
  24098. 15:28:50first data frame. We also have the first
  24099. 15:28:52name. So Froto and Sam or Sam Wise are
  24100. 15:28:55in the very first and the second data
  24101. 15:28:57frame. But now we have three new people.
  24102. 15:28:59Baramir, Eland, and Legalis. And now we
  24103. 15:29:02have this age column, which again is
  24104. 15:29:04unique to just this second dataf frame.
  24105. 15:29:06Really quickly, I want to give a huge
  24106. 15:29:07shout out to the sponsor of this video,
  24107. 15:29:08and that is Zenesk. I've been using
  24108. 15:29:10Zenesk for my company's customer
  24109. 15:29:12analytics, and has been absolutely
  24110. 15:29:13phenomenal. They're going to be hosting
  24111. 15:29:14a conference called Zenesk Relate on May
  24112. 15:29:1610th, and they're going to talk all
  24113. 15:29:18about customer analytics, chat bots, and
  24114. 15:29:20AI in this space. You can attend in
  24115. 15:29:22person in San Francisco, or you can
  24116. 15:29:23attend virtually, but space is limited,
  24117. 15:29:26so be sure to apply if you want to
  24118. 15:29:27attend. So, if you are a business leader
  24119. 15:29:29and you want to make the most out of
  24120. 15:29:30your customer data or you want to learn
  24121. 15:29:32customer data analytics, I will leave
  24122. 15:29:34links in the description. Again, huge
  24123. 15:29:36shout out to Zenesk for sponsoring this
  24124. 15:29:37video. Now, the first one that I want to
  24125. 15:29:39look at is merge. And I want to look at
  24126. 15:29:41merge first because I think this one is
  24127. 15:29:42the most important. I use this one more
  24128. 15:29:44than any of the ones that we're going to
  24129. 15:29:46talk about today. The merge is just like
  24130. 15:29:49the joins that we were just looking at,
  24131. 15:29:51the outer, the inner, the left, and the
  24132. 15:29:53right. And there's also one called
  24133. 15:29:54cross, and I'll show you that one.
  24134. 15:29:56Although if I'm being honest, I don't
  24135. 15:29:58really use that one that much, but it's
  24136. 15:30:00worth showing just in case you come into
  24137. 15:30:01a scenario where you do want to do that.
  24138. 15:30:04So, let's go right down here. And I want
  24139. 15:30:05to be able to see these while we do it.
  24140. 15:30:08So, we're going to say dataf frame one.
  24141. 15:30:10And when we specify dataf frame one as
  24142. 15:30:13the very first dataf frame, we say dataf
  24143. 15:30:16frame. This is automatically going to be
  24144. 15:30:19our left dataf frame. Then if we do our
  24145. 15:30:23parenthesis right here and we say dataf
  24146. 15:30:24frame 2, this is our right dataf frame.
  24147. 15:30:27And let's see what happens when we do
  24148. 15:30:29this. So what it's going to do and this
  24149. 15:30:32we didn't specify this. It's just a
  24150. 15:30:34default. It's going to do an inner join.
  24151. 15:30:36So it's only going to give us an output
  24152. 15:30:38where specific values or the keys are
  24153. 15:30:41the same. Now you can't see this, but
  24154. 15:30:42what is happening is is it's taking this
  24155. 15:30:44fellowship ID and saying I have 1001
  24156. 15:30:47here, a 10, 102 here. This is the exact
  24157. 15:30:51same as up here with this fellowship ID
  24158. 15:30:53and fellowship ID of 101 and two. But
  24159. 15:30:56when we look at 1000 3 and 4, those
  24160. 15:30:59aren't in this right data frame. And 678
  24161. 15:31:02is not in this left data frame. So the
  24162. 15:31:04only ones that match are this 101 and
  24163. 15:31:07two. And that's why they get pulled in
  24164. 15:31:09down here. But because we didn't
  24165. 15:31:11explicitly say here's what I want to
  24166. 15:31:14join or merge between these two data
  24167. 15:31:16frames, it actually is looking at the
  24168. 15:31:18fellowship ID and the first name. So
  24169. 15:31:21it's taking in these unique values of
  24170. 15:31:22Froto and Samwise, which are the same in
  24171. 15:31:25both, which is why it pulled it over.
  24172. 15:31:27But really quickly, let's just check and
  24173. 15:31:29make sure that we did it on the inner
  24174. 15:31:32join because again, we didn't specify
  24175. 15:31:35anything. That was just the default. So,
  24176. 15:31:37we're going to say how is equal to and
  24177. 15:31:39then we'll say inner. And if we run
  24178. 15:31:42this, it's going to be the exact same
  24179. 15:31:43because again the inner is the default.
  24180. 15:31:46But now, just to show you how it's kind
  24181. 15:31:48of joining these two uh data frames
  24182. 15:31:50together, I'm going to say on is equal
  24183. 15:31:53to and then I'm only going to put
  24184. 15:31:56fellowship ID. So, let's run this. Now,
  24185. 15:31:59the first thing that you may have
  24186. 15:32:00noticed is this first name underscorex
  24187. 15:32:02and this first name underscorey.
  24188. 15:32:05What the merge does as kind of a default
  24189. 15:32:07is when you are only joining on a
  24190. 15:32:09fellowship ID, we have this right dataf
  24191. 15:32:11frame with fellowship ID, the left dataf
  24192. 15:32:13frame with the fellowship ID. If you're
  24193. 15:32:15just joining on these and you're not
  24194. 15:32:17joining on the first name and the first
  24195. 15:32:19name, then it's going to separate those
  24196. 15:32:21into an underscorex and an underscorey.
  24197. 15:32:24And even though they have the exact same
  24198. 15:32:26values, since we are not merging on that
  24199. 15:32:28column, it automatically separates that
  24200. 15:32:31into two separate columns. So we can see
  24201. 15:32:33the values within each of those columns.
  24202. 15:32:35If we went into this on and we make a
  24203. 15:32:37list and let's do it like that
  24204. 15:32:41and we say comma and then we write first
  24205. 15:32:44name oops first name and then we run
  24206. 15:32:48this. It's going to look exactly like it
  24207. 15:32:51did before. Again, it automatically
  24208. 15:32:53pulled in both of these columns when it
  24209. 15:32:55was merging it the first time even
  24210. 15:32:57though we didn't write anything. But if
  24211. 15:32:59we actually write this, it's doing
  24212. 15:33:00exactly what it was doing when we just
  24213. 15:33:01had DF2. We're just now writing it out.
  24214. 15:33:05Now, there are other arguments that we
  24215. 15:33:06can pass into this merge function. Let's
  24216. 15:33:08hit shift tab and let's scroll down
  24217. 15:33:11here. So, within this merge function, we
  24218. 15:33:13have a lot of different arguments that
  24219. 15:33:14you can pass into it. First, we have
  24220. 15:33:16this right, which is the right data
  24221. 15:33:18frame, which is this data frame 2. Then,
  24222. 15:33:20we have the how and the on, which we've
  24223. 15:33:22already shown how to do. There's a left
  24224. 15:33:25on, right on, left index, right index.
  24225. 15:33:28not something you'll probably use that
  24226. 15:33:30much, but you definitely can if you want
  24227. 15:33:32to look into that. And there's all these
  24228. 15:33:33doc strings which show you exactly how
  24229. 15:33:35to use all of these. So, if you're
  24230. 15:33:37interested in looking at the left and
  24231. 15:33:38the right and the left index, it's all
  24232. 15:33:40in here. But one that is really good is
  24233. 15:33:42the sort and you can sort it saying
  24234. 15:33:45either it's false or true. Then we have
  24235. 15:33:47these suffixes. Now, if you remember
  24236. 15:33:49when we took these out, what it
  24237. 15:33:51automatically did was it put in these
  24238. 15:33:54underscorex and underscorey. You can
  24239. 15:33:56customize that and you can put in
  24240. 15:33:59whatever you'd like. Instead of the
  24241. 15:34:00underscorex_y,
  24242. 15:34:02you can put in some custom um string for
  24243. 15:34:05that. We also have an indicator and a
  24244. 15:34:07validate. Again, all the things that you
  24245. 15:34:09can go in here and look at. I'm just
  24246. 15:34:11going to show you the stuff that I use
  24247. 15:34:12the most. So, these things right here
  24248. 15:34:14are things that I definitely use the
  24249. 15:34:16most. So, now that we've looked at the
  24250. 15:34:17inner join, let's copy this right down
  24251. 15:34:20here. And let's look at the outer join.
  24252. 15:34:23And these get a little bit more tricky.
  24253. 15:34:25I think the inner joint is probably the
  24254. 15:34:26easiest one to understand.
  24255. 15:34:29Let's look at the outer is spelled o u t
  24256. 15:34:32e r. I don't know why I always want to
  24257. 15:34:34say o u t e r, but let's run this and
  24258. 15:34:37see what we get. So now this looks quite
  24259. 15:34:40different. The inner join only gave us
  24260. 15:34:43the values that are the exact same. This
  24261. 15:34:46one is going to give us all of the
  24262. 15:34:48values regardless of if they are the
  24263. 15:34:50same. So we have 1 2 3 4 6 7 and 8. So
  24264. 15:34:55let's scroll back up here. So we have 1
  24265. 15:34:582 3 4 1 2 and 6 7 and 8. So we don't
  24266. 15:35:01have a 1005. And then if you notice in
  24267. 15:35:04this data frame right here, if the value
  24268. 15:35:07doesn't have So if we can't join on the
  24269. 15:35:10fellowship ID or the first name like
  24270. 15:35:12legal wasn't one that we joined on or
  24271. 15:35:14that has a similar value in the left
  24272. 15:35:16dataf frame, it just gives us an nan
  24273. 15:35:19which is not a number. And it's going to
  24274. 15:35:21do that for any value where it couldn't
  24275. 15:35:23find that join or it couldn't match uh
  24276. 15:35:25something within that either ID or first
  24277. 15:35:27name. So in age, we also have that for
  24278. 15:35:30the ones that weren't in the right data
  24279. 15:35:32frame. We only had 101 and 102. So we'll
  24280. 15:35:36have the age for both Froto and Sam, but
  24281. 15:35:38for Gandalf and Pippen, we don't have
  24282. 15:35:41their corresponding IDs. And so it's
  24283. 15:35:43just going to be blank for Gandalf and
  24284. 15:35:45Pippen. And you can see that right here.
  24285. 15:35:48So again, outer joins are kind of the
  24286. 15:35:50opposite of inner joins. They're going
  24287. 15:35:52to return everything from both. If there
  24288. 15:35:55is overlapping data, it won't be
  24289. 15:35:56duplicated. Now, let's go on to the left
  24290. 15:35:59join. And I'm going to pull this down
  24291. 15:36:01right here. And now we're just going to
  24292. 15:36:03say how is equal to left. And let's run
  24293. 15:36:06this. So what this is going to do is
  24294. 15:36:10it's going to take everything from the
  24295. 15:36:12left table or the left data frame right
  24296. 15:36:14here. So everything from dataf frame
  24297. 15:36:16one. Then if there is any overlap, it'll
  24298. 15:36:19also pull the over overlapped or the,
  24299. 15:36:21you know, whatever we're able to merge
  24300. 15:36:22on from dataf frame 2. So let's go back
  24301. 15:36:25up to our dataf frame one and two. So
  24302. 15:36:27it's going to pull everything from this
  24303. 15:36:28left dataf frame because we're
  24304. 15:36:30specifying we're doing a left join. So
  24305. 15:36:33everything from the left dataf frame
  24306. 15:36:34will be in there. We're also going to
  24307. 15:36:36try to bring in everything from the
  24308. 15:36:38right, but only if it matches or or is
  24309. 15:36:41able to merge. So just this information
  24310. 15:36:43right here will come over. We weren't
  24311. 15:36:46able to join on 10006, 10007 or 1008. So
  24312. 15:36:50really, none of that information is
  24313. 15:36:52going to come over. So let's go down and
  24314. 15:36:53check on this. So again, we have 1 2 3 4
  24315. 15:36:57all of the data with this first name and
  24316. 15:37:00skills. Everything is in here. But then
  24317. 15:37:03we are trying to bring over the age, but
  24318. 15:37:05we only have matches with 10001 and 102.
  24319. 15:37:08So only these two values will come in.
  24320. 15:37:10Let's look at the right join because
  24321. 15:37:12it's basically the exact opposite.
  24322. 15:37:15Let's look at the right.
  24323. 15:37:17And this is basically the exact opposite
  24324. 15:37:19of the left in the fact that now we're
  24325. 15:37:21only looking at the right hand. And then
  24326. 15:37:24if there's something that matches in
  24327. 15:37:25dataf frame one, then we will pull that
  24328. 15:37:28in. So this is basically just looking
  24329. 15:37:30like dataf frame 2 except we're pulling
  24330. 15:37:32in that skills column. And since only
  24331. 15:37:35101 and 102 are the same, that's why the
  24332. 15:37:39skills values are here. Now, those are
  24333. 15:37:41the main types of merges that I will use
  24334. 15:37:43when I'm using a dataf frame or when I'm
  24335. 15:37:46trying to merge a dataf frame. But there
  24336. 15:37:48also is one called a cross or a cross
  24337. 15:37:50join. Uh, and let's look at this one.
  24338. 15:37:52And this one is quite a bit different.
  24339. 15:37:55Here we go. Let's run this. So, this one
  24340. 15:37:58is different in that it takes each value
  24341. 15:38:01from the left dataf frame and compares
  24342. 15:38:03it to each value in the right data
  24343. 15:38:05frame. So for Frodo in this left data
  24344. 15:38:08frame, it looks at the Froto in the
  24345. 15:38:10right dataf frame, Sam Wise in the right
  24346. 15:38:12dataf frame, Legololis, Elron, and
  24347. 15:38:14Baramir all in the right dataf frame.
  24348. 15:38:16Then it goes to the next value, Sam
  24349. 15:38:18Wise, and does the exact same thing.
  24350. 15:38:20Roto, Samwise, Legololis, Elron,
  24351. 15:38:22Baramir. And it does that for every
  24352. 15:38:24single value. So let's go right back up
  24353. 15:38:27here. So it's taking this this 1001.
  24354. 15:38:31It's comparing it to one two three four
  24355. 15:38:33five. Then it's taking Sam Wise and it's
  24356. 15:38:36comparing it to one two three four five
  24357. 15:38:38Gandalf one two three four five Pippen
  24358. 15:38:40and then you kind of see that pattern
  24359. 15:38:41and that's what a cross join is. Um
  24360. 15:38:43there are very few in my opinion reasons
  24361. 15:38:46for a cross join although you'll if you
  24362. 15:38:48ever do like an interview where you're
  24363. 15:38:50being interviewed on Python you will
  24364. 15:38:52sometimes be asked on cross joins but
  24365. 15:38:54there aren't a lot of instances in
  24366. 15:38:57actual work where you really use or need
  24367. 15:38:59a cross join. Now, let's take a look at
  24368. 15:39:02joins. And joins are pretty similar to
  24369. 15:39:05the merge function. And it can do a lot
  24370. 15:39:08of the same thing, except in my opinion,
  24371. 15:39:10the join function isn't as easily
  24372. 15:39:12understood as the merge function. It's a
  24373. 15:39:14little bit more complicated. Um, but
  24374. 15:39:17let's take a look and see how we can
  24375. 15:39:19join together these data frames using
  24376. 15:39:21the join function. So, let's go right up
  24377. 15:39:22here. We're going to say dataf frame
  24378. 15:39:24one.
  24379. 15:39:26And then we'll do dataf frame two. very
  24380. 15:39:29similar to how we did it before. And
  24381. 15:39:31let's try running this. And it's not
  24382. 15:39:33going to work. Um, when we did the merge
  24383. 15:39:35function, it had a lot of defaults for
  24384. 15:39:37us. Let's go down and see what this
  24385. 15:39:39error is. It says the columns overlap,
  24386. 15:39:41but no suffix was specified. So, it's
  24387. 15:39:44telling us that it's trying to use the
  24388. 15:39:45fellowship ID and the first name just
  24389. 15:39:48like the join did, except it's not able
  24390. 15:39:50to distinguish which is which. And so,
  24391. 15:39:53we need to go in there and kind of help
  24392. 15:39:54it out a little bit. Again, a little bit
  24393. 15:39:57more hands-on than the merge, but let's
  24394. 15:40:00see what we can do to make this work.
  24395. 15:40:02Let's do comma and we'll say on and
  24396. 15:40:05let's really quickly let's open this up
  24397. 15:40:06and kind of see what we have. So, this
  24398. 15:40:09one has less options than the merge
  24399. 15:40:11does. We have other and that's our other
  24400. 15:40:13data frame. We can do on and we're going
  24401. 15:40:15to specify, you know, what column do we
  24402. 15:40:17want to join on and then we can look at
  24403. 15:40:19how do we want it to be a left, an
  24404. 15:40:21inner, an outer, the same kind of types
  24405. 15:40:23of joins as the merge. Then we have that
  24406. 15:40:25left suffix, right suffix. And that's
  24407. 15:40:28right here is kind of part of the issue
  24408. 15:40:30that we were just facing is that those
  24409. 15:40:32columns are the same. But if we say left
  24410. 15:40:34suffix, it'll give us an underscore
  24411. 15:40:37whatever we want to specify. Any string
  24412. 15:40:39for columns that are both in the left
  24413. 15:40:41and the right, we can give it a unique
  24414. 15:40:43name. So we'll no longer have that
  24415. 15:40:45issue. And then we can also sort it like
  24416. 15:40:47we did on the other one. But anyways,
  24417. 15:40:48let's go back to our on. We'll say on is
  24418. 15:40:50equal to and then we'll say fellowship
  24419. 15:40:55ID. Let's try running this. And we're
  24420. 15:40:58still getting an error. It's just not as
  24421. 15:41:00simple as the merge. So let's keep
  24422. 15:41:02going. So now let's specify the type. So
  24423. 15:41:04we'll say how is equal to and we'll do
  24424. 15:41:06an outer.
  24425. 15:41:08And if we run this, it still doesn't
  24426. 15:41:10work. We're still getting the exact same
  24427. 15:41:11issue as the left suffix and the right
  24428. 15:41:13suffix. So now let's finally resolve it.
  24429. 15:41:16I just wanted to show you how a little
  24430. 15:41:18bit more frustrating it was. But now
  24431. 15:41:19let's say uh L suffix is equal to and
  24432. 15:41:24now it automatically when we did the
  24433. 15:41:26merge did an underscorex but we can do
  24434. 15:41:28let's do underscore
  24435. 15:41:30uh left and then we can do a comma we'll
  24436. 15:41:34do right suffix
  24437. 15:41:36and we'll say is equal to and we'll do
  24438. 15:41:39underscore right. Now when we run this
  24439. 15:41:42it should work properly. Let's run this.
  24440. 15:41:45So this is our output and obviously it
  24441. 15:41:47looks quite a bit different over here.
  24442. 15:41:49We have this fellowship ID. Then we also
  24443. 15:41:52have fellowship ID left, first name
  24444. 15:41:54left, fellowship ID right, and first
  24445. 15:41:57name right. So it just doesn't look
  24446. 15:41:59right. Now something I didn't specify
  24447. 15:42:01when I first started this cuz I kind of
  24448. 15:42:02wanted to show you is that the join
  24449. 15:42:05usually is better for when you're
  24450. 15:42:06working with indexes. Before when we
  24451. 15:42:09were using the merge, we were using the
  24452. 15:42:12column names and that worked really well
  24453. 15:42:13and is pretty easy to do. But as you can
  24454. 15:42:16see right here, when we're trying to use
  24455. 15:42:17these column names, it's not working
  24456. 15:42:19exceptionally well. Let's go ahead and
  24457. 15:42:21create our index and then I can show you
  24458. 15:42:23how this actually works and how it works
  24459. 15:42:25a little bit better when we're working
  24460. 15:42:26with just the index. Although you can
  24461. 15:42:28get it to work just the same as the
  24462. 15:42:30merge. It's just a lot more work. So
  24463. 15:42:32let's go right down here and let's go
  24464. 15:42:35and say DF4. So we'll create a new data
  24465. 15:42:37frame. We'll say df1
  24466. 15:42:40set index and we'll do an open
  24467. 15:42:44parenthesis and we'll say we want to do
  24468. 15:42:46this index on the fellowship
  24469. 15:42:50ID and then we're going to do the join.
  24470. 15:42:52So now we're going to say join. So we're
  24471. 15:42:54setting an index. So we're setting that
  24472. 15:42:56index on the fellowship ID. Now we're
  24473. 15:42:58going to join it on df2
  24474. 15:43:02set_index.
  24475. 15:43:04And then we're also going to do that on
  24476. 15:43:06the fellowship ID. And I'll just copy
  24477. 15:43:08this.
  24478. 15:43:13Oh jeez, I hate it when I do that. Okay,
  24479. 15:43:16now we also want to do and specify the
  24480. 15:43:19left and the right index. So I'll just
  24481. 15:43:20copy this because we do need to specify
  24482. 15:43:23this. Now let's try running the data
  24483. 15:43:26frame for. So really quickly, just to
  24484. 15:43:29recap, we were setting the indexes. We
  24485. 15:43:31were doing the same thing above, right?
  24486. 15:43:33Right? We have this join. We were
  24487. 15:43:34joining dataf frame one with dataf frame
  24488. 15:43:362. Now we're joining dataf frame one
  24489. 15:43:39with dataf frame 2 except in both
  24490. 15:43:41instances we're setting the index as
  24491. 15:43:43fellowship ID. So we're joining now on
  24492. 15:43:46that index. So now let's run this. And
  24493. 15:43:48this should look a lot more similar to
  24494. 15:43:50the merge than the join that we did
  24495. 15:43:52above except now the fellowship ID right
  24496. 15:43:55here is actually an index. So it's just
  24497. 15:43:57a little bit different. But we can still
  24498. 15:44:00go in here and do how is equal to outer.
  24499. 15:44:04Oops, let's say outer. So we can still
  24500. 15:44:07specify our different types of joins or
  24501. 15:44:09the different way that we can merge or
  24502. 15:44:11join these data frames together. We can
  24503. 15:44:13still specify that. Again, it's just a
  24504. 15:44:15little bit different. And that's why for
  24505. 15:44:17most instances, I'm using that merge
  24506. 15:44:19function because it's just a little bit
  24507. 15:44:20more seamless, a little bit more
  24508. 15:44:22intuitive. The join function can still
  24509. 15:44:24get the job done, but as you can see, it
  24510. 15:44:26takes a little bit more work. Now let's
  24511. 15:44:28look at concatenate. Concatenating dataf
  24512. 15:44:30frames can be really useful. And the
  24513. 15:44:32distinction between a merge and join
  24514. 15:44:34versus the concatenate is that the
  24515. 15:44:36concatenate is kind of like putting one
  24516. 15:44:38data frame on top of the other rather
  24517. 15:44:40than putting one dataf frame next to one
  24518. 15:44:42another which is like the merge and the
  24519. 15:44:44join. So concatenating them is just a
  24520. 15:44:46little bit different in how it'll
  24521. 15:44:47operate. But let's actually write this
  24522. 15:44:49out and see how this looks. Let's go up
  24523. 15:44:51here and we'll say pd.conat.
  24524. 15:44:55We'll do an open parenthesis and then
  24525. 15:44:57we're going to concatenate dataf frame
  24526. 15:44:59one, dataf frame 2. That's all we have
  24527. 15:45:02to write. And let's run this. And so
  24528. 15:45:05just like I said, it literally took the
  24529. 15:45:07first dataf frame 1 2 3 4 and put it on
  24530. 15:45:10top of the right data frame 1 2 6 7 8.
  24531. 15:45:14So that is our left data frame. This is
  24532. 15:45:16our right data frame. And they're
  24533. 15:45:17literally just sitting one on top of the
  24534. 15:45:19other. But just like when we merge
  24535. 15:45:21either with a left or a right, when you
  24536. 15:45:23have these skills and there aren't any
  24537. 15:45:25values that populate for them, it is
  24538. 15:45:27going to say not a number. And since
  24539. 15:45:29we're not actually joining, we're not
  24540. 15:45:30joining on one and two. Even though this
  24541. 15:45:33one and this one is the same rows, it's
  24542. 15:45:35not populating that value because again,
  24543. 15:45:37we're not joining these together. We're
  24544. 15:45:39just concatenating and putting one on
  24545. 15:45:40top of the other. Now if we go into this
  24546. 15:45:43concat we say shift tab there are a lot
  24547. 15:45:47of different things that we can do which
  24548. 15:45:48if you remember the zero axis is the
  24549. 15:45:51left-hand index and the axis of one is
  24550. 15:45:54the top index which is the columns so
  24551. 15:45:56you can specify that and we can also do
  24552. 15:45:59joins and this is the one that I'm going
  24553. 15:46:01to take a look at but there are other
  24554. 15:46:02ones that you can um look into as well
  24555. 15:46:05but let's look at join let's do comma
  24556. 15:46:08and we'll say join is equal to and let's
  24557. 15:46:10do an inner join. So let's see what
  24558. 15:46:13happens with this. As you can see, it is
  24559. 15:46:15only taking the columns that are the
  24560. 15:46:17same. That's what this inner is doing.
  24561. 15:46:19It's joining these columns together. And
  24562. 15:46:21the ones that were different, they
  24563. 15:46:23didn't take because again, we weren't
  24564. 15:46:25able to combine them. They aren't
  24565. 15:46:27similar between both data frames. Let's
  24566. 15:46:29do an outer. And now it's going to take
  24567. 15:46:32all of them. And like I said, that's
  24568. 15:46:34doing this on these columns right here.
  24569. 15:46:35But we can also do it on this axis as
  24570. 15:46:38well. So let's go ahead and say axis is
  24571. 15:46:41equal to 1. And when we run this now
  24572. 15:46:44it's joining us on this index right here
  24573. 15:46:46of 0 1 2 3 4. So now these ones are
  24574. 15:46:49being joined together and it's putting
  24575. 15:46:51it side by side much like a merge would.
  24576. 15:46:54So that's how concatenate works. And I'm
  24577. 15:46:56going to show you one more thing. And
  24578. 15:46:58again it's not up here in this you know
  24579. 15:47:00title because it's not one that I
  24580. 15:47:01recommend but it's one called append.
  24581. 15:47:04The append function is used to append
  24582. 15:47:06rows from one dataf frame to the end of
  24583. 15:47:08another dataf frame. And then we can
  24584. 15:47:09return that new dataf frame. And so
  24585. 15:47:11let's do dataf frame one.append.
  24586. 15:47:14We'll do an open parenthesis. And we'll
  24587. 15:47:16say dataf frame 2. Very similar to how
  24588. 15:47:18we've been doing other things. And let's
  24589. 15:47:20run this. And as you can see, this is
  24590. 15:47:22almost exactly like how the concatenate
  24591. 15:47:24did when we first did it. But if we read
  24592. 15:47:26kind of this warning, it's saying the
  24593. 15:47:28frame.append not append method is
  24594. 15:47:30deprecated and will be removed from
  24595. 15:47:32pandas in the future version. Use
  24596. 15:47:34pandas.conat instead. So it's literally
  24597. 15:47:36warning us, you know, append is on its
  24598. 15:47:38way out. If you want to do exactly what
  24599. 15:47:40you're doing right here, go and try
  24600. 15:47:42concat or concatenate because that'll do
  24601. 15:47:44the exact same thing. So I'm not really
  24602. 15:47:46going to show you any other variations
  24603. 15:47:48of append because there's no reason it's
  24604. 15:47:50going to be on its way out in the next
  24605. 15:47:52version. So that is our video on merge,
  24606. 15:47:54join, and concatenate and append as well
  24607. 15:47:57uh in pandas. And I hope that that was
  24608. 15:47:59helpful. I hope that you learned
  24609. 15:48:00something. I mean, this stuff is really
  24610. 15:48:02important because oftentimes you're not
  24611. 15:48:03just working with one CSV or one JSON or
  24612. 15:48:06one text file. You're working with
  24613. 15:48:07multiple of them and you need to combine
  24614. 15:48:09them all into one data frame. And so
  24615. 15:48:11this is a really, really important
  24616. 15:48:13concept and thing to understand. With
  24617. 15:48:15that being said, be sure to like and
  24618. 15:48:17subscribe, check out all my other videos
  24619. 15:48:18on Python and pandas, and I will see you
  24620. 15:48:20in the next video.
  24621. 15:48:24>> [music]
  24622. 15:48:34>> Hello everybody. Today we're going to be
  24623. 15:48:35building visualizations in pandas. In
  24624. 15:48:38this video we'll look at how we can
  24625. 15:48:39build visualizations like line plots,
  24626. 15:48:41scatter plots, bar charts, histograms,
  24627. 15:48:44and more. I'll also show you some of the
  24628. 15:48:46ways that you can customize these
  24629. 15:48:47visualizations to make them just a
  24630. 15:48:48little bit better. With that being said,
  24631. 15:48:50let's go right over here, start
  24632. 15:48:51importing our libraries. And we'll start
  24633. 15:48:53with importing pandas spd. And this one
  24634. 15:48:57is really all you need to actually
  24635. 15:48:58create the visualizations in pandas. But
  24636. 15:49:00we may get a little bit crazy. Uh, and
  24637. 15:49:03so we're going to do a few different
  24638. 15:49:04ones as well, like import numpy
  24639. 15:49:08as np. And then we're going to do import
  24640. 15:49:11mattplot lib.pipplot
  24641. 15:49:16as plt. Now I may or may not use this. I
  24642. 15:49:19just, you know, when I get into
  24643. 15:49:20visualizations, I may want to change
  24644. 15:49:21some different things. So, we're going
  24645. 15:49:23to at least have them here in case we do
  24646. 15:49:25want to use them. Let's go ahead and run
  24647. 15:49:27this.
  24648. 15:49:29So, now let's get our data set that
  24649. 15:49:30we're going to be using. So, let's say
  24650. 15:49:32dataf frames equal to pdread
  24651. 15:49:36csv.
  24652. 15:49:38And let's get this in right here. Now,
  24653. 15:49:40we're going to be doing these ice cream
  24654. 15:49:41ratings. Let's take a look at this
  24655. 15:49:43really quickly. Now, these values are
  24656. 15:49:46completely randomly generated. They're
  24657. 15:49:48not real in any way. Um, but that's what
  24658. 15:49:51we're going to be using cuz I just
  24659. 15:49:52wanted something kind of generic,
  24660. 15:49:54something that wouldn't be too crazy
  24661. 15:49:55confusing, just something that we could
  24662. 15:49:57use and you guys can understand that
  24663. 15:49:58they're just numerical values. But let's
  24664. 15:50:00also set that index really quick. So,
  24665. 15:50:03we'll say dataf frame set_index
  24666. 15:50:06and then we'll say date and then we'll
  24667. 15:50:08say that's equal to the dataf frame. And
  24668. 15:50:10we have this date column right here as
  24669. 15:50:13our index. So, we have uh January 1st,
  24670. 15:50:152nd, 3rd, 4th, and then we have our
  24671. 15:50:17ratings right here. And again, these are
  24672. 15:50:20all just integers and they're pretty
  24673. 15:50:21easy or or really easy to demonstrate
  24674. 15:50:23how you can visualize these. So, that's
  24675. 15:50:25why we're using it today. So, the way
  24676. 15:50:27that we visualize something in pandas is
  24677. 15:50:29we use something called plot. So, let's
  24678. 15:50:31just take our data frame. We'll do dataf
  24679. 15:50:33frame.plot
  24680. 15:50:35and we'll do our parenthesis. Now, let's
  24681. 15:50:37go in here really quickly. Let's hit
  24682. 15:50:39shift tab. And this is going to come up.
  24683. 15:50:41And this is pretty important because
  24684. 15:50:44this kind of is going to tell us what we
  24685. 15:50:46can do within this plot. And
  24686. 15:50:48unfortunately, there isn't like a quick
  24687. 15:50:50overview. We just have this doc string,
  24688. 15:50:52but we have our parameters right here.
  24689. 15:50:54These are what we can pass in to kind of
  24690. 15:50:56customize our visualization. So the data
  24691. 15:50:59is going to be our data frame. Then we
  24692. 15:51:01have our X and Y labels. We can specify
  24693. 15:51:04the kind, and this one's important
  24694. 15:51:05because we can specify what kind of
  24695. 15:51:08visualization do we want. We can do a
  24696. 15:51:10line plot, horizontal, a vertical bar
  24697. 15:51:13plot, histogram, box plot, and then a
  24698. 15:51:16few others including area, pi, density,
  24699. 15:51:18all these other things. We can also
  24700. 15:51:20specify if we want it to be a subplot.
  24701. 15:51:22And a lot of these things that I'm
  24702. 15:51:24specifying, you know, I'm going to show
  24703. 15:51:25you how to do. You can use uh different
  24704. 15:51:28indexes, you can add titles, add grids,
  24705. 15:51:30legends, styles, all these different
  24706. 15:51:33things. I mean, you can go through here
  24707. 15:51:34because there are a lot, but you can
  24708. 15:51:36specify and and, you know, customize all
  24709. 15:51:38of these things. We won't be going into
  24710. 15:51:41all of them, but I will show you some of
  24711. 15:51:42the ones that I probably use the most
  24712. 15:51:44and that I think are the most useful to
  24713. 15:51:46know right away. So, let's get out of
  24714. 15:51:47here. And we're just going to do
  24715. 15:51:48df.plot.
  24716. 15:51:50And when we run this, we'll get this
  24717. 15:51:52right here. And that was super super
  24718. 15:51:54easy. Created a line plot by literally
  24719. 15:51:56doing just about nothing. Um, but by
  24720. 15:51:59default, it's going to give us a line
  24721. 15:52:01plot. So if we come up here,
  24722. 15:52:04we say kind and let me get that out of
  24723. 15:52:06the way is equal to line and we run
  24724. 15:52:10this. So by default without us actually
  24725. 15:52:12having to input anything, it's giving us
  24726. 15:52:14that line plot as a default. So uh we
  24727. 15:52:17can specify it's a line plot. As you can
  24728. 15:52:19see, we already have all of our data
  24729. 15:52:21right here. We didn't have to specify
  24730. 15:52:22anything. It kind of automatically took
  24731. 15:52:24it in. It is visualizing all three of
  24732. 15:52:27these columns. And it has this little um
  24733. 15:52:30legend right here. And we can specify
  24734. 15:52:32where we want that. Uh there is an
  24735. 15:52:34argument to be able to do that. It also
  24736. 15:52:36gave us these tick marks of 2 4 6 8 10.
  24737. 15:52:40Again, it read in and said it's only
  24738. 15:52:42going from 0.0 to 1.0. That is kind of
  24739. 15:52:46the peak. And so it kind of
  24740. 15:52:48automatically gave us these ticks for
  24741. 15:52:50us. Again, that's another thing that you
  24742. 15:52:51can specify. We make it go up to 2, 5,
  24743. 15:52:5410, a,000, whatever you want it to be.
  24744. 15:52:56And then we're doing this based off of
  24745. 15:52:58this date value right here. Really
  24746. 15:53:00quickly, I wanted to give a huge shout
  24747. 15:53:01out to the sponsor of this entire Panda
  24748. 15:53:03series, and that is Udemy. Udemy has
  24749. 15:53:05some of the best courses at the best
  24750. 15:53:07prices, and it is no exception when it
  24751. 15:53:08comes to pandas courses. If you want to
  24752. 15:53:10master pandas, this is the course that I
  24753. 15:53:12would recommend. It's going to teach you
  24754. 15:53:13just about everything you need to know
  24755. 15:53:15about pandas. So, huge shout out to
  24756. 15:53:16Udemy for sponsoring this Panda series.
  24757. 15:53:18And let's get back to the video. If we
  24758. 15:53:20wanted to break these out by the actual
  24759. 15:53:23column, we could go in here and say
  24760. 15:53:25subplot is equal to true. And it's
  24761. 15:53:29actually subplots. Whoops. And now we
  24762. 15:53:32can run that. And then we can see each
  24763. 15:53:34of those columns being broken out by
  24764. 15:53:36themselves. Instead of them all being in
  24765. 15:53:38one visualization, it's now uh three
  24766. 15:53:41separate visualizations. Now, let's go
  24767. 15:53:43right over here. We're going to get rid
  24768. 15:53:44of the subplots. I want to show you just
  24769. 15:53:45some of the different arguments that you
  24770. 15:53:47can use to make this look nice. uh
  24771. 15:53:49because I don't want to do this on every
  24772. 15:53:51single visualization. I just want to
  24773. 15:53:52show you what you can do. So, we have
  24774. 15:53:54this one right here. We can add a title.
  24775. 15:53:57Notice there's no title or anything
  24776. 15:53:58really telling us what that is. So, we
  24777. 15:54:00can say comma title and we'll say ice
  24778. 15:54:04cream ratings. If we run this, we now
  24779. 15:54:08have this nice title right here. Now, we
  24780. 15:54:10can also customize the labels or the
  24781. 15:54:12titles for the X and Y axis. It
  24782. 15:54:14automatically took this date which is
  24783. 15:54:16right here. This is our date index. It
  24784. 15:54:19automatically took that for us, but we
  24785. 15:54:21can customize that if we'd like to. All
  24786. 15:54:24we have to do is comma and then we'll
  24787. 15:54:25say x label is equal to. And so our x is
  24788. 15:54:29this date one right here. And we can say
  24789. 15:54:32daily rating. And then we can do the y
  24790. 15:54:36label. We'll say y label is equal to and
  24791. 15:54:39for this one we can say scores.
  24792. 15:54:42Hope you cannot hear my dog in the
  24793. 15:54:43background because they are being
  24794. 15:54:44insane. Uh but let's go ahead and run
  24795. 15:54:46this. And now we have these daily
  24796. 15:54:48ratings on the x- axis and on the y-
  24797. 15:54:50axis we have scores. Now let's go right
  24798. 15:54:53down here and start taking a look at our
  24799. 15:54:55next kind of visualization which is
  24800. 15:54:57going to be a bar plot. So we'll do
  24801. 15:54:59df.plot.
  24802. 15:55:01We'll do kind is equal to and for this
  24803. 15:55:04one we're going to say bar. Now this is
  24804. 15:55:06what your typical bar plot will look
  24805. 15:55:08like and a lot of the arguments that we
  24806. 15:55:09just did on the line plot you can also
  24807. 15:55:12apply to this bar plot. Something that's
  24808. 15:55:14unique to the bar plot is that you can
  24809. 15:55:16also make it a stacked bar plot. All we
  24810. 15:55:18have to do is go in here. We'll say
  24811. 15:55:20comma and we'll say stacked is equal to
  24812. 15:55:23true. So now it's going to make it a
  24813. 15:55:25stacked bar chart instead of just you
  24814. 15:55:27know your regular bar chart. Let's go
  24815. 15:55:29ahead and run this. And as you can see
  24816. 15:55:31this is now stacked on top of one
  24817. 15:55:32another with each of these columns all
  24818. 15:55:35representing the values that they have.
  24819. 15:55:37Now we don't always [snorts] have to do
  24820. 15:55:38every single column. We can also specify
  24821. 15:55:40the column that we want. So let's take
  24822. 15:55:42the flavor rating for example. We could
  24823. 15:55:45do
  24824. 15:55:47flavor oops flavor rating. Good night
  24825. 15:55:51flavor rating. And then it's only going
  24826. 15:55:54to take in that flavor rating column.
  24827. 15:55:56And if you notice, we don't have a
  24828. 15:55:57legend. That's only when you have
  24829. 15:55:59multiple values, which we are only
  24830. 15:56:01looking at this one column. So all the
  24831. 15:56:03values are right here. Now in this bar
  24832. 15:56:04chart, it automatically defaults to a
  24833. 15:56:07vertical bar chart, but you can change
  24834. 15:56:09it to a horizontal bar chart. Let's go
  24835. 15:56:11ahead and take a look at how to do that.
  24836. 15:56:13Bring back all of them. We'll do df.plot
  24837. 15:56:17dot and then we'll say barh. And I don't
  24838. 15:56:21know if I can keep in that kind equals
  24839. 15:56:22bar. Let me run this. Yeah, I need to
  24840. 15:56:24get rid of that because the bar.h is its
  24841. 15:56:26own um this is its own function. So now
  24842. 15:56:30I'm going to run this. It should just
  24843. 15:56:31have a stacked bar chart except now it
  24844. 15:56:34should be horizontal. So now you can see
  24845. 15:56:37this worked properly. It's basically the
  24846. 15:56:39exact same thing as a vertical bar
  24847. 15:56:41chart, just now horizontal, which may
  24848. 15:56:43look better, especially depending on if
  24849. 15:56:45you have values like this or, you know,
  24850. 15:56:48something else that just looks better
  24851. 15:56:49being horizontal. Now, the next one that
  24852. 15:56:51we're going to take a look at is the
  24853. 15:56:53scatter plot. So, we're going to say
  24854. 15:56:55df.plot.catter.
  24855. 15:56:58And if we run this, we're going to get
  24856. 15:57:00an error. What we need in order to run
  24857. 15:57:03this properly is we need to specify the
  24858. 15:57:05x and the y axis in order for this
  24859. 15:57:07scatter plot to work. So let's go here
  24860. 15:57:11and we'll say x is equal to and we can
  24861. 15:57:14take any of our columns that we have up
  24862. 15:57:16here. So we'll say x is equal to texture
  24863. 15:57:21rating and then oops y is equal to we'll
  24864. 15:57:26do overall rating.
  24865. 15:57:28Now, when we run this, it should work
  24866. 15:57:30properly. Let's go ahead and take a
  24867. 15:57:31look. Now, if we go in here and we do
  24868. 15:57:34shift tab, we can also see some other
  24869. 15:57:37things that we can specify. So, let's go
  24870. 15:57:39right down here. So, we have our X and
  24871. 15:57:41we have our Y, and those are the ones
  24872. 15:57:42that we just did. We can also pass
  24873. 15:57:44through an S, which is going to tell us
  24874. 15:57:46or or change the size of the actual dots
  24875. 15:57:50right here in our scatter plot. Then, we
  24876. 15:57:52can also do a C, which is the color of
  24877. 15:57:55each point. Let's start with the S.
  24878. 15:57:58Let's say S is equal to and let's just
  24879. 15:58:00do 100. We'll see what that looks like.
  24880. 15:58:02So we have a much larger number. Let's
  24881. 15:58:04do 500 and see what that looks like. So
  24882. 15:58:07we can make these much larger on our
  24883. 15:58:09visualization depending on what you're
  24884. 15:58:11looking for. We can also look at the
  24885. 15:58:12color. Let's put comma C. So for color
  24886. 15:58:16we can say color is equal to and let's
  24887. 15:58:19do uh yellow. Let's see if this works.
  24888. 15:58:23So now we've changed it to yellow. That
  24889. 15:58:24looks absolutely terrible, but it does
  24890. 15:58:27work. Now, let's move on to the
  24891. 15:58:29histogram. Histogram is always a good
  24892. 15:58:31one. It's very similar to something like
  24893. 15:58:33a bar chart, but what's great about a
  24894. 15:58:35histogram is you can specify the bins.
  24895. 15:58:37Um, so let's go ahead and say
  24896. 15:58:39df.plot.hist.
  24897. 15:58:43Then we'll do an open parenthesis. And
  24898. 15:58:46let's go ahead and hit shift tab in
  24899. 15:58:48here. Take a look at this one as well.
  24900. 15:58:51So some of our parameters are the actual
  24901. 15:58:53columns or the data frames that we want
  24902. 15:58:55to pull in. We can choose the bins and
  24903. 15:58:58they have a default of 10 in here. And
  24904. 15:59:00so let's take a look at how this works.
  24905. 15:59:02So we'll just run this as it is. So this
  24906. 15:59:06is by default what this histogram is
  24907. 15:59:08going to look like. Let's go ahead and
  24908. 15:59:10specify our bins. We'll just say it was
  24909. 15:59:1310 by default. Let's just do 20. See
  24910. 15:59:16what that looks like. There are smaller
  24911. 15:59:17columns right off the bat. And remember,
  24912. 15:59:20histograms are really good for showing
  24913. 15:59:22distribution of variables. You know,
  24914. 15:59:24that's really what a histogram is for.
  24915. 15:59:26But of course, since these are
  24916. 15:59:27[clears throat] completely random
  24917. 15:59:29numbers, this histogram isn't going to
  24918. 15:59:30make any sense at all. But you can at
  24919. 15:59:32least kind of see visually how it works.
  24920. 15:59:34And if I didn't mention it before, which
  24921. 15:59:36I should have, the bins represent how
  24922. 15:59:38many kind of tick marks are down here.
  24923. 15:59:40So, if we just do one, it's only going
  24924. 15:59:43to be one very large uh, you know,
  24925. 15:59:46histogram. We could even go further down
  24926. 15:59:50from 10 and do five. So now there's only
  24927. 15:59:52one, two, three, four, five. So the
  24928. 15:59:55distribution gets smaller and things get
  24929. 15:59:57more compact. As you spread it out
  24930. 16:00:00again, like we did 100, [clears throat]
  24931. 16:00:03it's going to spread it out a lot. Um,
  24932. 16:00:05and this is what it shows. You know,
  24933. 16:00:07it's showing the distribution of those
  24934. 16:00:09bins across however many you want. So
  24935. 16:00:12the 10 by default, you know, it usually
  24936. 16:00:14is pretty good for a lot of different
  24937. 16:00:15things. Now, let's go down here and look
  24938. 16:00:17at the box plot. And the box plot is a
  24939. 16:00:20pretty interesting one. Let's go ahead
  24940. 16:00:22and visualize it really quickly, and
  24941. 16:00:23then I'll kind of explain how this one
  24942. 16:00:25works. So, let's do df.boxplot.
  24943. 16:00:28Let's run this. And really, what we're
  24944. 16:00:30looking at is some different markers
  24945. 16:00:32within our data. This line right here is
  24946. 16:00:34the minimum value within that column. We
  24947. 16:00:37also have the bottom of the box, which
  24948. 16:00:38is the 25th percentile of all the values
  24949. 16:00:42within just this column. This is 50%.
  24950. 16:00:45Then we have 75% and then up here we
  24951. 16:00:48have our maximum value. So I can take a
  24952. 16:00:50glance at this and see that we have a
  24953. 16:00:51low minimum a high maximum and it
  24954. 16:00:54definitely skews towards the lower
  24955. 16:00:56range. Whereas if I look over here we
  24956. 16:00:59have a lower minimum and a higher
  24957. 16:01:01maximum and you can see that this m
  24958. 16:01:03medium point is at 6 versus 04 over
  24959. 16:01:05here. So the skews a lot higher. Now
  24960. 16:01:07let's go down here and take a look at an
  24961. 16:01:09area plot. We'll do df.plot plot area.
  24962. 16:01:14And let's just run this. This is what
  24963. 16:01:16we're going to get by default. Now,
  24964. 16:01:18something I wanted to show you earlier,
  24965. 16:01:20I just haven't gotten around to. I want
  24966. 16:01:21to show you something called figure size
  24967. 16:01:23or fig size. Um, so for this, it's know
  24968. 16:01:26it's just looks small, looks a little
  24969. 16:01:27bit cramped. So, let's say we want to
  24970. 16:01:29increase the size of this. And we'll say
  24971. 16:01:31fig size, oops, fig size is equal to,
  24972. 16:01:34and let's just do a parenthesis and say
  24973. 16:01:3710, 5. That should be pretty large. This
  24974. 16:01:40is going to make it a lot larger. Just
  24975. 16:01:42something I wanted to throw in there.
  24976. 16:01:44But I look at these area charts as
  24977. 16:01:45pretty similar to like a line chart. If
  24978. 16:01:47we went and compared those be pretty
  24979. 16:01:49similar. Um, but they're different
  24980. 16:01:51visually. And you know, you absolutely
  24981. 16:01:53can use these for different types of
  24982. 16:01:55visualizations. But I don't use this one
  24983. 16:01:57a lot if I'm being honest. That's why
  24984. 16:01:58it's kind of towards the end of the
  24985. 16:02:00video, but you definitely can do it.
  24986. 16:02:02Let's go on to our very last one of the
  24987. 16:02:04video. That's going to be the beautiful
  24988. 16:02:06pie chart. Let's say df.plot.py.
  24989. 16:02:09pi. We're going to open parenthesis and
  24990. 16:02:12let's run it. We're going to get this
  24991. 16:02:14error. That's because we need to specify
  24992. 16:02:17what column we're working with here. So,
  24993. 16:02:19let's just say the y and that's what we
  24994. 16:02:21need. Let me open this up for us.
  24995. 16:02:25Right here, we have our y and this is
  24996. 16:02:27our our label or our column that we're
  24997. 16:02:29going to plot. That's really all we
  24998. 16:02:30need. So, we can just say y is equal to
  24999. 16:02:34labor rating. Oops. Labor rating. Let's
  25000. 16:02:38run this. And now we get this
  25001. 16:02:40visualization right here. Let's make
  25002. 16:02:42this one a little bit bigger. Big size
  25003. 16:02:46is equal to 10,
  25004. 16:02:50six. So now it's a little bit bigger. It
  25005. 16:02:52definitely depends. So this legend is
  25006. 16:02:54going to autopop populate. You know, you
  25007. 16:02:56can make this as big as you want. And
  25008. 16:02:59obviously it's going to look a little
  25009. 16:03:00bit better if you do it larger. And
  25010. 16:03:02these colors autopop populate. Now you
  25011. 16:03:03can customize these colors. Although I
  25012. 16:03:05found these ones to be just when you
  25013. 16:03:07have a lot of them, it's harder to
  25014. 16:03:08customize them as easily. But, you know,
  25015. 16:03:11definitely look into it. These are
  25016. 16:03:12things that everything in here is almost
  25017. 16:03:14something that you can customize in some
  25018. 16:03:16way. Although, it does get a little bit
  25019. 16:03:18tricky. You definitely have to do some
  25020. 16:03:19research and some Googling around just
  25021. 16:03:21to kind of figure out how to do those
  25022. 16:03:23things. Now, one last thing that I
  25023. 16:03:25wanted to show and something, you know,
  25024. 16:03:27I could have probably done at the
  25025. 16:03:28beginning, um, is you can actually
  25026. 16:03:30change what visual this is. And we can
  25027. 16:03:33do that pretty easily. Within Mattplot
  25028. 16:03:36Lib, there are different styles. Um, and
  25029. 16:03:38so let's go right here. Let's add a new
  25030. 16:03:41row or a new cell. And we'll say print.
  25031. 16:03:44We'll do plt. So that's that mapplot lib
  25032. 16:03:47right here. We'll do
  25033. 16:03:48plt.style.available.
  25034. 16:03:53And what this is going to do, whoops.
  25035. 16:03:54What this is going to do is show us all
  25036. 16:03:56these different types of stylings that
  25037. 16:04:00you can do to kind of change up this
  25038. 16:04:01visualization. And then once we find the
  25039. 16:04:04one that we like, we'll just do
  25040. 16:04:05plt.style
  25041. 16:04:08use. And then in the parenthesis, we'll
  25042. 16:04:11just specify which one we want. Now,
  25043. 16:04:13there's all these seabor ones. And
  25044. 16:04:15seabour is a really great um really
  25045. 16:04:18great library. Let's try seabour deep. I
  25046. 16:04:21haven't tried this one at all. Let's go
  25047. 16:04:23ahead and try this. It just changes some
  25048. 16:04:25of the colors, some of the visuals. We
  25049. 16:04:27can try something like 538.
  25050. 16:04:31Let's try this. That looks quite a bit
  25051. 16:04:34different. And let's try something like
  25052. 16:04:38um classic. I don't know what this one
  25053. 16:04:40looks like. Let's just try it.
  25054. 16:04:42So, you can try out all these different
  25055. 16:04:44styles. Find one that you like. Find one
  25056. 16:04:46that you think looks really nice. And
  25057. 16:04:48you can run with it through all your
  25058. 16:04:49visualizations. So this has been our
  25059. 16:04:51video on visualizing data in pandas. I
  25060. 16:04:53think it's a really good introduction on
  25061. 16:04:55how you can visualize data within
  25062. 16:04:56Python. And in future videos we'll look
  25063. 16:04:58at map lib and seaborn which are some
  25064. 16:05:01really great libraries for visualizing
  25065. 16:05:03data which I use a lot. So I hope that
  25066. 16:05:05you enjoyed this video. If you did be
  25067. 16:05:07sure to check out all my other videos on
  25068. 16:05:08Python and pandas and I will see you in
  25069. 16:05:10the next video.
  25070. 16:05:23Hello everybody. Today we're going to be
  25071. 16:05:25cleaning data using pandas. Now there
  25072. 16:05:27are literally hundreds of ways that you
  25073. 16:05:29can clean data within pandas, but I'm
  25074. 16:05:31going to show you some of the ones that
  25075. 16:05:32I use a lot and ones that I think are
  25076. 16:05:34really good to know when you are
  25077. 16:05:35cleaning your data sets. So we're going
  25078. 16:05:37to start by saying import pandas as pd
  25079. 16:05:41and we're going to run that. And now
  25080. 16:05:43we're going to import our file. So we're
  25081. 16:05:45going to say dataf frame is equal to pd.
  25082. 16:05:47So that's pandas read underscore and we
  25083. 16:05:50actually have this in an excel file. So
  25084. 16:05:52we'll say read oops say read excel do an
  25085. 16:05:56open parenthesis and we'll do r and then
  25086. 16:05:59we'll paste the path right here. And now
  25087. 16:06:01we're just going to call that variable.
  25088. 16:06:02So we'll call dataf frame and we'll
  25089. 16:06:03actually read it in and look at the
  25090. 16:06:05data. So let's scroll down here and
  25091. 16:06:07let's take a look at this data frame or
  25092. 16:06:09this excel file that we're reading in.
  25093. 16:06:10So, right off the bat, we have this
  25094. 16:06:12customer ID that goes from 1001 all the
  25095. 16:06:14way down to 1,020.
  25096. 16:06:17We have this first name, and everything
  25097. 16:06:20looks pretty good here, except in this
  25098. 16:06:22last name column, uh, looks like we have
  25099. 16:06:25some errors. We have some forward
  25100. 16:06:27slashes, some dots, some null values.
  25101. 16:06:31Um, so definitely going to have to clean
  25102. 16:06:32that up because we don't want that in
  25103. 16:06:34the data. We have phone number, and it
  25104. 16:06:37looks like we have a lot of different
  25105. 16:06:39formats. um as well as NAS, not a
  25106. 16:06:42number. Um just lots of different stuff.
  25107. 16:06:46So, we're going to need to standardize
  25108. 16:06:47that. So, clean it up and then
  25109. 16:06:48standardize it to where it all looks the
  25110. 16:06:50same. Um we also have address. And it
  25111. 16:06:54looks like on some of these we just have
  25112. 16:06:55a street address, but on some of the
  25113. 16:06:57other ones we have like a street address
  25114. 16:07:00and another location as well as a zip
  25115. 16:07:02code in some of them. So, we'll probably
  25116. 16:07:05want to split those out. We have a
  25117. 16:07:07paying customer uh which is yes and nos
  25118. 16:07:09and some of those are not the same. So I
  25119. 16:07:12have to standardize that. We have a do
  25120. 16:07:14not contact kind of the same thing as
  25121. 16:07:16the paying customer. And we have this
  25122. 16:07:18not useful column which we'll probably
  25123. 16:07:20just want to get rid of. Okay. So the
  25124. 16:07:22scenario is is that we got handed this
  25125. 16:07:24list of names and we need to clean it up
  25126. 16:07:26and hand it off to the people who are
  25127. 16:07:28actually going to make these calls to
  25128. 16:07:30this customer list. So, they want all
  25129. 16:07:32the data in here standardized and
  25130. 16:07:34cleaned so that the people who are
  25131. 16:07:35making those calls can just make those
  25132. 16:07:36calls as quickly as possible, but they
  25133. 16:07:39also don't want columns and rows that
  25134. 16:07:41aren't useful to them. So, things like
  25135. 16:07:43this not useful column, we're probably
  25136. 16:07:45going to get rid of. And then ones that
  25137. 16:07:47say do not contact, if it says yes, we
  25138. 16:07:50should not contact them, we probably
  25139. 16:07:52will want to get rid of those somehow.
  25140. 16:07:54So, that's a lot of what we're going to
  25141. 16:07:55be doing to clean this data set.
  25142. 16:07:57Normally the very first thing that I do
  25143. 16:07:59when I'm working with a data set most of
  25144. 16:08:01the time except very rare cases when
  25145. 16:08:03you're actually supposed to have
  25146. 16:08:04duplicates is I actually go and drop the
  25147. 16:08:07duplicates from the data set completely.
  25148. 16:08:09All you have to do for that is say
  25149. 16:08:11df.drop
  25150. 16:08:14duplicates. So they make it super easy
  25151. 16:08:17for you. Let's just run it. And up here
  25152. 16:08:20is our original data set. We have this
  25153. 16:08:2319 and 20. And those are obviously
  25154. 16:08:25duplicates. They have the exact same
  25155. 16:08:26data. It's just a duplicate row that we
  25156. 16:08:28need to get rid of. If we look right
  25157. 16:08:31down here, we no longer have that 20. We
  25158. 16:08:33now just have one row of Anakin
  25159. 16:08:36Skywalker. And of course, we want to
  25160. 16:08:38save that. So, we're just going to say
  25161. 16:08:40DF is equal to and DF. So, now it's
  25162. 16:08:44going to save that to the dataf frame
  25163. 16:08:46variable again. And now when we run
  25164. 16:08:48this, our dataf frame now does not have
  25165. 16:08:50any duplicates. That's definitely one of
  25166. 16:08:52the easier steps that we're going to
  25167. 16:08:54look at. Uh things are going to get
  25168. 16:08:55quite a bit more complicated as we go,
  25169. 16:08:57but I'm starting out, you know, kind of
  25170. 16:08:59simple so that we can kind of get a feel
  25171. 16:09:01for it and then we'll start getting into
  25172. 16:09:03the really tough stuff. So the next
  25173. 16:09:05thing that I want to do is remove any
  25174. 16:09:07columns that we don't need. I don't want
  25175. 16:09:08to clean data that we're not going to
  25176. 16:09:10use. So if we're just looking through
  25177. 16:09:12here, you know, they may need, you know,
  25178. 16:09:14first name, last name, phone number for
  25179. 16:09:16sure. Address might give them some
  25180. 16:09:18information of where they're calling to
  25181. 16:09:20or time zone. So we want that. This not
  25182. 16:09:23useful column looks like a pretty good
  25183. 16:09:25candidate to delete and it's very easy
  25184. 16:09:28to do that. We're going to go right down
  25185. 16:09:29here and we're going to say df do drop.
  25186. 16:09:34We'll do an open parenthesis. Drop just
  25187. 16:09:36means we are dropping that column. And
  25188. 16:09:38we can specify that by saying columns is
  25189. 16:09:41equal to and then we'll paste in that
  25190. 16:09:44column that we want to delete. So let's
  25191. 16:09:46run this and see what it looks like. and
  25192. 16:09:48it literally just drops that column
  25193. 16:09:50exactly like we were talking about. It
  25194. 16:09:52no longer has that column. Again, we
  25195. 16:09:54want to save that. We can always do in
  25196. 16:09:56place equals true. Um, if you follow
  25197. 16:09:58this tutorial series, you can always do
  25198. 16:09:59in place equals true and that'll save it
  25199. 16:10:01as well. But just for our workflow, most
  25200. 16:10:04of the time I'm going to assign it back
  25201. 16:10:05to that variable. Um, just for keeping
  25202. 16:10:08it the same. Really quickly, I wanted to
  25203. 16:10:10give a huge shout out to the sponsor of
  25204. 16:10:12this entire Panda series, and that is
  25205. 16:10:14Udemy. Udemy has some of the best
  25206. 16:10:15courses at the best prices and it is no
  25207. 16:10:17exception when it comes to pandas
  25208. 16:10:19courses. If you want to master pandas,
  25209. 16:10:21this is the course that I would
  25210. 16:10:22recommend. It's going to teach you just
  25211. 16:10:23about everything you need to know about
  25212. 16:10:25pandas. So, huge shout out to Udemy for
  25213. 16:10:27sponsoring this pandas series. And let's
  25214. 16:10:28get back to the video. Now, let's kind
  25215. 16:10:30of go column by column and see what we
  25216. 16:10:32need to fix. And we'll start on this
  25217. 16:10:34left hand side. This customer ID to me
  25218. 16:10:36looks perfectly fine. I'm not going to
  25219. 16:10:38mess with it at all. The first name at a
  25220. 16:10:41glance also looks perfectly fine. and I
  25221. 16:10:44don't see anything wrong with it
  25222. 16:10:45visually, which is a good thing. Um,
  25223. 16:10:47although sometimes that can be deceiving
  25224. 16:10:49and that can cause errors down the line,
  25225. 16:10:50but we're not going to uh assume that
  25226. 16:10:53there are errors in here. Now, let's
  25227. 16:10:54look at this last name. Now, the last
  25228. 16:10:56name, obviously, I'm I'm seeing some
  25229. 16:10:58obvious things, things that we talked
  25230. 16:10:59about when we were first looking at this
  25231. 16:11:00data set. We have this forward slash,
  25232. 16:11:04which we definitely need to get rid of.
  25233. 16:11:06We have null values, so not a number.
  25234. 16:11:09Right here, we have some periods as well
  25235. 16:11:11as an underscore right here. So all
  25236. 16:11:13those things I think we should clean up
  25237. 16:11:15and get rid of it so that when the
  25238. 16:11:17person is making these calls, you know,
  25239. 16:11:19it's all cleaned up for them. So how are
  25240. 16:11:21we going to do that? We can actually do
  25241. 16:11:23this in several different ways, but
  25242. 16:11:25let's just copy this last name. The
  25243. 16:11:27first one I'm going to show you is
  25244. 16:11:29strip. And we'll write it kind of like
  25245. 16:11:30this. We'll say data frame and then
  25246. 16:11:32we'll specify the column that we're
  25247. 16:11:34working with because we don't want to
  25248. 16:11:36make these changes or strip all of these
  25249. 16:11:38values from everywhere. We only want to
  25250. 16:11:40do it on just this column. If we do this
  25251. 16:11:43and we don't specify the column name, it
  25252. 16:11:45will apply it to everywhere. So, if
  25253. 16:11:46we're trying to do these, yeah, let's
  25254. 16:11:48say these underscores, maybe that would
  25255. 16:11:51mess with something else in another
  25256. 16:11:53column, and we don't want that. So, we
  25257. 16:11:55just want to specify just this last
  25258. 16:11:57name. So, let's go last name.
  25259. 16:12:02Strip. Now, what strip does, and let's
  25260. 16:12:04see if we can open this up really
  25261. 16:12:06quickly. We can't. Um, but what strip
  25262. 16:12:08does, I was just I was hitting shift tab
  25263. 16:12:11in here to see if it could bring up um,
  25264. 16:12:12you know, some of the notes on it. But
  25265. 16:12:14what strip does is it takes either the
  25266. 16:12:16left side or the right side. Well, lrip
  25267. 16:12:19takes from the left side. Rrip takes
  25268. 16:12:21from the right side and strip takes from
  25269. 16:12:23both. But you can strip values off the
  25270. 16:12:26left and the right hand side. And we can
  25271. 16:12:28specify those values. Now, for what
  25272. 16:12:30we're doing in this column, we can just
  25273. 16:12:32use strip because, as you can see, this
  25274. 16:12:34forward slash, these dots, as well as
  25275. 16:12:37this um underscore are all on the far
  25276. 16:12:40sides. If there was a value like
  25277. 16:12:43swan_son,
  25278. 16:12:45the strip wouldn't work at all because
  25279. 16:12:46it's not on the outside of of the value
  25280. 16:12:49or the word. So, we can use strip. I'll
  25281. 16:12:51also show you how to use replace. And
  25282. 16:12:54replace is another really good option
  25283. 16:12:56for things like this. But let's start
  25284. 16:12:58with strip and just see what it looks
  25285. 16:13:00like and see if we can get what we need
  25286. 16:13:01done. So let's just run this for now.
  25287. 16:13:04See what happens. So it looks like
  25288. 16:13:07nothing has changed because again we're
  25289. 16:13:09not specifying any specific value. Just
  25290. 16:13:11by default it's only taking out white
  25291. 16:13:13space. So like spaces that shouldn't be
  25292. 16:13:15there. That's what it does by default.
  25293. 16:13:17Now we can specify within this exactly
  25294. 16:13:21what values we want to take out. So,
  25295. 16:13:23let's go ahead and do that. Let's say
  25296. 16:13:26left strip and let's try to take out
  25297. 16:13:28these dots real quick. So, we're just
  25298. 16:13:29going to do a parenthesis dot dot dot.
  25299. 16:13:32Now, let's run this and see what it
  25300. 16:13:34looks like for this one. Potter, it is
  25301. 16:13:38now gone. So, those three dots were
  25302. 16:13:40there before. Let's just show it. So,
  25303. 16:13:42they were there and then when I ran it
  25304. 16:13:45like this, now they're gone. That's what
  25305. 16:13:47the L strip does. It takes it only off
  25306. 16:13:50the left hand side. Now, we can also do
  25307. 16:13:52a forward slash. So, we'll do something
  25308. 16:13:54like this, and it'll get rid of the
  25309. 16:13:56white. But, as you can see, now we
  25310. 16:13:59aren't taking out these three dots, so
  25311. 16:14:00they're still there. Now, is it possible
  25312. 16:14:03to do something like this, where we put
  25313. 16:14:06these values inside of a list. Um, let's
  25314. 16:14:08try it. So, we'll say just like this 1 2
  25315. 16:14:113. Let's run it. And no, it doesn't. Um,
  25316. 16:14:15this lrip actually sits within the the
  25317. 16:14:17realm of regular expression. So if
  25318. 16:14:20you've ever worked with regular
  25319. 16:14:21expression, you know it gets very
  25320. 16:14:23complicated, very complex. So you want
  25321. 16:14:25to keep it kind of simple, especially
  25322. 16:14:26with these values where we're just
  25323. 16:14:28taking a few out. So what we're going to
  25324. 16:14:30do is we're going to do dot dot dot and
  25325. 16:14:33we're going to take it out one by one.
  25326. 16:14:35Now in order to save this, because we
  25327. 16:14:37want to save this, we want to take out
  25328. 16:14:38that value. We don't just want to say
  25329. 16:14:40dataf frame equals cuz that would be uh
  25330. 16:14:43very bad. What this would say is now
  25331. 16:14:45this data frame is only equal to these
  25332. 16:14:47values that we're seeing right here. We
  25333. 16:14:49want to only apply it to this column. So
  25334. 16:14:53we're going to go like this. So now when
  25335. 16:14:55we do it and then we call the entire
  25336. 16:14:58data frame, it's only applying this to
  25337. 16:15:01this one column, the last name column.
  25338. 16:15:04So let's run it. And now when we go down
  25339. 16:15:07to Potter right here, it's cleaned up.
  25340. 16:15:10So we're going to do the same thing but
  25341. 16:15:12for those other values.
  25342. 16:15:14And we'll do it just like this. So,
  25343. 16:15:15we'll do a forward slash and it's a left
  25344. 16:15:19strip and then we'll do I'll do the left
  25345. 16:15:21strip on this underscore to just to show
  25346. 16:15:23you that it won't work and then we will
  25347. 16:15:27go on from there. So, it's not pulling
  25348. 16:15:29it because we're looking at the left
  25349. 16:15:30hand side only. We need to use R strip.
  25350. 16:15:33So, now let's use R strip.
  25351. 16:15:37And now that looks perfect. Has no
  25352. 16:15:39underscore. So, that's how you can use
  25353. 16:15:41strip for either the left side, the
  25354. 16:15:43right side, or just strip by itself,
  25355. 16:15:45which covers both sides. Now, I showed
  25356. 16:15:47you all of that because I am going to
  25357. 16:15:48show you a different way to do it. Um,
  25358. 16:15:50and I apologize because I somewhat lied
  25359. 16:15:52to you earlier. Um, let's run
  25360. 16:15:56this right here. Actually, we're just
  25361. 16:15:57going to pull it in like this.
  25362. 16:16:00We're going to remove the duplicates
  25363. 16:16:01again. Bear with me. We're going to drop
  25364. 16:16:04that column. And then now we're sitting
  25365. 16:16:07with that data frame again with those
  25366. 16:16:08exact same mistakes. I just wanted to
  25367. 16:16:10reset it for a second. There is a way uh
  25368. 16:16:12that you can do this and I just wanted
  25369. 16:16:14to, you know, kind of show you how you
  25370. 16:16:16can do it. You can do this right here.
  25371. 16:16:21And we'll say so we're now again we're
  25372. 16:16:23just looking at this column, just this
  25373. 16:16:25column and we're using strip and let's
  25374. 16:16:27get rid of R because we want to do apply
  25375. 16:16:29it to everywhere. You can input all of
  25376. 16:16:32those values individually and it will
  25377. 16:16:35clean it up. So let's say we want to get
  25378. 16:16:36rid of numbers. We'll do 1 2 3. Then we
  25379. 16:16:39can do the dot. So that's going to be
  25380. 16:16:41for a period or for our dot dot dot
  25381. 16:16:43Potter. We could also do the underscore
  25382. 16:16:46and we can do the forward slash. So we
  25383. 16:16:48put it all in one string right here. Now
  25384. 16:16:52let's take a look at this. We'll get rid
  25385. 16:16:54of this really quickly. Now let's take a
  25386. 16:16:56look. And all of them were removed. I
  25387. 16:16:59showed you how to do it before because
  25388. 16:17:00that's at least how my mind would think
  25389. 16:17:02about it. I'd think, oh, I can put it in
  25390. 16:17:03a list and run it through this L strip
  25391. 16:17:05or this right strip and it would work.
  25392. 16:17:07Um, but that's not how strip works. You
  25393. 16:17:09have to kind of combine it all into one
  25394. 16:17:10value. So, uh, yes, I deceived you. I
  25395. 16:17:13apologize. But now when we call dataf
  25396. 16:17:16frame and we assign it to that column,
  25397. 16:17:19so the last name column, we're assigning
  25398. 16:17:20what we just did to this last name
  25399. 16:17:22column. Everything should look perfect.
  25400. 16:17:26And it does. So, our customer ID, first
  25401. 16:17:28name, last name are all cleaned up. Now,
  25402. 16:17:30we're going to come to a much more
  25403. 16:17:32difficult one. This is probably, if I'm
  25404. 16:17:34being honest, the hardest one. I said we
  25405. 16:17:36were going to work up, but this is
  25406. 16:17:37probably the hardest one of the whole
  25407. 16:17:39video. Working with phone numbers. And
  25408. 16:17:41look at all these different types of of
  25409. 16:17:45formats. I mean, it is um it's not going
  25410. 16:17:48to be fun. And imagine, you know,
  25411. 16:17:49there's 20,000 of these. You can't just
  25412. 16:17:51go and manually clean those up. You need
  25413. 16:17:54something to kind of automate that. So,
  25414. 16:17:57that is what we're going to do. So,
  25415. 16:17:59let's go right down here. We'll copy the
  25416. 16:18:01data frame and I'm going to pull it
  25417. 16:18:04right here. So now we need to clean up
  25418. 16:18:06this phone number. What we want is it
  25419. 16:18:09all to look exactly the same unless it's
  25420. 16:18:12blank and we'll keep it blank. We don't
  25421. 16:18:13want to populate that data. But we want
  25422. 16:18:16all of them to look exactly like this
  25423. 16:18:18one. And what we're going to do is right
  25424. 16:18:21off the bat we're going to take all of
  25425. 16:18:23the non-numeric values and just
  25426. 16:18:25completely get rid of them. Strip it
  25427. 16:18:27down to just the numbers. So this 1 2
  25428. 16:18:293-643 or forward slash will just be the
  25429. 16:18:33numbers. Same with these bars and these
  25430. 16:18:36slashes and everything. All of these
  25431. 16:18:39will just be numeric. Then we'll go back
  25432. 16:18:41and reformat it how we want to format
  25433. 16:18:44it, which will look exactly like this
  25434. 16:18:46one. Um, but we just want to do it for
  25435. 16:18:48the entire column. So let's go right up
  25436. 16:18:50here and we're going to try replace for
  25437. 16:18:52the first time. So let's do phone
  25438. 16:18:55number. it just oops that's not what I
  25439. 16:18:58wanted. So we're going to do a bracket
  25440. 16:19:02say phone number dot string.replace
  25441. 16:19:06just like we did before. Now we're going
  25442. 16:19:08to use some regular expression in here
  25443. 16:19:10and I'll kind of do a really high
  25444. 16:19:12overview although I'm not going to dive
  25445. 16:19:14super deep into the regular expression.
  25446. 16:19:16Then we're going to do a parenthesis and
  25447. 16:19:18within there we're going to do a
  25448. 16:19:20bracket. Um I can't remember what this
  25449. 16:19:22is called. Is it called a carrot? I
  25450. 16:19:24think it's called a carrot. uh program.
  25451. 16:19:25I'm just going to call it that. It may
  25452. 16:19:27not be correct, but I think it's an
  25453. 16:19:28upper arrow. So, it's an upper arrow. A
  25454. 16:19:31dash oops a-z.
  25455. 16:19:38Now, at a super high level, what that
  25456. 16:19:40character or that first thing is doing.
  25457. 16:19:41It's saying we're going to return any
  25458. 16:19:42character except and then we specify
  25459. 16:19:45anything A to Z. A to Z, upper or lower
  25460. 16:19:48case. And then actually, I think this
  25461. 16:19:50should be like this. A to Z. Uh and then
  25462. 16:19:530 to 9. So any value like ABC 1 2 3
  25463. 16:19:56those are not going to be matched. It's
  25464. 16:19:58going to match all of them except these
  25465. 16:20:00values. And then we're going to replace
  25466. 16:20:02them by saying comma and we're going to
  25467. 16:20:04replace them with nothing. So this is
  25468. 16:20:06just an empty string. So literally we're
  25469. 16:20:09taking everything that is not an a b c a
  25470. 16:20:111 2 3. So a letter or a number. We're
  25471. 16:20:14replacing all of that and then we're
  25472. 16:20:16replacing it with nothing. So let's run
  25473. 16:20:18this and see what it looks like. And it
  25474. 16:20:20looks like that worked properly. Now, we
  25475. 16:20:23do have this NA because we had an N- A
  25476. 16:20:26for I don't know, maybe that was Creed
  25477. 16:20:29Bratton. Um, but it worked for basically
  25478. 16:20:31everything else. We're going to go
  25479. 16:20:33through the entire process and then at
  25480. 16:20:35the end we'll remove any values. We want
  25481. 16:20:37them to just be completely null. We we
  25482. 16:20:39don't want them to even see Nan and
  25483. 16:20:41wonder what that is. We just want it to
  25484. 16:20:43be blank. And we'll do that at the very
  25485. 16:20:44end. So, now that we know that that
  25486. 16:20:47worked, let's assign it. We'll do df
  25487. 16:20:51phone number is equal to and then we'll
  25488. 16:20:53say dataf frame. And this looks a lot
  25489. 16:20:57more standardized than it did before
  25490. 16:20:59already. But now what we want to do is
  25491. 16:21:01try to format this. Um, and I've done
  25492. 16:21:04this many many times. I always use a
  25493. 16:21:06lambda. You can definitely use a for
  25494. 16:21:09loop. I just I don't do it that way
  25495. 16:21:10myself. So I'm going to show you how to
  25496. 16:21:12do it using a lambda. Let's get rid of
  25497. 16:21:14this. And we're gonna say DF phone
  25498. 16:21:17number. We've already done that. I'm
  25499. 16:21:19just going to get rid of it. Now we're
  25500. 16:21:20gonna say DF phone number. Then we're
  25501. 16:21:22going to say apply. We'll do an open
  25502. 16:21:25parenthesis. And then this is where
  25503. 16:21:26we're going to build out our lambda. So
  25504. 16:21:28we'll say lambda x colon. Now this is
  25505. 16:21:32where we're going to kind of format it.
  25506. 16:21:34So what I want to do is I want to take
  25507. 16:21:35the first three strings 1 2 3. Then I
  25508. 16:21:38want to add a slash. And then the next
  25509. 16:21:40three strings add a slash or a dash. uh
  25510. 16:21:43and then that be the value that's
  25511. 16:21:45returned. So it's not super difficult.
  25512. 16:21:47We're just going to do x then a bracket.
  25513. 16:21:50Let me get rid of that. An x and then a
  25514. 16:21:52bracket. And then we want the 0 to
  25515. 16:21:54three. So it goes 0 1 2. So 0 1 2. It
  25516. 16:22:00doesn't include the three. It goes up to
  25517. 16:22:02three. So 0 1 2. That's our third first
  25518. 16:22:04three values. Then we'll do plus and do
  25519. 16:22:08a quote and do a dash. So this is our
  25520. 16:22:11first kind of sequence. And I'm just
  25521. 16:22:13going to copy this. We'll do plus and
  25522. 16:22:17instead of three or we are going to
  25523. 16:22:19start at three because that now it's
  25524. 16:22:20inclusive. So we're going to go from
  25525. 16:22:21three and we're going to go all the way
  25526. 16:22:23up to six. So it should be three, four,
  25527. 16:22:26five, our next three values. Then we
  25528. 16:22:28have a dash and we'll copy this and
  25529. 16:22:32we'll say plus. And now we go from six
  25530. 16:22:37all the way to 10. Now let's try running
  25531. 16:22:40this. And as you can see, we get an
  25532. 16:22:44error. Now, I already know what the
  25533. 16:22:45error is. Float object is not
  25534. 16:22:48subscriptable, which means we're trying
  25535. 16:22:50to um basically look at it like a
  25536. 16:22:52string. Right now, it's not a string.
  25537. 16:22:54It's actually a number. So, let me get
  25538. 16:22:57rid of this for just a second. I want to
  25539. 16:22:59show you what it's talking about. So,
  25540. 16:23:01right now, we have values that are
  25541. 16:23:04floats and values that are strings or
  25542. 16:23:07not even a number. So, we have values
  25543. 16:23:08that are strings or not a number. So if
  25544. 16:23:11we want to actually look through it like
  25545. 16:23:13kind of like indexing if we want to do
  25546. 16:23:14that they all have to be strings. So we
  25547. 16:23:17need to change this entire column into
  25548. 16:23:20strings before we can apply this um
  25549. 16:23:23formatting. Now when I was creating this
  25550. 16:23:25if I'm being honest my first thought
  25551. 16:23:27when I was doing this was to do it like
  25552. 16:23:28this string df phone number. Um let's
  25553. 16:23:32just run that.
  25554. 16:23:34This is what the values look like. Um,
  25555. 16:23:36and I don't remember why or why it was
  25556. 16:23:40doing this. I can't I can't remember.
  25557. 16:23:42But I looked into it quite a bit and I
  25558. 16:23:43was like, "Oh, I need to apply this
  25559. 16:23:47string, converting it to a string on
  25560. 16:23:49each value, not the entire row or not
  25561. 16:23:52the entire column." So, how we can do
  25562. 16:23:54that is actually fairly easy because
  25563. 16:23:56we've already done a lot of the heavy
  25564. 16:23:57lifting. We're just going to copy this
  25565. 16:24:00and we're going to say x.
  25566. 16:24:04So string of x. And again, lambda is
  25567. 16:24:07like a little anonymous function. So you
  25568. 16:24:10could do this by saying for um x in this
  25569. 16:24:14uh column. We could do a for loop and
  25570. 16:24:17then say for every x it equals the
  25571. 16:24:18string of x and then it changes it to a
  25572. 16:24:20string. But a lambda just does it a lot
  25573. 16:24:22quicker. Um so we're going to say so
  25574. 16:24:25let's do that really quickly. And all of
  25575. 16:24:28our values look exactly the same, and
  25576. 16:24:29that's how we want it. So, we're just
  25577. 16:24:31going to copy this, apply it.
  25578. 16:24:36Good. And now we're going to take this
  25579. 16:24:41and we're going to run this again. Just
  25580. 16:24:43ignore all my commented out stuff.
  25581. 16:24:45Pretend I don't have that. Um, so now
  25582. 16:24:47when we run this, it should work. There
  25583. 16:24:50we go. Now if we look at these numbers 1
  25584. 16:24:522 3-545-5421
  25585. 16:24:59and it does that for every single one
  25586. 16:25:01where there's values even where there's
  25587. 16:25:02nan or na it's still adding those values
  25588. 16:25:06but we expected that so let's apply it
  25589. 16:25:11says equal to and then we'll look at the
  25590. 16:25:14data frame and this looks almost exactly
  25591. 16:25:18what we're hoping for we just need to
  25592. 16:25:19get rid of these
  25593. 16:25:20So, this nan- dash and this na dash, we
  25594. 16:25:24need to get rid of those. And that is
  25595. 16:25:25super easy to do. Um, we're just going
  25596. 16:25:28to say, so now that we've done it, and
  25597. 16:25:30we'll comment that out. We'll say df
  25598. 16:25:35and let's copy this. Ignore the
  25599. 16:25:38messiness. I do apologize for that. It's
  25600. 16:25:39very messy. Um, but if you're following
  25601. 16:25:41along with me, you get what we're doing.
  25602. 16:25:43So, df phone number. So only on the
  25603. 16:25:46phone number sayreplace
  25604. 16:25:50no open parenthesis. Now we can specify
  25605. 16:25:53this value. So we want to take this
  25606. 16:25:56exact value
  25607. 16:25:58and replace it with nothing. And let's
  25608. 16:26:01just see if that does work. It does. Now
  25609. 16:26:04we have these nas.
  25610. 16:26:07And so let's actually I'll paste that
  25611. 16:26:10right down here. We're going to do this
  25612. 16:26:13is equal to and then we're just going to
  25613. 16:26:15take this entire string put it right
  25614. 16:26:17here and put this value as our what
  25615. 16:26:21we're looking for and then replacing and
  25616. 16:26:23then when we call that data frame it
  25617. 16:26:26should work properly and it is perfectly
  25618. 16:26:29cleaned. So we have every single value
  25619. 16:26:33all the exact same. they don't have
  25620. 16:26:35different characters or different um you
  25621. 16:26:37know formatting and we got rid of all
  25622. 16:26:39the ones that we don't have or don't
  25623. 16:26:41need. Um all the ones that were just
  25624. 16:26:43random values. So this column is now
  25625. 16:26:46completely cleaned up. Again, definitely
  25626. 16:26:48one of the more difficult ones. Um ones
  25627. 16:26:51that I've done a thousand times. I've
  25628. 16:26:52had to work with a lot of phone numbers
  25629. 16:26:54and stuff like that. This one does get
  25630. 16:26:56very tricky, especially if you have like
  25631. 16:26:57a plus one, which is like an area code.
  25632. 16:27:00Um that can get tricky as well. But this
  25633. 16:27:02is on a kind of a high level. This is
  25634. 16:27:04how you can do that. And it's pretty
  25635. 16:27:06neat how you can actually, you know,
  25636. 16:27:07clean up and standardize those phone
  25637. 16:27:09numbers. So, let's go right down here.
  25638. 16:27:11Uh, let's run it. The next thing that
  25639. 16:27:13we're going to look at is this address.
  25640. 16:27:16Now, let's just pretend that the people
  25641. 16:27:17who are on the call center want all
  25642. 16:27:20these separated into three different
  25643. 16:27:21columns. They can read it easier, see
  25644. 16:27:23what the zip code is, where they live,
  25645. 16:27:25uh, you know, whatever they want it for.
  25646. 16:27:26Let's just say we want to do that. This
  25647. 16:27:28is, you know, again, for this use case,
  25648. 16:27:30it may not make sense, but you have to
  25649. 16:27:32do this. I do this all the time. Um, you
  25650. 16:27:34need to split those columns. Now,
  25651. 16:27:36luckily, all of these things are
  25652. 16:27:38separated by a comma. So, we can specify
  25653. 16:27:41that. We're going to split on this
  25654. 16:27:42column. And then we'll be able to create
  25655. 16:27:44three separate columns based off of this
  25656. 16:27:46one column, which is exactly what we
  25657. 16:27:48want. And we can name it as well. And we
  25658. 16:27:51can do that very easily by using this
  25659. 16:27:53split. So, we're going to say df and we
  25660. 16:27:56want to specify oops.
  25661. 16:27:59Oh jeez, not again. So, we want to
  25662. 16:28:02specify that we're looking at the
  25663. 16:28:04address. Then we're going to say dot
  25664. 16:28:07string dotsplit.
  25665. 16:28:10We'll do an open parenthesis. Now, the
  25666. 16:28:12very first value that we need to specify
  25667. 16:28:14is what we're splitting on. So, we want
  25668. 16:28:16to split on the comma. So, we want to
  25669. 16:28:18specify that. And then we need to
  25670. 16:28:20specify how many values from left to
  25671. 16:28:23right it should look for. Now we'll just
  25672. 16:28:25start with one and then we'll go from
  25673. 16:28:28there. Let's just see what this looks
  25674. 16:28:30like.
  25675. 16:28:32So
  25676. 16:28:34it doesn't really look like it did
  25677. 16:28:37anything. Let's do two. Well, let's go
  25678. 16:28:39back to one and then let's say expand
  25679. 16:28:43equals true. When we expand it, it's
  25680. 16:28:46actually going to uh separate it, I
  25681. 16:28:47believe. Okay, so we're expanding. We're
  25682. 16:28:49now we're only doing this with one
  25683. 16:28:51comma. So we're only looking at the very
  25684. 16:28:53first comma and splitting it. But in
  25685. 16:28:55some of these, well just in one there is
  25686. 16:28:58an additional comma. So we should do it
  25687. 16:28:59up to two. Let's do this. Okay. So now
  25688. 16:29:03we have three columns. If we just save
  25689. 16:29:06it like this, it's going to give us
  25690. 16:29:07these 012. These basically these indexed
  25691. 16:29:09values for these columns. And we don't
  25692. 16:29:12want that. We want to specify what these
  25693. 16:29:14actually are. And we can do that by
  25694. 16:29:16saying df. And let me just do is equal
  25695. 16:29:18to we'll do bracket and then within
  25696. 16:29:21there we're going to specify our list.
  25697. 16:29:23So we have three of them that we have.
  25698. 16:29:26So I'm going to do um the first one this
  25699. 16:29:29is the street address. So we'll say
  25700. 16:29:31street address. The next one is um it's
  25701. 16:29:36sh is not a state uh but these all are
  25702. 16:29:39state. So I'm just going to say state.
  25703. 16:29:42And then the very last one that looks
  25704. 16:29:45like a zip code. So we'll say zip and
  25705. 16:29:48we'll do underscore [clears throat]
  25706. 16:29:49code. In fact, I also want to do street
  25707. 16:29:52address. Um, so what this is now going
  25708. 16:29:55to do is these three columns are going
  25709. 16:29:56to be applied to these three names and
  25710. 16:29:58they'll basically be appended. It
  25711. 16:30:00doesn't replace the address. We're not
  25712. 16:30:03saying DF address equals the DF address.
  25713. 16:30:05We're not replacing it. We're now
  25714. 16:30:07creating different columns. So let's run
  25715. 16:30:10it. And then let's also call it. So
  25716. 16:30:12they're right over here on this right
  25717. 16:30:14hand side. I couldn't see them at first.
  25718. 16:30:16But it did exactly what we needed it to
  25719. 16:30:18do. So now if we wanted to at the very
  25720. 16:30:20end, if we want to, we're not going to,
  25721. 16:30:22we could just delete this address and
  25722. 16:30:24keep the street address, the state, and
  25723. 16:30:27the zip code. Another really common
  25724. 16:30:30thing that you can do, this happens
  25725. 16:30:32often again with like first name, last
  25726. 16:30:34name. Well, you have Alex Freeberg, but
  25727. 16:30:36it's Alex, Freeberg or Alex Space
  25728. 16:30:38Freeberg, and you can separate those out
  25729. 16:30:40into different columns. Now, the next
  25730. 16:30:42one that we want to look at is this
  25731. 16:30:44paying customer. and the paying customer
  25732. 16:30:46and do not contact are very similar. Um,
  25733. 16:30:50in the fact that it's yes, no, NY, yes,
  25734. 16:30:53no, NY.
  25735. 16:30:55Um, and so let's go right on down here
  25736. 16:30:58and we're going to say df dot and we
  25737. 16:31:00want to just replace these values as all
  25738. 16:31:04yeses or all nos, but just with the same
  25739. 16:31:07formatting um, just to keep it
  25740. 16:31:09consistent. So, let's make anything
  25741. 16:31:10that's an N into a no. Anything that's a
  25742. 16:31:13a Y into a yes. I like it spelled out.
  25743. 16:31:16So, let's change anything that's uh a
  25744. 16:31:18yes into a Y. Anything that's uh a no
  25745. 16:31:23into an N. That's usually how I do it.
  25746. 16:31:26Just saves on data because it's less
  25747. 16:31:28strings, although it's be often very
  25748. 16:31:30minimal. Um, but let's specify the
  25749. 16:31:34customer.
  25750. 16:31:36We'll s say df bracket paying customer.
  25751. 16:31:40Then we'll do string.replace.
  25752. 16:31:43So now we're just going to look for
  25753. 16:31:45those specific values. So if it's a y,
  25754. 16:31:49oops, a capital y, then we'll say yes.
  25755. 16:31:54Now let's run it. And now we have no
  25756. 16:31:56more y's. We now just have yeses.
  25757. 16:31:59Although now these are yeses. Okay, we
  25758. 16:32:02don't want to do that. Let's do if we're
  25759. 16:32:06looking because it's taking it's
  25760. 16:32:08literally looking up here and saying
  25761. 16:32:09okay there's here's a y. Um let's change
  25762. 16:32:12the let's change that y into a y. So now
  25763. 16:32:14it's doing y es. Uh we don't want that.
  25764. 16:32:17So let's look for the yes
  25765. 16:32:20and change into a y. Now when we run
  25766. 16:32:22this that looks a lot better. Um so
  25767. 16:32:26we'll do
  25768. 16:32:28df paying customers equal to and then
  25769. 16:32:31we'll copy this. We'll do the exact same
  25770. 16:32:34thing. No.
  25771. 16:32:36And N.
  25772. 16:32:38Then let's call it. And now that entire
  25773. 16:32:42column looks really good except for that
  25774. 16:32:44value right there. But I'm going to
  25775. 16:32:46leave that because I'm just going to
  25776. 16:32:47apply it to the entire thing all at once
  25777. 16:32:50to get rid of those at the end instead
  25778. 16:32:52of just going column by column. And then
  25779. 16:32:54it's literally going to be the exact
  25780. 16:32:55same thing. So I'm not even going to
  25781. 16:32:57scroll down. Whoops. I'm just going to
  25782. 16:33:00put it right up here because this is the
  25783. 16:33:02exact same thing. I'm going save us all
  25784. 16:33:04some time.
  25785. 16:33:08And when we run this, this looks exactly
  25786. 16:33:10like what we're looking for. Again, some
  25787. 16:33:12not a number values, but we can get rid
  25788. 16:33:14of that in just a second by doing our
  25789. 16:33:16place over the entire data frame. And
  25790. 16:33:19that is basically the end of cleaning up
  25791. 16:33:21individual columns. Now, let's go right
  25792. 16:33:24down here. We're going to say
  25793. 16:33:25df.string.replace
  25794. 16:33:27replace and then we'll first do these
  25795. 16:33:30values.
  25796. 16:33:32Oops. So, we'll do Oops. Let me do that.
  25797. 16:33:36There we go. And replace that with
  25798. 16:33:38nothing. And let's just see what it
  25799. 16:33:40looks like. Oops. Data frame object has
  25800. 16:33:43no value string. Well, that's cuz we
  25801. 16:33:45were looking at columns before. Yeah, I
  25802. 16:33:47think I just need to get rid of this
  25803. 16:33:49string. We're not looking we're doing it
  25804. 16:33:51across the entire data frame. Now, let's
  25805. 16:33:53try that.
  25806. 16:33:54Okay, that worked appropriately. And
  25807. 16:33:57we'll just say data frame is equal to.
  25808. 16:34:00And then we'll copy this. And we'll do
  25809. 16:34:03the nan as well.
  25810. 16:34:06And we'll do
  25811. 16:34:11and now when we do this, it is not going
  25812. 16:34:13to replace these because these aren't
  25813. 16:34:15actually a value because we're looking
  25814. 16:34:17for that string. We actually need to use
  25815. 16:34:18and I I completely forgot this. I'm not
  25816. 16:34:20going to lie to you. Um let's get rid of
  25817. 16:34:23this. uh to get rid of those values
  25818. 16:34:24because it's literally not a number
  25819. 16:34:26there. It is technically empty. Um I
  25820. 16:34:30forgot we can do um or we could not even
  25821. 16:34:33specify it. We'll do df.fill na. So
  25822. 16:34:37we're going to fill these values if
  25823. 16:34:39there's nothing in them. We're going to
  25824. 16:34:41fill it and we're going to say
  25825. 16:34:44blank. And when we run that, every value
  25826. 16:34:47that doesn't have something in it is
  25827. 16:34:49going to show up blank. Even over here
  25828. 16:34:51where we only had a few all of them
  25829. 16:34:53throughout the data frame if it doesn't
  25830. 16:34:54have a value it is now blank. So let's
  25831. 16:34:57apply that
  25832. 16:35:00and we'll run this.
  25833. 16:35:02And now all of our cleaning we're
  25834. 16:35:05actually cleaning up the individual
  25835. 16:35:07columns is completely done. We've
  25836. 16:35:10removed columns. We've split columns.
  25837. 16:35:12We've formatted and cleaned up phone
  25838. 16:35:14numbers. We've also taken values off of
  25839. 16:35:17first name or or this last name column
  25840. 16:35:20and then we formatted and just kind of
  25841. 16:35:22standardized paying customer and do not
  25842. 16:35:24contact. Now they also asked us to only
  25843. 16:35:28give them a list of phone numbers that
  25844. 16:35:30they can call. So if we take a look some
  25845. 16:35:33of these do not contacts are why which
  25846. 16:35:35means we cannot contact them. And then
  25847. 16:35:39there are some that don't even have
  25848. 16:35:40phone numbers. So, we don't want to give
  25849. 16:35:42the people the call center numbers that
  25850. 16:35:45or or people who don't have numbers. So,
  25851. 16:35:48we want to remove those. Now, there's a
  25852. 16:35:50few different ways that we can do this.
  25853. 16:35:53But let's start with and we'll just go
  25854. 16:35:55by do this. Do not contact. It seems
  25855. 16:35:58like the most obvious one. Now, if it's
  25856. 16:36:00blank, we want to give them a call. We
  25857. 16:36:03only want to not call them if they've
  25858. 16:36:05specifically said we cannot call them.
  25859. 16:36:07So, if it's why, we're not going to call
  25860. 16:36:09them. So what we need to do and it's not
  25861. 16:36:12anything like this. We probably need to
  25862. 16:36:15loop through this column and then look
  25863. 16:36:18at each row that has a value of this and
  25864. 16:36:21drop that entire row. Uh and we probably
  25865. 16:36:24will need to do that based off this
  25866. 16:36:26index instead of doing it based off just
  25867. 16:36:29this column. Uh that may not make sense,
  25868. 16:36:32but let's actually let's actually start
  25869. 16:36:34writing it. So we'll do 4x in and we
  25870. 16:36:38need to look at our index. So we're just
  25871. 16:36:40going to do let's do in df.index
  25872. 16:36:44and we'll do a colon enter. And then we
  25873. 16:36:47want to look at these indexes. How do we
  25874. 16:36:50look at these indexes? We use lock.
  25875. 16:36:52That's going to be df.loc.
  25876. 16:36:55And then we need to look at the value
  25877. 16:36:57which is this x right here. So each time
  25878. 16:37:00it looks at the index, it's looking at
  25879. 16:37:02the value. But we want to look at the
  25880. 16:37:04value of this column. Do not contact. I
  25881. 16:37:08don't know if I copied this before. Let
  25882. 16:37:09me copy it. We only want to look at the
  25883. 16:37:11value in this one column. If we didn't,
  25884. 16:37:14it would look at um a different value.
  25885. 16:37:16So we don't want that. So we're looking
  25886. 16:37:18at just that value if it's equal to y.
  25887. 16:37:22So if this value is equal to y, then we
  25888. 16:37:26want to drop it. So we actually need to
  25889. 16:37:27say if.
  25890. 16:37:29So if this value x in this column is
  25891. 16:37:33equal to y then we want to do df.drop
  25892. 16:37:37and then we'll say x and we I think we
  25893. 16:37:41have to say in place equals true here
  25894. 16:37:43otherwise it won't take effect. Um
  25895. 16:37:46otherwise you have to say like df is
  25896. 16:37:48equal to df.ai and I don't I don't want
  25897. 16:37:50to start messing with that. Let's just
  25898. 16:37:51do in place equals true.
  25899. 16:37:54Um and let's see if that works. I I
  25900. 16:37:58can't remember if this is going to work
  25901. 16:37:59or not. Invalid syntax. Okay. Need a
  25902. 16:38:02colon.
  25903. 16:38:04And now let's try to run this.
  25904. 16:38:07Okay. Okay. Yeah. If we look at our
  25905. 16:38:09index, we can already tell that there
  25906. 16:38:11are ones missing. The one the one is
  25907. 16:38:13missing, the three is missing. Uh let's
  25908. 16:38:16see. And the 18 is missing. So, we
  25909. 16:38:18already got rid of those values. And you
  25910. 16:38:20can you can see that there's no Y's in
  25911. 16:38:21here anymore, which is really good. We
  25912. 16:38:24can if we want to, and we probably
  25913. 16:38:25should. We should probably populate that
  25914. 16:38:28um really quickly.
  25915. 16:38:30Um let me just go up here really quick.
  25916. 16:38:35I'll copy this. We probably should
  25917. 16:38:38populate that. And I didn't plan on
  25918. 16:38:40doing this. So, um if it's blank, oops.
  25919. 16:38:44If it's blank, give it an N. And we want
  25920. 16:38:47to attribute it to do not contact.
  25921. 16:38:52Do
  25922. 16:38:53not contact. Whoops.
  25923. 16:38:57Let's see if that works.
  25924. 16:39:00And we probably need to do string.
  25925. 16:39:03Let's just see if it works.
  25926. 16:39:06So, if it's blank,
  25927. 16:39:09dude. Okay. I don't know why it's giving
  25928. 16:39:10us a triple N.
  25929. 16:39:13Maybe there's Maybe I need to strip this
  25930. 16:39:15or something.
  25931. 16:39:17Uh, okay. Never mind. Let's not do that.
  25932. 16:39:22But now we basically need to do the
  25933. 16:39:24exact same thing for this phone number.
  25934. 16:39:26Um because if it's blank, we don't want
  25935. 16:39:29them calling it. Um so we can copy this
  25936. 16:39:32entire thing. Go right down here. And
  25937. 16:39:35but now we're looking at phone number.
  25938. 16:39:38So now we're looking just at the values
  25939. 16:39:41within phone number. And we only want to
  25940. 16:39:43look at if it's blank. So if it
  25941. 16:39:44literally has no value, we want to get
  25942. 16:39:46rid of it. Let's run this and see if it
  25943. 16:39:49works again. It should. Good. And now
  25944. 16:39:52our list is getting much smaller. So you
  25945. 16:39:54can see in our index a lot of um those
  25946. 16:39:58rows were removed. And okay, good.
  25947. 16:40:01Actually, this worked itself out because
  25948. 16:40:02these all have ends. Um so right now
  25949. 16:40:05we're sitting really good. Everything
  25950. 16:40:07looks really um standardized, cleaned.
  25951. 16:40:11Everything looks great. I might drop
  25952. 16:40:13this address. If you want to, you can
  25953. 16:40:15drop this address, but besides that,
  25954. 16:40:17this is all looking really good. this
  25955. 16:40:18paying customer doesn't uh the yes and
  25956. 16:40:20nos aren't really anything. Um, now we
  25957. 16:40:24could and we probably should before we
  25958. 16:40:26hand this off to the client or the
  25959. 16:40:29customer called list, we probably should
  25960. 16:40:30reset this index because they might be
  25961. 16:40:33confused as why there's numbers missing
  25962. 16:40:34or you know they might use
  25963. 16:40:36[clears throat] this index um to show
  25964. 16:40:38how many people they've called or I
  25965. 16:40:39don't know something like that. So let's
  25966. 16:40:41go right down here. We're gonna say df
  25967. 16:40:44dot and then we'll do reset
  25968. 16:40:47index.
  25969. 16:40:49And let's just see what this looks like.
  25970. 16:40:51Um, it does work, but as you can tell,
  25971. 16:40:53it didn't uh get rid of that index
  25972. 16:40:55completely. It actually took the index
  25973. 16:40:57and saved that original one. We do not
  25974. 16:41:00need to save that. Whoops. Let's put it
  25975. 16:41:02right in here. Now, we're just going to
  25976. 16:41:03do drop equals true. And when we do
  25977. 16:41:06that, it just completely resets. It
  25978. 16:41:08drops the original index and gives us a
  25979. 16:41:10new index. And that is what we want.
  25980. 16:41:13Let's do df equals. And this is our
  25981. 16:41:16final product. Now, one thing that I you
  25982. 16:41:20definitely could have done here, um, and
  25983. 16:41:22I made this a little probably more
  25984. 16:41:23complicated than it needed to be. Um,
  25985. 16:41:25that was just how my brain was working
  25986. 16:41:26at the time when I'm, you know, typing
  25987. 16:41:28this out. We could have done df.rop
  25988. 16:41:33a um, which is literally going to look
  25989. 16:41:35at these null values. Um, before
  25990. 16:41:39we couldn't do that with this one
  25991. 16:41:40because these aren't we're not looking
  25992. 16:41:41at NA, we're looking at Y's. So, we
  25993. 16:41:43couldn't do that. But because we're
  25994. 16:41:45looking at null values, we could have
  25995. 16:41:46also done drop NA. Um, and done subset
  25996. 16:41:51is equal to and then done it just on
  25997. 16:41:54this phone number and then done like
  25998. 16:41:58this and done in place equals true. So,
  25999. 16:42:01we could have also done this then said
  26000. 16:42:04df equals. Um, I can't I mean I can run
  26001. 16:42:07it. It's just not going to do anything.
  26002. 16:42:09I can run it on the different column,
  26003. 16:42:11but that'll mess everything up. But this
  26004. 16:42:13is another way you can do it. And I'll
  26005. 16:42:15just save it in case you want to. Um,
  26006. 16:42:17I'll say another way to drop null
  26007. 16:42:21values.
  26008. 16:42:23There you go. And that'll just be a note
  26009. 16:42:24for us in the future. Um, but this is
  26010. 16:42:27our final product. It looks a lot
  26011. 16:42:31different than when we first started. I
  26012. 16:42:33mean, we had mistakes here. Completely
  26013. 16:42:36different formatting in the phone
  26014. 16:42:37number, different address, everything
  26015. 16:42:38that we just talked about. Um, and this
  26016. 16:42:40looks just a lot lot better. And you can
  26017. 16:42:42tell why it's really important to do
  26018. 16:42:44this process because again, we're
  26019. 16:42:46working on a very small data set. I I
  26020. 16:42:49purposely, you know, created this data
  26021. 16:42:51set with these mistakes because, you
  26022. 16:42:53know, when you're looking at data that
  26023. 16:42:55has tens of thousands, a hundred
  26024. 16:42:56thousands, a million rows, these are all
  26025. 16:43:00things that are going to be applied to
  26026. 16:43:01much larger scale and you won't be able
  26027. 16:43:02to as easily see them. Um, you'll have
  26028. 16:43:05to do some exploratory data analysis to
  26029. 16:43:08find these mistakes and then you're
  26030. 16:43:10going to need to clean the data or doing
  26031. 16:43:12it at the same time when you're
  26032. 16:43:13exploring the data. Uh, so you'll clean
  26033. 16:43:15it up as you go. But these are a lot of
  26034. 16:43:18the ways that I clean data, a lot of the
  26035. 16:43:20things that you can do to make your data
  26036. 16:43:22just a lot more standardized, a lot more
  26037. 16:43:24um visually better. And then it really
  26038. 16:43:27helps later on with visualizations and
  26039. 16:43:29your you know actual data analysis. So I
  26040. 16:43:32hope that that was helpful. I know that
  26041. 16:43:33this was a long video. I'm sure it was.
  26042. 16:43:35Uh but I hope that you got something out
  26043. 16:43:38of this and you learned some of the
  26044. 16:43:39techniques on how to actually clean data
  26045. 16:43:40in pandas. If you like this video, be
  26046. 16:43:42sure to like and subscribe. Check out
  26047. 16:43:44all my other videos on pandas as well as
  26048. 16:43:46Python. and I will see you in the next
  26049. 16:43:47video.
  26050. 16:44:00Hello everybody. Today we're going to be
  26051. 16:44:02looking at exploratory data analysis
  26052. 16:44:04using pandas. Exploratory data analysis
  26053. 16:44:07or EDA for short is basically just the
  26054. 16:44:10first look at your data. During this
  26055. 16:44:12process, we'll look at identifying
  26056. 16:44:13patterns within the data, understanding
  26057. 16:44:15the relationships between the features
  26058. 16:44:17and looking at outliers that may exist
  26059. 16:44:18within your data set. During this
  26060. 16:44:20process, you are looking for patterns
  26061. 16:44:22and all these things, but you're also
  26062. 16:44:23looking for um mistakes and missing
  26063. 16:44:25values that you need to clean up during
  26064. 16:44:27your cleaning process in the future.
  26065. 16:44:29Now, there are hundreds of ways to
  26066. 16:44:30perform EDA on your data set, but we
  26067. 16:44:33can't possibly look at every single
  26068. 16:44:35thing. So I'm just going to show you
  26069. 16:44:36what I think are some of the most
  26070. 16:44:38popular and the best things that you can
  26071. 16:44:40do when you're first looking at a data
  26072. 16:44:41set. The first thing that we're going to
  26073. 16:44:43do are import our libraries. So we'll do
  26074. 16:44:45import pandas as pd.
  26075. 16:44:48We're also going to import seabor and
  26076. 16:44:51mapplot lib. Now, during this
  26077. 16:44:53exploratory data analysis process, I
  26078. 16:44:56often like to visualize things as I go
  26079. 16:44:59because sometimes you just can't fully
  26080. 16:45:01comprehend it unless you just visualize
  26081. 16:45:03it and it gives you a a larger broader
  26082. 16:45:06glimpse of everything. So, we're going
  26083. 16:45:08to import and let's do seabour oops
  26084. 16:45:13sns and then we'll import
  26085. 16:45:16mattplot.lib.pipplot
  26086. 16:45:19piplot
  26087. 16:45:20as plt.
  26088. 16:45:23Let's run this.
  26089. 16:45:26That should work. Okay, perfect. Now, we
  26090. 16:45:29need to bring in our data set. So, we've
  26091. 16:45:31worked with that world population data
  26092. 16:45:32set. That is the exact one that we're
  26093. 16:45:34going to use now. So, we'll say dataf
  26094. 16:45:36frame equals pdread
  26095. 16:45:40csv. Do r and we'll paste in our CSV.
  26096. 16:45:45And this is what it should look like.
  26097. 16:45:47Although your path may be different, be
  26098. 16:45:48sure to make sure that you have the
  26099. 16:45:50correct file path. Then we'll read it
  26100. 16:45:52in. Now, this data set should look
  26101. 16:45:54extremely familiar if you've done some
  26102. 16:45:56of my previous pandas tutorials, but I
  26103. 16:45:59did make some alterations to this one.
  26104. 16:46:01Took out a little bit of data, put in a
  26105. 16:46:03little bit of data here and there. um to
  26106. 16:46:05change things up because if it was just
  26107. 16:46:08exactly how I pulled it, which I got
  26108. 16:46:09this data set from Kaggle, if it was
  26109. 16:46:11exactly how we pulled it, like we've
  26110. 16:46:13looked at in the previous videos, it's
  26111. 16:46:15too simple. You know, we wouldn't
  26112. 16:46:16actually be able to do some of the
  26113. 16:46:17things that I would like to show you.
  26114. 16:46:19So, be sure to actually download this
  26115. 16:46:21exact data set for this video because it
  26116. 16:46:24is a little bit different.
  26117. 16:46:26But what we're going to do now is just
  26118. 16:46:28try to get some highlevel information
  26119. 16:46:30from this. Now, if yours looks just a
  26120. 16:46:32little bit different, like your values
  26121. 16:46:34are in scientific notation, uh I have
  26122. 16:46:37applied this so many times I think it's
  26123. 16:46:39um you know, still applied to this, you
  26124. 16:46:41can do something and we'll write it
  26125. 16:46:43right down here. We're going to do PD
  26126. 16:46:45set option and we'll do an open
  26127. 16:46:49parenthesis and we'll say
  26128. 16:46:51display.flat_mat.
  26129. 16:46:55And so we're going to change that float
  26130. 16:46:56format by just saying lambda x colon and
  26131. 16:47:00then we're going to change basically how
  26132. 16:47:02many um decimal points we're looking at.
  26133. 16:47:05So let's just do here. So we'll do a
  26134. 16:47:09quote percent sign 2f. So we're
  26135. 16:47:12formatting it. Whoops. 2F. So we're
  26136. 16:47:14going to format it and we'll do percent
  26137. 16:47:17x. This is going to format it
  26138. 16:47:19appropriately. I'm I can run it. Um, and
  26139. 16:47:21actually it will change it cuz this is
  26140. 16:47:23at 0.1 I believe last time I did it. So
  26141. 16:47:25let's run this. And then let's run this
  26142. 16:47:28again. It'll change it to 0 2. So that's
  26143. 16:47:30two. I like it at 0.1. We don't really
  26144. 16:47:33need it any Well, let's keep it at 0 2.
  26145. 16:47:36Why not? We're going to keep it at 0 2.
  26146. 16:47:38That's how you change that. And I like
  26147. 16:47:40looking at it like this a lot better
  26148. 16:47:41than scientific notation. So just
  26149. 16:47:44something to point out. Um, let's go
  26150. 16:47:46down here and let's just pull up data
  26151. 16:47:48frame. So we have this data. One of the
  26152. 16:47:51first things that I like to do when I
  26153. 16:47:53get a data set is to just look at the
  26154. 16:47:55info. So we're going to do info. And
  26155. 16:47:57this gives us just some really highlevel
  26156. 16:48:00information. This is how many columns we
  26157. 16:48:02have. Here are the column names. Here
  26158. 16:48:04are how many uh values we have. And if
  26159. 16:48:07you notice, this is where it kind of
  26160. 16:48:09gets. So we have 234 in each of these.
  26161. 16:48:13So in each of these columns, we have 234
  26162. 16:48:15until we get to this 2022 population.
  26163. 16:48:18Once we get there, we start losing some
  26164. 16:48:21values. And then at the world population
  26165. 16:48:24percentage, we have all of our values,
  26166. 16:48:26all 234 of them. The count tells us that
  26167. 16:48:29it's non-null, so it does have values in
  26168. 16:48:31it. And then we also have the data
  26169. 16:48:32types, and these come in handy later.
  26170. 16:48:35Um, and these are really great to know,
  26171. 16:48:37and we'll be able to kind of use those
  26172. 16:48:39in a few different ways later on in this
  26173. 16:48:41tutorial. Really quickly, I wanted to
  26174. 16:48:43give a huge shout out to the sponsor of
  26175. 16:48:44this entire Panda series, and that is
  26176. 16:48:46Udemy. Udemy has some of the best
  26177. 16:48:48courses at the best prices and it is no
  26178. 16:48:50exception when it comes to pandas
  26179. 16:48:51courses. If you want to master pandas,
  26180. 16:48:53this is the course that I would
  26181. 16:48:54recommend. It's going to teach you just
  26182. 16:48:55about everything you need to know about
  26183. 16:48:57pandas. So, huge shout out to Udemy for
  26184. 16:48:59sponsoring this Panda series. And let's
  26185. 16:49:00get back to the video. The next thing
  26186. 16:49:02that I really like to do, and this one
  26187. 16:49:04is df.describe.
  26188. 16:49:07This allows you to get really a
  26189. 16:49:09highlevel overview of all of your
  26190. 16:49:11columns very quickly. You can get the
  26191. 16:49:13count, the mean, the standard deviation,
  26192. 16:49:16the minimum value and the maximum value
  26193. 16:49:19as well as your 25, 50 and 75
  26194. 16:49:23percentiles of your values. So just at a
  26195. 16:49:26super quick glance, there is a row
  26196. 16:49:28somewhere in here and there, this
  26197. 16:49:30country, their population is 510 for
  26198. 16:49:332022. And in fact, if you go back to
  26199. 16:49:361970, it was higher. It was at 752. I
  26200. 16:49:39that's just interesting. Then if we look
  26201. 16:49:41at the um max population, one has 1.42
  26202. 16:49:45billion. I believe that's China. And
  26203. 16:49:47then over here in 1970, we have 822
  26204. 16:49:50million. Again, I still believe that's
  26205. 16:49:52China. But this gives you just a really
  26206. 16:49:54nice high level of all of these values
  26207. 16:49:57or all these different calculations that
  26208. 16:49:59you can run on it. And we can run all
  26209. 16:50:01these individually on even specific
  26210. 16:50:03columns. But you know, this is just a
  26211. 16:50:05nice highle overview. One thing that we
  26212. 16:50:07just talked about was the null values
  26213. 16:50:09that we're seeing in here. Um, I'd like
  26214. 16:50:12to see how many values we're actually
  26215. 16:50:13missing because that is a problem. Um,
  26216. 16:50:15we don't want to have too many missing
  26217. 16:50:18values or could really obscure or change
  26218. 16:50:21the data set entirely and so we don't
  26219. 16:50:23want that. So, we'll say df.isnull
  26220. 16:50:26and then we'll do a parenthesis and
  26221. 16:50:27we'll say dot sum. And when we do this,
  26222. 16:50:31whoops,
  26223. 16:50:33dotsum. There we go. When we do this,
  26224. 16:50:36it's going to give us all the columns
  26225. 16:50:38and how many values we're actually
  26226. 16:50:40missing. Now, we have 234
  26227. 16:50:42rows of data. So, we have 41 47755424.
  26228. 16:50:48Um, so we have we definitely have data
  26229. 16:50:50missing. What we choose to do with it in
  26230. 16:50:54the data cleaning process, maybe we want
  26231. 16:50:55to populate it with a median value.
  26232. 16:50:57Maybe we just want to delete those
  26233. 16:50:59countries entirely if the data is
  26234. 16:51:01missing. um you know, I don't think
  26235. 16:51:03you're going to do that, but these are
  26236. 16:51:05things that you need to think about when
  26237. 16:51:07you're actually finding these missing
  26238. 16:51:09values. This is what the EDA process is
  26239. 16:51:11all about. We want to find different um
  26240. 16:51:14either outliers, missing values, things
  26241. 16:51:17that are wrong with the data or we can
  26242. 16:51:19find insights into it while we're doing
  26243. 16:51:21this as well. So, this is definitely
  26244. 16:51:23something that I would consider um when
  26245. 16:51:25I'm actually going through that data
  26246. 16:51:26cleaning process. Really, really
  26247. 16:51:28important information to know. Now,
  26248. 16:51:29let's go right down here. go to our next
  26249. 16:51:32cell, say df.
  26250. 16:51:35This is going to show us how many unique
  26251. 16:51:37values, and it's actually n unique. Uh,
  26252. 16:51:40this is going to show us how many unique
  26253. 16:51:42values are actually in each of these uh
  26254. 16:51:46columns. And this one makes the most
  26255. 16:51:48sense um for continent because I think
  26256. 16:51:51there's only seven continents, right? Um
  26257. 16:51:54but we have six right here. And for all
  26258. 16:51:56of these, each of these ranks,
  26259. 16:51:58countries, capitals should all be
  26260. 16:52:00unique. That makes perfect sense. As
  26261. 16:52:02well as these, you know, these
  26262. 16:52:03populations are such specific numbers
  26263. 16:52:05and such large numbers. I would be
  26264. 16:52:07shocked if any of these were similar.
  26265. 16:52:09And then for these world population
  26266. 16:52:11percentages, it's much lower. And again,
  26267. 16:52:14that makes a lot of sense because when
  26268. 16:52:15we're looking at, and we'll pull it up
  26269. 16:52:17right here. When we're looking at these
  26270. 16:52:19world population percentages,
  26271. 16:52:22um, a lot of them are really low.
  26272. 16:52:230.00.01,
  26273. 16:52:26like this one, um, 0.2. there are a lot
  26274. 16:52:29of really low values for those small
  26275. 16:52:31countries and so those are all um you
  26276. 16:52:33know one unique value. Now let's say we
  26277. 16:52:36just have this data right here and we
  26278. 16:52:38want to take a look at some of the
  26279. 16:52:39largest countries and we can easily do
  26280. 16:52:42that. We could even we could say max and
  26281. 16:52:44take a look at the largest country but I
  26282. 16:52:46want to be a little bit more strategic.
  26283. 16:52:47I want to be able to look at some of the
  26284. 16:52:49top range of countries and we can do
  26285. 16:52:51that based off this 2022
  26286. 16:52:54population. So we'll say df.sort sort
  26287. 16:52:58values. This is how we sort and um not
  26288. 16:53:00filter but um order our data. So we'll
  26289. 16:53:03do sort values and then we'll do by is
  26290. 16:53:06equal and then we'll specify that we
  26291. 16:53:08want uh this 2022 population and then
  26292. 16:53:11we're going to say comma and we'll say
  26293. 16:53:14actually let's just run this as is but
  26294. 16:53:16we'll do head because we just want to
  26295. 16:53:18look at the top values. So now we're
  26296. 16:53:20just looking at the very top values. So,
  26297. 16:53:23what we're looking at is actually these
  26298. 16:53:252022 population. Um, that's what we're
  26299. 16:53:28filtering on or sorting on basically.
  26300. 16:53:30And we're looking at the very bottom
  26301. 16:53:32values because it's sorting ascending.
  26302. 16:53:34So, from lowest to highest. So, this
  26303. 16:53:36Vatican City in Europe is um, you know,
  26304. 16:53:40510. That's the value that we were
  26305. 16:53:42looking at earlier. Now, we can do comma
  26306. 16:53:45ascending equal to false because it was
  26307. 16:53:47by default true. We can do false.
  26308. 16:53:49Whoops. We can do false and then it'll
  26309. 16:53:52give us the very largest ones. So if we
  26310. 16:53:54just take a look at the top five largest
  26311. 16:53:56by population, we're looking at China,
  26312. 16:53:59India, United States, Indonesia, and
  26313. 16:54:01Pakistan. And we can even specify that
  26314. 16:54:04we want the top 10 in this head. We can
  26315. 16:54:07bring in the top 10. We also have
  26316. 16:54:09Nigeria, Brazil, Bangladesh, Russia, and
  26317. 16:54:12Mexico. And you can do this for
  26318. 16:54:13literally any of these columns. Whether
  26319. 16:54:16you want to look at continent, capital,
  26320. 16:54:18country, um you can sort on these and
  26321. 16:54:20look at them and you can even look at,
  26322. 16:54:22you know, things like growth rate, world
  26323. 16:54:23percentage. This one seems really
  26324. 16:54:25interesting. Let's just look at this one
  26325. 16:54:27really quickly before we move on to the
  26326. 16:54:28next thing. Um if we look at this world
  26327. 16:54:32percentage, just China alone, I believe,
  26328. 16:54:35yep, just China alone is 17.88%
  26329. 16:54:39of the world. So 17.88 88 and 17.77
  26330. 16:54:44and that's China and India and those are
  26331. 16:54:46very large countries with a high high
  26332. 16:54:48high population. That makes a lot of
  26333. 16:54:50sense why that is the highest world
  26334. 16:54:52population percentage. Again, just
  26335. 16:54:54getting in here looking around. That's
  26336. 16:54:56all we're really doing. Now, I want to
  26337. 16:54:58look at something and I have always like
  26338. 16:55:00doing this which is looking at
  26339. 16:55:01correlations. Um, so a correlation
  26340. 16:55:03between usually only numeric values. We
  26341. 16:55:07can do that by saying df.co C O R R and
  26342. 16:55:10a parenthesis. And we'll run this. And
  26343. 16:55:13what this is is it is comparing every
  26344. 16:55:16column to every other column and looking
  26345. 16:55:19at how closely correlated they are. So
  26346. 16:55:22this 2022 population, if we look across
  26347. 16:55:24the board, it's very highly I mean this
  26348. 16:55:27is a one one. This is highly correlated
  26349. 16:55:30to each other. And that almost for all
  26350. 16:55:32of these populations, they're very very
  26351. 16:55:34closely tied to each other, which makes
  26352. 16:55:35perfect sense because for most
  26353. 16:55:38countries, they're going to be steadily
  26354. 16:55:40increasing. And so they're probably
  26355. 16:55:42almost exactly correlated. But we can
  26356. 16:55:45look at these populations and if you
  26357. 16:55:47look at the area, it's only somewhat
  26358. 16:55:50correlated. And that's because in some
  26359. 16:55:52countries, you know, they have a very
  26360. 16:55:54high population but a small area. Or
  26361. 16:55:56vice versa, small area and a very high
  26362. 16:55:58population. So there isn't a onetoone
  26363. 16:56:00correlation there, but it's hard to
  26364. 16:56:02really just glance at this um and
  26365. 16:56:04understand everything that's there. We
  26366. 16:56:06could just visualize it and it would be
  26367. 16:56:08a lot easier. So let's go ahead and do
  26368. 16:56:11that. Let's go down here. We're just
  26369. 16:56:13going to visualize this using a heat map
  26370. 16:56:16basically. So we're going to say
  26371. 16:56:17sns.heatmap
  26372. 16:56:20and an open parenthesis. And the data
  26373. 16:56:23that we're going to be looking at is
  26374. 16:56:24df.core
  26375. 16:56:26correlation. And then we also want to
  26376. 16:56:28say anote equals true. We'll kind of
  26377. 16:56:32show you what that looks like in just a
  26378. 16:56:33little bit. Um, but let's do plt.show.
  26379. 16:56:38And this will be our first look. And I
  26380. 16:56:40need to say show, not shot. Um,
  26381. 16:56:45we can get a little glimpse of what it
  26382. 16:56:46looks like, but this looks um,
  26383. 16:56:47absolutely terrible. Let's change the
  26384. 16:56:50figure size really quickly. So, I want
  26385. 16:56:52to make this much larger than it already
  26386. 16:56:54is. We'll do pltr
  26387. 16:56:58params rc params. Oops. Right there. Do
  26388. 16:57:03an open parenthesis. And then right here
  26389. 16:57:05we're going to do in quotes. Do figure
  26390. 16:57:09size. This actually needs to be in
  26391. 16:57:11brackets I believe.
  26392. 16:57:13Just like this, not parentheses. We'll
  26393. 16:57:16say fig size is equal to. And now we can
  26394. 16:57:19specify the value that we want. Let's do
  26395. 16:57:2110 comma 7 and see if this looks any
  26396. 16:57:24better.
  26397. 16:57:25No. No, that doesn't look good. Do 20.
  26398. 16:57:30Okay, that looks a lot better. And um
  26399. 16:57:34you know, this is just a quick way
  26400. 16:57:36because it gives you basically a
  26401. 16:57:37color-coded system. Highly correlated is
  26402. 16:57:40this tan all the way down to basically
  26403. 16:57:42no correlation or negative correlation
  26404. 16:57:44even, which is black. So when we're
  26405. 16:57:46looking at these 2022 populations and
  26406. 16:57:48these are populations right down here on
  26407. 16:57:51this axis, we can see that all of these
  26408. 16:57:53are extremely highly correlated very
  26409. 16:57:57very quickly. Whereas the rank really
  26410. 16:57:59has nothing to do it's it's negatively
  26411. 16:58:02correlated doesn't really have anything
  26412. 16:58:03to do with it. Then for the population
  26413. 16:58:05and the world population percentage it
  26414. 16:58:08again is quite correlated except for the
  26415. 16:58:12area density and growth rate. So I find
  26416. 16:58:15that really interesting that you know
  26417. 16:58:17the density the growth rate in the area
  26418. 16:58:19aren't really all that associated or
  26419. 16:58:23correlated with the population numbers
  26420. 16:58:26that is I kind of would have assumed
  26421. 16:58:29that on some level they went handinand
  26422. 16:58:31the area does um which you know again
  26423. 16:58:34makes sense you know larger area larger
  26424. 16:58:35population that kind of thing but even
  26425. 16:58:37density um I guess I guess density and
  26426. 16:58:40growth rate um growth rate I can see
  26427. 16:58:42because that's a percentile thing that
  26428. 16:58:44could Definitely not correlated. I
  26429. 16:58:46thought the density would be more
  26430. 16:58:48correlated than it is. All that to say
  26431. 16:58:50is this is one way that you can kind of
  26432. 16:58:52look at your data, see how correlated it
  26433. 16:58:54is to one another. That can definitely
  26434. 16:58:56um help you know what to analyze and
  26435. 16:58:58look at later when you're actually doing
  26436. 16:59:00your data analysis. Let's go right down
  26437. 16:59:02here. Um something that I do almost all
  26438. 16:59:05the time when I'm doing any type of
  26439. 16:59:07exploratory data analysis like this, I'm
  26440. 16:59:09going to group together columns, start
  26441. 16:59:11looking at the data a little bit closer.
  26442. 16:59:14Um, so let's go ahead and group on the
  26443. 16:59:16continent. So let's look at it right
  26444. 16:59:19here. Let's group on this continent
  26445. 16:59:20because sometimes when you're doing this
  26446. 16:59:22EDA, you already know kind of what the
  26447. 16:59:24end goal of this data set is. You know
  26448. 16:59:27kind of what you're looking for, what
  26449. 16:59:28you're going to visualize at the end
  26450. 16:59:29that you really comes in handy when
  26451. 16:59:30doing this. But sometimes you don't.
  26452. 16:59:33Sometimes you're just going in blind.
  26453. 16:59:34And so far we've really just been going
  26454. 16:59:36in blind. We're just throwing things at
  26455. 16:59:38the wind, kind of seeing some overviews,
  26456. 16:59:40um, looking at correlation. That's all
  26457. 16:59:42we've done. Now I kind of want to get
  26458. 16:59:44more specific. I want to have like a use
  26459. 16:59:46case, something I'm kind of looking for.
  26460. 16:59:49Not doing full data analysis or not
  26461. 16:59:51diving into the depths, but something we
  26462. 16:59:53can kind of aim for. So the use case or
  26463. 16:59:55the question for us is are there certain
  26464. 16:59:57continents that have grown faster than
  26465. 16:59:59others and in which ways? So we want to
  26466. 17:00:03focus on these continents. We know that
  26467. 17:00:04that's the most important column for
  26468. 17:00:06this use case, this very fake use case.
  26469. 17:00:08Um, so we can group on this continent
  26470. 17:00:11and we can look at these populations
  26471. 17:00:13right here because we can't really see
  26472. 17:00:15growth. You can see a growth rate, but
  26473. 17:00:18the density per uh kilometer, we don't
  26474. 17:00:21have multiple values for that. It's just
  26475. 17:00:23a static one single value. Same for
  26476. 17:00:25growth rate, same for world population
  26477. 17:00:27percentage. But we have this over a long
  26478. 17:00:30span, many many years um you know 50
  26479. 17:00:33years of data here. So this we can see
  26480. 17:00:36which countries have really done well or
  26481. 17:00:38which continents have really done well.
  26482. 17:00:40So without you know talking about it
  26483. 17:00:42even more let's do dfgroup by and then
  26484. 17:00:45we'll say continent. Oops. Let me just
  26485. 17:00:50copy this. I'm I am not good at
  26486. 17:00:52spelling. We're going to say dfgroup by
  26487. 17:00:54and then we'll do mean. And we can just
  26488. 17:00:57do it just like this. And now we have
  26489. 17:01:00Africa, Asia, Europe, North America,
  26490. 17:01:03Oceanana, and South America.
  26491. 17:01:07Okay, so if I'm being completely honest,
  26492. 17:01:10I knew most of these. All right, I'm no
  26493. 17:01:12geography expert, but I I knew most of
  26494. 17:01:14these. I don't know what this ocean is.
  26495. 17:01:16Um this that [clears throat] I don't I
  26496. 17:01:19genuinely don't know what that is. Um so
  26497. 17:01:22let's just search for that value and
  26498. 17:01:25see. We'll come back up here in just a
  26499. 17:01:27second, but I want to I want to kind of
  26500. 17:01:29understand um what this is. So, we're
  26501. 17:01:31going to df um then we'll say content.
  26502. 17:01:36Let me sound that out for you guys. Um
  26503. 17:01:39then we'll do string.contains.
  26504. 17:01:42Oops. Contains. Good night. And then I
  26505. 17:01:46want to look for ocean. Uh and let's
  26506. 17:01:50let's run this. Oh, I need to do like
  26507. 17:01:53this.
  26508. 17:01:57Now let's run this. So now we're looking
  26509. 17:01:59at our data frame and we're seeing when
  26510. 17:02:01the values have this continent as ocean.
  26511. 17:02:05Um okay. So these look like islands I'm
  26512. 17:02:08guessing. So we have Fiji, Guam,
  26513. 17:02:12um New Zealand,
  26514. 17:02:15Papa New Guinea. Yeah, these look like
  26515. 17:02:17all I'm I'm guessing based off the
  26516. 17:02:20continent Oceanana. Um, Oceanania Oceana
  26517. 17:02:25Oceania, guys, this is tough for me.
  26518. 17:02:28Okay, I'm doing my best. I, you know,
  26519. 17:02:30this is part of the EDA process. I don't
  26520. 17:02:32know what that means. I don't know what
  26521. 17:02:33Oceanana Oceania.
  26522. 17:02:37Jeez, I'm just going to call it
  26523. 17:02:38Oceanana. That's so wrong, but I'm just
  26524. 17:02:40going to so easy for me to say, you
  26525. 17:02:42know, I I now am seeing this and it
  26526. 17:02:45[snorts] looks like islands. Um, which
  26527. 17:02:48would make sense because
  26528. 17:02:51for their average, they have the highest
  26529. 17:02:52average rank. Um, and I'm guessing
  26530. 17:02:56that's because they're just mostly small
  26531. 17:02:58continents. So, let's let's order this
  26532. 17:03:00really quickly. We're going to do dot
  26533. 17:03:02sort
  26534. 17:03:04values. Do an open parenthesis. And I
  26535. 17:03:07want to sort on the population. We're
  26536. 17:03:09just doing the average population. Um,
  26537. 17:03:12we'll do by um equal. So on the average
  26538. 17:03:16population and we'll do ascending equals
  26539. 17:03:20false. So when we're looking at this
  26540. 17:03:22average or the mean population, Asia has
  26541. 17:03:25the highest population on average. Then
  26542. 17:03:28we have South America, Africa, Europe,
  26543. 17:03:31North America, and then Oceanana at the
  26544. 17:03:35very bottom, which makes perfect sense.
  26545. 17:03:36Again, small islands. Um world
  26546. 17:03:40population percentage. So each of the
  26547. 17:03:42countries each of those countries in
  26548. 17:03:44Asia makes up about 1% on average.
  26549. 17:03:47Really interesting um to know and just
  26550. 17:03:50kind of look at this and the density in
  26551. 17:03:54Asia is far higher than double almost
  26552. 17:03:57double every single other continent. Um
  26553. 17:04:01really really interesting actually now
  26554. 17:04:02that I'm looking at this. But you know
  26555. 17:04:04that's something that I would actually
  26556. 17:04:06look into and I I would be like what is
  26557. 17:04:08this Oceanana or Oceania? what does that
  26558. 17:04:11mean? And you know, let me look into
  26559. 17:04:13that. Let me explore that more because I
  26560. 17:04:15want to know this data set. I'm trying
  26561. 17:04:16to really understand this data set well.
  26562. 17:04:18But what I want to do now is I want to
  26563. 17:04:20visualize this. Um because I just feel
  26564. 17:04:23like looking at it, I don't it's hard to
  26565. 17:04:25visualize. And again, the use case that
  26566. 17:04:27we're saying is is which continent has
  26567. 17:04:29grown the fastest. Like it could be
  26568. 17:04:31percentage- wise, it could be um you
  26569. 17:04:34know, as just a whole on average. Let's
  26570. 17:04:36take a look. So we're going to take this
  26571. 17:04:39and let's copy it like this. Let's bring
  26572. 17:04:42this right down here. So let's look at
  26573. 17:04:44this. So if I try to visualize this and
  26574. 17:04:49let's do that. Let's do DF2 is equal to
  26575. 17:04:52because I'm I already know it's not
  26576. 17:04:54going to look good just based off how
  26577. 17:04:56the data is sitting. Um we can do DF2.
  26578. 17:05:00Oops, what am I doing? I don't need to
  26579. 17:05:03do that, but I will. Okay, DF2. and
  26580. 17:05:05we'll do df2.lot
  26581. 17:05:08and we'll run it just like this. Um,
  26582. 17:05:11[clears throat]
  26583. 17:05:12as you can see, Asia, South America,
  26584. 17:05:15Africa, Europe, North America, Oceanana,
  26585. 17:05:18we can kind of understand what's
  26586. 17:05:20happening, but these are the actual um
  26587. 17:05:23values that are being visualized, not
  26588. 17:05:26the continents, which is what I wanted
  26589. 17:05:28um in order to switch it. And it's
  26590. 17:05:30actually pretty easy and this is
  26591. 17:05:31something that um you know is good to
  26592. 17:05:34know. We can actually transpose it to
  26593. 17:05:36where these these continents become the
  26594. 17:05:38columns and the columns become the
  26595. 17:05:40index. And all we have to do is say df2
  26596. 17:05:45transpose
  26597. 17:05:47and we'll do this parenthesy right here.
  26598. 17:05:49And let's just look at it and then we'll
  26599. 17:05:51save it. So now all these columns are
  26600. 17:05:55right here.
  26601. 17:05:57and all of the indexes are the columns.
  26602. 17:06:00So let's say df3 is equal to and I'm
  26603. 17:06:03just doing that so I don't you know
  26604. 17:06:04write over the df for my earlier dataf
  26605. 17:06:06frames. So now we have this dataf frame
  26606. 17:06:08three. So now let's do dataf frame
  26607. 17:06:11three.plot and it should look quite a
  26608. 17:06:13bit different.
  26609. 17:06:15Uh whoops I didn't run this. Let's run
  26610. 17:06:18this and run this.
  26611. 17:06:22And as you can see this does not look
  26612. 17:06:24right at all. And the reason is is
  26613. 17:06:26because we're not only looking at uh the
  26614. 17:06:29correct columns. We have this density in
  26615. 17:06:31here. We're population percentage rank.
  26616. 17:06:33We don't need any of those. The only
  26617. 17:06:35ones that we want to keep are these ones
  26618. 17:06:37right here. This population. Now, we can
  26619. 17:06:40do that. And we can just go right up
  26620. 17:06:42here. This is where we created that data
  26621. 17:06:44frame 2 that we transposed. We can go
  26622. 17:06:46right up here and we can specify within
  26623. 17:06:49this. We actually only want specific
  26624. 17:06:51values. Now, we can go through and
  26625. 17:06:54handwrite all of these. And by all
  26626. 17:06:56means, go for it. But I am going to go
  26627. 17:06:59down here. I'm going to say df.c
  26628. 17:07:01columns. And I'm going to run this. It's
  26629. 17:07:04going to give us this list of all of our
  26630. 17:07:06columns. And I'm just going to You can
  26631. 17:07:09just copy this.
  26632. 17:07:11And you can put it right in here. Again,
  26633. 17:07:13you get list with I think it needs to be
  26634. 17:07:15like this if I'm Let me try running
  26635. 17:07:17this. Okay. So, this worked properly.
  26636. 17:07:19You can do it just like this or a little
  26637. 17:07:21shortcut if you want to do it like that.
  26638. 17:07:24If you want to do a shortcut like um I I
  26639. 17:07:27would hope you would you would just do
  26640. 17:07:29df.c [clears throat]
  26641. 17:07:30columns just like how we looked at down
  26642. 17:07:32here except since this is our an index
  26643. 17:07:36we can search through it. So we can just
  26644. 17:07:37say 0 1 2 3. Okay. So we can do five up
  26645. 17:07:42to 13 because I think it's seven. And
  26646. 17:07:44we'll just let's see if this works.
  26647. 17:07:48Uh it may not. I may actually need to go
  26648. 17:07:49like this. Let's see. There we go. So,
  26649. 17:07:53you can just use, you know, the indexing
  26650. 17:07:55to save you some visual space. Gives you
  26651. 17:07:58the exact same output. So, now we have
  26652. 17:08:00this. This is our DF2. Now, let's go
  26653. 17:08:02down and transpose it. So, now we just
  26654. 17:08:05have these populations and we have our
  26655. 17:08:06continents right here. And then now
  26656. 17:08:09we're going to plot it. And this looks
  26657. 17:08:12good, although it's backward. Um, okay.
  26658. 17:08:16It's backward.
  26659. 17:08:18So, what I actually want to do is not
  26660. 17:08:22this. Uh, that is a quick way to do it,
  26661. 17:08:25although not the best way to do it. Um,
  26662. 17:08:28so I'm actually going to copy all of
  26663. 17:08:30these. And although I said it would save
  26664. 17:08:32us time, it did not at all. So, I'm
  26665. 17:08:35going to
  26666. 17:08:36put a bracket right here.
  26667. 17:08:39I'm going to paste this in here. And I'm
  26668. 17:08:41literally going to change these up. I
  26669. 17:08:44might speed this up or I might just have
  26670. 17:08:47you sit through this because, you know,
  26671. 17:08:49this is an interesting part of the
  26672. 17:08:51process and I want, you know, you to get
  26673. 17:08:52the full experience. You know what? Now
  26674. 17:08:54that I'm talking about it, that is what
  26675. 17:08:56we're going to do. You guys can hang out
  26676. 17:08:57with me. This is a good time. We have
  26677. 17:09:002010,
  26678. 17:09:022015,
  26679. 17:09:042020,
  26680. 17:09:06and 2022. Now, let's run it. What did I
  26681. 17:09:10do? Oh, too many brackets. There we go.
  26682. 17:09:13So now it's ordered appropriately. We
  26683. 17:09:15have 1970 all the way up to 2022. This
  26684. 17:09:17is how we want it. Let's transpose it
  26685. 17:09:20appropriately. Let's run it. And now we
  26686. 17:09:23have basically have the inverted uh
  26687. 17:09:25image of this. Now just at a glance and
  26688. 17:09:28we haven't done anything to this except
  26689. 17:09:30for literally what we are looking at. At
  26690. 17:09:32a glance, we can see that from 1970,
  26691. 17:09:36China, you know, Asia and China are
  26692. 17:09:38already in the lead by quite a bit. And
  26693. 17:09:41it continues to drastically go up,
  26694. 17:09:44especially in the 2000s. Like right
  26695. 17:09:46here, it explodes like just straight up,
  26696. 17:09:50then kind of starts going up and just
  26697. 17:09:52leveling off. Every other continent,
  26698. 17:09:55especially ocean, ocean, is just really
  26699. 17:09:58low. It It never has done a bunch. Let's
  26700. 17:10:00see. Look at green. green has gone up um
  26701. 17:10:02from you know point let's say 0.1
  26702. 17:10:06up to about 02 so they've almost doubled
  26703. 17:10:09um in the last 50 years and again you
  26704. 17:10:12can just get an overview a highle
  26705. 17:10:14overview of each of these you know
  26706. 17:10:17continents over the span of this time so
  26707. 17:10:20this is kind of one way that we can you
  26708. 17:10:22know look at that use case we're not
  26709. 17:10:25going to harp on that too long I just
  26710. 17:10:26wanted to give you an example like you
  26711. 17:10:28know when you're looking at this
  26712. 17:10:30sometimes times you'll have something in
  26713. 17:10:31mind of what you're looking for and you
  26714. 17:10:33go exploring and just kind of find
  26715. 17:10:35what's out there and find what you see.
  26716. 17:10:37Um, the next thing I want to look at is
  26717. 17:10:39a box plot. Now, I personally I love box
  26718. 17:10:42plots. You know, they're really good for
  26719. 17:10:44finding outliers and there's a lot of
  26720. 17:10:48outliers. I already know this because
  26721. 17:10:50the average, the 25th, 50th percentile
  26722. 17:10:53are very low and then there's some
  26723. 17:10:54really just big outliers. But for your
  26724. 17:10:57data set, it may not be that way. And
  26725. 17:10:59those outliers may be something that you
  26726. 17:11:01really need to look into. And box plots
  26727. 17:11:03have been something that I've used a lot
  26728. 17:11:05where I found those outliers that way
  26729. 17:11:06and started to dig into the data to find
  26730. 17:11:08those outliers and you know came across
  26731. 17:11:11some stuff that I'm like oh I have to
  26732. 17:11:12clean this up. I have to go back to the
  26733. 17:11:13source. Really um really really powerful
  26734. 17:11:16and useful to be able to find these. So
  26735. 17:11:18all you have to do is df.boxplot.
  26736. 17:11:21Yeah. Let's take a look at it. And this
  26737. 17:11:24already looks good as is. Maybe I'll
  26738. 17:11:26make it a little bit wider. Um, let's do
  26739. 17:11:28fig size. Oops.
  26740. 17:11:32Sorry. Fig size is equal to let's try 20
  26741. 17:11:37by 10.
  26742. 17:11:39Um, okay. That didn't help at all. I
  26743. 17:11:42apologize. I thought it would, but let's
  26744. 17:11:44keep going. [clears throat] What this is
  26745. 17:11:45showing us is that these little boxes
  26746. 17:11:48down here, which are actually usually
  26747. 17:11:50much larger because you have a more
  26748. 17:11:52equal distribution of of um numbers or
  26749. 17:11:54values in this small value. This is
  26750. 17:11:57where our averages lie. This number
  26751. 17:12:00right here is the upper range. And then
  26752. 17:12:03all these values, all these open
  26753. 17:12:05circles, those actually stand for
  26754. 17:12:07outliers. So we're looking at the 2022
  26755. 17:12:10population. There's a lot of outliers.
  26756. 17:12:12[clears throat]
  26757. 17:12:12Now for our data set, knowing our data
  26758. 17:12:15set is really important. Outliers are to
  26759. 17:12:17be expected, especially when most
  26760. 17:12:20countries or continents are small. So
  26761. 17:12:22we're looking at, you know, all of these
  26762. 17:12:24little dots are outlier countries
  26763. 17:12:27um or outlier values, which each value
  26764. 17:12:30corresponds to a country. So if this was
  26765. 17:12:32a different data set, I would be, you
  26766. 17:12:34know, searching on these and trying to
  26767. 17:12:36find these so that I can see what's
  26768. 17:12:38wrong with them, if anything, or if they
  26769. 17:12:40are real um numbers. Like if this was
  26770. 17:12:42revenue, everyone's revenue is way down
  26771. 17:12:43here, and then there's one company
  26772. 17:12:44that's making like $10 trillion. that'd
  26773. 17:12:47be an outlier up here and it would
  26774. 17:12:49definitely be something that you want to
  26775. 17:12:50look into for our data set knowing that
  26776. 17:12:52you know we're looking at population.
  26777. 17:12:54This is more than acceptable and you
  26778. 17:12:56know oddly enough but that's what box
  26779. 17:12:59plots are really good for showing you
  26780. 17:13:01some of those cortiles the upper and the
  26781. 17:13:02lower um as well as denoting these
  26782. 17:13:05points that fall outside of those normal
  26783. 17:13:06ranges for you to look into. So really
  26784. 17:13:09really useful. So now let's go down
  26785. 17:13:11here, pull up our data frame again, and
  26786. 17:13:13we've kind of just zoomed into the whole
  26787. 17:13:16EDA process. There was one last thing
  26788. 17:13:18that I wanted to show you. Uh, this is
  26789. 17:13:20the very last thing that we're going to
  26790. 17:13:21look at. We're ending on really a low
  26791. 17:13:22point if I'm being honest because the
  26792. 17:13:24last kind of stuff was more much more
  26793. 17:13:25exciting. But there is something
  26794. 17:13:28dftypes.
  26795. 17:13:31Oops. Let's do df.dtypes.
  26796. 17:13:34And we'll run this. Now just like info
  26797. 17:13:36it gave us these values but we're
  26798. 17:13:39actually able to search on these values
  26799. 17:13:41now. So these um object float and
  26800. 17:13:44integer we can search on those which is
  26801. 17:13:47really great because we can do include
  26802. 17:13:49equal and we can do something like
  26803. 17:13:51number and none of these are numbers
  26804. 17:13:54right or none of them explicitly say
  26805. 17:13:56number but when we run it I'm getting an
  26806. 17:13:59error series object not oh that's
  26807. 17:14:01because I'm doing um dtypes is for a
  26808. 17:14:04series we need to do select underscore
  26809. 17:14:08dtypes now let's run this now it's only
  26810. 17:14:11returning um the columns in this data
  26811. 17:14:14frame where the data types are included
  26812. 17:14:17in this number. So you won't see any you
  26813. 17:14:19know country or any of those text or the
  26814. 17:14:22strings. If we wanted to do that, we go
  26815. 17:14:25in here and say object
  26816. 17:14:28and run that. And this is another really
  26817. 17:14:30quick way where we can just filter those
  26818. 17:14:33columns to look for specific whether
  26819. 17:14:36it's numeric. Um we could even do float
  26820. 17:14:38in here. And so now it's not including
  26821. 17:14:41that rank which was an integer. So we
  26822. 17:14:43can specify the type of data type and
  26823. 17:14:45it'll filter all of the columns based
  26824. 17:14:47off of that which you know when you're
  26825. 17:14:49doing stuff like this you it is good to
  26826. 17:14:51know what kind of data types you're
  26827. 17:14:53working with and look at just those
  26828. 17:14:54types of data types because there might
  26829. 17:14:56be some type of analysis you want to
  26830. 17:14:57perform on just that whether it's
  26831. 17:14:59numeric or just the string or integer
  26832. 17:15:02columns within your data set. So again,
  26833. 17:15:04ending on a low note, I apologize. Um,
  26834. 17:15:06you know, everything else that we looked
  26835. 17:15:08at, all those other things that we
  26836. 17:15:09looked at are all things that I
  26837. 17:15:11typically do uh in some way or another
  26838. 17:15:14when I'm looking at a data set.
  26839. 17:15:16Exploratory data analysis is really just
  26840. 17:15:19the first look. you're looking at it,
  26841. 17:15:21you're going to be cleaning it up, doing
  26842. 17:15:22the data cleaning process, and then
  26843. 17:15:24you're going to be doing your actual
  26844. 17:15:26data analysis, actually finding those
  26845. 17:15:28trends and patterns, and then
  26846. 17:15:29visualizing it um in some way to find
  26847. 17:15:32some kind of meaning or insight or value
  26848. 17:15:35from that data. And again, there's a
  26849. 17:15:37thousand different ways you can go about
  26850. 17:15:39this. It it does typically um you know,
  26851. 17:15:42depend on the data set, but these are a
  26852. 17:15:44lot of the ways that you'll clean a lot
  26853. 17:15:46of different data sets. And so, you
  26854. 17:15:48know, that's why I went into the things
  26855. 17:15:49that we looked at in this video. So, I
  26856. 17:15:51hope that you guys liked it. I hope that
  26857. 17:15:52you enjoyed something in this tutorial.
  26858. 17:15:54If you like this video, be sure to like
  26859. 17:15:55and subscribe, as well as check out all
  26860. 17:15:57my other videos on pandas and Python.
  26861. 17:15:59And I will see you in the next video.
  26862. 17:16:02[music]
  26863. 17:16:13What's going on everybody? Welcome back
  26864. 17:16:15to another video. Today we are back with
  26865. 17:16:17another data analyst portfolio project
  26866. 17:16:18where we will be scraping data from
  26867. 17:16:20Amazon using Python.
  26868. 17:16:24[music]
  26869. 17:16:27Now you may be asking do I need to know
  26870. 17:16:29web scraping to become a data analyst
  26871. 17:16:31and the answer is no you absolutely
  26872. 17:16:33don't need to know it but it is a very
  26873. 17:16:35cool skill to learn and in fact I have
  26874. 17:16:37used it in my job in the past and so it
  26875. 17:16:39is useful but you really don't need to
  26876. 17:16:42know it. something that it is used for
  26877. 17:16:44is kind of creating your own data sets.
  26878. 17:16:46Um, and we're going to be looking at one
  26879. 17:16:48where you can create your own data set
  26880. 17:16:49today, but there are a lot of other uses
  26881. 17:16:51for web scraping and I'm sure I'll talk
  26882. 17:16:53a little bit more about that while we're
  26883. 17:16:54actually walking through the project.
  26884. 17:16:56One last thing I want to say before we
  26885. 17:16:57get started is that this is most likely
  26886. 17:16:59an intermediate project. So, if you are
  26887. 17:17:01just now learning the basics of Python,
  26888. 17:17:02this might be a little bit challenging
  26889. 17:17:04for you, but I still recommend going
  26890. 17:17:06through it because I will do my best to
  26891. 17:17:08walk through everything every single
  26892. 17:17:09step of the way and and kind of explain
  26893. 17:17:11all of the concepts and so you can still
  26894. 17:17:13learn something even if you aren't super
  26895. 17:17:15good at Python right now. With that
  26896. 17:17:17being said, let's jump over to my screen
  26897. 17:17:18and get started on the project. All
  26898. 17:17:19right, so we are going to get started.
  26899. 17:17:21And if you didn't watch the last
  26900. 17:17:22project, I had people download Anaconda.
  26901. 17:17:25Uh we use Jupiter notebooks. Um, and
  26902. 17:17:28I'll show you how to get to that in just
  26903. 17:17:29a second, but I'll I'll leave this link
  26904. 17:17:30in the description if you haven't done
  26905. 17:17:32that already and you are just doing this
  26906. 17:17:34project. Um, but you'll go, you'll
  26907. 17:17:36download Andaconda, you know, download
  26908. 17:17:38super easy. Um, and you're going to open
  26909. 17:17:39up Jupyter Notebooks. I'll launch it
  26910. 17:17:41right now. I already have it open. Uh,
  26911. 17:17:43but I'll open up another one just for,
  26912. 17:17:45you know, the purposes of demonstration.
  26913. 17:17:48What we are going to do today and what
  26914. 17:17:50we um what people voted on. I mean,
  26915. 17:17:53there's like there was like 8,000 people
  26916. 17:17:55that voted um in the poll that I made of
  26917. 17:17:58what data you wanted me to scrape. There
  26918. 17:17:59was like Amazon cryptocurrency weather
  26919. 17:18:03um something else, I don't remember.
  26920. 17:18:05Overwhelmingly, I mean, like 70% of
  26921. 17:18:07people, maybe even 80%, I you know,
  26922. 17:18:09don't don't fact check me on that, voted
  26923. 17:18:11for Amazon. Um and so I'm going to do
  26924. 17:18:14it. Now, there are many things that you
  26925. 17:18:17can scrape um off of Amazon. Just a ton
  26926. 17:18:20of stuff. Um, and I'm going to show you
  26927. 17:18:24how to do it. I'm going to show you how
  26928. 17:18:26to make it useful, how to make a data
  26929. 17:18:28set. Um, and it's going to be really
  26930. 17:18:31interesting, but there are lots of other
  26931. 17:18:33ways to do this. And so, I think, um,
  26932. 17:18:35and I have already kind of created it.
  26933. 17:18:37I'm going to show you how to do it off
  26934. 17:18:39of this page. Um, when you're actually
  26935. 17:18:41in an item, and you can scrape, you
  26936. 17:18:43know, basically anything in here. Um,
  26937. 17:18:45and I'll show you how to do that.
  26938. 17:18:47Another thing that is a little bit more
  26939. 17:18:49advanced and that's why this first video
  26940. 17:18:51is starting off I think on the more easy
  26941. 17:18:53side. It's not easy but it's easier. The
  26942. 17:18:56next thing the next video that I'm going
  26943. 17:18:58to make is how to actually do um
  26944. 17:19:02basically do multiple items, right? So
  26945. 17:19:05this item, this item, this item, this
  26946. 17:19:07item, and then traverse through the
  26947. 17:19:10different pages. So there's 20 pages. Um
  26948. 17:19:13you want all of that data. How do you
  26949. 17:19:15get all of that? That'll be the next
  26950. 17:19:17project. Um, I don't know when I plan on
  26951. 17:19:19doing that. I have it like 90% of the
  26952. 17:19:21way done. Um, but I have this one
  26953. 17:19:23completed and so I wanted to get that
  26954. 17:19:25out to you guys now. But that'll
  26955. 17:19:26probably be the next project. I think
  26956. 17:19:27that is much more difficult. Um, and so
  26957. 17:19:30if you can understand this one and you
  26958. 17:19:32get it and and you understand it, then
  26959. 17:19:34the next project you should be able to
  26960. 17:19:35understand too is just a little bit more
  26961. 17:19:37complicated. So with that being said,
  26962. 17:19:40um, we are going to actually get into
  26963. 17:19:41the project. I'm going to delete one of
  26964. 17:19:43these. Um, all we're going to do is go
  26965. 17:19:45to new, do Python 3. It'll open up a new
  26966. 17:19:50one. We'll call this um Amazon
  26967. 17:19:54Web
  26968. 17:19:55Scraper
  26969. 17:19:57um project. That's what we'll call it.
  26970. 17:20:00Did I spell that right? Perfect. Um, the
  26971. 17:20:03first thing that we need to do uh or
  26972. 17:20:05that we should do is upload um or or or
  26973. 17:20:10import our libraries. So, I'm going to
  26974. 17:20:12say um import Oops. What am I doing? Was
  26975. 17:20:16off to a terrible start. There we go.
  26976. 17:20:19Import libraries. Now, I'm not going to
  26977. 17:20:21write out all the libraries. Um I have
  26978. 17:20:23some things that I'm going to be copying
  26979. 17:20:25and pasting throughout this. I won't
  26980. 17:20:27there's only a few things that I'm
  26981. 17:20:28copying and pasting. You can take a
  26982. 17:20:29quick glance. Um some of the things that
  26983. 17:20:31I just don't want to waste time on. Um
  26984. 17:20:32because this could be a long video. I
  26985. 17:20:34don't know. I don't want to waste time
  26986. 17:20:36on stuff like this. Um and so, you know,
  26987. 17:20:39I'm just going to copy and paste it. You
  26988. 17:20:41guys are going to I'm going there will
  26989. 17:20:43be a link below if you haven't clicked
  26990. 17:20:44it already that will go to the GitHub
  26991. 17:20:46page where you can literally have all of
  26992. 17:20:48this code already written. I do
  26993. 17:20:51recommend writing it all yourself
  26994. 17:20:52because you will learn it much better. I
  26995. 17:20:54promise because then you'll make
  26996. 17:20:55mistakes and you'll figure it out and
  26997. 17:20:56all that all that good stuff. But you
  26998. 17:20:58will have that code available. So just
  26999. 17:20:59go copy and paste it. Um that's what I
  27000. 17:21:01would do. But what we are we are going
  27001. 17:21:03to be using today is uh something called
  27002. 17:21:05beautiful soup requests. Um, then we're
  27003. 17:21:09going to be using time and datetime. And
  27004. 17:21:12a potential one if you want to get, and
  27005. 17:21:14I'm going to show you this at the end.
  27006. 17:21:16This is not really part of the project.
  27007. 17:21:17It goes above and beyond. But this
  27008. 17:21:19library right here is for sending emails
  27009. 17:21:22to yourself. Um, and I'll show you how
  27010. 17:21:24uh you can use it if you want to. I
  27011. 17:21:27already have the whole code written out.
  27012. 17:21:28Um, you can just steal it and try it out
  27013. 17:21:30yourself and see if you can get it to
  27014. 17:21:32work. But this one is not um as
  27015. 17:21:34important. I'll put it down here. So,
  27016. 17:21:38um, let's move on. Now, one thing I want
  27017. 17:21:40to say before we get too into it is
  27018. 17:21:42[clears throat] that, well, give me a
  27019. 17:21:43second
  27020. 17:21:45is that right here in front of me is a
  27021. 17:21:48different laptop. Now, it took me a
  27022. 17:21:51solid, I would say, you know, 10 hours
  27023. 17:21:55or so to write all of this. It took over
  27024. 17:21:58the course of like two weeks in my free
  27025. 17:21:59time. I'd pick it up. It took me a
  27026. 17:22:01solid, you know, two weeks on and off,
  27027. 17:22:04an hour here, an hour there. to finish
  27028. 17:22:06this project. Um, and I made a ton of
  27029. 17:22:09mistakes and messed a bunch of things up
  27030. 17:22:11and I finally got it to work. Um, you
  27031. 17:22:13know, after a bunch of revisions, that's
  27032. 17:22:14typically how things go when I do
  27033. 17:22:16projects. And so, uh, I'm about to give
  27034. 17:22:19you a streamlined version of this
  27035. 17:22:21because I have all the code right down
  27036. 17:22:24here. And so, I'm going to be glancing
  27037. 17:22:25at this a lot. Um, just so I don't make
  27038. 17:22:29this video 20 hours of trying to
  27039. 17:22:30remember all the code off the top of my
  27040. 17:22:32head. I have it written out already. I
  27041. 17:22:34already did the project. It works. It's
  27042. 17:22:35beautiful. It's a good project. So, um I
  27043. 17:22:37don't want to waste your time and I just
  27044. 17:22:39want you to know that, you know, you
  27045. 17:22:42nobody should be able to do this off top
  27046. 17:22:44of their head in an hour. Most people
  27047. 17:22:46won't. Um it takes time. You make
  27048. 17:22:49mistakes. Um but [clears throat]
  27049. 17:22:52uh let's get started on the project. Now
  27050. 17:22:55in this uh in this what we're going to
  27051. 17:22:59have to do is we going to have to tell
  27052. 17:23:03beautiful soup and requests where we are
  27053. 17:23:05actually getting this data from. What
  27054. 17:23:07website um what is our computer you know
  27055. 17:23:10some information from our computer. I'm
  27056. 17:23:12going to again there's going to be a
  27057. 17:23:14little copying and pasting in here
  27058. 17:23:15because you don't ever you will never
  27059. 17:23:16ever ever need to know this. Um but
  27060. 17:23:19right here we're going to basically
  27061. 17:23:21connect [clears throat] to the website.
  27062. 17:23:22So, I'm just going to say connect to
  27063. 17:23:24website and we're going to say URL is
  27064. 17:23:27equal to and let's go get our
  27065. 17:23:30[clears throat] URL.
  27066. 17:23:32So, we have this right here. So,
  27067. 17:23:33literally just go up here, do you know
  27068. 17:23:36uh control A, copy that. Oops, that's
  27069. 17:23:40the actual project. Get rid of that.
  27070. 17:23:43Uh, paste it in here. And that is our
  27071. 17:23:45URL. We will use that in just a second.
  27072. 17:23:48Uh, what am I doing?
  27073. 17:23:52me just get some room here. And then we
  27074. 17:23:55what we're going to need is something
  27075. 17:23:57called headers. Now again, you will
  27076. 17:24:00never ever ever need to know this. So
  27077. 17:24:02I'm just going to say headers. Um what
  27078. 17:24:04I'm going to do is I'm going to copy
  27079. 17:24:05this. I'm going to show you how to get
  27080. 17:24:06this really quick. Um but is something
  27081. 17:24:09called headers. So
  27082. 17:24:14uh let me show you how to use how to get
  27083. 17:24:16this
  27084. 17:24:18and why you don't need to know any of
  27085. 17:24:20this. So, what this headers is is this
  27086. 17:24:22something called a user agent. You need
  27087. 17:24:24to do this for your computer. Um, and
  27088. 17:24:27you can do that by going to this link
  27089. 17:24:29right here. So, I'm going to put this
  27090. 17:24:31link in the description so that you can
  27091. 17:24:33go and get that. And there's something
  27092. 17:24:34right here called the user agent. So,
  27093. 17:24:37all you have to do is copy this just
  27094. 17:24:40like this. Do copy. I'm going to go back
  27095. 17:24:43here and I'll show you that it's I'm
  27096. 17:24:45going to copy it in. Um, it'll be the
  27097. 17:24:47exact same. So, there you go.
  27098. 17:24:50It's the exact same um [clears throat]
  27099. 17:24:53all of this extra stuff except encoding
  27100. 17:24:57except um this HTML stuff connection
  27101. 17:25:01close all the you don't need to know any
  27102. 17:25:02of it. I promise you'll never come in
  27103. 17:25:04handy ever in life.
  27104. 17:25:06Actually there will be one person who
  27105. 17:25:08that becomes in handy for and then
  27106. 17:25:09they'll message me. Um but we are now
  27107. 17:25:13connecting um using our computer using
  27108. 17:25:16this URL and then what we want to write
  27109. 17:25:19is we want to write page we're going to
  27110. 17:25:22say equals and this is where we start
  27111. 17:25:23using uh these libraries. So we're going
  27112. 17:25:25to use requests.get
  27113. 17:25:28and we are going to pull in that URL and
  27114. 17:25:31we're just going to say headers is equal
  27115. 17:25:34to our headers right here. So, uh, we
  27116. 17:25:38have this, and this is where we're going
  27117. 17:25:40to actually start
  27118. 17:25:43getting the data, bringing in the data.
  27119. 17:25:46Um, and it's not going to look like that
  27120. 17:25:47at first, but I'll try to print some
  27121. 17:25:49stuff out as we go along the way so that
  27122. 17:25:52you can kind of see what it looks like
  27123. 17:25:53and how we're going to kind of make it
  27124. 17:25:55more useful because it comes in very
  27125. 17:25:57dirty uh, when we first get it. And some
  27126. 17:26:00of the things I'm going to show you will
  27127. 17:26:01just help clean that up. Um, and before
  27128. 17:26:04we actually go any any further, I don't
  27129. 17:26:06want my head to be here for the entire
  27130. 17:26:07time. I'm going to get rid of myself so
  27131. 17:26:08you can just see the page. Uh, I just
  27132. 17:26:12it's less distracting. Uh, I hate when I
  27133. 17:26:15feel like people are always watching me.
  27134. 17:26:16So, I want people to just focus on the
  27135. 17:26:18code. Uh, so I will see you in a little
  27136. 17:26:21bit. Let's get back into it. All right.
  27137. 17:26:23So, what we are going to do is we are
  27138. 17:26:24actually going to start using the
  27139. 17:26:26beautiful soup library. All right. So,
  27140. 17:26:28we are going to say soup one is equal
  27141. 17:26:31to, and this is where we actually start
  27142. 17:26:33bringing beautiful soup. And you guessed
  27143. 17:26:34it, you're going to say beautiful soup.
  27144. 17:26:36And then in parenthesis, we're going to
  27145. 17:26:38do page.content.
  27146. 17:26:40Um, and again, these aren't really
  27147. 17:26:43things that you need to remember or need
  27148. 17:26:45to memorize. We're just pulling in the
  27149. 17:26:47content from the page. That's really all
  27150. 17:26:49we're doing right now. And it comes in
  27151. 17:26:51as HTML. So, we're going to do
  27152. 17:26:52HTML.parser.
  27153. 17:26:55Uh, and let's see if I can print out.
  27154. 17:26:57Uh, actually, let me just do soup one. I
  27155. 17:27:00don't like I don't like doing uppercaps
  27156. 17:27:01on stuff.
  27157. 17:27:03Let's see if anything prints out real
  27158. 17:27:05quick. So, we are literally pulling in
  27159. 17:27:09all of the HTML.
  27160. 17:27:11Um, and let me go show you really quick
  27161. 17:27:14because we're going to get to this in a
  27162. 17:27:15second anyways. Um, if you come here,
  27163. 17:27:19this is this is a static page basically
  27164. 17:27:23written in HTML. Um, if you have never
  27165. 17:27:25seen HTML before, um, you know,
  27166. 17:27:29actually a lot of this is, you know,
  27167. 17:27:32just stuff that most people will never
  27168. 17:27:34use. Uh, it's just good to know. Some of
  27169. 17:27:37this stuff is good to know. So, as you
  27170. 17:27:38see, I'm scrolling on this right side.
  27171. 17:27:39By the way, I did rightclick and inspect
  27172. 17:27:42or control shift I, whichever one works
  27173. 17:27:45better for you. But, as I'm scrolling
  27174. 17:27:47over this, you should see it kind of
  27175. 17:27:48highlighting different areas. Um, it's
  27176. 17:27:51hard to kind of get what you want. Let's
  27177. 17:27:52say we want this title. Um, what I can
  27178. 17:27:55do is I can click select element, go
  27179. 17:27:58right here. Um, and then we can select
  27180. 17:28:00like a t the the the header or the title
  27181. 17:28:02of the the page. Now, I just want to
  27182. 17:28:05show you though of what we're pulling
  27183. 17:28:07in. So, we're pulling in this doc type
  27184. 17:28:09HTML. All of this is coming in. So,
  27185. 17:28:12that's what this is right here. This doc
  27186. 17:28:14type HTML and we're pulling every single
  27187. 17:28:17thing in. That is what we're doing right
  27188. 17:28:19now. Uh so let's get or let's go down a
  27189. 17:28:23little bit. Let's do soup two. We're
  27190. 17:28:25just going to do a very uh you know uh
  27191. 17:28:27an upgrade to soup one basically. We'll
  27192. 17:28:30do beautiful soup again.
  27193. 17:28:34And then we're going to do uh soup one.
  27194. 17:28:37So we're pulling in that content again.
  27195. 17:28:40So that's soup one. And we're going to
  27196. 17:28:42do
  27197. 17:28:44pritify. Uh, if you don't know what that
  27198. 17:28:46is, it is common in a lot of different
  27199. 17:28:49languages and a lot of different stuff.
  27200. 17:28:51Um, it just makes things look better. It
  27201. 17:28:54that's really all it is.
  27202. 17:28:57Uh, I don't know why I'm using double
  27203. 17:28:59quotes.
  27204. 17:29:01I don't know why I can. You can do
  27205. 17:29:03single ones if you want. Um, and now
  27206. 17:29:04let's do beautiful soup 2. And it should
  27207. 17:29:07just be a it should be better formatted.
  27208. 17:29:10Um, and let's see if that's true. And it
  27209. 17:29:13is. So, before if you did, if you can
  27210. 17:29:15tell, it was it didn't have basically
  27211. 17:29:16any formatting. It has a little bit of
  27212. 17:29:17formatting now. Um, it'll help in a
  27213. 17:29:20second. Um, and you'll see that. But
  27214. 17:29:24now, [clears throat] what we want to do
  27215. 17:29:25is go back and we want to actually get
  27216. 17:29:27the data that we want. Now, you can get
  27217. 17:29:29any data you want. I'm going to show you
  27218. 17:29:32simple things, really, really easy. Um,
  27219. 17:29:35in my in my in in my opinion, it gets
  27220. 17:29:38more difficult the more complicated
  27221. 17:29:40stuff you start pulling. Um and and
  27222. 17:29:42you'll understand that as we go into it.
  27223. 17:29:45So what I'm going to do is I'm going to
  27224. 17:29:46select this and I'm going to select this
  27225. 17:29:49um the title. I want that. And so if you
  27226. 17:29:52do span ID, it's equal to product uh
  27227. 17:29:56title. So we need to remember that. Um
  27228. 17:29:58class, we don't need to know class, I
  27229. 17:30:01believe.
  27230. 17:30:03Uh we're going to be [clears throat]
  27231. 17:30:03using that ID, this um ID equals product
  27232. 17:30:07title. So that's what we're going to be
  27233. 17:30:08using. um class will come in in the next
  27234. 17:30:11video when we start looking at these uh
  27235. 17:30:13but not in this one. So let's remember
  27236. 17:30:16ID equals product title. So let's go
  27237. 17:30:18back over here. So we have this soup 2.
  27238. 17:30:21It's basically all of that HTML in it
  27239. 17:30:24right down here. That that is what we're
  27240. 17:30:26pulling in. So we need to kind of
  27241. 17:30:27specify what we actually want. So let's
  27242. 17:30:30say title. That's what we're going to be
  27243. 17:30:31getting. Um and we're going to do soup
  27244. 17:30:342. So using taking all that content and
  27245. 17:30:37we're do find and we're going to do open
  27246. 17:30:40parenthesis and we're going to say we
  27247. 17:30:41want to find that ID where it's equal to
  27248. 17:30:45product title
  27249. 17:30:48and then we're going to do dot get
  27250. 17:30:52text and then we're going to do open
  27251. 17:30:55parenthesis. So now let's um
  27252. 17:30:58[clears throat] let's print the title
  27253. 17:31:02and see what we get. All right. So that
  27254. 17:31:04is exactly what we're looking for. It's
  27255. 17:31:06funny got data MIS um t-shirt. That that
  27256. 17:31:12is what we're trying to pull in. So
  27257. 17:31:13that's perfect. That's exactly what we
  27258. 17:31:15want. We don't uh let me let me me just
  27259. 17:31:18do this. Save me some time later on. We
  27260. 17:31:21don't only want the title. We are also
  27261. 17:31:22going to be pulling in the price. So if
  27262. 17:31:25[clears throat] you can guess uh we'll
  27263. 17:31:27be doing some uh a data set on the
  27264. 17:31:31actual pricing.
  27265. 17:31:33Um, and so let's go back here. We're
  27266. 17:31:36going to again use this right here and
  27267. 17:31:38we're going to go to this price.
  27268. 17:31:41And it says again, we're going to look
  27269. 17:31:43at this ID. The ID equals price block
  27270. 17:31:46our price. So fairly easy. You can copy
  27271. 17:31:49this. I'm just going to write it out.
  27272. 17:31:51Um, we're going to say price is equal to
  27273. 17:31:55soup 2.find.
  27274. 17:31:58And then it's going to be again ID is
  27275. 17:32:01equal to and then it's going to be price
  27276. 17:32:03block_rric.
  27277. 17:32:06Did I spell that right? Oops.
  27278. 17:32:10Excuse me. [clears throat] There we go.
  27279. 17:32:12And the exact same thing.get
  27280. 17:32:15text
  27281. 17:32:17parenthesis.
  27282. 17:32:18Uh, and there's a get text, there's a
  27283. 17:32:20get all or get all text. Um, so you know
  27284. 17:32:24that get text is a specific thing that
  27285. 17:32:26we are using. you we might use a
  27286. 17:32:29different one later on. Um but that that
  27287. 17:32:32is what we have. So now let's
  27288. 17:32:35let's print the title and print what why
  27289. 17:32:38do I have all this
  27290. 17:32:41too much uh too much space? So let's t
  27291. 17:32:44print the title and print the price. Now
  27292. 17:32:47let's see what we get. Okay, so we have
  27293. 17:32:49[clears throat] our title and we have
  27294. 17:32:51our price. I mean, you know, I don't
  27295. 17:32:53know what all this white space is over
  27296. 17:32:54here. Um, but it looks like there's a
  27297. 17:32:57lot of white space over here. We'll have
  27298. 17:32:59to get rid of that uh in a little bit as
  27299. 17:33:01we clean it up a little bit. You can, if
  27300. 17:33:05you want, do things like um you can get,
  27301. 17:33:10and this is up to you. I'm not going to
  27302. 17:33:11do this right now, but I'm just going to
  27303. 17:33:12show you how to do it. you can get this
  27304. 17:33:14where you're pulling in the ratings um
  27305. 17:33:17which is you know if you want to look at
  27306. 17:33:20like how the ratings over time or or
  27307. 17:33:22what ratings are for specific products
  27308. 17:33:24that could be really useful. Um you can
  27309. 17:33:27pull basically anything you can go down
  27310. 17:33:29the product details and look at
  27311. 17:33:30dimensions uh anything you want on this
  27312. 17:33:33page. It is static so you can go in here
  27313. 17:33:37and pull anything. It's you just have to
  27314. 17:33:39pull it from the HTML know where you're
  27315. 17:33:40looking pull it in. Um, and now when we
  27316. 17:33:43go back here, excuse me. I'm going to
  27317. 17:33:45show you now kind of how to use this,
  27318. 17:33:47right? Because we have this, but how are
  27319. 17:33:50we going to use it? Um, that's kind of
  27320. 17:33:52the important part, I think. First thing
  27321. 17:33:54we need to do is clean this up a little
  27322. 17:33:56bit because it it just is, you know, if
  27323. 17:34:01we try to use this, it wouldn't be super
  27324. 17:34:03useful because it'd be it's just a
  27325. 17:34:05little bit dirty. It's not super clean.
  27326. 17:34:08Um, so what we want to do is let's start
  27327. 17:34:11with the price. Why not? Uh, we're going
  27328. 17:34:14to say price.
  27329. 17:34:16Um, and that's just going to take uh
  27330. 17:34:19basically the the junk off of either
  27331. 17:34:22side. And so let's run that real quick.
  27332. 17:34:25So this is what we have. But what we can
  27333. 17:34:27also do is I don't want that dollar
  27334. 17:34:29sign. I just want the numeric value. Um
  27335. 17:34:32later on we are going to be putting this
  27336. 17:34:33and we're going to be um creating a
  27337. 17:34:35process to put this into an Excel file.
  27338. 17:34:38Again, we're trying to create a data
  27339. 17:34:40set. I don't want you to have to copy
  27340. 17:34:41and paste stuff. This is all going to be
  27341. 17:34:43automated basically to input this data
  27342. 17:34:46into an Excel file for you or a CSV file
  27343. 17:34:48for you. So um you know, think about
  27344. 17:34:51making it useful in a CSV or in an Excel
  27345. 17:34:54later on. So what we can do is do a
  27346. 17:34:57bracket and we're going to do one and
  27347. 17:35:00then everything after that. So basically
  27348. 17:35:01it's just going to take everything from
  27349. 17:35:03the first position onward. Uh so let's
  27350. 17:35:06run that and there we go. So let's just
  27351. 17:35:09say price is equal to price.
  27352. 17:35:13Um and pull uh just do everything after
  27353. 17:35:16that first um that first not value. What
  27354. 17:35:20am I saying? What's the word for that? I
  27355. 17:35:22can't remember the word. The first
  27356. 17:35:23space. That's not the right word, but
  27357. 17:35:25all right, let's do the title. Um, this
  27358. 17:35:27is basically going to be the exact same
  27359. 17:35:29thing. Um, super easy. So, we're just
  27360. 17:35:31going to do title strip and open
  27361. 17:35:34parentheses. Um, and we can, you know,
  27362. 17:35:38if you want to do this exact same thing.
  27363. 17:35:42So, now we have it. It's a little bit
  27364. 17:35:43cleaner. So, this is what it originally
  27365. 17:35:44looked like. And now this is what it
  27366. 17:35:46looks like. So, you know, nothing super
  27367. 17:35:51crazy, but you know, something
  27368. 17:35:52interesting to know. Now we are about to
  27369. 17:35:56in the very next part what we are going
  27370. 17:35:58to do let me just add a few of these
  27371. 17:36:00because makes me feel better. Um what we
  27372. 17:36:02are about to do is we're going to create
  27373. 17:36:05our CSV to insert this data into the CSV
  27374. 17:36:08and then later on what I'm going to do
  27375. 17:36:10is show you kind of how to um automate
  27376. 17:36:12this process to pull this data um
  27377. 17:36:17to create a data set. Right? Just
  27378. 17:36:18pulling this one time and putting it
  27379. 17:36:19into a CSV really doesn't do anything.
  27380. 17:36:21you can just copy and paste that and
  27381. 17:36:23save yourself a lot of time. Um, what
  27382. 17:36:25I'm going to show you is is um basically
  27383. 17:36:28doing it over over time and just having
  27384. 17:36:31it automated in the background. That is
  27385. 17:36:33what I'm going to show you. Um, I guess
  27386. 17:36:34a spoiler, but what we need to do is we
  27387. 17:36:38need to
  27388. 17:36:40create uh create the CSV, insert it into
  27389. 17:36:44the CSV, and then create a process to
  27390. 17:36:46append more data into that CSV. Um, I'm
  27391. 17:36:50doing a lot of talking. Let's do some
  27392. 17:36:51writing. So, what we need to do is we're
  27393. 17:36:54going to use um I should have done this
  27394. 17:36:56at the top. Maybe I'll go back and add
  27395. 17:36:59that later on. We're going to do import
  27396. 17:37:01CSV. Now, in a CSV, what you want is you
  27397. 17:37:04want headers and then you want the data,
  27398. 17:37:06right? So, for our headers, and we're
  27399. 17:37:08going to call it header. We're going to
  27400. 17:37:10do um we're going to do a bracket. And
  27401. 17:37:12let's make the first one a title because
  27402. 17:37:16that's going to be uh we can call it
  27403. 17:37:18title. You can call it product, whatever
  27404. 17:37:21you want. I'm just going to call it
  27405. 17:37:22because I've been using title, I'm going
  27406. 17:37:23to call it title. And then we'll also
  27407. 17:37:25have
  27408. 17:37:27price.
  27409. 17:37:29Now, we need our data. So, I'm going to
  27410. 17:37:31say data is equal to. Now, this is
  27411. 17:37:33important. Um, right now,
  27412. 17:37:35[clears throat] how our data is, and I
  27413. 17:37:37can do this right here. We're going to
  27414. 17:37:38do type um title or no, let's do type
  27415. 17:37:42price.
  27416. 17:37:44So, these are strings. And that's
  27417. 17:37:46important to know. Um, again, I don't
  27418. 17:37:49want to get too much into, you know,
  27419. 17:37:51dictionaries and arrays and lists and
  27420. 17:37:53and strings and all these things, but
  27421. 17:37:55this is a string and you can't put
  27422. 17:37:57[clears throat] that right now. It's not
  27423. 17:37:59super usable. What we're going to do is
  27424. 17:38:01make this a list. Um, and so I'm doing
  27425. 17:38:05an open bracket and I'm going to say our
  27426. 17:38:07data is title,
  27427. 17:38:11price. Oops, price. Now, oops. If I do
  27428. 17:38:18type oops of data, I'll just run that.
  27429. 17:38:22It's a list now. Um, and this is
  27430. 17:38:24important because you can run into a lot
  27431. 17:38:27of issues with this stuff. It's really
  27432. 17:38:29important to remember what what type um
  27433. 17:38:34how do I say this? Uh, how your data is.
  27434. 17:38:37Is it a list? Is it an array? Is it a
  27435. 17:38:39dictionary? Um, you know, what is it?
  27436. 17:38:42These things are important. they do play
  27437. 17:38:44a big impact especially with this type
  27438. 17:38:46of stuff. So just want to show you that
  27439. 17:38:47really quick. But what we are now going
  27440. 17:38:50to do is create a CSV. Um you're create
  27441. 17:38:54an Excel. I I call an Excel CSV, you
  27442. 17:38:57know, whatever you want to call it. So
  27443. 17:38:59what we are going to do is we're going
  27444. 17:39:01to say with and we're going to say open.
  27445. 17:39:04And now we're going to name our file.
  27446. 17:39:06You can name this whatever you want. I'm
  27447. 17:39:08going to call it uh
  27448. 17:39:12um Amazon
  27449. 17:39:16Web Scraper
  27450. 17:39:18data set. That's real long. Uh CSV. And
  27451. 17:39:22we're going to do underscore W and that
  27452. 17:39:24means write.
  27453. 17:39:27Um oh, whoops. That's not right. Just
  27454. 17:39:30like I was wondering why that was uh in
  27455. 17:39:32black. Uh so we're going to do W, which
  27456. 17:39:34means write. Um, and then we're going to
  27457. 17:39:36do new line. And if you don't know what
  27458. 17:39:39new line is, uh, all that does is when
  27459. 17:39:42we insert the data, it doesn't have a a
  27460. 17:39:45space in between each CSV. And then we
  27461. 17:39:48are going to do encoding
  27462. 17:39:51is equal to oops is equal to UTF8.
  27463. 17:39:58And that is it. And we'll just say as
  27464. 17:40:00uh, let's do f. So some of
  27465. 17:40:03[clears throat] that stuff you don't
  27466. 17:40:04need to know. Some of it's useful. This
  27467. 17:40:06W definitely needs to know. This new
  27468. 17:40:08line is is good to know. And um I'll
  27469. 17:40:10take it I might take it out just to show
  27470. 17:40:12you what it actually does because it's
  27471. 17:40:13annoying if you don't have it. I
  27472. 17:40:15promise. Um but you know that that new
  27473. 17:40:18line is important. This encoding, you
  27474. 17:40:20know, good to know. I think that's by
  27475. 17:40:22default is is it's like that. Uh
  27476. 17:40:24anyways, what we're going to do now is
  27477. 17:40:26we're going to uh it's something within
  27478. 17:40:28the CSV
  27479. 17:40:30within the CSV um library. So, we're
  27480. 17:40:33going to do something called CSV writer
  27481. 17:40:37and oops CSV.riter
  27482. 17:40:41and we're going to do open parenthesis
  27483. 17:40:43and that is that and we'll just call
  27484. 17:40:45that writer
  27485. 17:40:48and then we'll do and this is where we
  27486. 17:40:51need to [clears throat] actually create
  27487. 17:40:52the header. So uh we're going to do
  27488. 17:40:54writer is dot sorry writer.right
  27489. 17:40:59row uh and this is just for the initial
  27490. 17:41:05um the initial
  27491. 17:41:07import or or or um not import the
  27492. 17:41:11initial insertion of the data into the
  27493. 17:41:13CSV. This is what's important. The next
  27494. 17:41:15one that we're going to write is for
  27495. 17:41:17when we're actually appending the data,
  27496. 17:41:18which is going to be a little bit
  27497. 17:41:19different. But anyways, we're going to
  27498. 17:41:21do write
  27499. 17:41:21>> [clears throat]
  27500. 17:41:21>> row open parenthesis. And this is where
  27501. 17:41:24that header is going to go. So, we're
  27502. 17:41:26going to the these headers are going to
  27503. 17:41:28be the title and the price.
  27504. 17:41:31And then for our last one, we're going
  27505. 17:41:32to actually write the data, which is
  27506. 17:41:34this data right here. And we're going to
  27507. 17:41:36say writer
  27508. 17:41:38write row. And we're going to do data.
  27509. 17:41:42So this one we are creating the CSV
  27510. 17:41:46and then we are inserting the header and
  27511. 17:41:49inserting the data. So super easy. Um
  27512. 17:41:54yeah I think that's fairly
  27513. 17:41:55straightforward right now. Let's do this
  27514. 17:41:59and let's see what happens. So I just
  27515. 17:42:02ran it. Um let's go over here in here
  27516. 17:42:06somewhere. Amazon web scraper data set.
  27517. 17:42:10Let's open that up.
  27518. 17:42:13And there we go. Oh jeez.
  27519. 17:42:16This isn't good. Can't verify my um
  27520. 17:42:21my subscription. Uh why does it say
  27521. 17:42:23$6.99? Uh I'm going to go back and look,
  27522. 17:42:26but I think I know the issue. Um but
  27523. 17:42:30this is exactly what we want. Now, of
  27524. 17:42:32course, we want more data and maybe a
  27525. 17:42:34little bit more useful data. Um and I'll
  27526. 17:42:36show you how to get that in just a
  27527. 17:42:37second, but we just created that out of
  27528. 17:42:40thin air. Uh that was not I didn't have
  27529. 17:42:42that saved before. So we have this data
  27530. 17:42:44set and the issue was is that I ran this
  27531. 17:42:48multiple times. So now it's 699. If I do
  27532. 17:42:51it again it's 99. Uh and if I did it
  27533. 17:42:54again it's you got it gets rid of
  27534. 17:42:55everything. So I'm just going to run
  27535. 17:42:56this again. Run this again.
  27536. 17:43:01Uh now everything's back to normal.
  27537. 17:43:04Okay. So now if we run this, it's going
  27538. 17:43:07to overwrite this Amazon Web Scraper
  27539. 17:43:10data set.csv
  27540. 17:43:11and it will put the data in properly. So
  27541. 17:43:15there we go. Oh jeez, guys. This is
  27542. 17:43:18embarrassing.
  27543. 17:43:20I'm embarrassed.
  27544. 17:43:22No, I don't want this. Okay, perfect.
  27545. 17:43:26Um, guys, I if you can't tell, I'm in
  27546. 17:43:30need of some um I'm in need of I'm in
  27547. 17:43:33need of some help here, but [laughter]
  27548. 17:43:36I'm just kidding. I'm I'm doing fine. Uh
  27549. 17:43:38I just I don't know why that uh I don't
  27550. 17:43:41have my uh subscription activated. It's
  27551. 17:43:43not going to matter for this video, I
  27552. 17:43:45guess, but that's really random. Um so,
  27553. 17:43:47we got what we need. That's perfect.
  27554. 17:43:50Now what we want to do after this um I
  27555. 17:43:54guess actually what is important is some
  27556. 17:43:56more useful data. Something that I like
  27557. 17:44:00to do a lot when I do this type of this
  27558. 17:44:02type of stuff is I like to have some
  27559. 17:44:04type of date stamp um or some type of
  27560. 17:44:06timestamp to know when I collected this
  27561. 17:44:09data. It usually comes in handy later
  27562. 17:44:11on. Um I I have never regretted putting
  27563. 17:44:14it in there. I'll show you really quick
  27564. 17:44:16how you can do it. Uh, you're going to
  27565. 17:44:17do import datetime.
  27566. 17:44:20Jeez, I hate having to format stuff like
  27567. 17:44:22that. And what you can do is you can do
  27568. 17:44:24date. Let me get date time. And you do
  27569. 17:44:29date today open parenthesis. And that is
  27570. 17:44:33going to give us this right here. Uh,
  27571. 17:44:36and so we're just going to do um today,
  27572. 17:44:39that's what we'll call it, is equal to
  27573. 17:44:41this.
  27574. 17:44:42And we'll say print today. And there we
  27575. 17:44:46go. So that is today's date is the 21st
  27576. 17:44:49of August in 2021.
  27577. 17:44:52So today is now um is now this.
  27578. 17:44:55[clears throat] So actually I'm going to
  27579. 17:44:57get rid of that. I'm going to put it
  27580. 17:44:59back up here. I'm going to put it right
  27581. 17:45:02there. I'm going to run it again. Let's
  27582. 17:45:05add this right here. We'll do um
  27583. 17:45:10we'll do we'll call it date
  27584. 17:45:13and then we'll add today.
  27585. 17:45:17And we'll just run this again.
  27586. 17:45:19And what we can do just to check the
  27587. 17:45:24data without having to open up the data
  27588. 17:45:26every single time, which is super
  27589. 17:45:27annoying, is we're going to use pandas.
  27590. 17:45:29Again, I should have imported this at
  27591. 17:45:31the top. I'm just kind of um I'm not
  27592. 17:45:33doing this off the top of my head, but
  27593. 17:45:35uh I didn't have it 100% planned. So,
  27594. 17:45:37import pandas and we're just going to
  27595. 17:45:38say pdread_csv
  27596. 17:45:42and then we'll read it in. Um, what you
  27597. 17:45:45can do or what I often do is I go to
  27598. 17:45:48properties and I go right here
  27599. 17:45:55and we'll say boom boom backslash
  27600. 17:46:01this right here. This I am doing off the
  27601. 17:46:03top of my head. I don't do this often. I
  27602. 17:46:04think I have this memorized by now. Uh,
  27603. 17:46:06I I I hope. And then we'll do print. Oh,
  27604. 17:46:11no. We don't have to do print. We'll
  27605. 17:46:12just do this. uh what I do our uh let's
  27606. 17:46:15actually call this um data frame and
  27607. 17:46:20we'll do print.
  27608. 17:46:23Let's see what happens. Perfect.
  27609. 17:46:25[clears throat] Okay. So, what we have
  27610. 17:46:27now is the new our new header, our new
  27611. 17:46:30data that we added in there. So, we have
  27612. 17:46:33our title, we have our price, and we
  27613. 17:46:36have our date. Now, again, you can
  27614. 17:46:38customize this whatever you want to add.
  27615. 17:46:39go back here. Um, you know, find what
  27616. 17:46:42you want. You know, do you want it to
  27617. 17:46:44make sure it has a men's option or
  27618. 17:46:47different colors or you want to pull in
  27619. 17:46:49this information? Whatever you want. It
  27620. 17:46:51it really does not matter. Um, just
  27621. 17:46:53matters that you know, you get what you
  27622. 17:46:56need for whatever purpose, whatever
  27623. 17:46:58you're making this for. This is more of
  27624. 17:46:59an introductory video to how to scrape
  27625. 17:47:02data from Amazon. Um the next video will
  27626. 17:47:04probably be a little bit more difficult
  27627. 17:47:06and in-depth, but this is kind of let's
  27628. 17:47:08get you guys started. So um we now have
  27629. 17:47:11this and this is beautiful.
  27630. 17:47:14Now, something that
  27631. 17:47:18you want to do when you're scraping data
  27632. 17:47:21and you're getting um I [clears throat]
  27633. 17:47:24guess data over time, and that's kind of
  27634. 17:47:25what we're doing. It's going to be
  27635. 17:47:27almost like um a price tracker
  27636. 17:47:29[clears throat] over time is you want to
  27637. 17:47:32then append data to this. So, we can't
  27638. 17:47:36only create it. And that's what this
  27639. 17:47:38does because if I run this a 100 times,
  27640. 17:47:39it'll only give me this first row. we
  27641. 17:47:41need to now append data to this. So, um
  27642. 17:47:45let's
  27643. 17:47:46let's pull this down here. Um again, I'm
  27644. 17:47:50I'm not I haven't added a bunch of
  27645. 17:47:52notes. I'm going to say now we are
  27646. 17:47:55appending data to this CSV. I haven't
  27647. 17:47:58added a ton of notes. I'll try to go
  27648. 17:47:59back maybe afterwards and add some notes
  27649. 17:48:01for people who like to read notes. Um
  27650. 17:48:05[clears throat]
  27651. 17:48:06so, what we are now going to do is we're
  27652. 17:48:07going to change this W to an A+. Now,
  27653. 17:48:10this is going to be how we append the
  27654. 17:48:13data. Um, and we no longer need the
  27655. 17:48:15header. So, we don't aren't going to do
  27656. 17:48:17the header anymore. And there we go. So,
  27657. 17:48:20now instead of
  27658. 17:48:22excuse me, so now instead of creating
  27659. 17:48:24that header again, creating that first
  27660. 17:48:26row of data again, we are ignoring the
  27661. 17:48:30data and we're now going to the next
  27662. 17:48:31nearest free row and appending data,
  27663. 17:48:35which means to add on data to that. Um,
  27664. 17:48:39and so if I run this, which I'm not
  27665. 17:48:40going to right now, oh, I mean, why not?
  27666. 17:48:43I can I can run it. Um, and then we can
  27667. 17:48:45read this in. So now there there's our
  27668. 17:48:48data. I'll run it a few more times.
  27669. 17:48:51I ran it like three or four more times.
  27670. 17:48:53I I run that in. And there we go. Now
  27671. 17:48:55it's all the exact same data. Super um
  27672. 17:48:57boring, but very very uh, you know, good
  27673. 17:49:02to have. Now, we don't want to have to
  27674. 17:49:04come in here and run this every day.
  27675. 17:49:06Let's say we're going to do this daily.
  27676. 17:49:08Um, we don't want to have to come and
  27677. 17:49:09write run this every single day, right?
  27678. 17:49:11We want a way where it does it while we
  27679. 17:49:14sleep. It does it in the background of
  27680. 17:49:16our laptop. Um, and is easy to do,
  27681. 17:49:18right? I don't want to come in here
  27682. 17:49:21every single morning with set an alarm
  27683. 17:49:22on my phone every single morning. Come
  27684. 17:49:24in here. I want to automate this.
  27685. 17:49:27[clears throat] So, uh, how are we going
  27686. 17:49:29to do that? Give me one second. Uh, if
  27687. 17:49:32you didn't know, I have three kids and
  27688. 17:49:34one of them is waking up. I will be
  27689. 17:49:35right back. All right. I think he is
  27690. 17:49:38asleep. Um, at least let's hope he's
  27691. 17:49:40asleep. So, now what we're
  27692. 17:49:42[clears throat] going to do is we are
  27693. 17:49:43going to
  27694. 17:49:45put this all
  27695. 17:49:48into
  27696. 17:49:50uh this check
  27697. 17:49:53price.
  27698. 17:49:55[clears throat] Now, you may never have
  27699. 17:49:57used Oh jeez, what are these things
  27700. 17:49:59called? Oh my gosh. Super
  27701. 17:50:03used all the time. you'll know what I
  27702. 17:50:06what it is. Uh
  27703. 17:50:09not a function. I don't even remember
  27704. 17:50:11what it's called. Maybe there's a
  27705. 17:50:13function. Um I can't think. I'm having
  27706. 17:50:15like a writer's block or whatever that
  27707. 17:50:17is. We're going to put it all in here
  27708. 17:50:19and then we're going to be able to use
  27709. 17:50:20this price check later. Um because we
  27710. 17:50:22want to be able to automate this. So,
  27711. 17:50:24let's go back all the way up here.
  27712. 17:50:27We are going to use this. So, let's copy
  27713. 17:50:30all of that in
  27714. 17:50:34and oh jeez, I hate this.
  27715. 17:50:41All right. Everything just like that.
  27716. 17:50:43Um, so this pulls in our data.
  27717. 17:50:46Pulls in uh or or yeah, pulls in all of
  27718. 17:50:49our data down to the title and the
  27719. 17:50:51price. We want to
  27720. 17:50:54make it look right.
  27721. 17:50:58So, we're going to put it right here.
  27722. 17:51:01So, now we have it formatted properly.
  27723. 17:51:04Um, we want to add our date time.
  27724. 17:51:11Just like that. I don't know if there's
  27725. 17:51:14a better I'm sure there's a better way
  27726. 17:51:15to do this.
  27727. 17:51:17Um, then we need
  27728. 17:51:21this right here.
  27729. 17:51:27And just like that. Like that. So now we
  27730. 17:51:29have our header and our data. And then
  27731. 17:51:31we want to pull this in right here.
  27732. 17:51:36Boom. Boom. Boom. Okay.
  27733. 17:51:40[clears throat] So everything that we
  27734. 17:51:42just wrote out, we are now putting into
  27735. 17:51:45this check price. Uh you can call it
  27736. 17:51:48whatever you want. Doesn't matter. But
  27737. 17:51:51let's run that. See if we get any
  27738. 17:51:52errors. We don't. So this is now good to
  27739. 17:51:56go. Basically
  27740. 17:51:58um what we are going to use this for um
  27741. 17:52:02and what this is going to do is we are
  27742. 17:52:04going to put this on a timer. Um you
  27743. 17:52:06know have you ever wanted to like check
  27744. 17:52:09something once a day, once every 10
  27745. 17:52:12seconds, once a minute, whatever you
  27746. 17:52:14want and you don't want to have to
  27747. 17:52:15actually pull up your phone and look at
  27748. 17:52:17it. This is how we are going to do that.
  27749. 17:52:19So, we had something called, let's see,
  27750. 17:52:23time. This this library time right here.
  27751. 17:52:25That's what we're going to use right
  27752. 17:52:26now. So, we're going to say while oops,
  27753. 17:52:31while true
  27754. 17:52:34and go like [snorts] this, do a colon.
  27755. 17:52:37We're going to say check price. That's
  27756. 17:52:40what we just wrote out. And we're going
  27757. 17:52:43to do time.
  27758. 17:52:45Now, this is completely up to you how
  27759. 17:52:49much time you want to put in here. For
  27760. 17:52:51the purposes of demonstration, I'm going
  27761. 17:52:53to put 5 seconds, which means every 5
  27762. 17:52:57seconds, it is going to run through this
  27763. 17:52:59entire process. And so, let's run this
  27764. 17:53:02really quick. And I'm going to run it
  27765. 17:53:04for let's say 30 seconds. And then I'm
  27766. 17:53:07going to
  27767. 17:53:09pull this in right here.
  27768. 17:53:13So, we just looked at it earlier. We had
  27769. 17:53:15four um well, five [clears throat] rows
  27770. 17:53:19of data, right? What we are going to do
  27771. 17:53:22is in just a second I'm going to stop
  27772. 17:53:24this, you know, maybe after 30 seconds
  27773. 17:53:25or so and we're going to see how much
  27774. 17:53:27data is in there. Uh and let's stop it
  27775. 17:53:30right now. It's been going far enough.
  27776. 17:53:32Um and now let's run it. So, now we have
  27777. 17:53:35five, six, seven, eight. So, I guess I
  27778. 17:53:36ran for 20 seconds.
  27779. 17:53:38We can,
  27780. 17:53:40that was for demonstration purposes.
  27781. 17:53:42I've never do any some anything ever
  27782. 17:53:44every 5 seconds. Um, unless it was like
  27783. 17:53:45Black Friday on Amazon. [clears throat]
  27784. 17:53:48We can put this as
  27785. 17:53:51long or as short as you want. You can
  27786. 17:53:53run it every second if you want. Um,
  27787. 17:53:55that doesn't make sense to me, but you
  27788. 17:53:57can. What we can do is do a little bit
  27789. 17:54:00of math. Uh, and I don't know this off
  27790. 17:54:02the top of my head, so I'm going to uh
  27791. 17:54:04do the math with you live. Pretty
  27792. 17:54:07exciting stuff. Got the calculator out.
  27793. 17:54:10So, there are 60 seconds in a minute.
  27794. 17:54:14And this goes by seconds, by the way.
  27795. 17:54:16And you could do, you know, you can do
  27796. 17:54:19some um some string up here of
  27797. 17:54:23calculating this, but I'm just going to
  27798. 17:54:24put in the number because it's easier.
  27799. 17:54:27Uh maybe not easier. I'm just going to
  27800. 17:54:28do it. There's 60 seconds
  27801. 17:54:30[clears throat] um in a minute. There
  27802. 17:54:33are 60 seconds or 60 minutes in an hour.
  27803. 17:54:36So that's one hour. Uh, and we can do 24
  27804. 17:54:39hours in a day. So that that's 86,
  27805. 17:54:44400, I believe. Did I read that right?
  27806. 17:54:47Oops. Did I read that right?
  27807. 17:54:50Yes. So this now, if I ran this, and I'm
  27808. 17:54:54going to this is going to check the
  27809. 17:54:57price every single day. And this is the
  27810. 17:54:59entire point of this um of of this
  27811. 17:55:04project. Not the entire point, but this
  27812. 17:55:06is a big part of this project is we want
  27813. 17:55:08to create our own data set. Now,
  27814. 17:55:10something that I personally really love
  27815. 17:55:13is a data set that has,
  27816. 17:55:16you know, that I can do some type of
  27817. 17:55:18time series with. Now, this is not
  27818. 17:55:21exciting. It's probably not super
  27819. 17:55:23exciting for this, right? But you get
  27820. 17:55:27the idea that if this price were to
  27821. 17:55:30change, we would then see that reflected
  27822. 17:55:33in the data at some point.
  27823. 17:55:35You can do this on any item you could
  27824. 17:55:38ever imagine on Amazon. It's the exact
  27825. 17:55:40same process and some items change
  27826. 17:55:43often. This t-shirt will most likely
  27827. 17:55:46never change. Um, and so, you know,
  27828. 17:55:48again, this is for demonstration
  27829. 17:55:50purposes. The code itself will be nice
  27830. 17:55:52to put in a project, although the data
  27831. 17:55:54set that you get from this probably
  27832. 17:55:56won't be the best, I would imagine.
  27833. 17:55:59But notice that this is running. Um, I
  27834. 17:56:01can then minimize this and this can run
  27835. 17:56:04on my computer basically as long as my
  27836. 17:56:07computer uh is is working. Um, one thing
  27837. 17:56:12I will say before I go on to some more
  27838. 17:56:15stuff, one thing that I will say is that
  27839. 17:56:18I personally when I did this for a when
  27840. 17:56:21I um created this, I did something
  27841. 17:56:25similar and I put this in Visual Studio
  27842. 17:56:27Code um and I didn't put it in Jupyter
  27843. 17:56:31Notebooks. That's a personal preference.
  27844. 17:56:34I would look into that if that is
  27845. 17:56:35something that you want. Um, I think
  27846. 17:56:37Visual Studio Code is a little bit
  27847. 17:56:39easier for automating these types of
  27848. 17:56:41tasks. Um, but for illustrator purposes
  27849. 17:56:44and for demonstration purposes, you
  27850. 17:56:46cannot beat Jupyter Notebooks. That's
  27851. 17:56:48why I did it. So, with all that being
  27852. 17:56:50said, that is basically the end of the
  27853. 17:56:52project. Now, um, I'm not going to stop
  27854. 17:56:54this and read it again, but you get the
  27855. 17:56:57point. Um, we now have um a data set
  27856. 17:57:03that Oh, jeez. All this again. That now
  27857. 17:57:06has um data. I'm getting out of here. Oh
  27858. 17:57:09jeez, it's hounding me. Let me get out
  27859. 17:57:10of here. Oh no.
  27860. 17:57:13I This is embarrassing, guys. I'm
  27861. 17:57:15embarrassed. We now have a
  27862. 17:57:17[clears throat] CSV file with data in
  27863. 17:57:19it. Now, you run this in the background
  27864. 17:57:20of your computer. You can do that. I
  27865. 17:57:22have done it. I've ran it for weeks. I
  27866. 17:57:25have ran it for months. Um, if you
  27867. 17:57:27restart your computer, just come back in
  27868. 17:57:29here and restart running this process.
  27869. 17:57:31Um, it's the same for any automated
  27870. 17:57:34process unless you start using some
  27871. 17:57:36online um, automation service which will
  27872. 17:57:39run it regardless of your computer. They
  27873. 17:57:41do it, you know, either in the cloud or
  27874. 17:57:44on some um, server. So, you know that
  27875. 17:57:47this is a really good option. Again, if
  27876. 17:57:49if you restart your computer or
  27877. 17:57:51something happens, you lose connection,
  27878. 17:57:52just come in here, run this through the
  27879. 17:57:54script again. um except for the one
  27880. 17:57:57where it deletes all your data. Don't
  27881. 17:57:59run that one again. Only run that one
  27882. 17:58:01time. [clears throat]
  27883. 17:58:02Um and then you will and in fact what I
  27884. 17:58:06would do is then um I would just comment
  27885. 17:58:09this out, right? I'd come in here and I
  27886. 17:58:12would just comment this out
  27887. 17:58:14so that anytime I come back in here, I
  27888. 17:58:16would never accidentally delete all my
  27889. 17:58:18data.
  27890. 17:58:19But that is what this project does. Now,
  27891. 17:58:22something really interesting, something
  27892. 17:58:24that I have done in the past that I
  27893. 17:58:25thought was really cool, really useful.
  27894. 17:58:29I actually did it for um I actually did
  27895. 17:58:32it for some watches that I was watching,
  27896. 17:58:36especially on Black Friday. It's when I
  27897. 17:58:38used it. I was interested in a price
  27898. 17:58:42drop or a specific price change. And
  27899. 17:58:46what I did was is I said, and I don't
  27900. 17:58:50know
  27901. 17:58:52So, what I basically did was is I said
  27902. 17:58:56if the price is lower than let's say
  27903. 17:59:00let's say we wanted to drop below $14,
  27904. 17:59:04it would then send an email. Um, and I'm
  27905. 17:59:07going to show you the script that I
  27906. 17:59:09used. It still works. Um, and if this is
  27907. 17:59:12something that you are interested in,
  27908. 17:59:14this could be a completely different
  27909. 17:59:15project. I just think it's interesting
  27910. 17:59:17and I wanted to show it to you. Although
  27911. 17:59:19I wouldn't say this this is part of the
  27912. 17:59:21um final project. Let me just come in
  27913. 17:59:24here
  27914. 17:59:26and we're going to create this. Super
  27915. 17:59:31simple. Um and that's super simple.
  27916. 17:59:34We're sending a mail. We're connecting
  27917. 17:59:35to a server. We we're using Gmail. We're
  27918. 17:59:38logging into our account. That is my
  27919. 17:59:40email. You will not get my password.
  27920. 17:59:42We're creating the subject, the body. um
  27921. 17:59:45we we configure or or just kind of
  27922. 17:59:47create this message and then we send a
  27923. 17:59:49mail. So then I have this define uh or
  27924. 17:59:53this send mail. I I'm blanking on what
  27925. 17:59:56this is called. I'm going to call it a
  27926. 17:59:57function, but that's probably not right.
  27927. 17:59:59So if that price drops below a certain
  27928. 18:00:02point, it'll send me an email. Um I have
  27929. 18:00:05used this and I used it and was able to
  27930. 18:00:07buy a watch that was like, you know,
  27931. 18:00:09let's say 140 bucks for like 90 bucks um
  27932. 18:00:12on a Black Friday sale. I was really
  27933. 18:00:13really happy about that. So, this can be
  27934. 18:00:16used in that way as well. Um, not
  27935. 18:00:18something you have to write into your
  27936. 18:00:19project, just something I'm going to
  27937. 18:00:20include down here if you want to try it.
  27938. 18:00:24I think it's super interesting,
  27939. 18:00:25something really fun. Um, really fun to
  27940. 18:00:29mess around with. I enjoyed this. So,
  27941. 18:00:32with that being said, uh, this is this
  27942. 18:00:36is the project. Um I in the next one and
  27943. 18:00:39I promise you this one is probably going
  27944. 18:00:41to get a lot more
  27945. 18:00:43difficult. If you thought this one was
  27946. 18:00:45easy, which I hope maybe I hope you do,
  27947. 18:00:46then that means you're, you know, pretty
  27948. 18:00:48good at Python, you know, in the next
  27949. 18:00:51the next um web scraping project. And I
  27950. 18:00:54hope to do many of these. I might do um
  27951. 18:00:56even all the ones that I put in that
  27952. 18:00:58poll, but I started with the one that
  27953. 18:00:59was the most popular.
  27954. 18:01:01Um you know, if you were able to get
  27955. 18:01:03through this, I think that that is
  27956. 18:01:05fantastic. I think this is a solid
  27957. 18:01:08project to create um a data set and so
  27958. 18:01:12use this how you will you can copy my
  27959. 18:01:14code exactly I don't have a problem with
  27960. 18:01:16that again I don't think this is
  27961. 18:01:18beginner there are some a little bit
  27962. 18:01:20more um advanced things and I not even
  27963. 18:01:22advanced just like intermediate level
  27964. 18:01:24things um that you kind of learn as you
  27965. 18:01:26get into it and so um I hope that this
  27966. 18:01:29was instructional I hope I explained it
  27967. 18:01:31you know well um and I hope that this is
  27968. 18:01:34useful Again, you know, when you
  27969. 18:01:36actually use this, you'll have 22, 23,
  27970. 18:01:4124, 25. You know, you'll see a price
  27971. 18:01:44change, a price change, a price change,
  27972. 18:01:46a price change. Go use a product or go
  27973. 18:01:50to something that you are interested in
  27974. 18:01:51or you know, fluctuates often. Um, and
  27975. 18:01:54there are plenty of those on Amazon. I
  27976. 18:01:57promise you, there's some that literally
  27977. 18:01:58change almost every other day, like down
  27978. 18:02:00a dollar, up a dollar. Um, and then
  27979. 18:02:03Black Friday just goes crazy um, with
  27980. 18:02:06these price changes. So, use this as you
  27981. 18:02:08will. I hope that this was
  27982. 18:02:09instructional. I hope that it's useful.
  27983. 18:02:12I think I said that before is, you know,
  27984. 18:02:14I'm doing this because I think it's
  27985. 18:02:15really interesting. It's really useful.
  27986. 18:02:18Um, this to me again was a good
  27987. 18:02:22introduction,
  27988. 18:02:23a really good introduction to web
  27989. 18:02:25scraping because in this next one it
  27990. 18:02:27gets quite a bit more difficult. Um, I
  27991. 18:02:30would say on a scale of like difficulty,
  27992. 18:02:33this is like maybe a four and it'll
  27993. 18:02:35probably jump up to like a seven on this
  27994. 18:02:37next one. Um, just just much more
  27995. 18:02:41um technical or or coding heavy. So, um,
  27996. 18:02:45you know, look forward to that if that's
  27997. 18:02:47something that you look forward to. With
  27998. 18:02:49that being said, I'm going to go back
  27999. 18:02:50over here for my sendoff. With that
  28000. 18:02:53being said, I hope this was helpful. I
  28001. 18:02:56hope that you learned something. Um,
  28002. 18:02:59don't get mad at me if it was too easy.
  28003. 18:03:01Don't get mad if you was me if it was
  28004. 18:03:02too hard. Uh, I'm doing my best over
  28005. 18:03:04here. So, I appreciate your patience.
  28006. 18:03:06Thank you so much for watching. I really
  28007. 18:03:08appreciate it. If you like this video,
  28008. 18:03:11be sure to like and subscribe below, and
  28009. 18:03:13I will see you in the next video.
  28010. 18:03:26What's going on everybody? Welcome back
  28011. 18:03:28to another video. Today we're going to
  28012. 18:03:29be creating a script to automatically
  28013. 18:03:31take data from a crypto API.
  28014. 18:03:39Now, this project stems from an earlier
  28015. 18:03:41video that I did where I walked through
  28016. 18:03:42what an API was and how you can use it.
  28017. 18:03:44And in that video, I showed you how to
  28018. 18:03:46use Coin Market Cap's API so you could
  28019. 18:03:48start pulling in their crypto data. And
  28020. 18:03:49in this video, we're going to take it
  28021. 18:03:50one step further and automate that
  28022. 18:03:52process. Then, we're going to do a
  28023. 18:03:53little bit of transformation with the
  28024. 18:03:54data. I'm going to show you some cool
  28025. 18:03:56stuff on how you can use it and maybe
  28026. 18:03:58we'll do a little bit of visualization
  28027. 18:03:59at the end, but that is not the main
  28028. 18:04:01point of this video. It's mostly around
  28029. 18:04:03the automation piece and a little bit of
  28030. 18:04:05the data cleaning piece as well. Now,
  28031. 18:04:07fair warning, this is not a beginner's
  28032. 18:04:08level project. It's probably more like
  28033. 18:04:10an intermediate project. And it's not
  28034. 18:04:12even a complete project per se because
  28035. 18:04:14we're not doing all the data cleaning.
  28036. 18:04:16We're not doing all the visualizations.
  28037. 18:04:18But if you follow along, we're going to
  28038. 18:04:20cover a lot of different things and
  28039. 18:04:22you're really going to set yourself up
  28040. 18:04:23to be able to do just about anything you
  28041. 18:04:25want with this data or different APIs
  28042. 18:04:27that you pull from. So with that being
  28043. 18:04:28said, let's jump on my screen and get
  28044. 18:04:30started with the project. All right, so
  28045. 18:04:31this is where we stopped in our last
  28046. 18:04:33video. So if you haven't watched it, now
  28047. 18:04:35is the time to go back and do that. I'll
  28048. 18:04:37have a link in the description. Also,
  28049. 18:04:39all the code that we're going to be
  28050. 18:04:40looking at today and working through is
  28051. 18:04:42going to be in a GitHub repo below. So,
  28052. 18:04:45you can go and get all the code and have
  28053. 18:04:47it completely finished and just follow
  28054. 18:04:48along or you can code it from scratch
  28055. 18:04:51along with me. I do recommend writing it
  28056. 18:04:53from scratch if you can because I think
  28057. 18:04:55you'll learn more and you'll make
  28058. 18:04:56mistakes and you'll learn from that as
  28059. 18:04:58we go through it. But, it is up to you.
  28060. 18:05:00So, let's get started. And as you can
  28061. 18:05:03see, uh we have this script right here
  28062. 18:05:05and I'm starting basically from scratch.
  28063. 18:05:07I have a completed one up here. Actually
  28064. 18:05:09going to get rid of those. Um, and what
  28065. 18:05:12we're going to do is we're going to
  28066. 18:05:13start from exactly where we started in
  28067. 18:05:15our last one. I'm going to run the
  28068. 18:05:16script. Um, this is going to pull from
  28069. 18:05:19our API
  28070. 18:05:21and we're going to look at the
  28071. 18:05:23dictionary setter option and do our JSON
  28072. 18:05:26normalize. So, this is where we
  28073. 18:05:27literally left off from the from the
  28074. 18:05:30last video. So, we have all of this data
  28075. 18:05:34and
  28076. 18:05:36what we want to do with it is we want to
  28077. 18:05:38kind of automate that process, right?
  28078. 18:05:40Because we don't want to have to come in
  28079. 18:05:41here, run this, and you know, put into a
  28080. 18:05:45CSV manually or something like that. We
  28081. 18:05:47want to automate this data collection
  28082. 18:05:49process so that we can just have the
  28083. 18:05:51data ready for us to use. Um, and it all
  28084. 18:05:53be ready to go. So, we're going to be
  28085. 18:05:56using this script. Um but you know we we
  28086. 18:05:59might want to add a little bit more to
  28087. 18:06:01it before we do that. Uh the first thing
  28088. 18:06:03that I want to do before um before
  28089. 18:06:07anything is something that I like to do
  28090. 18:06:10when I'm creating these automation
  28091. 18:06:11scripts is I I like to add a timestamp.
  28092. 18:06:14Uh and the reason for that is because I
  28093. 18:06:17want to know when I ran or when each of
  28094. 18:06:20those um loops you can say runs through
  28095. 18:06:23an and does those automated runs, right?
  28096. 18:06:25So, if I do it every day, I want to know
  28097. 18:06:27what time of day I ran it, making sure
  28098. 18:06:29each run ran successfully. And so, all
  28099. 18:06:33I'm going to do is I'm going to add a
  28100. 18:06:34new column at the end, just call it
  28101. 18:06:36timestamp. So, let's go right up here
  28102. 18:06:40and we're going to say PD dot and
  28103. 18:06:43there's something called to datetime.
  28104. 18:06:45So, we're going to do two
  28105. 18:06:48date
  28106. 18:06:50time and then we're going to do now. And
  28107. 18:06:54what this is literally going to do is
  28108. 18:06:56take the the date uh the the time stamp
  28109. 18:06:59of right now when it's running and it's
  28110. 18:07:03going to show that. Now we need to of
  28111. 18:07:05course add a new uh a new column for
  28112. 18:07:08that. So all we're going to do is we're
  28113. 18:07:09going to say data frame. Whoops. Say
  28114. 18:07:12dataf frame. And let me see real quick.
  28115. 18:07:16So we just have the data.
  28116. 18:07:19We need to add we need to create this
  28117. 18:07:20data frame right here. So dataf frame
  28118. 18:07:22equals and then this JSON normalized and
  28119. 18:07:25we're going to say dataf frame and then
  28120. 18:07:26we're going to do a bracket and we're
  28121. 18:07:28going to say timestamp and we'll do well
  28122. 18:07:31all these lowercase. We're going to keep
  28123. 18:07:34with the the lowercase. We're going to
  28124. 18:07:35say timestamp
  28125. 18:07:38and we do that bracket and we'll say
  28126. 18:07:39equals. So what this going to do is
  28127. 18:07:41going to first off it's going to create
  28128. 18:07:42this data or or assign this df as our
  28129. 18:07:45data frame and then we're going to add
  28130. 18:07:47this timestamp and add this new column.
  28131. 18:07:50And so let's run this really quickly
  28132. 18:07:54and let's go all the way to the right.
  28133. 18:07:56And this is our time stamp. And this is
  28134. 18:07:59the time uh that it is right now. This
  28135. 18:08:01is the day that I'm running it. This is
  28136. 18:08:03the time that I'm running it. And so
  28137. 18:08:04this is working properly. Now, if you
  28138. 18:08:07look really quickly, there is a last
  28139. 18:08:09updated in here. And this is very close
  28140. 18:08:13to this time stamp, but it is not the
  28141. 18:08:15same thing. Um, but if you looked
  28142. 18:08:17through this data and you really dug
  28143. 18:08:18into it a little bit, there's this last
  28144. 18:08:21update is coming from Coin Market Cap's
  28145. 18:08:24API and this is when the actual um
  28146. 18:08:28cryptocurrency was updated in their
  28147. 18:08:29system. And so it is going to be really
  28148. 18:08:31close, but it's not going to be exact.
  28149. 18:08:33And so I don't like to rely on built-in
  28150. 18:08:36ones that, you know, are coming from an
  28151. 18:08:38API or something. I want to make one
  28152. 18:08:39myself that's running on the system
  28153. 18:08:40where I'm creating the automated process
  28154. 18:08:42just like just something I do. Um, so
  28155. 18:08:46now we have this original data frame
  28156. 18:08:49created, right? We h we now have what we
  28157. 18:08:53need, but what we want to do is to keep
  28158. 18:08:56adding data to this. Um, we don't want
  28159. 18:08:58it to just go through um, you know,
  28160. 18:09:01create these 5,000 rows. We want it to
  28161. 18:09:04create 5,000 5,000 5,000 over time,
  28162. 18:09:07whether it's a day, an hour, a week, um,
  28163. 18:09:10whenever you want to run it. So, um,
  28164. 18:09:12what I'm actually going to do is I'm
  28165. 18:09:14going to limit this a lot. I just want
  28166. 18:09:15to look at the top, let's say, 15. So,
  28167. 18:09:18we're do that. We're going to run
  28168. 18:09:19through all this again. So, now I just
  28169. 18:09:21have top 15. It's going to be um easier
  28170. 18:09:25to to see and it won't take as much time
  28171. 18:09:28to run our scripts. Again, you can keep
  28172. 18:09:30as many as you'd like. If you want a
  28173. 18:09:32100, 200, all 5,000, you do whatever
  28174. 18:09:34you'd like. But what we are now going to
  28175. 18:09:37do is we're going to create a function
  28176. 18:09:40using this original script. So we again
  28177. 18:09:42we have this data frame and we are going
  28178. 18:09:45to create an automated process that is
  28179. 18:09:48going to or an automate a script to
  28180. 18:09:49automate this that is going to append
  28181. 18:09:51data to this data frame right here. So
  28182. 18:09:53that's kind of you know the big thing
  28183. 18:09:55that we're trying to accomplish in this
  28184. 18:09:56project. Um, so let's go up here and
  28185. 18:10:00we're going to we'll just take from here
  28186. 18:10:04all the way to here. I'm just going to
  28187. 18:10:07copy this and
  28188. 18:10:10going to paste it down here. Now what we
  28189. 18:10:12need to do is we need to create a
  28190. 18:10:14function. So we're going to say def
  28191. 18:10:17and we're going to call this the
  28192. 18:10:18API_runner.
  28193. 18:10:20This is going to run our API um whenever
  28194. 18:10:24we need it to run. Now, when you are
  28195. 18:10:27formatting um something for a function,
  28196. 18:10:30it it needs to be formatted properly.
  28197. 18:10:33And so, what we need to do is you need
  28198. 18:10:34to go over here. I'm going to hit tap.
  28199. 18:10:36We're going to do this all the way down.
  28200. 18:10:37I'm just going to skip forward when it's
  28201. 18:10:38all the way done. All right. So, now we
  28202. 18:10:40have this URL. And what we want to add
  28203. 18:10:43because this is again, this is going to
  28204. 18:10:44run through kind of this this automated
  28205. 18:10:47process. We're going to run this um this
  28206. 18:10:49function there. What we want is to also
  28207. 18:10:51add this right here. So, we need to take
  28208. 18:10:53this and we're going to need to add
  28209. 18:10:56this.
  28210. 18:10:58We'll just put it down here.
  28211. 18:11:01Okay.
  28212. 18:11:04And let's do that. So, what we have so
  28213. 18:11:07far is really close to what we want our
  28214. 18:11:11function to be. Um, we have this
  28215. 18:11:14function that we're going to be running
  28216. 18:11:16through. It's going to call this
  28217. 18:11:17function. It's going to call the the
  28218. 18:11:20API. We're going to use our key. We are
  28219. 18:11:22going to um you know test it, load it,
  28220. 18:11:25format it, format it right here. Then
  28221. 18:11:28we're going to add this timestamp and
  28222. 18:11:29then we will have this. Now, right now
  28223. 18:11:32it's just call it's just going to print
  28224. 18:11:34this data frame basically. But that's
  28225. 18:11:36not what we want right now. What we want
  28226. 18:11:38is to actually append this data. So when
  28227. 18:11:41it gets to here, when it gets to this
  28228. 18:11:43data that's going to be right um right
  28229. 18:11:45here, what we want to do now since we
  28230. 18:11:48already have the original dataf frame
  28231. 18:11:50set up up top is we now want to say that
  28232. 18:11:52this is going to be dataf frame 2. And
  28233. 18:11:55we're going to say it's going to append
  28234. 18:11:57it to dataf frame 2. And so the original
  28235. 18:11:59dataf frame, we're going to say dataf
  28236. 18:12:01frame 2.append
  28237. 18:12:04and we're going to say df2. All this
  28238. 18:12:07does is this says this new data that's
  28239. 18:12:10going to be coming in every time. Let's
  28240. 18:12:12say it's a loop and it's just looping
  28241. 18:12:13through pulling the data, pulling the
  28242. 18:12:15data, pulling the data. We're going to
  28243. 18:12:17create this data frame. We're going to
  28244. 18:12:19add add this time stamp like like we
  28245. 18:12:21want and then we're going to append that
  28246. 18:12:23to this original data frame. So, as of
  28247. 18:12:27right now, this looks good. I will we'll
  28248. 18:12:29run it in a second. I'll create it. So,
  28249. 18:12:33I just created it.
  28250. 18:12:35>> [clears throat]
  28251. 18:12:35>> So now we need to actually create our
  28252. 18:12:37script to automatically run this. So
  28253. 18:12:39we're going to do something called
  28254. 18:12:41import OS. And let me tell you there's a
  28255. 18:12:44thousand different ways to do this. And
  28256. 18:12:46there are better ways to do this, but
  28257. 18:12:48they're much more complex, much more
  28258. 18:12:50complicated, and some cost money in
  28259. 18:12:53order to do it. I'm going to show you
  28260. 18:12:55different options on how to do this in
  28261. 18:12:57future videos on how to automate your
  28262. 18:12:59Python scripts. But this one to me is
  28263. 18:13:02one I've used a lot um many many times
  28264. 18:13:04for different projects and it works. So
  28265. 18:13:07I'm not going to show you the most
  28266. 18:13:09complicated thing in the world. I'm
  28267. 18:13:10going to show you something that I've
  28268. 18:13:11just used a lot. And so we're going to
  28269. 18:13:13say from time import time from time
  28270. 18:13:18import sleep. That one's important.
  28271. 18:13:21And now we're going to create our loop.
  28272. 18:13:24So, what these um what the time and the
  28273. 18:13:26sleep and the OS uh or your operating
  28274. 18:13:29system, what what these are going to do
  28275. 18:13:31is they're going to give us the ability
  28276. 18:13:34to track the time and we're going to be
  28277. 18:13:36able to run through and call this
  28278. 18:13:39function in certain intervals that we
  28279. 18:13:42want. So, let's create our for loop.
  28280. 18:13:45We're going to say for i in. Now you can
  28281. 18:13:49create this specific part in different
  28282. 18:13:53ways, but what I'm going to do is I'm
  28283. 18:13:55going to say range of one. Uh let's say
  28284. 18:13:57333.
  28285. 18:13:58And I say 333. And if you remember from
  28286. 18:14:01the first video on the API, you only
  28287. 18:14:03have 333 runs per day. And so if I ran
  28288. 18:14:09ran this 333 times today, that would be
  28289. 18:14:13our max. And so that's why I'm using
  28290. 18:14:15that 333 just for reference. So now
  28291. 18:14:18we're going to do API_Runner.
  28292. 18:14:22So in this loop we're going to call this
  28293. 18:14:24function up here and then I'm going to
  28294. 18:14:26say I want to prove or or show have an
  28295. 18:14:29output to show that this is running
  28296. 18:14:31through successfully. So I'm just going
  28297. 18:14:33to and you can write anything here.
  28298. 18:14:34We're just going to say API runner
  28299. 18:14:38completed
  28300. 18:14:41uh completed successfully.
  28301. 18:14:44Successfully. How do you spell that?
  28302. 18:14:47successfully.
  28303. 18:14:48That doesn't look right.
  28304. 18:14:51I'm just going to say completed. All
  28305. 18:14:52right, forget that. I don't remember how
  28306. 18:14:54to say uh spell successfully. If that's
  28307. 18:14:57if it's spelled it right, you guys spell
  28308. 18:14:58it that way, but I can't remember. Now,
  28309. 18:15:00we're going to use this sleep right
  28310. 18:15:02here. Now, this counts it in seconds.
  28311. 18:15:05You can change it to minutes, hours,
  28312. 18:15:07whatever. We're going to have it run
  28313. 18:15:09every minute, which is every 60 seconds.
  28314. 18:15:12And so this is going to I'm just going
  28315. 18:15:14to say it's going to sleep for one
  28316. 18:15:17minute.
  28317. 18:15:18And then we're going to say exit.
  28318. 18:15:23So all this is going to do and this is
  28319. 18:15:26again fairly simple. It's just a simple
  28320. 18:15:29for loop. And what it says is it's going
  28321. 18:15:31to call this API. It's going to tell us
  28322. 18:15:34that it ran successfully and then it's
  28323. 18:15:36going to wait for 60 seconds and it's
  28324. 18:15:37going to run again. That's it.
  28325. 18:15:40So, let's run this and see what happens.
  28326. 18:15:43See if what we did works. So, it ran the
  28327. 18:15:45first time. Now, I'm not going to I'm
  28328. 18:15:49not going to bore you because I'm doing
  28329. 18:15:50this live. Exactly what we're about to
  28330. 18:15:52get is what we're going to use. I didn't
  28331. 18:15:53run it overnight or or for a week so
  28332. 18:15:56that we have a bunch of data. I'm what
  28333. 18:15:58you were going to work with, I'm going
  28334. 18:15:59to work with as well. So, I'm going to
  28335. 18:16:01wait a few minutes. I'm going to let
  28336. 18:16:02this run. I want you to do the same
  28337. 18:16:04thing. I'm going to let this run for
  28338. 18:16:06maybe like five minutes or so and we'll
  28339. 18:16:09work with what we have and we'll keep
  28340. 18:16:11going with the project because again
  28341. 18:16:13we're not the point of this project is
  28342. 18:16:15not to create the final product where
  28343. 18:16:17we're creating all the visualizations
  28344. 18:16:18that will most likely be in another
  28345. 18:16:21video where we're taking all this data
  28346. 18:16:23and doing all these things with it. The
  28347. 18:16:24point of this video is to automate it,
  28348. 18:16:26clean it up to where we have it to where
  28349. 18:16:28we can really use it and then I'm going
  28350. 18:16:30to let you guys loose and you guys can
  28351. 18:16:31do whatever you want with it. And I
  28352. 18:16:33think it's really setting you up for a
  28353. 18:16:36lot of successful projects in the future
  28354. 18:16:38that you can do all by yourself without
  28355. 18:16:39me having to walk you through it. So, as
  28356. 18:16:41you can see, it's already ran through
  28357. 18:16:43twice. I'm going to pause for a second.
  28358. 18:16:45I'm going to let that run through uh
  28359. 18:16:47just a few more times and then we will
  28360. 18:16:48continue with the project. All right, we
  28361. 18:16:51are back. And of course, it's only ran
  28362. 18:16:53what, five times. Um it has not reached
  28363. 18:16:56the limit of 333. So, we are perfectly
  28364. 18:16:58fine. What I'm going to do is I'm just
  28365. 18:16:59going to stop this by clicking this uh
  28366. 18:17:01square up here and it's going to give us
  28367. 18:17:03some error and then we're going to check
  28368. 18:17:05it and we will see what we have. I don't
  28369. 18:17:09know why it's taking so long if I'm
  28370. 18:17:10being honest. All right, so I
  28371. 18:17:11interrupted it and let's run this. Let's
  28372. 18:17:14see what we got. I hope we have more
  28373. 18:17:15than 15 because if not, I'm going be
  28374. 18:17:17very upset.
  28375. 18:17:20Okay,
  28376. 18:17:22so okay. Well,
  28377. 18:17:25uh I made a mistake. Um, I was supposed
  28378. 18:17:28to put data frame right here and I had
  28379. 18:17:32dataf frame 2. So, um, take change your
  28380. 18:17:37script. Do not do what I just did. We're
  28381. 18:17:39supposed to be append. It's supposed to
  28382. 18:17:41be dataf frame append. And we're
  28383. 18:17:43supposed to be appending the original d
  28384. 18:17:45this data frame two to the original data
  28385. 18:17:48frame. So, um, I messed up on that one.
  28386. 18:17:51Let's rerun that. Let's rerun that. Um,
  28387. 18:17:55let's see. Um,
  28388. 18:17:58local variable DF reference before
  28389. 18:18:00assignment. Okay, this is perfect
  28390. 18:18:02because this happened to me before. Um,
  28391. 18:18:05we're running into all sorts of good
  28392. 18:18:06stuff. I like to keep this stuff in my
  28393. 18:18:08videos. I laugh because I hate running
  28394. 18:18:10into mistakes, but everybody says they
  28395. 18:18:12they are happy that I do this. Um, so
  28396. 18:18:15I'm going to keep doing it. I'm not
  28397. 18:18:16going to cut this out. I promise. Um,
  28398. 18:18:18but what we actually need to do is we
  28399. 18:18:20need to go back up to this function
  28400. 18:18:22because what happened was is we called
  28401. 18:18:24this data frame
  28402. 18:18:27and now it's it's because it's in a
  28403. 18:18:29function, it's in what they would call a
  28404. 18:18:31local variable. What we need to do is we
  28405. 18:18:34now need to state that this is a global.
  28406. 18:18:38Um, it's just called a global. That's
  28407. 18:18:41all it is. Um, and so what we're going
  28408. 18:18:42to do is we're going to do tab. We're
  28409. 18:18:44going to say global say df.
  28410. 18:18:48And what this should do is this should
  28411. 18:18:50declare it as a global variable and it
  28412. 18:18:53should let this run properly. Let's hope
  28413. 18:18:56it does.
  28414. 18:18:58All right, it's running. Um, again, I
  28415. 18:19:01ran into mistakes. Let me tell you
  28416. 18:19:03something while we're here for just a
  28417. 18:19:05second. This project I ran into probably
  28418. 18:19:08a hundred mistakes or a hundred errors
  28419. 18:19:11or issues that I had to research for
  28420. 18:19:13hours um and hours. I'm legitimately on
  28421. 18:19:16Stack Overflow and just googling and
  28422. 18:19:18figuring figuring these things out.
  28423. 18:19:20There were a lot of new things that I
  28424. 18:19:21had never run into before um just on
  28425. 18:19:23this project. And so um everything that
  28426. 18:19:26you're seeing is from after I went
  28427. 18:19:28through all of those things or after I
  28428. 18:19:30fixed all of those things and had to
  28429. 18:19:32really work through them. It was it was
  28430. 18:19:33very um it was frustrating at times. I
  28431. 18:19:36just I couldn't figure it out. And so
  28432. 18:19:38what you're looking at is kind of the
  28433. 18:19:39polished version of that now that I have
  28434. 18:19:41everything laid out because I I can't
  28435. 18:19:43spend 10 hours on a project. nobody
  28436. 18:19:45would watch it. So, just know that if
  28437. 18:19:48you are running into some of these
  28438. 18:19:49mistakes or you run into mistakes later
  28439. 18:19:51on when you're expanding this project,
  28440. 18:19:53that's completely normal. So, what we're
  28441. 18:19:55going to do is we're going to let this
  28442. 18:19:56run for a little bit and then after
  28443. 18:19:59maybe three or four minutes, we'll come
  28444. 18:20:01back and we'll keep going with the
  28445. 18:20:03project. All right. So, let's run this
  28446. 18:20:06and check and see if we have uh the data
  28447. 18:20:09that we're looking for. Uh, and it looks
  28448. 18:20:12like we do. Let's go actually back up
  28449. 18:20:14here really quick up.
  28450. 18:20:18We want to set this to display max rows
  28451. 18:20:21because I want to be able to see all the
  28452. 18:20:23rows and not just um a few of them. So,
  28453. 18:20:27and that just instead of it gives us
  28454. 18:20:29this scrolling instead of that dot dot
  28455. 18:20:31dot that shows us just a few. So,
  28456. 18:20:33there's our original 15. Then we have
  28457. 18:20:36the next um the next loop and then we
  28458. 18:20:40have the next loop. And let me scroll
  28459. 18:20:42over to the timestamps and I'll show you
  28460. 18:20:44what I mean. Um, so this was ran on
  28461. 18:20:4652651.
  28462. 18:20:48Let's go down. 526 at 150 2905.
  28463. 18:20:55I say 1501 2905. And the next one you
  28464. 18:20:59can see was ran at 3006.
  28465. 18:21:0331. These are all the ones minute after
  28466. 18:21:05each other. My original one was from
  28467. 18:21:07earlier.
  28468. 18:21:0932 33. Yeah. So, you can see 32, 31,
  28469. 18:21:133030 or um 3029. And this one was about
  28470. 18:21:1615 minutes ago when I first um ran the
  28471. 18:21:19original data frame, right? All right,
  28472. 18:21:22guys. This is Alex from the future. I've
  28473. 18:21:24actually completed this entire project
  28474. 18:21:26uh in the video, and you're about to see
  28475. 18:21:28all that after this. But I wanted to
  28476. 18:21:30show you one more thing that you can do
  28477. 18:21:31in this function up here that I didn't
  28478. 18:21:33show you uh originally that I'm coming
  28479. 18:21:36back to show you, and that's how to
  28480. 18:21:37actually put it into a CSV. Now, all
  28481. 18:21:40we've done in this one is we we've kept
  28482. 18:21:43it all enclosed in a dataf frame, and
  28483. 18:21:45that's it. And that may be great, but a
  28484. 18:21:48lot of you guys are going to want to
  28485. 18:21:50automate this and put it into a CSV. And
  28486. 18:21:53I want to show you how to do that. All
  28487. 18:21:54right. So, what I'm going to show you
  28488. 18:21:55really quickly is right here in this uh
  28489. 18:21:58in this folder right here, I have all
  28490. 18:22:00these different API 3es and fours. These
  28491. 18:22:02were tests that I did before. But what
  28492. 18:22:04you can do is instead of just putting it
  28493. 18:22:06into a dataf frame, you can actually
  28494. 18:22:08append the data to a CSV and have that
  28495. 18:22:11CSV sitting out there for you instead of
  28496. 18:22:13just keeping it all in a dataf frame.
  28497. 18:22:16And there's a lot of different uses for
  28498. 18:22:17that. You may want to have that file
  28499. 18:22:21separately from here just in case
  28500. 18:22:23something times out or something breaks,
  28501. 18:22:25which is a legitimate concern, or your
  28502. 18:22:27computer shuts off or or something like
  28503. 18:22:28that. That is a legitimate concern. So
  28504. 18:22:31what we're going to do is we're going to
  28505. 18:22:32say um if not and this is basically an
  28506. 18:22:36if statement. We're going to say os.path
  28507. 18:22:41dot is file. So what this is going to do
  28508. 18:22:44is check if there's already a file under
  28509. 18:22:47this name. And we're going to do r dot
  28510. 18:22:50or or r. Um, if you have never done um
  28511. 18:22:55if you've never done CSV stuff before,
  28512. 18:22:58uh, it's really important that you put
  28513. 18:23:00that you you're going to get an error
  28514. 18:23:01every time. So, we're going to take this
  28515. 18:23:03right here and we're going to copy that
  28516. 18:23:06and we're going to put that right here.
  28517. 18:23:08And then we're also going to do a
  28518. 18:23:11slash and then we're going to name it
  28519. 18:23:12basically. Um, let's name this API
  28520. 18:23:15because I don't think I have that one in
  28521. 18:23:16there. I think I deleted it. Yeah. So, I
  28522. 18:23:18don't have API. So, I'm just going to
  28523. 18:23:19keep it API.csv. CSV
  28524. 18:23:22and then I'm going to close that
  28525. 18:23:23parentheses and then we're going to add
  28526. 18:23:26a colon right here and we're going to
  28527. 18:23:28say if that does not exist we are going
  28528. 18:23:32to write this to it and create it. So,
  28529. 18:23:35we're going to say dataf frames. That's
  28530. 18:23:37this dataf frame right here.
  28531. 18:23:40Dataf frame dot and we're going to say 2
  28532. 18:23:44CSV. And we're going to do that R. And
  28533. 18:23:48then we're going to copy this. So, let's
  28534. 18:23:52just let's just replace it like that.
  28535. 18:23:57And then we're going to say comma
  28536. 18:24:00header
  28537. 18:24:02oops header is equal to
  28538. 18:24:06column
  28539. 18:24:08names. So what this is going to do is if
  28540. 18:24:12we run through this and what we would
  28541. 18:24:14have to do is um I'll talk about this in
  28542. 18:24:17a little bit. We'll have to change this
  28543. 18:24:19up a little bit. But what this is going
  28544. 18:24:21to do is going to check to see if this
  28545. 18:24:24file right here exists. If it does not,
  28546. 18:24:27it is going to create it and create the
  28547. 18:24:30column headers based off the this data
  28548. 18:24:32frame. That is what that does. Now, what
  28549. 18:24:35we want to do is say else. And this next
  28550. 18:24:39part that we're going to write is saying
  28551. 18:24:40if there's already the API file there,
  28552. 18:24:43we want to append the data. We don't
  28553. 18:24:45want to overwrite it or anything like
  28554. 18:24:47that. We want to append the data. So,
  28555. 18:24:48we're going to say we're basically going
  28556. 18:24:50to copy this.
  28557. 18:24:52Maybe not the whole thing, but I already
  28558. 18:24:54did it. Um, so we're going to copy that
  28559. 18:24:57and we're going to say mode. Oops. Mode
  28560. 18:25:01equals A.
  28561. 18:25:04And A stands for append. And then we're
  28562. 18:25:06going to say header. Oops, keep messing
  28563. 18:25:09up header. And we're going to say false.
  28564. 18:25:11Oops. We're going to say false, which
  28565. 18:25:14means when it appends the data, it's not
  28566. 18:25:16going to use those col the column
  28567. 18:25:17headers every time, which you don't want
  28568. 18:25:19because every time you append it, if you
  28569. 18:25:21added the headers, every 15 rows, every
  28570. 18:25:2515 rows, you're going to have another
  28571. 18:25:27headers that you're going to have to
  28572. 18:25:28like go out into that CSV and filter out
  28573. 18:25:30and and get rid of them. So, we're going
  28574. 18:25:32to say header equals false. Now, just a
  28575. 18:25:34second ago, I said you would need to
  28576. 18:25:36mess with this just a little bit, and
  28577. 18:25:37you would because every time um you'd be
  28578. 18:25:41putting in this dataf frame, which it's
  28579. 18:25:43already appending it to this data frame.
  28580. 18:25:45So, every time you'd be creating a lot
  28581. 18:25:47of duplicates if you kept it exactly as
  28582. 18:25:49is. What you were going to need to do is
  28583. 18:25:51basically take it back to its to its um
  28584. 18:25:53bones. Um so, you need to
  28585. 18:25:57kind of keep it like this. So, what you
  28586. 18:26:00need to do is just now run this and it
  28587. 18:26:02would work perfectly. Uh, let's test it
  28588. 18:26:05really quick. Um, to see if it works.
  28589. 18:26:07Uh, because I'm I'm promising you
  28590. 18:26:09something. I want to make sure it
  28591. 18:26:10actually works. Let's run it this time.
  28592. 18:26:13Okay. So, it just ran for the first
  28593. 18:26:15time. So, it should have created this
  28594. 18:26:17file. Let's go see if that works
  28595. 18:26:19properly.
  28596. 18:26:21So, now it just created that file. And
  28597. 18:26:23now we're going to see if it actually
  28598. 18:26:26appends the data. So, let's wait just
  28599. 18:26:28one time. Um, and then I'm going to stop
  28600. 18:26:30it. I'm going to see if it works. Again,
  28601. 18:26:32I'm just verifying to make sure that
  28602. 18:26:34what I'm telling you is actually
  28603. 18:26:35working. Uh, because if it doesn't, I
  28604. 18:26:38would feel terrible. Uh, we don't want
  28605. 18:26:39that. And while that's running,
  28606. 18:26:41actually, I'm going to add this because
  28607. 18:26:45now I want to show you how to call it.
  28608. 18:26:47Um, super easy. We're just going to do
  28609. 18:26:49PD.
  28610. 18:26:53CSV. Do that.
  28611. 18:26:56We're going to call this
  28612. 18:27:00just like that.
  28613. 18:27:02And then we're going to say data frame.
  28614. 18:27:04And we're just going to do 72.
  28615. 18:27:08Something random because I've already
  28616. 18:27:10done this whole project. I don't want to
  28617. 18:27:11mess anything up. So we're going to say
  28618. 18:27:13[cough] data frame [clears throat] 72.
  28619. 18:27:15So now let's stop this.
  28620. 18:27:18Um, and what we're going to do is once
  28621. 18:27:21that stops, we're going to run this and
  28622. 18:27:23see if it actually um worked and to see
  28623. 18:27:26make sure that this actually pulled the
  28624. 18:27:28data in. All right, so we interrupted
  28625. 18:27:29it. The file is ready to be read in. So,
  28626. 18:27:33let's read it in. There's our file. Um,
  28627. 18:27:38let's see. What did I mess up or did I
  28628. 18:27:40mess anything up?
  28629. 18:27:42Ah, I didn't mess anything up. This is
  28630. 18:27:44the index for this file. And we already
  28631. 18:27:47had this in here. we'd probably be able
  28632. 18:27:48to get rid of it. But if you see, we
  28633. 18:27:50have 0 1 2 3 4 5 6 7 8 9 14. Then we
  28634. 18:27:54have zero 1 2 3 4. And if we look at the
  28635. 18:27:57time stamp, it should be 1 minute apart.
  28636. 18:27:59So it's 11945.
  28637. 18:28:02It said 120 45. So this worked exactly
  28638. 18:28:05as planned. Um again, you have two
  28639. 18:28:08different options. You can just keep it
  28640. 18:28:09how it was before. And I'll leave both
  28641. 18:28:11of those options, you know, in the in
  28642. 18:28:13the script so that you can kind of
  28643. 18:28:15choose which one you want. But um that's
  28644. 18:28:18how you do that. So then right here
  28645. 18:28:20you're appending it to a CSV file. And
  28646. 18:28:22then if you just keep this and you get
  28647. 18:28:24rid of all this, you're just appending
  28648. 18:28:25it to a dataf frame. Now please continue
  28649. 18:28:28with the rest of the video that I
  28650. 18:28:30already have done. Um but again I'm
  28651. 18:28:32future Alex. So uh please continue with
  28652. 18:28:34the rest of the video. Okay. So we have
  28653. 18:28:37all this data. We have we have so many
  28654. 18:28:40columns we can do. Now, you know, if you
  28655. 18:28:44want to completely just go and do your
  28656. 18:28:45own thing, you absolutely can do that.
  28657. 18:28:48I'm going to mess around with a few
  28658. 18:28:49things. Um, kind of show you something
  28659. 18:28:53that I did that I thought was really
  28660. 18:28:55interesting, um, in order to visualize
  28661. 18:28:58this data a little bit and transform it
  28662. 18:28:59a little bit to make it more usable. Um,
  28663. 18:29:02but we're not doing a full data clean.
  28664. 18:29:04That's not what this project is. We're
  28665. 18:29:05not doing a full data cleaning of this
  28666. 18:29:07data. That would be a m a very large
  28667. 18:29:09undertaking because honestly, this needs
  28668. 18:29:11a lot of work.
  28669. 18:29:12One thing that I do want to clean up
  28670. 18:29:14really quick uh is is this right here.
  28671. 18:29:18This the math will be fine. It's just
  28672. 18:29:21the way that it's shown on here is in
  28673. 18:29:22state uh the scientific notation and I
  28674. 18:29:24don't like it. So, what I'm going to do
  28675. 18:29:27really quickly
  28676. 18:29:29is just um get rid of that. So, we're
  28677. 18:29:31going to uh we're going to say PD
  28678. 18:29:36set and do underscore option and this is
  28679. 18:29:40going to be do parenthesis. We're going
  28680. 18:29:44to say display this is just this how
  28681. 18:29:47this is formatted. So we're going to
  28682. 18:29:48display uhflat_mat
  28683. 18:29:54and we're going to say comma and we're
  28684. 18:29:57now we're going to use this lambda say x
  28685. 18:30:01colon and we're going to say
  28686. 18:30:05percent
  28687. 18:30:075f
  28688. 18:30:10that right there and we're going to say
  28689. 18:30:12percent x. Now, if you don't know what
  28690. 18:30:15lambdas is, lambdas are, um, I highly
  28691. 18:30:18recommend looking those up. Um, again,
  28692. 18:30:21this is not a beginner tutorial. Whoops.
  28693. 18:30:25No such keys. Display floor format. That
  28694. 18:30:28makes sense. Uh, this is float. Yeah,
  28695. 18:30:32guys, this is not a beginner's level.
  28696. 18:30:34All right. Uh, you can't use the floor
  28697. 18:30:36format. This is the float format. All
  28698. 18:30:38right. So, now let's take a look at this
  28699. 18:30:39uh this df uh this data frame that we
  28700. 18:30:41have. So, we're just going to hit df.
  28701. 18:30:43Click enter. And now our numbers are a
  28702. 18:30:45little bit more easily readable. I
  28703. 18:30:47prefer it this way. You do not have to
  28704. 18:30:49do this. I'm doing this just because
  28705. 18:30:50this is what I prefer.
  28706. 18:30:53So, let's jump right into it. Um,
  28707. 18:30:55something that when I saw this data, I
  28708. 18:30:58was like, something that I really
  28709. 18:30:59thought was interesting is this percent
  28710. 18:31:02change of 1 hour, percent change 24
  28711. 18:31:05hours, 7 days, 30 days, 60 days, 90
  28712. 18:31:07days. If you're not in crypto or you
  28713. 18:31:09don't do investing or anything like
  28714. 18:31:10that, what this is going to show us is
  28715. 18:31:14how I mean it's pretty obvious how much
  28716. 18:31:16the price of this coin has changed over
  28717. 18:31:19the last hour, 24 hours, 7 days. So, as
  28718. 18:31:22you can see, it's it's barely fluctuated
  28719. 18:31:24over the past 24 hours. A little bit
  28720. 18:31:27over the past um 7 days, a lot over the
  28721. 18:31:30last 30 days, 60 days, and 90 days. 20 -
  28722. 18:31:3426% - 33%. We're in May. Hey, we just
  28723. 18:31:37had a kind of a crash in crypto a couple
  28724. 18:31:38weeks ago. So, I mean, this tracks,
  28725. 18:31:41right? But I want to visualize this, see
  28726. 18:31:45this, and kind of see um, you know, how
  28727. 18:31:49this is going to look and how if I can
  28728. 18:31:52gain any insight from that information
  28729. 18:31:54and just having it all displayed for me.
  28730. 18:31:56But in its current state, um, you know,
  28731. 18:32:00we really cannot do that. Um, now
  28732. 18:32:04another issue, not an issue, but another
  28733. 18:32:07thing that we have to take into
  28734. 18:32:07consideration is we have
  28735. 18:32:10Bitcoin right here. We have Bitcoin
  28736. 18:32:13right here after different polls. Now,
  28737. 18:32:15we just did it a minute after each
  28738. 18:32:16other, but for your project, you may do
  28739. 18:32:18it a a run each day, a run every hour or
  28740. 18:32:23something like that, right? And
  28741. 18:32:26if you did that, your data could be very
  28742. 18:32:29different. And so you may just want to
  28743. 18:32:32take this first one. But what I'm going
  28744. 18:32:35to do for the sake of this project, I'm
  28745. 18:32:36going to group them. So let's go down
  28746. 18:32:39here and we're going to say df.group
  28747. 18:32:45by. And so if you've ever done something
  28748. 18:32:47like SQL, uh this is how you group by in
  28749. 18:32:50pandas. Basically, we're going to group
  28750. 18:32:52by uh the name. So so on bitcoin,
  28751. 18:32:55ethereum to other. So, we're going to
  28752. 18:32:57we're going to do that on name.
  28753. 18:33:01And uh I'm not going to I'm going to say
  28754. 18:33:04sort is equal to false. Oops. I'm not
  28755. 18:33:08going to sort it. Uh you could say true
  28756. 18:33:10there, but we're not going to. And I
  28757. 18:33:13guess you'll see why later. We're going
  28758. 18:33:15to do an open bracket.
  28759. 18:33:17And now we need to choose what we're
  28760. 18:33:19going to group by uh or what we're going
  28761. 18:33:21to what columns we're going to have. So,
  28762. 18:33:24I'm going to do another open bracket.
  28763. 18:33:25And I'm just going to copy and paste
  28764. 18:33:27these. So I'm going to start right here
  28765. 18:33:29at quote percent one hour. So I'm gonna
  28766. 18:33:32do boom and then
  28767. 18:33:36go over one. And we're going to take 24
  28768. 18:33:40hours.
  28769. 18:33:42Paste that comma.
  28770. 18:33:46We have the 7-day 30-day.
  28771. 18:33:49And we're going to do like that.
  28772. 18:33:54And I'm just going to do comma. I'm
  28773. 18:33:57going to do the same one, but I'm just
  28774. 18:33:58going to manually change it to 30-day
  28775. 18:34:02rid of that at the end. I don't know
  28776. 18:34:03what that is. Uh then we're going to do
  28777. 18:34:0760 days
  28778. 18:34:10and comma. And we're going to do our
  28779. 18:34:12last one, which is 90 days. And let's
  28780. 18:34:17see what that gives us.
  28781. 18:34:19Uh doesn't give us anything.
  28782. 18:34:22Okay, I know what's wrong here. Um, we
  28783. 18:34:25forgot to add basically the what we're
  28784. 18:34:28we have we're grouping by something. We
  28785. 18:34:30need to have like an average, uh, a
  28786. 18:34:32mean,
  28787. 18:34:34a mode, or something like that, right?
  28788. 18:34:37So, all we have to do is go to the end
  28789. 18:34:39right here and let's just do mean. We're
  28790. 18:34:42going to do an average.
  28791. 18:34:44Um, and and so we're taking this number.
  28792. 18:34:48So, let's say this is for Bitcoin. So,
  28793. 18:34:50we're going to take this number in this
  28794. 18:34:52one hour for every time it's Bitcoin,
  28795. 18:34:53it's going to group them all together.
  28796. 18:34:55Um, and then it's going to average them.
  28797. 18:34:58So, in the past five minutes where it's
  28798. 18:35:00been running, we're going to take the
  28799. 18:35:02average or the mean of that. So, let's
  28800. 18:35:05run this again. And so, now this is our
  28801. 18:35:08output. Let's take a look.
  28802. 18:35:11Oops, I meant down here. Let's run this
  28803. 18:35:14now.
  28804. 18:35:18Now what we have is all of these um
  28805. 18:35:20cryptos. These are all 15 that we have.
  28806. 18:35:22And this is the average um for this 1
  28807. 18:35:24hour, 24, 7 days, 30 days, 60 days, and
  28808. 18:35:2890 days. So now we have all of our
  28809. 18:35:30cryptocurrencies over here. We have our
  28810. 18:35:33percent changes up top and then our
  28811. 18:35:35averages um here as well.
  28812. 18:35:38And so now what we're going to do is,
  28813. 18:35:41you know, if you try to visualize this
  28814. 18:35:43as is, it doesn't really work because
  28815. 18:35:46these percent changes are up here as
  28816. 18:35:48columns and we don't really want them as
  28817. 18:35:51columns because that it just doesn't
  28818. 18:35:52work for visual for actually creating
  28819. 18:35:54the visualizations. We really need these
  28820. 18:35:56to be rows. And so my initial thought
  28821. 18:35:59when I was doing this was I of course I
  28822. 18:36:01need to pivot. Um, you know, if you've
  28823. 18:36:03ever used pivot like in Excel or or
  28824. 18:36:06PowerBI or something like that, that was
  28825. 18:36:07my first thought and I tried everything
  28826. 18:36:10and I could not could not get it to work
  28827. 18:36:11and I almost gave up until I I ran
  28828. 18:36:14across um something called stacking or a
  28829. 18:36:17stack and and so this was not something
  28830. 18:36:20that I I I think I have used it before,
  28831. 18:36:22but I I couldn't remember to be if I'm
  28832. 18:36:24being completely frank. I couldn't
  28833. 18:36:25remember how to do this. So, I just did
  28834. 18:36:28um once I saw what it was, I did stack.
  28835. 18:36:31Let's make that day four. And you don't
  28836. 18:36:33have to do this. Uh you can keep this
  28837. 18:36:34all the original data frame. I'm just I
  28838. 18:36:37like for visual purposes. You can see
  28839. 18:36:38like the progression that we're making.
  28840. 18:36:40Um but I like to, you know, create it
  28841. 18:36:43new data frame. And I can always go back
  28842. 18:36:45and look at this data frame three um as
  28843. 18:36:48we go. But you don't you don't have to
  28844. 18:36:49do that. That's just what I'm doing. So
  28845. 18:36:52now let's take a look at this. Now uh up
  28846. 18:36:54here we had Bitcoin and we had all these
  28847. 18:36:56columns and we had uh these numbers as
  28848. 18:37:00rows. But now we have all of these as
  28849. 18:37:03rows as well. This how we have this is
  28850. 18:37:06much much more usable. Um and if you've
  28851. 18:37:09ever done something like pivot or this
  28852. 18:37:11stacking before, you'll know that you
  28853. 18:37:13you kind of have to do it if you really
  28854. 18:37:15want to visualize this well.
  28855. 18:37:18But um you because we just stacked it,
  28856. 18:37:21it kind of changed it. So if we look at
  28857. 18:37:24um let's look at the type of let's do
  28858. 18:37:27type of data frame three. This is before
  28859. 18:37:31um before we stacked it. This was in a
  28860. 18:37:34dataf frame. But now let's go and look
  28861. 18:37:36at dataf frame 4. So this is a series.
  28862. 18:37:40This is no longer a data frame. So we
  28863. 18:37:43have to remember that that's that's
  28864. 18:37:44really important because we can no
  28865. 18:37:46longer treat it as a data frame. It's
  28866. 18:37:48now a series. So we want to get it back
  28867. 18:37:50to a data frame. We don't want it to be
  28868. 18:37:53like that because you can't really use
  28869. 18:37:55it in the series. So what we're going to
  28870. 18:37:57do and let me just create a few of these
  28871. 18:37:59so it can be up here better. So now what
  28872. 18:38:02we're going to do is we're going to say
  28873. 18:38:04dataf frame 4 dot and something called
  28874. 18:38:07two frame. So we're going to make this
  28875. 18:38:10into a frame. And now we're going to
  28876. 18:38:12specify the name. And it doesn't mean um
  28877. 18:38:15the name like right here. We actually
  28878. 18:38:18mean the name of these values right
  28879. 18:38:20here. This is part of the stacking
  28880. 18:38:22process in in these columns or these two
  28881. 18:38:25columns. So let's go right here and
  28882. 18:38:28we're going to call it let's just say
  28883. 18:38:31values
  28884. 18:38:32and let's make this data frame five
  28885. 18:38:38and let's see the output whoops for data
  28886. 18:38:41frame five. And now so there's that
  28887. 18:38:44values and now this already looks a lot
  28888. 18:38:48better. Right? So it's in this it's in
  28889. 18:38:50this more um this is already a data. So
  28890. 18:38:53this is a data frame. So let's look type
  28891. 18:38:55dataf frame five. So now it's in a data
  28892. 18:38:58frame. But
  28893. 18:39:00the issue is is that this name is kind
  28894. 18:39:03of acting like a an index which we don't
  28895. 18:39:07want because we want to be able to use
  28896. 18:39:09this. So it doesn't really have an index
  28897. 18:39:11at the moment. So we need to give it an
  28898. 18:39:14index. But typically when you give an
  28899. 18:39:17index you'll do something like um we'll
  28900. 18:39:19say dataf frame five we'll do set
  28901. 18:39:22index and then you'll do something like
  28902. 18:39:25um name. So let's just do dat 6 is equal
  28903. 18:39:30to we'll see we'll see what happens
  28904. 18:39:32here. It's going to give us an error.
  28905. 18:39:34Oops. What I meant is we're going to do
  28906. 18:39:36day frame five bracket
  28907. 18:39:40name. That's a column right? We're going
  28908. 18:39:42to do that. And it's basically going to
  28909. 18:39:45say that that's not going to work. And
  28910. 18:39:48what we need to do is what or at least
  28911. 18:39:50what I want to do and what we're going
  28912. 18:39:52to do in this video is I'm going to
  28913. 18:39:54create numbers. I really would just want
  28914. 18:39:57it to be numbered. 1 2 3 4 5. That's
  28915. 18:39:59what I want. Um, but we don't have that
  28916. 18:40:02right now. I can't just will it into
  28917. 18:40:04existence. So now what we're going to do
  28918. 18:40:06is kind of create uh an index basically
  28919. 18:40:08out of thin air. So we're going to do
  28920. 18:40:10PD.index index
  28921. 18:40:13and we're going to say uh you know we
  28922. 18:40:16basically want how many um rows are in
  28923. 18:40:20here. So that's what we want our our um
  28924. 18:40:23index to be. We want it to count how
  28925. 18:40:25many are in here. Now you can make this
  28926. 18:40:26dynamic and I it probably wouldn't be
  28927. 18:40:28that hard, but I'm going to take the
  28928. 18:40:30super lazy route. Um and I'm just going
  28929. 18:40:32to say
  28930. 18:40:34let's do df5
  28931. 18:40:38or oops df5.count. count
  28932. 18:40:42and there's 90 values in here. So I'm
  28933. 18:40:45going to do is I'm going to do a range
  28934. 18:40:49of 90. Uh and this is not uh I would
  28935. 18:40:53definitely make this dynamic but I'm
  28936. 18:40:55again I'm just being
  28937. 18:40:58being a little bit lazy. We're call this
  28938. 18:41:00index is equal to and I'm going to put
  28939. 18:41:03this index right here. So now this is a
  28940. 18:41:05number. So now it's going to
  28941. 18:41:08literally index this for us. Now I've
  28942. 18:41:11ran into this issue many times. Um, and
  28943. 18:41:14so what I need to actually do is to
  28944. 18:41:16reset this index and then do it properly
  28945. 18:41:18the first time. Uh, so let's do re let's
  28946. 18:41:22get rid of this. Let's reset this index.
  28947. 18:41:24Um, and it actually fixed itself. Um, so
  28948. 18:41:29what was happening was is we were
  28949. 18:41:31indexing something that was already
  28950. 18:41:32indexed and we're causing issues
  28951. 18:41:35in in a nutshell. So we reset the index
  28952. 18:41:37and now this is what it looks like and
  28953. 18:41:39this is exactly what we want. This is
  28954. 18:41:42really how we wanted it formatted in
  28955. 18:41:44order to for our visualizations. We have
  28956. 18:41:46multiple rows for the bitcoin. Um each
  28957. 18:41:49of these columns are is now a row with
  28958. 18:41:51the value attached to it. Exactly what
  28959. 18:41:53we wanted. So, um, really quick, I for
  28960. 18:41:58whatever reason it it makes that, uh,
  28961. 18:42:01level one. I don't know why, but we're
  28962. 18:42:03just going to rename that column really
  28963. 18:42:05quickly. So, we're going to do dataf
  28964. 18:42:07frame six dot rename.
  28965. 18:42:10And then we're going to do an open
  28966. 18:42:12parenthesy. Say columns equal to, and
  28967. 18:42:17we're going to do one of these bad boys.
  28968. 18:42:18Oops. One of these bad boys. This this
  28969. 18:42:20type of bracket. And we're going to say
  28970. 18:42:23level underscore one and we do a colon
  28971. 18:42:27and then oops
  28972. 18:42:30and then a colon [snorts] and then we
  28973. 18:42:32want to change it to and I'm just going
  28974. 18:42:33to call this the percent
  28975. 18:42:36change. So let's call this dataf frame
  28976. 18:42:397.
  28977. 18:42:42You don't have to do that. I'm just
  28978. 18:42:44doing it. So now this looks much much
  28979. 18:42:47better. Now let's try to visualize this
  28980. 18:42:50one. Um because we haven't done any
  28981. 18:42:51visualizations yet. We've just been
  28982. 18:42:52messing with the data a little bit. I I
  28983. 18:42:54you know I kind of want to see how we
  28984. 18:42:56can use this. This is something that I
  28985. 18:42:58personally am interested in. So I kind
  28986. 18:43:00of wanted to see visualize how these
  28987. 18:43:02changed over these these time periods.
  28988. 18:43:04Um but we need to um import some stuff
  28989. 18:43:07in order to be able to visualize this.
  28990. 18:43:10So we're going to import Seabor as SNS.
  28991. 18:43:14And if we need to um we're going to
  28992. 18:43:16import mapplot lib as well. I don't know
  28993. 18:43:19if we'll use it right now or at all, but
  28994. 18:43:22um we're going to we're going to add it
  28995. 18:43:25in here either way. So now those are
  28996. 18:43:28added. And so what we're going to do is
  28997. 18:43:31come right here. We're going to do
  28998. 18:43:32SNS.plot.
  28999. 18:43:36And we're going to oops we're going to
  29000. 18:43:39say the xaxis is equal to and we want to
  29001. 18:43:43do this as the percent change percent
  29002. 18:43:48change.
  29003. 18:43:50And then we have the yaxis. Now we want
  29004. 18:43:54the y-axis to be these values right
  29005. 18:43:56here. Say comma y is equal to and we're
  29006. 18:44:01going to say values.
  29007. 18:44:03Oops. And then we're going to say comma
  29008. 18:44:06and we'll say we want to basically
  29009. 18:44:09create a legend. Um I guess you could
  29010. 18:44:11call it. We're going to say hue is equal
  29011. 18:44:14to name. Um I'll show you what it looks
  29012. 18:44:16like without it. And then you know you
  29013. 18:44:18can see that that we need that. We're
  29014. 18:44:22going to say the data is equal to this
  29015. 18:44:24data frame seven.
  29016. 18:44:28Data frame seven.
  29017. 18:44:31And then we are going to say the kind
  29018. 18:44:34is equal to.
  29019. 18:44:38Now, let's run this and see what we get.
  29020. 18:44:42And super quickly with just, you know,
  29021. 18:44:44limited um inputs, here's what we have.
  29022. 18:44:48Now, this looks really good. We can
  29023. 18:44:51narrow this down if we wanted to to a
  29024. 18:44:53few less because there's a lot here and
  29025. 18:44:55there's a lot of colors. But again,
  29026. 18:44:57[cough] that's just because
  29027. 18:44:57[clears throat] we have a lot of
  29028. 18:44:59different stuff. But there's a few that
  29029. 18:45:01are doing really well. I think this is
  29030. 18:45:03Tron.
  29031. 18:45:05Um, and then we have a few that are not
  29032. 18:45:08doing so well, but it's really hard to
  29033. 18:45:10see. If you look down here, it's really
  29034. 18:45:12hard to see this. Um, and that's just
  29035. 18:45:16because of the the column names. And so,
  29036. 18:45:18I actually want to change these column
  29037. 18:45:20names or these values so that when we
  29038. 18:45:23visualize it right down here, it it
  29039. 18:45:26doesn't look like that. I kind of want
  29040. 18:45:27this to be, you know, at least one good
  29041. 18:45:30visualization you can take out of here.
  29042. 18:45:32Now, this is definitely not perfect or
  29043. 18:45:33complete by any means, but you know, you
  29044. 18:45:35can take take that away from here. Um,
  29045. 18:45:38so let's um I did alt enter, which adds
  29046. 18:45:42another row. I could have just pushed
  29047. 18:45:43plus. I was kind of the lazy way. Um,
  29048. 18:45:46what I'm going to do is I'm going to
  29049. 18:45:49change these um these values in here.
  29050. 18:45:53So, how I'm going to do that is I'm
  29051. 18:45:54going to do dataf frame seven. And we
  29052. 18:45:55only want to look at this one column.
  29053. 18:45:58So, we'll do that right there.
  29054. 18:46:02and we want to say dotreplace
  29055. 18:46:06and we're going to do an open uh uh
  29056. 18:46:09parentheses and then a bracket. Now what
  29057. 18:46:12we need to do is I'm just to show you um
  29058. 18:46:15one of them is I'm going to say this one
  29059. 18:46:18hour
  29060. 18:46:20do that. Oops. And then what I need to
  29061. 18:46:22do is a comma another bracket. This is
  29062. 18:46:25what it's going to change to. I'm just
  29063. 18:46:26going to say 1 hour. Oops. 1 hour. Um,
  29064. 18:46:29and we'll do this one really quick and
  29065. 18:46:31then I'm going to I don't want you to
  29066. 18:46:33have to watch me type all this out, but
  29067. 18:46:34I'm going to go through and basically do
  29068. 18:46:35all of this uh for those. But let's
  29069. 18:46:37let's see this really quick. And so now,
  29070. 18:46:40as you can see that um the originally it
  29071. 18:46:42said quote usdp percent change 1 hour is
  29072. 18:46:45now only 1 hour. Now this didn't
  29073. 18:46:49actually [clears throat] do anything. We
  29074. 18:46:50need to apply it to this right here. So
  29075. 18:46:53I'm going to say dataf frame 7 is equal
  29076. 18:46:56to and then we'll run dataf frame 7
  29077. 18:47:00again. So now that has actually changed
  29078. 18:47:03that value. Now I'm going to go through
  29079. 18:47:05and I'm going to update that for every
  29080. 18:47:07single one. All right. So I basically
  29081. 18:47:09just put the other ones um in here that
  29082. 18:47:11we wanted to change with commas
  29083. 18:47:13underneath. So I have 24 hours, comma,
  29084. 18:47:16with the seven days, 30 days, 60 days,
  29085. 18:47:1990 days, and then this bracket over
  29086. 18:47:20here, which tells uh it what to change
  29087. 18:47:23it to. 24, 7 days, 30 days, 60 days, 90
  29088. 18:47:26days. So let's run this. I haven't even
  29089. 18:47:29tried it yet. Uh, and it looks like it
  29090. 18:47:32obviously worked properly. So now, let's
  29091. 18:47:35go back down here and let's run this
  29092. 18:47:37again.
  29093. 18:47:39And look at that. It looks so much
  29094. 18:47:41cleaner, so much nicer.
  29095. 18:47:43Um and as you I mean all of them with
  29096. 18:47:46that one hour change has very little
  29097. 18:47:48change and then you can look back so we
  29098. 18:47:51can see back within 90 days it's gone a
  29099. 18:47:54lot of these have gone down which again
  29100. 18:47:56if you're following crypto you know
  29101. 18:47:57there's a big crash recently um
  29102. 18:48:00especially with with you know all these
  29103. 18:48:01altcoins um that you're seeing right
  29104. 18:48:03here went down a ton. So, I think this
  29105. 18:48:06is um avalanche or die or whatever.
  29106. 18:48:09These ones are, you know, went down
  29107. 18:48:11dramatically, whereas there's one up
  29108. 18:48:14here, this lone wolf um that's just
  29109. 18:48:16that's just did doing really well for
  29110. 18:48:18whatever reason. So, it's really
  29111. 18:48:19interesting um to see. Now, this is a
  29112. 18:48:22pretty specific um visualization that I
  29113. 18:48:26personally wanted to see and I thought
  29114. 18:48:28was interesting. You can do absolutely
  29115. 18:48:30whatever you want to do with this data.
  29116. 18:48:32I mean, there's so much here. You can do
  29117. 18:48:35a lot, I mean a lot with this data,
  29118. 18:48:37especially depending on how long you
  29119. 18:48:39track it, right? I only did this over
  29120. 18:48:41the course of like five minutes, but if
  29121. 18:48:43you set this up, um, and you can track
  29122. 18:48:46it over a longer time. Now, um, let's
  29123. 18:48:50say you wanted to do something much
  29124. 18:48:52simpler, uh, you just wanted to look at
  29125. 18:48:54like Bitcoin over that time that you,
  29126. 18:48:58you know, uh, uh, took the data in.
  29127. 18:49:00That's going to be a lot simpler than
  29128. 18:49:01what we just did, and I'll show you how
  29129. 18:49:02to do that really quickly. So, we're
  29130. 18:49:04going to look at the data frame and we
  29131. 18:49:06are going to say uh or we're going to
  29132. 18:49:09take specific columns. We just want um a
  29133. 18:49:13few columns that we want to keep or or
  29134. 18:49:15pull from. So, we're going to take oops
  29135. 18:49:18we're going to take the name column.
  29136. 18:49:21We're going to do uh
  29137. 18:49:24might be easier if I copy them, but I'm
  29138. 18:49:26just going to write them out. Quote,
  29139. 18:49:28USUSD
  29140. 18:49:29price. This is the price of the actual
  29141. 18:49:32cryptocurrency.
  29142. 18:49:34Then we're going to do
  29143. 18:49:36time stamp.
  29144. 18:49:39And let's make this data frame. And
  29145. 18:49:42we're just going to do 10 for absolutely
  29146. 18:49:44no reason.
  29147. 18:49:47Maybe I should have made it nine. It
  29148. 18:49:48would have been easier. So now we just
  29149. 18:49:49have these um these columns. And you
  29150. 18:49:53know we have all these separate columns.
  29151. 18:49:56So what we can do and the re kind of the
  29152. 18:49:58reason I want to show you this is you
  29153. 18:49:59can just query this really quickly and
  29154. 18:50:01just take the columns that you want. So
  29155. 18:50:04let's say we just wanted to look at
  29156. 18:50:05Bitcoin. So we're going to say dataf
  29157. 18:50:08frame 10 dot query do open parenthesis
  29158. 18:50:12and we're going to say name is equal and
  29159. 18:50:16equal is not like that uh when you're
  29160. 18:50:18doing it like this you need to say equal
  29161. 18:50:20equal equal to
  29162. 18:50:23oops ignore that uh is equal to bitcoin
  29163. 18:50:28and we're going to do it just like that
  29164. 18:50:30and we're going to say dataf frame 10 is
  29165. 18:50:32equal to let's try running that think
  29166. 18:50:36Something's wrong with it. Try like
  29167. 18:50:39this.
  29168. 18:50:41All right, let's try that. There we go.
  29169. 18:50:44It was just the I needed a double
  29170. 18:50:46quotation instead of a single quotation.
  29171. 18:50:47That was the issue. So now we have
  29172. 18:50:49Bitcoin. We have the price and we have
  29173. 18:50:51these timestamps. So this is the actual
  29174. 18:50:52time when we ran it. So this is the
  29175. 18:50:55original data frame. And then in the,
  29176. 18:50:56you know, this this project, it took me
  29177. 18:50:5815 more minutes to get this one. And
  29178. 18:50:59then we had it running properly for the
  29179. 18:51:01next five minutes. So that's you know
  29180. 18:51:03that's actually what we have. Now if we
  29181. 18:51:06want to just visualize this really
  29182. 18:51:09simply what we can do is we're going to
  29183. 18:51:11say
  29184. 18:51:13uh we're going to do SNS
  29185. 18:51:15line plot and that's going to be like a
  29186. 18:51:17little line chart or line graph whatever
  29187. 18:51:20whatever you want to call it. Then we're
  29188. 18:51:23going to say x is equal to and we'll say
  29189. 18:51:27quote
  29190. 18:51:29no actually we want the time stamp to be
  29191. 18:51:31on the x axis. Um and then we'll do y is
  29192. 18:51:35equal to quote usd
  29193. 18:51:40price.
  29194. 18:51:42And let's see if that works.
  29195. 18:51:46Could not interpret timestamp for the
  29196. 18:51:49parameter.
  29197. 18:51:51Uh that's because it's not understanding
  29198. 18:51:55that the data
  29199. 18:51:57equals dataf frame 10. Now let's try
  29200. 18:52:01this. All right. So this is uh looks
  29201. 18:52:05terrible. Let me
  29202. 18:52:08just say snss. Set theme
  29203. 18:52:14open parentheses. We'll do style is
  29204. 18:52:17equal to dark.
  29205. 18:52:22This looks a little better. Now again,
  29206. 18:52:25we are looking just at a very very short
  29207. 18:52:29time series, but we can look at just
  29208. 18:52:33Bitcoin or we can look at multiple and
  29209. 18:52:36we're showing this, you know, this line
  29210. 18:52:38that's showing us this trajectory over
  29211. 18:52:40time. So, you can get really creative
  29212. 18:52:42with this. You can run this for a long
  29213. 18:52:43time. You can show Bitcoin over days,
  29214. 18:52:46weeks, or months, however long you run
  29215. 18:52:48this. And so that's really all I've got.
  29216. 18:52:51Um, honestly, like I said, this is not a
  29217. 18:52:53I wouldn't say this is a complete full
  29218. 18:52:56project, but I'm showing you how to do
  29219. 18:52:58something to enable you to kind of run
  29220. 18:53:00with it and run with the ball and do
  29221. 18:53:02basically whatever you want with this.
  29222. 18:53:04You can pull it from, you know, data
  29223. 18:53:06from a different API. You can use this
  29224. 18:53:08exact API and data, but I wanted to show
  29225. 18:53:12you just a few things that I initially
  29226. 18:53:14saw that I might do with the data. And
  29227. 18:53:17you have so much. Let me go back to this
  29228. 18:53:19original data frame.
  29229. 18:53:21Uh right, we'll use this one right here.
  29230. 18:53:24This one right here. Look at all this
  29231. 18:53:26data. I mean, you have so so so much
  29232. 18:53:29data. Actually, let's go to this one.
  29233. 18:53:30This one's better. You have so much
  29234. 18:53:32data. So many numbers here. Um so many
  29235. 18:53:35columns that we didn't even look at that
  29236. 18:53:37you can use. Um and so, you know,
  29237. 18:53:40there's a lot that you can use here. And
  29238. 18:53:44I'm really trying to just set you up so
  29239. 18:53:46that you can run with it and do whatever
  29240. 18:53:48you want. I could have done a thousand
  29241. 18:53:49different things here, but you know, I
  29242. 18:53:51tried to just show you two things that
  29243. 18:53:53you can do with the data that I thought
  29244. 18:53:55were pretty interesting or or simple to
  29245. 18:53:57do. And you know, I want you guys to go
  29246. 18:54:00out and do something way way better than
  29247. 18:54:02what I did. So, I hope that this was
  29248. 18:54:04helpful. I hope that this showed you how
  29249. 18:54:05to automate that process so you don't
  29250. 18:54:08have to sit there and click it and
  29251. 18:54:10append it and do all these different
  29252. 18:54:11things. that I can show you how to kind
  29253. 18:54:13of automate this process and hopefully
  29254. 18:54:15that will be helpful in your future
  29255. 18:54:16projects. So, with that being said,
  29256. 18:54:19thank you so much for watching. If you
  29257. 18:54:21made it all the way to the end, you guys
  29258. 18:54:22are fantastic. If you like this video,
  29259. 18:54:24be sure to like and subscribe below and
  29260. 18:54:26I'll see you in the next video.
  29261. 18:54:29[music]
  29262. 18:54:40What's going on everybody? Welcome back
  29263. 18:54:41to another video. Today I'm going to be
  29264. 18:54:43walking you through how to create your
  29265. 18:54:44very own portfolio website.
  29266. 18:54:49[music]
  29267. 18:54:52Now, we just completed our data analyst
  29268. 18:54:54portfolio project series where we walked
  29269. 18:54:55through four projects in SQL, Tableau,
  29270. 18:54:58and Python. And so, if you have
  29271. 18:55:00completed those projects, you now want
  29272. 18:55:02to share them with potential employers.
  29273. 18:55:03And I think the best way to do that is
  29274. 18:55:05to create your own website. In just a
  29275. 18:55:07little bit, I'm going to show you two
  29276. 18:55:08options on how you can actually create
  29277. 18:55:10your own website. The first one is a
  29278. 18:55:11website builder like wix.com. And the
  29279. 18:55:14second one is hosting your own website
  29280. 18:55:16through something called GitHub Pages.
  29281. 18:55:18Now, if you have never created your own
  29282. 18:55:19website before, it can sound a little
  29283. 18:55:20bit daunting, but don't worry. I'm going
  29284. 18:55:22to walk you through every single step of
  29285. 18:55:24the way from the very start to the very
  29286. 18:55:25end. And once you reach the end, you
  29287. 18:55:27will have a complete data analyst
  29288. 18:55:29portfolio website. So, without further
  29289. 18:55:30ado, let's jump on my screen and let's
  29290. 18:55:32get started. All right. So, the website
  29291. 18:55:33that you're looking at right now is the
  29292. 18:55:35actual website that we are going to
  29293. 18:55:36build in this video. Um, it is hosted on
  29294. 18:55:39GitHub pages or github.io. So, this is
  29295. 18:55:42actually being hosted right now by
  29296. 18:55:43GitHub pages. So, if you type this in,
  29297. 18:55:45I'll leave a link in the description. If
  29298. 18:55:47you type this in, um, you will get this
  29299. 18:55:50page and you can check it out for
  29300. 18:55:51yourself if you don't want to just watch
  29301. 18:55:53me look at it. Um, so, you know, it has
  29302. 18:55:56this little header and you can write a
  29303. 18:55:57little bit about yourself. And then
  29304. 18:55:59these are actual projects. So this is
  29305. 18:56:01our data cleaning in SQL project. Um and
  29306. 18:56:04then there's the COVID uh data
  29307. 18:56:06exploration, Tableau dashboards, movie
  29308. 18:56:08correlation with Python. Um this is a
  29309. 18:56:10future video. I plan on doing a few more
  29310. 18:56:13of these projects because I just really
  29311. 18:56:15enjoy them. So um you know, and then
  29312. 18:56:18there's this contact information at the
  29313. 18:56:20bottom. So it's a really simple
  29314. 18:56:23website and it gets the point across.
  29315. 18:56:26And uh I have something similar to this
  29316. 18:56:28for my own personal one. I I use a
  29317. 18:56:30different variation, but um this all
  29318. 18:56:33comes from this website, HTML 5. There
  29319. 18:56:37are lots of templates, lots of options
  29320. 18:56:39that you can use. Um again, the one
  29321. 18:56:41we're going to be working with is this
  29322. 18:56:43one, but I use a different one for mine,
  29323. 18:56:46and they are really good. I mean, super
  29324. 18:56:48easy to build and customize yourself.
  29325. 18:56:53And I will say again, I have no
  29326. 18:56:54experience doing this. I just watched a
  29327. 18:56:57YouTube video that showed me how to do
  29328. 18:56:58this and now I am creating my own
  29329. 18:57:01YouTube video to show you how to do
  29330. 18:57:02this. So, it's coming um pretty much
  29331. 18:57:04full circle. So, like I said, there's no
  29332. 18:57:07no real narrative to it. It just clicks
  29333. 18:57:09to your project. Um if you click on this
  29334. 18:57:11and let's just open a new tab, it'll
  29335. 18:57:13take you right to our the GitHub
  29336. 18:57:15project. Um and then you this whoever's
  29337. 18:57:18checking this out like a an employer or
  29338. 18:57:20a recruiter can see your code. So, super
  29339. 18:57:23simple. Another way that you can do this
  29340. 18:57:25is kind of creating your own website
  29341. 18:57:28through like a template or something
  29342. 18:57:30like that. Um, almost like a blog style.
  29343. 18:57:33So, I imagine it being very something
  29344. 18:57:35very similar to this where there's this
  29345. 18:57:37introduction and you can talk about, you
  29346. 18:57:38know, where you got the data set, how
  29347. 18:57:40you got the data. Um, and then you can
  29348. 18:57:42kind of have a more narrative uh
  29349. 18:57:45approach with screenshots and with some
  29350. 18:57:47code as well. So, you know, this person
  29351. 18:57:49included screenshots. Um, and then
  29352. 18:57:51there's the code right here that I can
  29353. 18:57:53actually copy um, and paste that and it
  29354. 18:57:56just walks through the logic of how the
  29355. 18:57:59project was done. Um, there's a story to
  29356. 18:58:02it really. And so that might be
  29357. 18:58:04something that you're interested in.
  29358. 18:58:05Now, I have done something like this in
  29359. 18:58:08the past and I used Wix and there's a
  29360. 18:58:10you can do this completely for free. Um,
  29361. 18:58:12the one we're doing today is completely
  29362. 18:58:13free as well, but you know, if you want
  29363. 18:58:16the customized
  29364. 18:58:18um the customized URL, you do have to
  29365. 18:58:20pay for it on Wix, but you can get a
  29366. 18:58:23free Wix website with the Wix um in the
  29367. 18:58:26URL. So, you know, try this out. These
  29368. 18:58:29are super easy and you can find
  29369. 18:58:31thousands of templates and a million
  29370. 18:58:32tutorials on how to do them. Um, so
  29371. 18:58:34that's not the one we're going to be
  29372. 18:58:35working on today. So, with that being
  29373. 18:58:38said, uh the very very first thing that
  29374. 18:58:41we need to do before we do anything is
  29375. 18:58:43actually download Visual Studio Code.
  29376. 18:58:46This is where we're going to download
  29377. 18:58:47that HTML and we're going to be working
  29378. 18:58:49with it in there. Um again, I don't know
  29379. 18:58:52if I said this before, but it seems a
  29380. 18:58:55little bit intimidating at first, but
  29381. 18:58:56once we actually start looking at it,
  29382. 18:58:58it's a lot easier than it looks. I
  29383. 18:58:59promise you. So, if you are me and you
  29384. 18:59:02have a Windows computer, you'll just go
  29385. 18:59:04right here. you'll install it. Um, super
  29386. 18:59:07easy to install. I'm not going to walk
  29387. 18:59:08you through how to do that. Um, of
  29388. 18:59:10course, I already have it up and running
  29389. 18:59:12uh down here. So, once you have that
  29390. 18:59:15installed, what you're going to do is
  29391. 18:59:17you're going to come to this website. A
  29392. 18:59:18link should be in the description. We
  29393. 18:59:20are going to download this. All you have
  29394. 18:59:22to click is the free download. It's
  29395. 18:59:26going to pop up. I'm going to put it in
  29396. 18:59:27my downloads. I'm going to click save.
  29397. 18:59:31Fantastic. Uh, so let's go to the
  29398. 18:59:35downloads and it should be right here.
  29399. 18:59:36Now, if we open this up, it has a few
  29400. 18:59:39different things in it. Okay, so um I'm
  29401. 18:59:41using the Brave browser, so that's going
  29402. 18:59:43to be right here. So that's just the
  29403. 18:59:45symbol. But for you, if you're using
  29404. 18:59:46Google Chrome, that should be the symbol
  29405. 18:59:48there as well. But this is everything
  29406. 18:59:50that you should be seeing. And what we
  29407. 18:59:53want to do is we want to take it out of
  29408. 18:59:54this um zip folder because it's there
  29409. 18:59:59are things that can read into it with
  29410. 19:00:01Visual Studio Code, but I want to make
  29411. 19:00:02this as user friendly as I possibly can.
  29412. 19:00:05So, what we're going to do is we're
  29413. 19:00:07going to make create a new folder. I'm
  29414. 19:00:09just going to call it massively or you
  29415. 19:00:11can call it um port website. Whatever
  29416. 19:00:14you want to call it. I'm just going to
  29417. 19:00:15do port website. Um and we are just
  29418. 19:00:19going to I'm going to copy this in. I'm
  29419. 19:00:21not going to cut it in just in case I
  29420. 19:00:23make a mistake. So, gonna put all of
  29421. 19:00:27those um all of those things in here.
  29422. 19:00:30And now what we're going to do is we're
  29423. 19:00:33going to go to Visual Studio Code right
  29424. 19:00:35here. And you should be greeted with
  29425. 19:00:38this um this right here. And we're just
  29426. 19:00:40going to click open folder. And we're
  29427. 19:00:42going to go to port website. And we're
  29428. 19:00:44going to go select folder.
  29429. 19:00:46And you're going to say yes, I trust
  29430. 19:00:48this one. And right over here is all of
  29431. 19:00:51the documents that we were just looking
  29432. 19:00:53at. Now, the one that the only one
  29433. 19:00:56really that we're going to be working
  29434. 19:00:57in, um, we'll work a little bit in the
  29435. 19:00:59images, um, because I'll show you how to
  29436. 19:01:01add your own images. The really the only
  29437. 19:01:04one we're going to be working in is this
  29438. 19:01:06index. So, again, it looks complicated.
  29439. 19:01:10Um, if you've never looked at HTML
  29440. 19:01:12before, um, it does look a little bit
  29441. 19:01:14complicated, but HTML to me is one of
  29442. 19:01:18the more easily understood languages.
  29443. 19:01:21Um, once you start kind of getting into
  29444. 19:01:23it, which we're about to, we're going to
  29445. 19:01:24walk through the entire process, it
  29446. 19:01:26actually makes a lot of sense and it is
  29447. 19:01:28pretty simple. Um, something that you're
  29448. 19:01:31going to want is you're going to want
  29449. 19:01:33something called a live view. So, like
  29450. 19:01:35if I click right here and I click open
  29451. 19:01:37with live server, you don't have that
  29452. 19:01:38yet, I'm guessing, unless you've done
  29453. 19:01:40this before. Um, it's going to open up
  29454. 19:01:42this website. And this is what we're
  29455. 19:01:44looking at right now. So, it says a
  29456. 19:01:46bunch of um gibberish or some language
  29457. 19:01:49that I do not know. And so, we can view
  29458. 19:01:53this live. Um, in just a second, I'm
  29459. 19:01:56going to take myself off screen, but
  29460. 19:01:58before I do that, um, let's download or
  29461. 19:02:02let's, um, search for that that live,
  29462. 19:02:07um, I think it's called live share, live
  29463. 19:02:09server.
  29464. 19:02:11Let me see what this called.
  29465. 19:02:13Yeah, live server. So, come right here.
  29466. 19:02:16It's called this live server. There it
  29467. 19:02:17is. Yeah, that's the one. So, this is
  29468. 19:02:20our live server. You just need to click
  29469. 19:02:21install. takes like 5 seconds and it
  29470. 19:02:24should be completely installed. Um, what
  29471. 19:02:26this does is it just hosts a local
  29472. 19:02:29website. It's not something that anybody
  29473. 19:02:31can access. Um, but it connects to your
  29474. 19:02:33code and when we make updates, it'll
  29475. 19:02:35make a li you can see it live. You can
  29476. 19:02:36see those updates live. So, I'll show
  29477. 19:02:38you all that in a second. Just be sure
  29478. 19:02:40to um be sure to download that or
  29479. 19:02:42install that. Uh, with that being said,
  29480. 19:02:45let's get out of this. Let's go. Let's
  29481. 19:02:47go back right here. Uh with that being
  29482. 19:02:50said, I am going to take myself off
  29483. 19:02:51screen so that you can see everything
  29484. 19:02:53that I am seeing as well. Um it's been
  29485. 19:02:56really great seeing you. Have lots of
  29486. 19:02:59different videos coming up, lots of new
  29487. 19:03:01projects. Um I just I really enjoy this
  29488. 19:03:04project series. I think I'm just going
  29489. 19:03:05to do more of them. So uh all right, I'm
  29490. 19:03:08going to get myself off screen. So let's
  29491. 19:03:11look at what we actually need to do. So
  29492. 19:03:14I'm going to um
  29493. 19:03:17So let me see. Okay, so we're already
  29494. 19:03:19connected to the live. Um, actually, I
  29495. 19:03:22got rid of it. Whoops.
  29496. 19:03:25Let's pull this over. And let's pull
  29497. 19:03:28that.
  29498. 19:03:30And we're going to
  29499. 19:03:32open in live server. So, if we look
  29500. 19:03:36right over here, and I know this is
  29501. 19:03:38going to be a little bit squish, and I'm
  29502. 19:03:39sorry about that. Um, but if we look
  29503. 19:03:42right over here, this says this is
  29504. 19:03:44massively. So, you can change that.
  29505. 19:03:47That's that's this right here. And you
  29506. 19:03:49can say we're going to say Alex the
  29507. 19:03:52analyst
  29508. 19:03:53portfolio. And we'll get rid of this
  29509. 19:03:55massively. I'm going to hit control
  29510. 19:03:57save. You can also go up here and hit
  29511. 19:04:00save. But I'm I'm hit control S. So I
  29512. 19:04:03hit control S. And just like that, it
  29513. 19:04:07updates on the website. Now again, this
  29514. 19:04:09is just a local, so it's nothing that
  29515. 19:04:11anybody can see, so don't worry.
  29516. 19:04:13But what we're going to do is I'm going
  29517. 19:04:15to walk you through the entire process
  29518. 19:04:16of creating this and then at the end I
  29519. 19:04:19will show you how to host it on GitHub.
  29520. 19:04:21Um and it's honestly it's it's a fairly
  29521. 19:04:24easy process. It's just takes a little
  29522. 19:04:25bit of time to customize it all. So
  29523. 19:04:28let's get into it. So we have this um
  29524. 19:04:31you may not be able to see it. Let me
  29525. 19:04:32actually pull this up. So it says
  29526. 19:04:33massively by HTTP. We're going to
  29527. 19:04:36customize that. Customize that as well.
  29528. 19:04:38Whoops. I don't want to do that every
  29529. 19:04:39single time. I'm I'm gonna try not to go
  29530. 19:04:41full and go back and everything like
  29531. 19:04:43that. So, we're just gonna say Alex the
  29532. 19:04:46analyst portfolio.
  29533. 19:04:50Um, control S. And right up here, it
  29534. 19:04:52changed it. You may not be able to see.
  29535. 19:04:54Yeah. Don't ask me that again. Thank
  29536. 19:04:55you. Uh, right up here, you probably
  29537. 19:04:56can't see at the moment. We'll see that
  29538. 19:04:58later. Um, but it it customizes this um
  29539. 19:05:01tab, which is really cool.
  29540. 19:05:04So, let's go right down here. Now, this
  29541. 19:05:07is where it says a free, fully
  29542. 19:05:08responsive HTML uh 5 template. We can
  29543. 19:05:14customize that and I highly encourage
  29544. 19:05:16that you do. So, what you can do, and
  29545. 19:05:20they actually included their Twitter
  29546. 19:05:22handle right here, and you can do the
  29547. 19:05:24same. If you look at this one right
  29548. 19:05:27here, I included my Alex the Analyst
  29549. 19:05:30handle that that goes to my YouTube
  29550. 19:05:31channel. And you can do the exact same
  29551. 19:05:33thing. include your LinkedIn or your
  29552. 19:05:35GitHub profile or whatever you want to
  29553. 19:05:36include in there. Um, and so, you know,
  29554. 19:05:40be aware that you can do that. So, let's
  29555. 19:05:43say um, oops, I need to click back in
  29556. 19:05:46here. So, we're going to say
  29557. 19:05:50um,
  29558. 19:05:52data analyst skilled in and then again,
  29559. 19:05:56don't write what I'm writing. Um, you
  29560. 19:05:58can it's I'm just going to make it
  29561. 19:06:00really simple, but you know, this part
  29562. 19:06:02is meant to be a little bit about you um
  29563. 19:06:04as who you are. So, I'm going to say
  29564. 19:06:06data analyst skilled in SQL, Tableau,
  29565. 19:06:10and Python.
  29566. 19:06:13And then I'm just going to get rid of
  29567. 19:06:15all of this.
  29568. 19:06:18Yep.
  29569. 19:06:19Everything from here over
  29570. 19:06:22and control S.
  29571. 19:06:24And so, super simple. Um, actually, let
  29572. 19:06:26me Where was that? Four.
  29573. 19:06:30Four. Here it is. We don't need that.
  29574. 19:06:33Actually, we don't need any anything
  29575. 19:06:36from here over.
  29576. 19:06:39Probably here, honestly. See what that
  29577. 19:06:42looks like. Um, and yeah, and I can,
  29578. 19:06:44again, you can use any website right
  29579. 19:06:46here that you want, and you can
  29580. 19:06:48customize what it looks like. So, I'm
  29581. 19:06:49going to say Alex the Analyst. Um, and
  29582. 19:06:52then whatever URL you want to include in
  29583. 19:06:54there, that's what you need to put. So
  29584. 19:06:55now if I save, oops, if I hit control S.
  29585. 19:06:58So now it says Alex the analyst. Um, so
  29586. 19:07:02pretty easy.
  29587. 19:07:04Now we're going to go down and
  29588. 19:07:07[clears throat] you can use this however
  29589. 19:07:09you want to use it. I would you can even
  29590. 19:07:11make this um you can make this like one
  29591. 19:07:15of your one of your readmes like about
  29592. 19:07:17you and put the link for that. I decided
  29593. 19:07:19to include um again on this one I
  29594. 19:07:22decided to include the project that I
  29595. 19:07:24thought that we've done that was like
  29596. 19:07:26the the most impressive or the I don't
  29597. 19:07:28know the coolest one. I don't know if
  29598. 19:07:31you consider data cleaning and SQL cool
  29599. 19:07:33but um I do I think it's cool. So I
  29600. 19:07:36included that one as my very first one.
  29601. 19:07:38So that's what we're going to do um
  29602. 19:07:39right here.
  29603. 19:07:41So, we're going to go down and it's
  29604. 19:07:44going to say,
  29605. 19:07:47let's say it says this is massively.
  29606. 19:07:49That's not it. Uh, cool. So, let's see
  29607. 19:07:53what Oh, okay. I know what that is.
  29608. 19:07:54We'll come back to this up here um in
  29609. 19:07:57just a little bit. I'm going to go full
  29610. 19:07:58screen. I'll show you what this is and
  29611. 19:08:00then we'll come back to it. But, if we
  29612. 19:08:02go right down here, this is our what
  29613. 19:08:04they're calling a featured post and then
  29614. 19:08:06the ones below this are posts. So, in
  29615. 19:08:09our featured post, um I'm going to get
  29616. 19:08:11rid of the date. I don't want them to
  29617. 19:08:13know that I just created it like um I
  29618. 19:08:16don't know. Oops. I keep doing uh
  29619. 19:08:19control A selecting everything. Whoops.
  29620. 19:08:22So, we're going to say um data cleaning
  29621. 19:08:26in SQL.
  29622. 19:08:29And we'll get rid of this
  29623. 19:08:32and control S. Again, I'm just updating
  29624. 19:08:34it a lot so that you see what I'm doing
  29625. 19:08:36and where it's going. And we're going to
  29626. 19:08:38get rid of basically all of this and go
  29627. 19:08:42back. And we're just going to say
  29628. 19:08:45in this project we clean data in we
  29629. 19:08:49clean let's do we clean housing data in
  29630. 19:08:52SQL server
  29631. 19:08:55and control S. So, super easy. Again, uh
  29632. 19:08:57give a little bit more description. I
  29633. 19:08:59did in my other one. Um and you have the
  29634. 19:09:01you have you can see that website. So,
  29635. 19:09:02go check it out. And then we'll have an
  29636. 19:09:05image and I'm going to show you um at
  29637. 19:09:07the end. We're going to go back and redo
  29638. 19:09:09all the images, but I'm not going to do
  29639. 19:09:11that at this very moment.
  29640. 19:09:14Um so,
  29641. 19:09:16what we're now you can have this full
  29642. 19:09:18story. I chose to do view project.
  29643. 19:09:24And if I hit Ctrl S, it says view
  29644. 19:09:26project. I think that just looks better,
  29645. 19:09:28especially if you're displaying a
  29646. 19:09:29project. I think it is nice. Uh, now we
  29647. 19:09:32go into all the indiv individual posts.
  29648. 19:09:34Um, actually, no, wait. What I want you
  29649. 19:09:37I want to show you really quick is how
  29650. 19:09:39you actually link it to this. So, let's
  29651. 19:09:41go right over here. This is our COVID uh
  29652. 19:09:44that's our COVID one. Here's a data
  29653. 19:09:47cleaning project. So, all you have to do
  29654. 19:09:49is take um take this website. So that's
  29655. 19:09:53the URL and you're going to put it right
  29656. 19:09:56here. Now there's three different
  29657. 19:09:57places. This href is places are places
  29658. 19:10:00where you can put a link to a website.
  29659. 19:10:02Um and on here it references this right
  29660. 19:10:06here. So you can they can click on this
  29661. 19:10:08data cleaning and SQL. They can click on
  29662. 19:10:10the image um as because you know this
  29663. 19:10:12href is right next to this image. They
  29664. 19:10:15can also click on the view project
  29665. 19:10:18button. So you can put it in all three.
  29666. 19:10:20Um and you'll just go like this. You'll
  29667. 19:10:22you'll stick the URL right where that um
  29668. 19:10:26hashtag or pound sign is.
  29669. 19:10:30And then we're going to save that. Oops.
  29670. 19:10:33Oh, I I this is embarrassing. I am not a
  29671. 19:10:36website. I am not a web developer as you
  29672. 19:10:38can see. Um but then if I go in here and
  29673. 19:10:42I right click and I say open link, it is
  29674. 19:10:44going to take me to that project. So,
  29675. 19:10:46super simple. And we're going to do
  29676. 19:10:48basically that for all of these. Um, I'm
  29677. 19:10:50only going to show you three and then
  29678. 19:10:51you can do the rest, but I want to show
  29679. 19:10:53you how to also do the um put the
  29680. 19:10:55Tableau. It's the exact same thing, but
  29681. 19:10:58you know, it's different. So, wanted to
  29682. 19:10:59show it to you. So, the next one that
  29683. 19:11:02we're going to do is go down to posts
  29684. 19:11:05and
  29685. 19:11:07again, I'm going to get rid of this
  29686. 19:11:08date. You can keep that in there if you
  29687. 19:11:09want. Excuse me. And that's totally
  29688. 19:11:12fine. Just update
  29689. 19:11:14the date. Um, this is that said Magna.
  29690. 19:11:17Again, I think this might be like some
  29691. 19:11:18language. I just don't know about. The
  29692. 19:11:20next one is data exploration
  29693. 19:11:23in SQL.
  29694. 19:11:25And I'm going to get rid of this.
  29695. 19:11:28And we'll save that. Perfect.
  29696. 19:11:32And we'll do view project.
  29697. 19:11:38Cool.
  29698. 19:11:40And yeah, so now we need to um customize
  29699. 19:11:44this summary. And so I'm just going to
  29700. 19:11:47say something really simple. Um data
  29701. 19:11:51exploration of COVID 19
  29702. 19:11:57data set in SQL Server.
  29703. 19:12:02There we go. Let's save that. We have
  29704. 19:12:05view project. Now let's go get our
  29705. 19:12:07project. So this is the data
  29706. 19:12:09exploration. We're going to take this.
  29707. 19:12:12We're going to copy it and we're going
  29708. 19:12:14to put it right in here.
  29709. 19:12:17and right in here as well. And if you
  29710. 19:12:20want to, you can also include it right
  29711. 19:12:22up here. So, we have it in all three
  29712. 19:12:24places. Uh, again, once you click on
  29713. 19:12:27these, they will come up. Let's go to
  29714. 19:12:30the next one. We're going to get rid of
  29715. 19:12:33this.
  29716. 19:12:35This one is going to be our Tableau
  29717. 19:12:37projects. So, actually, let me just copy
  29718. 19:12:38that while we're here. This is going to
  29719. 19:12:40be our Tableau projects. So if you have
  29720. 19:12:43one specific project that you want to
  29721. 19:12:45include, what you would need to do is
  29722. 19:12:47actually go in here, click view, grab
  29723. 19:12:50that URL. What I am doing is I am just
  29724. 19:12:53sharing my Tableau public page. So if
  29725. 19:12:56you have tons of projects in here and um
  29726. 19:13:00you want to display all of them then or
  29727. 19:13:03you want them to be able to see all of
  29728. 19:13:04them and go and pick and see and choose
  29729. 19:13:06what they want to look at, then just
  29730. 19:13:08choose this URL that we're choosing
  29731. 19:13:09right here. So, um, in here or on in
  29732. 19:13:13the, um, HTML, we're going to put I'm
  29733. 19:13:16going to put Tableau projects.
  29734. 19:13:20And
  29735. 19:13:21let's go like this.
  29736. 19:13:24And then we will get rid of uh, that
  29737. 19:13:28hashtag,
  29738. 19:13:30pound sign, whatever you want to call
  29739. 19:13:31it.
  29740. 19:13:33And we'll hit Crl S. And oh, we got to
  29741. 19:13:37do the um
  29742. 19:13:39this as well.
  29743. 19:13:43This is my This is going to be a
  29744. 19:13:46terrible Don't use this. This is my
  29745. 19:13:48Tableau.
  29746. 19:13:50This holds I'm just This is bad. This
  29747. 19:13:52holds all of my Tableau
  29748. 19:13:56dashboards.
  29749. 19:13:58Don't Please don't do this. Um I am
  29750. 19:14:01doing this because I don't want to take
  29751. 19:14:03forever in a video to make it perfect.
  29752. 19:14:05Um, and then you know, you're going to
  29753. 19:14:07do the exact same thing. So, in this one
  29754. 19:14:10right here, I included four. So, I'm
  29755. 19:14:12going to keep four. Um,
  29756. 19:14:16let me do the uh, no, I'm just going to
  29757. 19:14:18do these three. I'm not going to take up
  29758. 19:14:21more of our time. Um, so we did those.
  29759. 19:14:25I'm just going to keep these three in
  29760. 19:14:26for visual purposes. But once you get
  29761. 19:14:29down here, um, you know what we're going
  29762. 19:14:32to do is delete some of this, right? So
  29763. 19:14:34we this is our data exploration and
  29764. 19:14:37where's our Tableau
  29765. 19:14:40this is our Tableau right here. So
  29766. 19:14:42Tableau projects they're separated by
  29767. 19:14:44these articles. So what we're going to
  29768. 19:14:45do is go around right here and we're
  29769. 19:14:47going to go down down down down
  29770. 19:14:49to right here. This is going to get rid
  29771. 19:14:51of all these other articles or all these
  29772. 19:14:53other what they're calling um posts. So
  29773. 19:14:57we're going to get rid of those and
  29774. 19:14:58we're going to hit save.
  29775. 19:15:01And now, as you can see, we have our
  29776. 19:15:03header, we have our first project, and
  29777. 19:15:06we have our second and our third. I
  29778. 19:15:08would include those other projects that
  29779. 19:15:10we've done in here so that it looks
  29780. 19:15:12good. This is this footer right here. We
  29781. 19:15:15don't need that cuz we don't have any um
  29782. 19:15:17anything else in there. So, we're going
  29783. 19:15:19to get rid of that as well. And now we
  29784. 19:15:21just have this information. Now,
  29785. 19:15:24I don't have anything where they can do
  29786. 19:15:27the name, email, message, or you can
  29787. 19:15:28keep that in there if you'd like. Um,
  29788. 19:15:30but I am going to get rid of this. So,
  29789. 19:15:33we're going to go right here. That's
  29790. 19:15:35this section. So, don't delete this
  29791. 19:15:37section. We want that. I'm going to
  29792. 19:15:38delete this footer section is what
  29793. 19:15:40they're calling it. And now we have this
  29794. 19:15:44address, phone, email, social. Um, and
  29795. 19:15:46I'm going to get to the social in just a
  29796. 19:15:48second. It's again super easy.
  29797. 19:15:51But for the address, I just put
  29798. 19:15:53location. I don't want to give somebody
  29799. 19:15:54my address or put it on a website
  29800. 19:15:55anywhere. Um, it's not something I want
  29801. 19:15:58to do. So, what we're going to do is
  29802. 19:16:00just put I'm going to put Dallas and
  29803. 19:16:03Texas. And we can keep it like that. And
  29804. 19:16:06we'll hit Oops. We'll hit save. And
  29805. 19:16:09it'll have Dallas, Texas. Um, hate the
  29806. 19:16:12look of the zeros. 67890. So, we're
  29807. 19:16:16going to do that. Phone number one, two,
  29808. 19:16:20three, five, six, 789.
  29809. 19:16:24And then email. and we'll put
  29810. 19:16:28Alex thean analyst 95gmail.com.
  29811. 19:16:34If you have issues with this, um, you
  29812. 19:16:36can email me, but
  29813. 19:16:39I'll try I will try to respond to all
  29814. 19:16:41your emails. I get a lot. Um, so I will
  29815. 19:16:44do my best. That is my actual email if
  29816. 19:16:46you are curious. Now, um, now that we
  29817. 19:16:49have this, we also have these this
  29818. 19:16:51social media. Now I want to display my
  29819. 19:16:55LinkedIn and I also want to display my
  29820. 19:16:59GitHub. So what I'm going to do right
  29821. 19:17:01here is I'm going to go over here and do
  29822. 19:17:02LinkedIn.
  29823. 19:17:05Perfect. Let's go to this. So I'm going
  29824. 19:17:09to take my LinkedIn URL
  29825. 19:17:13and I am going to get rid of these first
  29826. 19:17:16two because I'm only going to include
  29827. 19:17:19two. And for this one, I'm going to do
  29828. 19:17:23uh LinkedIn.
  29829. 19:17:25Oops. LinkedIn in. And then for right
  29830. 19:17:29here, I'm going to replace that with
  29831. 19:17:31linked in.
  29832. 19:17:34And what you're going to do is put this
  29833. 19:17:37link right here. And then we're going to
  29834. 19:17:39go get do get the GitHub.
  29835. 19:17:42So, let's do GitHub. Oh, who's is this
  29836. 19:17:45sign up? What is going on? Um,
  29837. 19:17:49I don't there. Let's just go back here.
  29838. 19:17:52That was something I was like viewing a
  29839. 19:17:54while back or something. Um, so we're
  29840. 19:17:56going to take the GitHub and we're going
  29841. 19:17:58to put that right here.
  29842. 19:18:01So, it already has it as um the GitHub.
  29843. 19:18:05Is this supposed to be lowercase?
  29844. 19:18:08I think it is. Let me see if this is
  29845. 19:18:10lowercased as well. Yeah. Um, so do it
  29846. 19:18:13like that. Do it lowercased. Um, I
  29847. 19:18:15forgot that that was how they did it.
  29848. 19:18:18Um,
  29849. 19:18:19and oh, that's the label. That doesn't
  29850. 19:18:21matter as much. But this right here is
  29851. 19:18:22the class is actually the important part
  29852. 19:18:24because then when we go back here, there
  29853. 19:18:27is no LinkedIn image. But when we save
  29854. 19:18:29it, oops, when we save it, it has the
  29855. 19:18:33LinkedIn image because it's already a
  29856. 19:18:34class that was created in this HTML um,
  29857. 19:18:37template.
  29858. 19:18:39So, we have that. Um, and let me bring
  29859. 19:18:42this full screen really quick because
  29860. 19:18:44there are a few things that we couldn't
  29861. 19:18:45see in that that screen. These right
  29862. 19:18:48here are things that we could not see
  29863. 19:18:51before. Um, and these as well. So, what
  29864. 19:18:56we can do is we're going to go down
  29865. 19:18:57here. We're just going to copy these
  29866. 19:18:59social. We're going to replace them
  29867. 19:19:00right here so they can have those. And
  29868. 19:19:02then we're going to get rid of these two
  29869. 19:19:03right here. And this says this is
  29870. 19:19:05massively um, and we're going to change
  29871. 19:19:07that as well. Let's make this full
  29872. 19:19:09screen for the first time. Feels good.
  29873. 19:19:12Um, I hate doing split screen, but I do
  29874. 19:19:14it for you guys. Um, so [clears throat]
  29875. 19:19:18this is Massively. And we're just going
  29876. 19:19:20to put we're just going to get rid of
  29877. 19:19:21these two. This is um it's called the
  29878. 19:19:24navigator, the the different tabs. We're
  29879. 19:19:26going to get rid of those two tabs. And
  29880. 19:19:27then for this, I'm just going to call it
  29881. 19:19:30projects.
  29882. 19:19:31And I'll once I once we go back and
  29883. 19:19:33update all of this, then you will um
  29884. 19:19:36you'll see those changes.
  29885. 19:19:38So, let's see. So, we made those
  29886. 19:19:40changes. Here's our social or the social
  29887. 19:19:42medias uh social media stuff. We're
  29888. 19:19:45going to go and copy these two.
  29889. 19:19:50And we're going to replace all of these
  29890. 19:19:53with this.
  29891. 19:19:56Um
  29892. 19:19:57[clears throat] and let's save that. and
  29893. 19:20:00let's go back. So now, as you can see,
  29894. 19:20:02those two are gone. This says projects.
  29895. 19:20:04There's only two right here. And if you
  29896. 19:20:06click on it, it's going to go to my
  29897. 19:20:09LinkedIn or your LinkedIn when you do
  29898. 19:20:11it. Um, and this will take you to the
  29899. 19:20:14GitHub. So, it is all working as
  29900. 19:20:17intended. This is great. Um, when you
  29901. 19:20:19scroll down and it says massively, we
  29902. 19:20:21can change that as well, and we should.
  29903. 19:20:23Let's do that really quick. Um, we'll
  29904. 19:20:26just say
  29905. 19:20:28Alex the analyst
  29906. 19:20:30and we'll update that.
  29907. 19:20:33And there we go. So, in a nutshell, this
  29908. 19:20:37is all the a lot of it. Um, we need
  29909. 19:20:40images.
  29910. 19:20:41And I don't think I set this up for this
  29911. 19:20:44video. So, I'm going to I'm going to
  29912. 19:20:47like cut myself off for like two
  29913. 19:20:49seconds. Go pull those images in um
  29914. 19:20:51because it could take like a few
  29915. 19:20:53minutes. I don't want to waste your
  29916. 19:20:54time. And then I'll come back. So, I'll
  29917. 19:20:55see you in two seconds. All right, so I
  29918. 19:20:57just pulled over the images that we are
  29919. 19:20:59going to use. Let's go to the downloads.
  29920. 19:21:02Um, they're right here. They're the
  29921. 19:21:03housing, Tableau, and COVID. Um, if I
  29922. 19:21:06open up this COVID one, this is what the
  29923. 19:21:08image looks like. This is what we're
  29924. 19:21:09going to use for that COVID project. So,
  29925. 19:21:12I'm going to copy these. I'm going to go
  29926. 19:21:13into the port website um that we just
  29927. 19:21:16had. I'm going to go to images and I'm
  29928. 19:21:18going to insert these in here.
  29929. 19:21:20So, now that we have those images in
  29930. 19:21:22here, let's go back
  29931. 19:21:25and let's see what we got. So, we just
  29932. 19:21:28put these images in this um you'll have
  29933. 19:21:31this folder right here. And you can open
  29934. 19:21:34it up and you can see all of these that
  29935. 19:21:36we have. So, all we're going to do is go
  29936. 19:21:38and replace the images, these these, you
  29937. 19:21:41know, um temporary images that they had
  29938. 19:21:43for us, and we should be golden. and
  29939. 19:21:47then we're going to actually upload it
  29940. 19:21:48to to GitHub and then create our website
  29941. 19:21:51for free. So, let's go right down here.
  29942. 19:21:54This is our very first uh one. This is
  29943. 19:21:57our data cleaning in SQL. This is with
  29944. 19:21:59the housing data. So, this image right
  29945. 19:22:02over here, it says images/pick01.jpeg.
  29946. 19:22:06So, uh JPEG, I don't know why I said it
  29947. 19:22:08like that. So, this is the housing. So,
  29948. 19:22:10what we're going to do right here is do
  29949. 19:22:12housing and it'll autocomplete for us.
  29950. 19:22:14Um, so that housing should be in there.
  29951. 19:22:16Now, next one is the data exploration in
  29952. 19:22:19SQL. That was with the COVID. So, we're
  29953. 19:22:22going to get rid of this. Want to say
  29954. 19:22:23COVID. Um, because that is the image
  29955. 19:22:26that I have right over here. And then
  29956. 19:22:28the last one is, excuse me, Tableau. So,
  29957. 19:22:31let's go right over here. Let's do
  29958. 19:22:33Tableau.
  29959. 19:22:36Let's get rid. Oh, I got to save that.
  29960. 19:22:38Uh, control S. Perfect. And now, let's
  29961. 19:22:43look at it.
  29962. 19:22:45There you go. There you go. Oh, this one
  29963. 19:22:47still says full story. Go change that.
  29964. 19:22:49Um, I'm gonna go change it. Just doesn't
  29965. 19:22:51feel right.
  29966. 19:22:53Uh, view project. That's not useful.
  29967. 19:22:59Okay. [cough and clears throat] Crl S.
  29968. 19:23:02Perfect. Okay. So, now this looks a lot
  29969. 19:23:06better. Um, and when we host it um
  29970. 19:23:09through GitHub pages or github.io, Oh,
  29971. 19:23:11this is going to be what it looks like.
  29972. 19:23:14I mean, it is. And you can add a lot
  29973. 19:23:16more to it. You can take away from it.
  29974. 19:23:18You can add as many projects as you
  29975. 19:23:20want. You can keep adding. You can copy
  29976. 19:23:21those articles or those posts and you
  29977. 19:23:23can just keep adding them. Um, so this
  29978. 19:23:27is kind of what it's going to look like.
  29979. 19:23:30And
  29980. 19:23:32it was not that hard. I don't think I
  29981. 19:23:34hope this was not too difficult. I
  29982. 19:23:35really don't think it is. um it's really
  29983. 19:23:37just using a template and kind of
  29984. 19:23:38understanding a little basics of HTML.
  29985. 19:23:41So um we are going to take this and we
  29986. 19:23:44we have this saved already. We have this
  29987. 19:23:46all saved.
  29988. 19:23:48What we are going to do now is upload
  29989. 19:23:51this to GitHub. So let's go right over
  29990. 19:23:54here. Let's go to here and let's go to
  29991. 19:23:58repositories
  29992. 19:24:00and how do where where's the new one?
  29993. 19:24:03Oh, I need to sign in. Okay, I'm going
  29994. 19:24:06to get rid of this part so you can't see
  29995. 19:24:07it. So, we are going to say a new
  29996. 19:24:10repository.
  29997. 19:24:11We're going to call it Alex theanalyst
  29998. 19:24:152.github.io.
  29999. 19:24:19So, we're going to write it just like
  30000. 19:24:20that. You know, if your name's um Alex
  30001. 19:24:25Jimmy, I don't know why I said Jimmy.
  30002. 19:24:28Alex Jimmy, Alex Jimmy.github.io,
  30003. 19:24:31um you can always go back after the fact
  30004. 19:24:33and change this. So, it's not a big deal
  30005. 19:24:35whether you change it or not. And we're
  30006. 19:24:38going to create this repository.
  30007. 19:24:41We're going to say upload an existing
  30008. 19:24:43file.
  30009. 19:24:45And instead of choosing them, what we're
  30010. 19:24:47going to do is just go right over here,
  30011. 19:24:50go to this, and we're just going to copy
  30012. 19:24:51this in. Or not copy it in, but drag it
  30013. 19:24:53in. Okay. So, we're going to take this,
  30014. 19:24:56drag it in right here. And it can take a
  30015. 19:24:57it'll take a little bit. Says 75, but it
  30016. 19:25:00shouldn't take [clears throat] that
  30017. 19:25:01long.
  30018. 19:25:05And let's just wait for it. I was taking
  30019. 19:25:08a sip of water. I apologize.
  30020. 19:25:10But it is literally uploading just
  30021. 19:25:12everything that we had in there. So all
  30022. 19:25:13the updates and all the changes and all
  30023. 19:25:14the stuff that we um had. And it looks
  30024. 19:25:17like it's done. So let's just write
  30025. 19:25:20initial [snorts] commit.
  30026. 19:25:23Commit changes.
  30027. 19:25:25It is processing it.
  30028. 19:25:28All right. And it should be done very
  30029. 19:25:31very soon as long as I have a good
  30030. 19:25:33internet connection.
  30031. 19:25:36We shall see.
  30032. 19:25:40[cough and clears throat]
  30033. 19:25:41Stick with me. It's taking its time.
  30034. 19:25:45Um, while it's loading, let's go over to
  30035. 19:25:48Oh. Oh, there it is. So, perfect. So,
  30036. 19:25:50here's everything that we have. Has this
  30037. 19:25:52read me that it generated. Let's go over
  30038. 19:25:54to settings.
  30039. 19:25:56And we have this u github.io. io. And if
  30040. 19:26:02we go right down here to GitHub pages,
  30041. 19:26:04pages settings now has its own dedicated
  30042. 19:26:07tab. Let's check it out here. So, it is
  30043. 19:26:12um
  30044. 19:26:14it's currently disabled, but we're going
  30045. 19:26:15to say we want it to do pull from the
  30046. 19:26:17main. Um I think it's the docs. We'll
  30047. 19:26:20see. I'm going to save this. Your site
  30048. 19:26:22is ready to be published. Let's open
  30049. 19:26:25this up. Okay. Site not found. Maybe
  30050. 19:26:28it's from the root. Save.
  30051. 19:26:33Um, your site is having a build a
  30052. 19:26:35problem. Let me see if I can actually
  30053. 19:26:37change the name. I already have an Alex
  30054. 19:26:40[clears throat] analyst, but I'm going
  30055. 19:26:41to see it's already taken. Um, I'm just
  30056. 19:26:43going to try this one one more time. Oh,
  30057. 19:26:46and now it's working. Uh, I have no idea
  30058. 19:26:49why it uh didn't work before, but this
  30059. 19:26:52is fantastic. It was giving me all this.
  30060. 19:26:55I was maybe I was just reading too much
  30061. 19:26:56into that. I had I had never tried to
  30062. 19:26:58create another umio
  30063. 19:27:02or or GitHub pages on this. So anyways,
  30064. 19:27:05thanks for sticking with me through all
  30065. 19:27:06that um stuff. So now we have our actual
  30066. 19:27:11website. Um it doesn't look the same up
  30067. 19:27:14here because of that thing that we were
  30068. 19:27:16just looking at. It should just be this
  30069. 19:27:19part right here. But um this is an
  30070. 19:27:21actual website now and it's being ho
  30071. 19:27:23hosted through GitHub and it's
  30072. 19:27:25completely free. If you want to pay you
  30073. 19:27:29can hide this from your GitHub. Um your
  30074. 19:27:32repository has to be public. Uh
  30075. 19:27:34something I didn't mention when you're
  30076. 19:27:36doing this your repository has to be
  30077. 19:27:39public. Um if I change the visibility to
  30078. 19:27:42private um you will not be able to see
  30079. 19:27:46it anymore. You'll have to then pay if
  30080. 19:27:48you want to make this repository
  30081. 19:27:49private. you have to then pay. I think
  30082. 19:27:50it's like $4 a month or something like
  30083. 19:27:52that. So, worth looking into. Um, if you
  30084. 19:27:56don't want to display that on your
  30085. 19:27:57GitHub, worth looking into, but this is
  30086. 19:28:01our final product. I mean, it looks
  30087. 19:28:03pretty fantastic. And you can use any of
  30088. 19:28:05these templates, right? There are lots
  30089. 19:28:07of different templates that are
  30090. 19:28:08fantastic. I mean, they look amazing.
  30091. 19:28:12They look professional. Um, it's really
  30092. 19:28:14up to your style. like this one looks
  30093. 19:28:16kind of cool, a little bit um edgy for
  30094. 19:28:18for my taste, but uh this one looks
  30095. 19:28:21really good, too. Might may be able to
  30096. 19:28:23add some more narrative to that one. So,
  30097. 19:28:25again, go through it, make your make a
  30098. 19:28:28good choice in it, and then update it
  30099. 19:28:30how we updated it. Uh, I will include
  30100. 19:28:34the um, let's see. I will include
  30101. 19:28:38everything that's in here and I'll keep
  30102. 19:28:40this on my on this GitHub so that you
  30103. 19:28:43can go in there and if you want to
  30104. 19:28:44download these images, you can download
  30105. 19:28:45the images that I used. Um, or you can
  30106. 19:28:48go find your own. Just um, you know,
  30107. 19:28:49look for try to get like HD images on
  30108. 19:28:53Google. Just type in Google images and
  30109. 19:28:54search for whatever image you want to
  30110. 19:28:56search. Try to get an HD image. With
  30111. 19:28:58that being said, that is the entire
  30112. 19:29:00project. I I I I hope this didn't go too
  30113. 19:29:02long. Um this may have gone, you know,
  30114. 19:29:05this may have gone like 30 45 minutes,
  30115. 19:29:08but in the end of it, at the at the end,
  30116. 19:29:10which is where we are now, we have an
  30117. 19:29:12entire website. It was completely free.
  30118. 19:29:15And I hope that you can now host the
  30119. 19:29:16projects and you can create create more
  30120. 19:29:18projects. I will be coming out with more
  30121. 19:29:20projects myself that hopefully will be
  30122. 19:29:22interesting to you in the future. So,
  30123. 19:29:25with that being said, thank you guys for
  30124. 19:29:27joining me. for you who stuck it out to
  30125. 19:29:28the very end. You are fantastic. You
  30126. 19:29:31know, send me a post to your website on
  30127. 19:29:33LinkedIn and tag me in it because I love
  30128. 19:29:35seeing um you guys do these projects and
  30129. 19:29:38this stuff. So, I'm super excited to see
  30130. 19:29:40all of these um that you guys tag me on
  30131. 19:29:42on LinkedIn and whatnot. So, with that
  30132. 19:29:44being said, this is it. I hope you
  30133. 19:29:46learned something. I hope that it worked
  30134. 19:29:48for you and I appreciate you watching.
  30135. 19:29:51Be sure to like and subscribe below and
  30136. 19:29:54I will see you in the next video.
  30137. 19:29:55[music] Goodbye.
  30138. 19:30:08What's going on everybody? Welcome back
  30139. 19:30:09to another video. Today I'm going to
  30140. 19:30:11help you create a data analyst resume.
  30141. 19:30:19Now, when I say data analyst resume,
  30142. 19:30:21it's not that much different than a
  30143. 19:30:23regular resume, except that it's going
  30144. 19:30:25to be catered for a data analyst job. In
  30145. 19:30:27just a second, we're going to take a
  30146. 19:30:28look on my screen at a sample resume.
  30147. 19:30:30I'll have the template in the
  30148. 19:30:32description so you can just go and
  30149. 19:30:33download it and fill in your
  30150. 19:30:34information, but it's a fantastic
  30151. 19:30:36starting place to actually creating your
  30152. 19:30:37resume. When we're looking at this
  30153. 19:30:39resume, we'll take a look at each
  30154. 19:30:40section and kind of dissect each part of
  30155. 19:30:42it. And then at the very end, I'll give
  30156. 19:30:43some extra tips on what you should
  30157. 19:30:45include and how to actually write your
  30158. 19:30:46resume as well. So, without further ado,
  30159. 19:30:48let's jump on my screen, take a look at
  30160. 19:30:50the resume, and see how you can create
  30161. 19:30:51your own data analyst resume. So, here's
  30162. 19:30:53our sample resume. I'm just going to
  30163. 19:30:55walk through the entire thing super
  30164. 19:30:56quick, and then we'll break down each
  30165. 19:30:58section individually. I'll give my
  30166. 19:30:59thoughts and some tips on each section.
  30167. 19:31:02And remember, you can download this
  30168. 19:31:03exact thing in the description below.
  30169. 19:31:05I'll have a link. I'll probably put it
  30170. 19:31:06on my GitHub or somewhere else, but
  30171. 19:31:08it'll be free to download. Uh, so you
  30172. 19:31:10can go ahead and do that. But let's zoom
  30173. 19:31:12in just a little bit. So at the very top
  30174. 19:31:14we have our header. We have some just
  30175. 19:31:17basic uh contact information. Then we
  30176. 19:31:20have skills. Then we have projects. And
  30177. 19:31:22notice the projects are up here at the
  30178. 19:31:24top. And we'll get to that later about
  30179. 19:31:25the order of where you should be putting
  30180. 19:31:27your things. Then we have work
  30181. 19:31:29experience. And then we have education.
  30182. 19:31:31So really quickly, I'm going to zoom out
  30183. 19:31:34and I hope you can still see it. The
  30184. 19:31:37order is actually quite important. Now,
  30185. 19:31:39there is one piece that is not in here
  30186. 19:31:41right now, and that is a summary
  30187. 19:31:43section. I don't have a summary section
  30188. 19:31:45on my real resume. I just I don't think
  30189. 19:31:48it's useful or helpful. I don't have
  30190. 19:31:50one. You can include one, and it would
  30191. 19:31:52be right up here at the very top. Now,
  30192. 19:31:54why do we have the skills and projects
  30193. 19:31:56at the top? Well, it's because that most
  30194. 19:32:00people who are trying to break into data
  30195. 19:32:02analytics don't have any experience in
  30196. 19:32:04data analytics. If I am reading this
  30197. 19:32:07resume as a hiring manager and the first
  30198. 19:32:09thing that I look up here and I see is
  30199. 19:32:11experience and it's not analyst, it's a
  30200. 19:32:14teacher or a nurse or something, I'm
  30201. 19:32:15going to be like, uh, this person
  30202. 19:32:17doesn't have any experience, I don't
  30203. 19:32:18want to hire them. The first thing that
  30204. 19:32:20you want to have on your resume is
  30205. 19:32:21something that is good for the hiring
  30206. 19:32:23manager to see. The first several things
  30207. 19:32:25you should put all your best stuff at
  30208. 19:32:26the top. That's my uh what I believe.
  30209. 19:32:29So, I think that these skills are really
  30210. 19:32:32strong, a lot of great skills. And then
  30211. 19:32:34these projects are all really good
  30212. 19:32:36projects. Now, this is just a sample.
  30213. 19:32:37These aren't all real projects. Um, or
  30214. 19:32:40they are real real projects. They're
  30215. 19:32:41just not, you know, ones that I built
  30216. 19:32:43myself. It's just a sample. So, uh, then
  30217. 19:32:47right here we have our work experience.
  30218. 19:32:49Now, if you're, like I said, a nurse or
  30219. 19:32:50a teacher or a lawyer or something
  30220. 19:32:52that's not relevant to data analytics,
  30221. 19:32:53you want that at the bottom. Um, and
  30222. 19:32:55then you're going to want to tie in, uh,
  30223. 19:32:57some things in these descriptions. And
  30224. 19:32:58then the education at the bottom. My
  30225. 19:33:00education was terrible. Okay, I had a
  30226. 19:33:02bachelor's in recreational therapy which
  30227. 19:33:05had nothing to do with data analytics.
  30228. 19:33:07So for a tech job has was not good. I
  30229. 19:33:09always had mine at the bottom. So let's
  30230. 19:33:12start at the very top and walk through
  30231. 19:33:14each section. So at the very top you
  30232. 19:33:18want to have maybe a title, but for sure
  30233. 19:33:20your full name. You definitely want to
  30234. 19:33:23include your phone number if you're okay
  30235. 19:33:24with them calling you, but definitely an
  30236. 19:33:26email. for sure include things like a
  30237. 19:33:29LinkedIn profile or a GitHub profile.
  30238. 19:33:31You can also put your portfolio. In
  30239. 19:33:33fact, I highly recommend putting your
  30240. 19:33:34portfolio because it just looks good or
  30241. 19:33:36if they check it out, that's a really
  30242. 19:33:38good thing. And then your location
  30243. 19:33:40because sometimes your job is going to
  30244. 19:33:41be location-based, whether you're in
  30245. 19:33:43Dallas or another metropolitan city.
  30246. 19:33:45It's just nice to have that on there.
  30247. 19:33:47This should be the simplest one to fill
  30248. 19:33:49out unless you haven't built out
  30249. 19:33:51something like a portfolio, you just
  30250. 19:33:52don't include it. Um, but this one
  30251. 19:33:54should be the simplest one, right?
  30252. 19:33:56you're just putting contact information,
  30253. 19:33:58maybe a link to a website. Next, we have
  30254. 19:34:00the skill section. And this one on my
  30255. 19:34:03own personal resume I have at the very
  30256. 19:34:04top. I typically recommend anyone who
  30257. 19:34:07does not have experience, who is trying
  30258. 19:34:08to break into data analytics to put this
  30259. 19:34:10at the top as well and have these skills
  30260. 19:34:13and know these skills. That's important.
  30261. 19:34:15Um, but when the hiring manager first
  30262. 19:34:17initially sees this, there's just going
  30263. 19:34:18to be a mental check. Okay, they have
  30264. 19:34:20the skills that we're looking for. Let's
  30265. 19:34:22move on to the rest of the resume. Um,
  30266. 19:34:24but you want as many mental checks for
  30267. 19:34:26what they're looking for at the
  30268. 19:34:28beginning. Just going to I'm going to
  30269. 19:34:30keep repeating that. Um, this is how I
  30270. 19:34:33personally write my skills. So, I write
  30271. 19:34:36something like SQL and then I'll say SQL
  30272. 19:34:38server, my SQL, Postgrade SQL. Now, I
  30273. 19:34:40have used all these different types of
  30274. 19:34:42SQL in my actual job. If you don't you
  30275. 19:34:45haven't done that and you're just
  30276. 19:34:46starting out maybe you put something
  30277. 19:34:48like um you know sub queries store
  30278. 19:34:52procedures joins whatever the actual
  30279. 19:34:54things within SQL I don't really think I
  30280. 19:34:57don't recommend that as much because
  30281. 19:35:00typically people know what SQL is like
  30282. 19:35:02if they use SQL they know what SQL is so
  30283. 19:35:04they're just going to expect that you
  30284. 19:35:05know those things now for something like
  30285. 19:35:07Python it's different because there are
  30286. 19:35:09packages something like R there are
  30287. 19:35:10packages and libraries within them so
  30288. 19:35:12you can specify I I have worked with
  30289. 19:35:15pandas in my actual job and I look for
  30290. 19:35:17people who know pandas as well because
  30291. 19:35:18you know we use it. So actually
  30292. 19:35:20specifying these packages or libraries
  30293. 19:35:23is really helpful. So this is how I
  30294. 19:35:25would put these things on a resume. Now
  30295. 19:35:28this is another resume. This is our
  30296. 19:35:30sample two. I'm going to maybe include
  30297. 19:35:32this one down below. Although I don't
  30298. 19:35:34like this format as much but if you like
  30299. 19:35:36it you can. But here's another way that
  30300. 19:35:38you can um show these skills. Just a
  30301. 19:35:41different way to do it. I want to show
  30302. 19:35:42you both ways. Um, where you have like
  30303. 19:35:44Python and the libraries underneath it.
  30304. 19:35:46I've even seen it to where people will
  30305. 19:35:47write out almost like um, let me go down
  30306. 19:35:50here. They'll write out like a
  30307. 19:35:51narrative. Um, they'll do Python
  30308. 19:35:54and then they'll have like a colon and
  30309. 19:35:56then they'll say use to um, manipulate
  30310. 19:36:02data and I'm not spelling that right in
  30311. 19:36:04pandas dot dot dot and they write it
  30312. 19:36:06out. You can do that as well. Again, I
  30313. 19:36:08like bullet points because it's to the
  30314. 19:36:10point. That's exactly what you need.
  30315. 19:36:12Let's get rid of this one real quick.
  30316. 19:36:14So, this is the one uh that I like. So,
  30317. 19:36:18that's the skills section. Let's move
  30318. 19:36:20down to the projects. Now, the project
  30319. 19:36:23section is almost primarily for people
  30320. 19:36:26who are just starting out. Once you get
  30321. 19:36:28experience, typically you maybe have one
  30322. 19:36:30project on there or no projects at all.
  30323. 19:36:33But the project section is used as kind
  30324. 19:36:35of um in lie of actual experience,
  30325. 19:36:38right? I've always said that you need to
  30326. 19:36:41build projects not just for your resume
  30327. 19:36:43but also for the interviews. So then
  30328. 19:36:45when you get into an interview you can
  30329. 19:36:47point to these projects and say yes I've
  30330. 19:36:49used SQL I did it in this project and
  30331. 19:36:51they may have seen it and you can walk
  30332. 19:36:53them through how you actually used it.
  30333. 19:36:55It gives you more credibility than just
  30334. 19:36:57saying you know how to use SQL. So
  30335. 19:36:59within the project section we're going
  30336. 19:37:02to have a project. This one says data
  30337. 19:37:04science job market exploratory data
  30338. 19:37:06analysis. So this is a personal project
  30339. 19:37:09and then within it they did some really
  30340. 19:37:11great stuff. Here's usually what I
  30341. 19:37:14recommend and this is in here which is
  30342. 19:37:16you specify what you did. You say I used
  30343. 19:37:18Python and what did you do to analyze
  30344. 19:37:21this and gain insights in the job
  30345. 19:37:23market. Then you walk through some of
  30346. 19:37:25the things that you actually did things
  30347. 19:37:26like regex techniques. You used pandas
  30348. 19:37:29mapplot lib. You built a wordcloud.
  30349. 19:37:31These are keywords that somebody will
  30350. 19:37:34look for and they even highlighted them
  30351. 19:37:36which I personally like and do as
  30352. 19:37:38myself. They highlighted these things so
  30353. 19:37:41that the viewer or the um hiring manager
  30354. 19:37:43is actually seeing them making sure that
  30355. 19:37:45they're bold so that they are catching
  30356. 19:37:46their eye. So I personally do this and I
  30357. 19:37:49recommend this. That's all it needs to
  30358. 19:37:51be. It just needs to be I built a
  30359. 19:37:53Tableau dashboard doing this from this
  30360. 19:37:56data set. I cleaned it in SQL and you
  30361. 19:37:58show those skills. Something that's
  30362. 19:38:00important in both the skills section and
  30363. 19:38:03the project section is using and
  30364. 19:38:05highlighting your skills as much as
  30365. 19:38:08possible. Especially if you don't have
  30366. 19:38:10any experience, if you've never had a
  30367. 19:38:12job before. Once you have a job and you
  30368. 19:38:14come down to like the work experience,
  30369. 19:38:16then it kind of speaks for you. But if
  30370. 19:38:18you don't, you want the projects and the
  30371. 19:38:20skills to speak towards your skills and
  30372. 19:38:22credibility. So, we have this right
  30373. 19:38:24here. Now, one thing that's not in here
  30374. 19:38:26that I actually do recommend is a
  30375. 19:38:28hyperlink. maybe right here or actually
  30376. 19:38:32this being a hyperlink to the project
  30377. 19:38:35because they might read this and be like
  30378. 19:38:36I we work with you know data science job
  30379. 19:38:39market data I don't know and then
  30380. 19:38:42they'll click on this link and they can
  30381. 19:38:43see your work that is the one thing that
  30382. 19:38:45I would change in this other than that
  30383. 19:38:47this is exactly how I would have it very
  30384. 19:38:49very very similar to my own um and a lot
  30385. 19:38:51of this that I did I actually took from
  30386. 19:38:54other résumés and formatted it how I
  30387. 19:38:56prefer and like it um so again some of
  30388. 19:38:58this personal preference and you can
  30389. 19:38:59change it however you want. That's just
  30390. 19:39:01how I like it. So, that is the project
  30391. 19:39:04section. Now, we're going to go down to
  30392. 19:39:05the work experience section. Now, this
  30393. 19:39:07person does have a little bit of analyst
  30394. 19:39:11uh experience. So, you know, if you
  30395. 19:39:14don't, that's okay, but you put your
  30396. 19:39:17previous experience. Now, here's what I
  30397. 19:39:19recommend. If you've been a teacher for
  30398. 19:39:2115 years, you've been a nurse for 10
  30399. 19:39:23years, you've had 10 different jobs,
  30400. 19:39:24don't put all your experience on here.
  30401. 19:39:26Um, maybe put your last two jobs going
  30402. 19:39:29back maybe three years. I don't
  30403. 19:39:31recommend you filling it up because it's
  30404. 19:39:33not going to be super relevant. Unless
  30405. 19:39:34you're applying for a healthcare data
  30406. 19:39:36analyst position and you have a nursing
  30407. 19:39:38degree, then it's relevant and that
  30408. 19:39:40experience is super helpful because it's
  30409. 19:39:41domain experience, right? Then you may
  30410. 19:39:43go back five years. Just, you know, use
  30411. 19:39:46your discretion. But what do you need to
  30412. 19:39:47include? Of course, your title, where
  30413. 19:39:50you worked, your location, and the
  30414. 19:39:52times. That's standard for almost any
  30415. 19:39:54resume. But within here, uh, what you
  30416. 19:39:57really want to do is highlight again the
  30417. 19:39:58skills if you can. If you can't, that'll
  30418. 19:40:01change. But in here, he says,
  30419. 19:40:03"Implemented a new reporting using Excel
  30420. 19:40:05Pivot and VBA, which reduced processing
  30421. 19:40:08time by 50%." These types of um
  30422. 19:40:11quantitative information. I reduced
  30423. 19:40:13time. I I I saved the company money. I I
  30424. 19:40:16did something quantitative. Putting that
  30425. 19:40:19in here is always helpful. always highly
  30426. 19:40:21recommended, although it can be tough to
  30427. 19:40:23measure these things, right? Typically,
  30428. 19:40:25what I recommend, especially if you're
  30429. 19:40:26first starting out, is to highlight
  30430. 19:40:28skills. If you're a teacher, you've
  30431. 19:40:30probably used Excel and you've probably
  30432. 19:40:32used Excel for closer to data analytics
  30433. 19:40:34than you'd think, just in a teacher way
  30434. 19:40:36and not a data analytics way. But you
  30435. 19:40:39can reward these things and make them
  30436. 19:40:41sound good. If you are a a nurse, like I
  30437. 19:40:43was saying, you've used Excel, you've
  30438. 19:40:46used a health information system, you've
  30439. 19:40:49used uh some type of database, talk to
  30440. 19:40:52that. Include that in here. Um, and it
  30441. 19:40:54can be hard to write these out. And I'm
  30442. 19:40:57going to show you a way in just a little
  30443. 19:40:58bit about how you can write these out
  30444. 19:41:00and think about these things or have a
  30445. 19:41:01way to help you write them or give you
  30446. 19:41:03ideas. We'll get to that in a second.
  30447. 19:41:06Lastly, we have the education piece.
  30448. 19:41:07This is again really simple. at the very
  30449. 19:41:10bottom, education, what your degree was,
  30450. 19:41:12where you went. Um, and if you have, you
  30451. 19:41:14know, some helpful things to include,
  30452. 19:41:16you can do that, and then when you
  30453. 19:41:18actually went. Now, you can include
  30454. 19:41:20other things in here as well, like boot
  30455. 19:41:22camps, if you went to a boot camp, or
  30456. 19:41:24you could also include things like a
  30457. 19:41:25GPA. Although, I don't personally
  30458. 19:41:27recommend it. GPA has never been
  30459. 19:41:29anything that I've ever cared about or
  30460. 19:41:31I've seen anyone care about, ever. Um,
  30461. 19:41:34so you don't normally have to include
  30462. 19:41:35it. One other thing that you can include
  30463. 19:41:37at the very bottom is something like
  30464. 19:41:40certifications. Uh I personally don't
  30465. 19:41:42put a lot of stock in certifications
  30466. 19:41:44unless it is one that I have recommended
  30467. 19:41:46in previous video like the Tableau
  30468. 19:41:48certification or Tableau desktop
  30469. 19:41:50certification. If you're applying to a
  30470. 19:41:51job that uses Tableau that actually
  30471. 19:41:54could be really good. So definitely
  30472. 19:41:56include that. But one's on Udemy, one's
  30473. 19:41:58on Corsera, or like my Alex the analyst
  30474. 19:42:02boot camp that I have on my channel. I
  30475. 19:42:04wouldn't really include that in your
  30476. 19:42:06resume. It's mostly for learning. If you
  30477. 19:42:08get something like the Tableau one or
  30478. 19:42:10the AWS uh cloud one or the um Azure
  30479. 19:42:13cloud one, those are all actual
  30480. 19:42:15certifications that can help you and
  30481. 19:42:16give you credibility towards a certain
  30482. 19:42:18skill. Now, really quickly, let's just
  30483. 19:42:19take a glance at the other resume. This
  30484. 19:42:21is ré 2. So, we have the education at
  30485. 19:42:24the top. doesn't have to be at the top
  30486. 19:42:26unless it's relevant which you could put
  30487. 19:42:28at the top. We have a skills section.
  30488. 19:42:30They again this is the project same
  30489. 19:42:31projects and then work experience. So
  30490. 19:42:33this is just a little bit different um
  30491. 19:42:35order. So you can do it like this as
  30492. 19:42:37well and different way you can write the
  30493. 19:42:39skills and you can also include a
  30494. 19:42:41summary section as well. So that's the
  30495. 19:42:43meat and potatoes of how I would create
  30496. 19:42:45a data analyst resume. Now writing it is
  30497. 19:42:48actually a different beast, right? You
  30498. 19:42:49have to actually write it out, get
  30499. 19:42:51something on the resume and then apply
  30500. 19:42:53using that resume. But it can be hard to
  30501. 19:42:55come up with these ideas. So, uh, I just
  30502. 19:42:58want to show you something that a lot of
  30503. 19:42:59people have been using. I personally
  30504. 19:43:01haven't written a resume in a little
  30505. 19:43:03while. So, I don't use it for my own
  30506. 19:43:05resume or haven't used it, but I will.
  30507. 19:43:07Um, and that's using chat GBT or some
  30508. 19:43:09variation, whether it's on Bing or, you
  30509. 19:43:11know, you get some different version or
  30510. 19:43:13some new product that's out there at the
  30511. 19:43:14moment. I'm just going to show you how
  30512. 19:43:16to do it in chat GBT. Some of the things
  30513. 19:43:17that you can prompt it to do, and
  30514. 19:43:19that'll be it. I'm just going to show
  30515. 19:43:21you kind of some ideas that it can
  30516. 19:43:22generate for you to help you write these
  30517. 19:43:24things. All right. All right. So, here
  30518. 19:43:25on my screen, we're on Chad GBT. If you
  30519. 19:43:27haven't used it, I'll leave a link in
  30520. 19:43:29the description. I also have a whole
  30521. 19:43:30video on how to use Chad GBT for a data
  30522. 19:43:32analysis. Um, so I like Chad GBT. Now,
  30523. 19:43:35I've already written out these questions
  30524. 19:43:37because I don't want to wait for the
  30525. 19:43:38responses. But here's what I asked it to
  30526. 19:43:40do, and you can do some variation of
  30527. 19:43:42this, whether you're a nurse or a lawyer
  30528. 19:43:44or a teacher, whatever. I said, I'm a
  30529. 19:43:47math high school teacher trying to
  30530. 19:43:48become a data analyst. How can I use my
  30531. 19:43:50experience on my resume to help me get a
  30532. 19:43:52job? This is just to help provoke some
  30533. 19:43:55ideas and it says, you know, you most
  30534. 19:43:57likely have some skills. Emphasize your
  30535. 19:43:59quantitative skills. So, those are some
  30536. 19:44:01of the things you can focus on. Showcase
  30537. 19:44:02your ability to commute complex
  30538. 19:44:04concepts, which is really important in
  30539. 19:44:06data analytics, being able to present
  30540. 19:44:07information, which teachers have.
  30541. 19:44:10Highlight your experience with
  30542. 19:44:11technology. Hopefully, you're using some
  30543. 19:44:13type of uh, you know, database for
  30544. 19:44:15students or, you know, Excel or
  30545. 19:44:17something like that. And you can
  30546. 19:44:18highlight that and showcase your ability
  30547. 19:44:20to solve problems. Now, the next thing
  30548. 19:44:22that I asked it was, I built a COVID
  30549. 19:44:24Tableau dashboard using Tableau. How can
  30550. 19:44:28I add this to my resume? And then it's
  30551. 19:44:30going to tell you exactly how you can do
  30552. 19:44:32that. It's going to say, include the
  30553. 19:44:33link to your dashboard, which I also
  30554. 19:44:35recommend. Provide a brief description,
  30555. 19:44:37highlight your data visualization
  30556. 19:44:38skills, include screenshots or images,
  30557. 19:44:40which that's what I would be putting in
  30558. 19:44:42the project itself, not on your resume.
  30559. 19:44:44Then provide context for the data. All
  30560. 19:44:47really good stuff. Really great. Now,
  30561. 19:44:49the last thing is kind of what I'm
  30562. 19:44:50trying to get at as a whole. It can help
  30563. 19:44:53you write things. So, I'm going to say
  30564. 19:44:55write a two sent I said write a two.
  30565. 19:44:57Write two sentences highlighting my
  30566. 19:44:59COVID tablet dashboard to add to my
  30567. 19:45:01resume. And it's going to say developed
  30568. 19:45:03a COVID tablet dashboard to visualize
  30569. 19:45:05pandemic trends using real-time data
  30570. 19:45:07sources demonstrating strong data
  30571. 19:45:09visualization and analysis skills. So,
  30572. 19:45:12this can help you generate those
  30573. 19:45:14descriptions in your work experience.
  30574. 19:45:16that can help you generate the
  30575. 19:45:17descriptions in your projects. And this
  30576. 19:45:20can be really helpful to just generate
  30577. 19:45:21some ideas because I personally really
  30578. 19:45:23struggle with like highlighting my
  30579. 19:45:25skills and descriptions within those
  30580. 19:45:27things. This can be a way to kind of
  30581. 19:45:30help you do that. So don't, you know,
  30582. 19:45:32just copy and paste, but let it prompt
  30583. 19:45:34you. Let it give you ideas. Now, the
  30584. 19:45:36last thing that I want to mention is
  30585. 19:45:37just your overall resume as a whole. The
  30586. 19:45:40template that I use, the template that I
  30587. 19:45:42recommend is very, very friendly to
  30588. 19:45:45these automated systems that check your
  30589. 19:45:47resume. If you did not know, most
  30590. 19:45:50companies, especially big companies, use
  30591. 19:45:52these automated systems that scan your
  30592. 19:45:54resume, see if it has what they're
  30593. 19:45:56looking for, and then that resume, if it
  30594. 19:45:58gets through that system, gets passed on
  30595. 19:46:00to a recruiter or hiring manager.
  30596. 19:46:02Typically, most companies don't go
  30597. 19:46:04straight to the hiring manager. So, you
  30598. 19:46:06need a resume that can pass through
  30599. 19:46:08those initial systems and pass those
  30600. 19:46:10tests. The résumés that I've shown you
  30601. 19:46:12today will do that. They have bullet
  30602. 19:46:14points. They have the keywords. They
  30603. 19:46:15have everything you need. That's why I
  30604. 19:46:17recommend or partially why I recommend
  30605. 19:46:19this type of resume. Other ones that
  30606. 19:46:21have images and different fonts and
  30607. 19:46:23different stylings can cause issues with
  30608. 19:46:26these automated systems where it just
  30609. 19:46:28doesn't read it properly or, you know,
  30610. 19:46:30it doesn't read the right words that you
  30611. 19:46:32want it to read. So, just know that
  30612. 19:46:35these types of résumés have different
  30613. 19:46:37uses, right? You're not just handing it
  30614. 19:46:39off to somebody to where they can read
  30615. 19:46:40it and it's needs to be visually
  30616. 19:46:42stimulating. Really, what you need is
  30617. 19:46:44you need it to get through those initial
  30618. 19:46:46systems, which these résumés, uh, if you
  30619. 19:46:48write them well, you have good, you
  30620. 19:46:50know, skills and the right things on
  30621. 19:46:51your resume. They will pass through that
  30622. 19:46:53first layer to get to those hiring
  30623. 19:46:55managers. So, again, be sure to download
  30624. 19:46:57those. Those are completely free. I just
  30625. 19:46:59I highly recommend using them. I think
  30626. 19:47:00they're really good. So, be sure to
  30627. 19:47:02download those, use those, just put in
  30628. 19:47:04your own information. Be sure to build
  30629. 19:47:06out your own projects. Don't just keep
  30630. 19:47:08the ones that are on there because
  30631. 19:47:09you'll need to be able to speak to them.
  30632. 19:47:11Sometimes recruiters or hiring managers
  30633. 19:47:12are going to ask you about them, how you
  30634. 19:47:14built it, what you did, and you can also
  30635. 19:47:16point to those projects in your actual
  30636. 19:47:18interview. So, I hope that this was
  30637. 19:47:20helpful. I hope that your resume is
  30638. 19:47:22ready to go. I hope that you're ready to
  30639. 19:47:24start applying for those data analyst
  30640. 19:47:25jobs. Thank you guys so much for
  30641. 19:47:27watching. I really appreciate it. If you
  30642. 19:47:29like this video, be sure to like and
  30643. 19:47:30subscribe below, and I'll see you in the
  30644. 19:47:32next video.
  30645. 19:47:34[music]
  30646. 19:47:45What's going on everybody? Welcome back
  30647. 19:47:46to another video. Today we are going to
  30648. 19:47:48be solving easy SQL technical interview
  30649. 19:47:50questions.
  30650. 19:47:56Now, when I was interviewing for data
  30651. 19:47:58analyst positions, I almost always got
  30652. 19:48:00some type of technical interview. And
  30653. 19:48:02the vast majority of the technical
  30654. 19:48:03interviews that I got were in SQL. Not
  30655. 19:48:05only that, but I was also on a hiring
  30656. 19:48:07team. And then later as a hiring
  30657. 19:48:08manager, I almost always conducted some
  30658. 19:48:10type of SQL technical interview. Now,
  30659. 19:48:12why do hiring managers conduct these
  30660. 19:48:14interviews? It's because they want to
  30661. 19:48:15make sure that you actually know the
  30662. 19:48:16skill. Because you can just put SQL on
  30663. 19:48:18your resume and not actually know it at
  30664. 19:48:20all. And then when they hire you, they
  30665. 19:48:21have to spend 2, three, four months
  30666. 19:48:23training you on the basics of SQL for
  30667. 19:48:25you to actually understand it and use
  30668. 19:48:27it. That is not what any hiring manager
  30669. 19:48:28wants. And so that's why they conduct
  30670. 19:48:30these SQL technical interviews. So in
  30671. 19:48:32this series, we're going to start with
  30672. 19:48:33easy questions. That'll be in today's
  30673. 19:48:34video. Then we'll go on to medium, hard,
  30674. 19:48:36and then very hard SQL technical
  30675. 19:48:38interview questions. So without further
  30676. 19:48:40ado, let's jump on my screen and take a
  30677. 19:48:41look at the easy SQL interview
  30678. 19:48:43questions. We're going to be practicing
  30679. 19:48:44these questions on analystbuilder.com.
  30680. 19:48:46And if we come right over here, we can
  30681. 19:48:48filter to the free questions and we can
  30682. 19:48:50filter to the easy questions. These are
  30683. 19:48:53all the free and easy questions that you
  30684. 19:48:54can go and take right now. I will leave
  30685. 19:48:56a link in the description. I will also
  30686. 19:48:58leave a link to the two questions that
  30687. 19:48:59we're going to be looking at today, but
  30688. 19:49:01go ahead and check out this if you want
  30689. 19:49:03to try out all of these different
  30690. 19:49:05questions. There's also different
  30691. 19:49:06difficulties. So, we're going to be
  30692. 19:49:08working through the moderate and the
  30693. 19:49:10hard ones in future videos. And then
  30694. 19:49:12we'll also be looking at the very
  30695. 19:49:14difficult ones in the very last video in
  30696. 19:49:16this series. But let's go ahead and get
  30697. 19:49:18rid of this because we're going to go
  30698. 19:49:19over to our very first question. Now,
  30699. 19:49:21really quickly, I just want to show you
  30700. 19:49:22the interface before we actually dive
  30701. 19:49:23into the question. Now, we're going to
  30702. 19:49:25be solving this in my SQL, but you can
  30703. 19:49:28also practice in Postgra SQL and
  30704. 19:49:30Microsoft SQL Server. Whichever one you
  30705. 19:49:32have an interview coming up for, if that
  30706. 19:49:34company uses Microsoft SQL Server, come
  30707. 19:49:36in here and use Microsoft SQL Server.
  30708. 19:49:38And we also have Python as well. But
  30709. 19:49:41we're going to be doing this in MySQL.
  30710. 19:49:43This is where we'll write our actual SQL
  30711. 19:49:44code. Then we have the prompt. Now, in
  30712. 19:49:47an interview, typically they're going to
  30713. 19:49:49give you some type of prompt and then
  30714. 19:49:50the data. They're going to ask you to do
  30715. 19:49:52something with the data and our data is
  30716. 19:49:55right down here. So, this is our data.
  30717. 19:49:57Now, this is a practicing platform,
  30718. 19:49:59right? To practice for technical
  30719. 19:50:01interview questions or practice for
  30720. 19:50:03technical interviews. So, we also have
  30721. 19:50:05hints and expected output, as well as a
  30722. 19:50:07video explanation walking through this
  30723. 19:50:09question, showing you exactly how to do
  30724. 19:50:11it. Um, but if you can't get it at all,
  30725. 19:50:14you can always come in here and look at
  30726. 19:50:16the solution for any of these. But let's
  30727. 19:50:18go ahead and start this question. The
  30728. 19:50:21question is called car failure. It says,
  30729. 19:50:23"Cars need to be inspected every year in
  30730. 19:50:25order to pass inspection and be street
  30731. 19:50:28legal. If a car has any critical issues,
  30732. 19:50:30it will fail inspection. Or if it has
  30733. 19:50:33more than three minor issues, it will
  30734. 19:50:35also fail. Write a query to identify the
  30735. 19:50:37cars that passed inspection. Output
  30736. 19:50:39should include the owner name and
  30737. 19:50:42vehicle name ordered by the owner name
  30738. 19:50:44alphabetically.
  30739. 19:50:45Let's go take a look at this data. So we
  30740. 19:50:48have the owner name, vehicle name, minor
  30741. 19:50:50issues, critical issues, and that's all
  30742. 19:50:53we have. So it's just a simple one. Um,
  30743. 19:50:56again, this is an easy question at least
  30744. 19:50:59on Analyst Builder. And so, let's try to
  30745. 19:51:02solve this without any of the hints or
  30746. 19:51:04looking at the expected output because I
  30747. 19:51:07think we can solve this one. Now, the
  30748. 19:51:09first thing that we need to take into
  30749. 19:51:10consideration is we're going to need to
  30750. 19:51:11be filtering. So, we'll need to filter
  30751. 19:51:14down some data. So, if a car has any
  30752. 19:51:16critical issues, it'll fail. So, if
  30753. 19:51:18critical issues is 1 2 3, it's going to
  30754. 19:51:22fail. So, it can't have uh no critical
  30755. 19:51:26issues.
  30756. 19:51:27And then I'll say and because even
  30757. 19:51:30though this says or right here, it
  30758. 19:51:32doesn't mean one or the other. It means
  30759. 19:51:34if it has this or it has this, it fails.
  30760. 19:51:36So, we actually need an and here. So,
  30761. 19:51:38both conditions need to be met or more
  30762. 19:51:41than three minor issues.
  30763. 19:51:45So, you can't have either of those. Now,
  30764. 19:51:48in our output for what we're going to
  30765. 19:51:50get down here, we need to have just two
  30766. 19:51:54things. We just need the owner name and
  30767. 19:51:56vehicle name. So, let's put that owner
  30768. 19:51:58name and vehicle name. And then lastly,
  30769. 19:52:02we just have to order by the owner name.
  30770. 19:52:07And that's going to be ascending ASC.
  30771. 19:52:10Ascending is just A to Z. So, I think we
  30772. 19:52:12can go ahead and start writing this out
  30773. 19:52:15because I think that's all we need to
  30774. 19:52:16do.
  30775. 19:52:17Now, let's go ahead and run this. And
  30776. 19:52:19so, we have our data right down here.
  30777. 19:52:21Now, here's what we need to do. We are
  30778. 19:52:23trying to identify cars that passed the
  30779. 19:52:26inspection. So, we need to filter out
  30780. 19:52:29the ones that had a critical issue or
  30781. 19:52:31that had three or more minor issues. So,
  30782. 19:52:34what we're going to do is we're going to
  30783. 19:52:35come right over here, and the first one
  30784. 19:52:37we'll do is critical issues. So, we're
  30785. 19:52:39going to say where critical
  30786. 19:52:43issues
  30787. 19:52:45and we need to say is equal to zero. And
  30788. 19:52:48let's run this. And it looks like I had
  30789. 19:52:50a space here. Let's run this again.
  30790. 19:52:52There we go. So now these are cars that
  30791. 19:52:56have no critical issues. So they're p
  30792. 19:52:58these ones are passing. But if we just
  30793. 19:53:00look at our data right down here, we
  30794. 19:53:02have some that have four, four, five.
  30795. 19:53:06So, we also have to say and and I'm
  30796. 19:53:09going to copy this so I don't have
  30797. 19:53:11another uh problem with that. So, I'm
  30798. 19:53:13going to say where it's less than or
  30799. 19:53:16equal to and I'm going to say three. So,
  30800. 19:53:18if has three or less, it should be in
  30801. 19:53:21our output. So, let's run this. And I
  30802. 19:53:24say greater than. Let me do less than.
  30803. 19:53:27There we go.
  30804. 19:53:29And we can see that now the minor issues
  30805. 19:53:31are all three or less. And let's just
  30806. 19:53:33make sure or if it has more than three.
  30807. 19:53:36So if it had four or five, it should not
  30808. 19:53:38be in our output. So this has 3 2 0 222
  30809. 19:53:41and this has 0000. So these are cars
  30810. 19:53:45that should pass. Now right now we've
  30811. 19:53:48been selecting everything, but what we
  30812. 19:53:50really need to do is just select the
  30813. 19:53:52columns that we need. That's going to be
  30814. 19:53:54owner name and vehicle.
  30815. 19:53:59So let's run this. And this looks really
  30816. 19:54:01good. And the last thing that we need to
  30817. 19:54:03do is order by. So we need to order by
  30818. 19:54:07the owner name. Let's get that owner
  30819. 19:54:09name. And we need to do that in
  30820. 19:54:11ascending. Now by default when you use
  30821. 19:54:14order by uh to organize and sort a
  30822. 19:54:17column, it automatically isn't
  30823. 19:54:18ascending. But I like to at least put it
  30824. 19:54:21there, you know, explicitly so I can see
  30825. 19:54:23it. And this to me should be the correct
  30826. 19:54:26answer. Now, what we need to do to check
  30827. 19:54:28our answer and actually show if we got
  30828. 19:54:30the answer right is just click this
  30829. 19:54:32check answer button. We can also do
  30830. 19:54:33control uh shift enter. But I'm going to
  30831. 19:54:36click the uh check answer. And there we
  30832. 19:54:39go. We got the solution correct. So,
  30833. 19:54:42let's go ahead and come up here. We're
  30834. 19:54:44going to go to our next question. This
  30835. 19:54:46is another easy question on analyst
  30836. 19:54:48builder. Again, I'm going to leave a
  30837. 19:54:49link in the description if you want to
  30838. 19:54:50try out this exact question. But let's
  30839. 19:54:52take a look at this one. This is called
  30840. 19:54:54apply discount. It says, "A computer
  30841. 19:54:56store is offering a 25% discount for all
  30842. 19:54:59new customers over the age of 65 or
  30843. 19:55:02customers that spend more than $200 on
  30844. 19:55:04their first purchase. The owner wants to
  30845. 19:55:06know how many customers received that
  30846. 19:55:08discount since they started the
  30847. 19:55:10promotion. Write a query to see how many
  30848. 19:55:12customers received that discount." Okay.
  30849. 19:55:16And let's go down and look at the data.
  30850. 19:55:18So, we have customer ID, we have their
  30851. 19:55:21age, and then we have their total
  30852. 19:55:23purchase. And let's just see if there's
  30853. 19:55:25any duplicates in this customer ID.
  30854. 19:55:28It doesn't look like it. It looks like
  30855. 19:55:30they're all just one purchase. The
  30856. 19:55:32reason I was looking at that is it says
  30857. 19:55:34all new customers and it looks like
  30858. 19:55:36these are all new customers. It doesn't
  30859. 19:55:38look like there's any repeat customers
  30860. 19:55:39that are old customers. So, we're going
  30861. 19:55:41to assume these are all new customers.
  30862. 19:55:43If there was a multiple 101s, I would
  30863. 19:55:46look for something like a transaction ID
  30864. 19:55:48or a transaction date. But those types
  30865. 19:55:51of questions are a little usually a
  30866. 19:55:52little bit more difficult um in like the
  30867. 19:55:54medium hard types of questions. But
  30868. 19:55:57let's go make some notes real quick. So
  30869. 19:56:00we have to filter on two different
  30870. 19:56:01things. They have to meet uh one of
  30871. 19:56:04these criteria in order to be in the
  30872. 19:56:06output. They either have to be over the
  30873. 19:56:08age of 65, so over 65, and let's do over
  30874. 19:56:1265,
  30875. 19:56:14or they just have to meet one of these,
  30876. 19:56:16or have spent more than 200 or spent
  30877. 19:56:20more than 200. And that's shouldn't be
  30878. 19:56:24capitalized. Uh, so that's what we need.
  30879. 19:56:26And then the owner is just wanting to
  30880. 19:56:27know how many customers received that
  30881. 19:56:30discount. So, we're going to do a count
  30882. 19:56:34on the number of customers
  30883. 19:56:37uh that fit that filter. I'll write it
  30884. 19:56:40like that. So, it's just going to be a
  30885. 19:56:42number in our output. This one should be
  30886. 19:56:44uh I would say even a little bit simpler
  30887. 19:56:46than the last one because we're not
  30888. 19:56:48having to filter or really um do
  30889. 19:56:51anything like that. Now, let's run this
  30890. 19:56:54and let's come down here. So we're going
  30891. 19:56:55to do a count eventually on this
  30892. 19:56:57customer ID, but what we need to do is
  30893. 19:56:59filter on both the age and the total
  30894. 19:57:01purchase. So let's write this out. So
  30895. 19:57:05age needs to be and I need to write
  30896. 19:57:07where where age is greater than 65. Now
  30897. 19:57:12I'm not saying greater than or equal to
  30898. 19:57:14because right here it says for new
  30899. 19:57:16customers over the age of 65. If it said
  30900. 19:57:20age 65 or over, I would say greater than
  30901. 19:57:23or equal to. I want to be these
  30902. 19:57:24questions can be very specific
  30903. 19:57:26and then we'll say and or actually or
  30904. 19:57:30because it's either of these need to be
  30905. 19:57:31true or the total purchase and again it
  30906. 19:57:35says more than 200. So we're going to
  30907. 19:57:38say greater than 200. Now let's run this
  30908. 19:57:41and let's just kind of look down here.
  30909. 19:57:44There's a lot of people that fit this
  30910. 19:57:45bill. It looks like
  30911. 19:57:48um yeah the majority of people. That's
  30912. 19:57:50great. So we're going to give them a
  30913. 19:57:51discount. These are people that received
  30914. 19:57:52a discount. So all we're going to do is
  30915. 19:57:54a count on this customer ID. So let's do
  30916. 19:57:57account on customer ID. Let's run this.
  30917. 19:58:01And our answer is 14. All we have to do
  30918. 19:58:03is check this answer to make sure uh it
  30919. 19:58:06is correct. So let's hit the check
  30920. 19:58:08answer. And there we go. Your solution
  30921. 19:58:11is correct. Now one thing I will say
  30922. 19:58:13about just technical interviews in
  30923. 19:58:15general is oftentimes they want to make
  30924. 19:58:17sure you know how to write it. But even
  30925. 19:58:19more so, they're really checking to make
  30926. 19:58:20sure you understand how SQL works. So,
  30927. 19:58:23when I'm writing this out, if I'm in an
  30928. 19:58:25actual interview, I would be talking
  30929. 19:58:27this out loud to the interviewer who's
  30930. 19:58:29interviewing me. I would say, "Okay, I
  30931. 19:58:31looks like I need to filter on this and
  30932. 19:58:33I need to do a count on these things."
  30933. 19:58:35Now, you only would know how to do that
  30934. 19:58:38if you know my SQL or if you know SQL,
  30935. 19:58:40right? Again, they really want to hear
  30936. 19:58:42your thought process. And so walking
  30937. 19:58:44through it exactly how I did in the
  30938. 19:58:46actual interview is exactly what the
  30939. 19:58:49interviewer wants to hear. Now, writing
  30940. 19:58:51it correctly is still very important,
  30941. 19:58:53especially as you get to the more uh
  30942. 19:58:56difficult questions, right? You want to
  30943. 19:58:57know certain functions and certain ways
  30944. 19:58:59to write things, but you should be
  30945. 19:59:01talking all this out loud during your
  30946. 19:59:03interview. Now, one other really cool
  30947. 19:59:04thing, I'm just going to show you this
  30948. 19:59:05at the end, is if I go over to my
  30949. 19:59:07profile, I'm actually earning points for
  30950. 19:59:10these questions. So right down here, I
  30951. 19:59:12just earned a couple extra points
  30952. 19:59:14towards my my SQL badge. And I can go
  30953. 19:59:16all the way up to expert and then master
  30954. 19:59:18as well. And so I am well on my way. And
  30955. 19:59:21then in future videos when we do the
  30956. 19:59:22medium and the hard and then the very
  30957. 19:59:24hard questions, we earn even more points
  30958. 19:59:26for those cuz they are more difficult
  30959. 19:59:27and they go towards these badges. So
  30960. 19:59:29that is how we solve those easy SQL
  30961. 19:59:31technical interview questions on Analyst
  30962. 19:59:33Builder. Go ahead and try those out.
  30963. 19:59:34There's tons of other free questions on
  30964. 19:59:36the platform that you can just try out
  30965. 19:59:38and there's lots of easy ones, but then
  30966. 19:59:39we're also going to be taking a look at
  30967. 19:59:40medium, hard, and very hard in future
  30968. 19:59:43lessons. With that being said, I hope
  30969. 19:59:44you enjoyed this video. If you did, be
  30970. 19:59:46sure to like and subscribe below and I
  30971. 19:59:48will see you in the next video.
  30972. 20:00:02What's going on everybody? Welcome back
  30973. 20:00:03to another video. Today we're going to
  30974. 20:00:05be solving Medium SQL technical
  30975. 20:00:06interview questions.
  30976. 20:00:11[music]
  30977. 20:00:13Now, if you watched [snorts] the first
  30978. 20:00:14video in this series, you saw that we
  30979. 20:00:16answered some easy SQL technical
  30980. 20:00:18interview questions. Now, we're going to
  30981. 20:00:19be solving medium level questions. The
  30982. 20:00:21medium questions are going to be a
  30983. 20:00:22little bit more difficult, but I will
  30984. 20:00:24say that if you are practicing for a SQL
  30985. 20:00:26technical interview, I highly recommend
  30986. 20:00:28practicing the easy and the medium
  30987. 20:00:30questions. But let's not waste any time.
  30988. 20:00:32Let's head over my screen and take a
  30989. 20:00:33look at our medium level questions. But
  30990. 20:00:35actually before we take a look at our
  30991. 20:00:36two questions up here, you can come over
  30992. 20:00:38here, go to the free questions, go to
  30993. 20:00:40the difficulty, and go to moderate. And
  30994. 20:00:43these are all the medium level questions
  30995. 20:00:45that you can try for free on
  30996. 20:00:47analystbuilder.com. If you've not tried
  30997. 20:00:48out analyst builder, I highly, highly,
  30998. 20:00:50highly recommend it. That is my data
  30999. 20:00:52analytics learning platform that I'm
  31000. 20:00:53extremely proud of. You can take my full
  31001. 20:00:55courses and try out these technical
  31002. 20:00:57interview questions all in one place.
  31003. 20:00:59But let's head over to our first
  31004. 20:01:02question which is called tech layoffs.
  31005. 20:01:04It says tech companies have been laying
  31006. 20:01:06off employees after a large surge of
  31007. 20:01:07hires in the past few years. Write a
  31008. 20:01:10query to determine the percentage of
  31009. 20:01:11employees that were laid off from each
  31010. 20:01:13company. Output should include the
  31011. 20:01:15company and the percentage to two
  31012. 20:01:17decimal places of laid-off employees.
  31013. 20:01:19Order by company name alphabetically. Uh
  31014. 20:01:22and I think this is extremely accurate
  31015. 20:01:24because uh that just happened. Uh, I'm
  31016. 20:01:27recording this in late late late late
  31017. 20:01:302023. Um, but I'm sure I'll release this
  31018. 20:01:32in 2024 and I think you guys know what
  31019. 20:01:34I'm talking about. Uh, it was just a bad
  31020. 20:01:36year for 2022 2023 with all the layoffs.
  31021. 20:01:39Now, we have Apple, Microsoft, Google,
  31022. 20:01:42Amazon, Facebook, Tesla, and these are
  31023. 20:01:46the employees fired. And what we're
  31024. 20:01:49trying to do is output a percentage. So,
  31025. 20:01:52we need to look at the company and then
  31026. 20:01:54percentage of laid-off employees. So, if
  31027. 20:01:57they had zero laid-off employees, the
  31028. 20:01:59percentage should be zero. But let's say
  31029. 20:02:02they had 6,000 of 181,000. We need to
  31030. 20:02:05see what percentage of the entire
  31031. 20:02:07company size was laid off. Was it 1% 2%?
  31032. 20:02:11Um, that's what we're trying to
  31033. 20:02:13determine. Now, we always can use hints
  31034. 20:02:16and expected output. if we need help or
  31035. 20:02:19if we need the video walkthrough, we can
  31036. 20:02:20use it, but I don't think we'll need it.
  31037. 20:02:22Let's come over here and make some notes
  31038. 20:02:24before we get started. Now, before we
  31039. 20:02:26write anything, remember when you're in
  31040. 20:02:27a technical interview, whether it's for
  31041. 20:02:29data analysis, data engineering, data
  31042. 20:02:31science, it doesn't matter. When you are
  31043. 20:02:33applying for these jobs, writing it out
  31044. 20:02:35correctly is important. But I would say
  31045. 20:02:37even more importantly, it's about how
  31046. 20:02:39you actually talk through the problem
  31047. 20:02:41because that really shows your skill
  31048. 20:02:43level. If you're walking through it and
  31049. 20:02:44you're just typing random stuff and it
  31050. 20:02:46kind of makes sense, but you're not
  31051. 20:02:48talking out loud, they may not
  31052. 20:02:49understand that you really know what
  31053. 20:02:51you're talking about. And so, you want
  31054. 20:02:53to practice these questions, know what
  31055. 20:02:55you're talking about, and while you're
  31056. 20:02:56solving them, do what I'm about to do,
  31057. 20:02:59which is I'm going to kind of talk
  31058. 20:03:00through the steps that I need to do,
  31059. 20:03:02then I'm going to write it out. That's
  31060. 20:03:03what I recommend during actual
  31061. 20:03:05interviews. So, the first thing that we
  31062. 20:03:08need is we need to find the percentage.
  31063. 20:03:10Now, this is going to be a calculation.
  31064. 20:03:12So I'll write percentage calculation.
  31065. 20:03:14Now how do we determine what the
  31066. 20:03:17percentage is? What we need to do is
  31067. 20:03:19employees fired divided by the company
  31068. 20:03:22size times 100. So it's employees
  31069. 20:03:27fired divided by comp size times 100.
  31070. 20:03:33That's the calculation that we need. So
  31071. 20:03:36we are going to go and do that in just a
  31072. 20:03:38little bit. But after that our output
  31073. 20:03:40needs something. So, our output needs
  31074. 20:03:43and I need to comment this out. Our
  31075. 20:03:45output needs the company name and it
  31076. 20:03:48needs the percentage.
  31077. 20:03:51So, we're definitely going to need to
  31078. 20:03:52include both of those. And then lastly,
  31079. 20:03:55we need to order by the company name as
  31080. 20:04:00C, which means ascending. So, A to Z.
  31081. 20:04:02So, this is what we need to do. Now,
  31082. 20:04:05let's do one thing first.
  31083. 20:04:08Let's just pull this up. But we don't
  31084. 20:04:11really need to start looking at the
  31085. 20:04:13output or the order by just yet. Let's
  31086. 20:04:15keep everything. We'll keep this uh
  31087. 20:04:18comma here. Let's keep everything, but
  31088. 20:04:21let's start working on our calculation.
  31089. 20:04:24So, let's see if our calculation is
  31090. 20:04:26correct. It should be employees fired
  31091. 20:04:28divided by the company size.
  31092. 20:04:31I'm going to put this all in parenthesis
  31093. 20:04:34um just to make sure we're doing PEMDOS
  31094. 20:04:37correctly. and let's multiply it times
  31095. 20:04:39100. So, let's run this.
  31096. 20:04:42And here we go. Now, this looks correct
  31097. 20:04:45just glancing at this because here we
  31098. 20:04:48have 0%. Because Apple didn't lay anyone
  31099. 20:04:51off. Uh 3% 6,000 of,800. That also looks
  31100. 20:04:55correct. This one, I think, is the most
  31101. 20:04:57um straightforward one. 15,000 into
  31102. 20:05:01140,000. That should be around 10%. But
  31103. 20:05:04because it's 11uh 15,000 to 140,000,
  31104. 20:05:08it's a little more than 10%. And so this
  31105. 20:05:10one looks very right to me. Now, one
  31106. 20:05:13thing I didn't say mention here is we
  31107. 20:05:15need to round to two decimal places. So
  31108. 20:05:18let's go ahead and round this before
  31109. 20:05:20anything. So let's put round and let's
  31110. 20:05:23wrap this entire thing. Now we need to
  31111. 20:05:26round this to two decimal places. So we
  31112. 20:05:29need to do is do a comma two here
  31113. 20:05:31because that says round to two decimal
  31114. 20:05:33places. So let's run this. And there we
  31115. 20:05:36go. That all looks correct. Now we can
  31116. 20:05:39say this as let's just rename this as
  31117. 20:05:42percentage
  31118. 20:05:43just so we don't have that really long
  31119. 20:05:46name. Uh it basically makes this the
  31120. 20:05:48column name that's way too long. So
  31121. 20:05:50we're going to call that percentage. Now
  31122. 20:05:51the only thing that we need in our
  31123. 20:05:53output is company name and percentage.
  31124. 20:05:55So let's come back here and let's put
  31125. 20:05:58company and let's run this. And this
  31126. 20:06:01looks good except we need to order by
  31127. 20:06:03the company name ascending. So we'll say
  31128. 20:06:07uh order by we'll do company and then we
  31129. 20:06:10can say ascending although by default
  31130. 20:06:13order by is in ascending. We just I like
  31131. 20:06:16explicitly writing it. So let's run
  31132. 20:06:18this. And there we have Amazon, Apple,
  31133. 20:06:22Facebook, Google, uh, Microsoft Tesla.
  31134. 20:06:25So, this looks great. I think this is
  31135. 20:06:27our final answer. Let's go ahead and
  31136. 20:06:30check our solution. And there we go. We
  31137. 20:06:33got the solution correct. Now, if you
  31138. 20:06:35remember in the last video, we checked
  31139. 20:06:36our profile. We earn points towards our
  31140. 20:06:38badges. A medium question, you earned 25
  31141. 20:06:41points. Um, and so if you're following
  31142. 20:06:43along, you're doing these questions,
  31143. 20:06:44then you should go check uh your profile
  31144. 20:06:46out because you should have uh in your
  31145. 20:06:48profile, you should have more points.
  31146. 20:06:49Now, let's go to the next question. This
  31147. 20:06:52one is called separation. It says, "Data
  31148. 20:06:55was input incorrectly into a database.
  31149. 20:06:58The ID was combined with the first name.
  31150. 20:07:01Write a query to separate the ID and
  31151. 20:07:03first name into two separate columns.
  31152. 20:07:06Each ID is five characters long." All
  31153. 20:07:10right. I've seen this in real databases
  31154. 20:07:13uh a million times. Usually when we're
  31155. 20:07:15like getting data from like an Excel
  31156. 20:07:17file or something, we always have issues
  31157. 20:07:20with Excel file or CSV files or stuff
  31158. 20:07:22like that. So let's talk about how we
  31159. 20:07:24are going to actually solve this. Now
  31160. 20:07:26we're doing this in my SQL but again you
  31161. 20:07:28can do this in Python, Postgra SQL,
  31162. 20:07:30Microsoft SQL Server, whichever one you
  31163. 20:07:33are practicing or or you know you have
  31164. 20:07:35an interview coming up. Whichever one
  31165. 20:07:36you have an interview coming up go ahead
  31166. 20:07:38and use that one. Now, I think one of
  31167. 20:07:40the main things that I'm interested in
  31168. 20:07:42right here is that each ID is five
  31169. 20:07:44characters long. Um, because we need to
  31170. 20:07:46separate this out. So, it doesn't matter
  31171. 20:07:48how long this name is. What matters,
  31172. 20:07:50it's kind of kind of the key to this is
  31173. 20:07:52how long this ID is. Cuz if it was 3 4 5
  31174. 20:07:556, we might have to use something like
  31175. 20:07:57regular expression to separate that out
  31176. 20:07:59to extract all the numbers. But luckily,
  31177. 20:08:02it's all five characters. So, with this
  31178. 20:08:04um we should be able to use something
  31179. 20:08:06like substring. This will be to pull out
  31180. 20:08:10numbers and then names. So that's what
  31181. 20:08:14we need. Uh and then we'll have two
  31182. 20:08:16separate columns. So the output will
  31183. 20:08:18then be the ID and the first name. And I
  31184. 20:08:23believe that's all we need to do is
  31185. 20:08:25separate them out into two separate
  31186. 20:08:27columns. And then uh we needed to figure
  31187. 20:08:29out how to actually separate it. So I
  31188. 20:08:32think that's all we need. Let's pull
  31189. 20:08:34this up.
  31190. 20:08:36There we go. Now I'm going to keep
  31191. 20:08:38everything. So just keeping this column,
  31192. 20:08:41but then we'll separate it out into two
  31193. 20:08:43and we'll see what this looks like. Now
  31194. 20:08:45this substring is going to take a few
  31195. 20:08:48different parameters. First we need to
  31196. 20:08:50pass through the string. Now when I say
  31197. 20:08:52string, I mean the column that contains
  31198. 20:08:54the string cuz it's going to go through
  31199. 20:08:56each row of that data. We need to select
  31200. 20:08:58the ID and then we need to specify the
  31201. 20:09:01start position and the end position. Now
  31202. 20:09:04that's where this comes into place. uh
  31203. 20:09:06where that five characters long comes
  31204. 20:09:08into place. So because it's five
  31205. 20:09:10characters long, we should start at
  31206. 20:09:11position one and then we'll do a comma
  31207. 20:09:14and end at position five. So start at
  31208. 20:09:16position one and take through position
  31209. 20:09:18five. Let's just run this and see if it
  31210. 20:09:20works.
  31211. 20:09:22There we go. So this pulled out just the
  31212. 20:09:25first five characters in this string.
  31213. 20:09:29Now we also need to pull out the full
  31214. 20:09:30first name. And we can actually label
  31215. 20:09:32this. Um let me bring this down. We'll
  31216. 20:09:34do as um let's name it something. I'll
  31217. 20:09:38say new ID. That's what we'll name it.
  31218. 20:09:41And then we'll do the next one. So this
  31219. 20:09:43will be substring.
  31220. 20:09:46Now we also are going to pass through
  31221. 20:09:47the ID. But this time we're not starting
  31222. 20:09:49at position one. Now we need to start at
  31223. 20:09:51position six. But we don't know how many
  31224. 20:09:55characters are in each name. It could be
  31225. 20:09:56S. It could be Harry. It could be uh
  31226. 20:10:00Escariat. I don't even know if that's a
  31227. 20:10:01name, but it could be really long. Um
  31228. 20:10:03Alexander. That's my name, a long name.
  31229. 20:10:05So, we don't know how long it could be.
  31230. 20:10:07So, we could put something like 20 here.
  31231. 20:10:10And if we run this, it's going to
  31232. 20:10:12extract it. But what if someone's name
  31233. 20:10:14is longer than 20 characters? That's not
  31234. 20:10:16good. Luckily though, that uh third
  31235. 20:10:19parameter, the end position, we can just
  31236. 20:10:22leave blank and it'll go from the sixth
  31237. 20:10:23position to the very end of that string.
  31238. 20:10:26So, let's run this. And that looks
  31239. 20:10:28really good. So we're going to say as
  31240. 20:10:30first
  31241. 20:10:32name. And there we go. So let's run this
  31242. 20:10:35again. So we have the new ID and we have
  31243. 20:10:38the first name. We can get rid of this
  31244. 20:10:41initial one that has everything. And I
  31245. 20:10:44believe this should be our full output.
  31246. 20:10:46Now we have this new ID and we have this
  31247. 20:10:49first name. Let's go ahead and check our
  31248. 20:10:51answer. And there we go. Your solution
  31249. 20:10:54is correct. Now these are just two of
  31250. 20:10:56the medium questions on the platform.
  31251. 20:10:57There are a ton of others. So, I'm going
  31252. 20:10:59to leave links in the description to
  31253. 20:11:00these questions as well as just to the
  31254. 20:11:02questions page. So, you can go on there
  31255. 20:11:04and you can practice and you can really
  31256. 20:11:06get comfortable writing these out and
  31257. 20:11:08using them because when you feel
  31258. 20:11:10comfortable going into that SQL
  31259. 20:11:12technical interview, you're going to do
  31260. 20:11:13a lot better and you'll know how to talk
  31261. 20:11:15through these things. And if you're ever
  31262. 20:11:17having trouble with them, you can always
  31263. 20:11:19go to this video explanation where I
  31264. 20:11:21will walk through it and tell you my
  31265. 20:11:22exact thought process on how I solve
  31266. 20:11:25these questions. And honestly, I think
  31267. 20:11:27that's one of the best features about
  31268. 20:11:28the whole platform because when I was
  31269. 20:11:30first starting out, I didn't have this.
  31270. 20:11:32And so, I'm really happy that this is
  31271. 20:11:34here for you. So, you can really learn.
  31272. 20:11:35It's really just a learning platform to
  31273. 20:11:38get better at these skills. So, if you
  31274. 20:11:39have a technical interview coming up
  31275. 20:11:41either in Python or SQL, try out
  31276. 20:11:43analystbuilder.com. It is phenomenal. I
  31277. 20:11:45created all the content myself. We also
  31278. 20:11:47have full courses on there, so you can
  31279. 20:11:49go ahead and check that out as well. In
  31280. 20:11:51the next video, we're going to be going
  31281. 20:11:52on to the hard questions. And it's going
  31282. 20:11:54to be quite a big leap from medium to
  31283. 20:11:56hard. And then after that, we're also
  31284. 20:11:58going to be going into very hard
  31285. 20:12:00questions. I would say the very hard
  31286. 20:12:01questions are more of like a challenge.
  31287. 20:12:03They're very difficult. They're a lot of
  31288. 20:12:05fun. But go ahead and check all that out
  31289. 20:12:07on Analyst Builder. With that being
  31290. 20:12:09said, if you like this video, be sure to
  31291. 20:12:10like and subscribe, and I will see you
  31292. 20:12:12in the next video.
  31293. 20:12:25What's going on everybody? Welcome back
  31294. 20:12:27to another video. Today we are going to
  31295. 20:12:28be solving hard SQL technical interview
  31296. 20:12:30questions.
  31297. 20:12:34[music]
  31298. 20:12:37These hard interview questions are
  31299. 20:12:38something that you would get in kind of
  31300. 20:12:39a medium or a senior level data analyst
  31301. 20:12:42position. The easy and the medium are
  31302. 20:12:44more towards the entry level or slashmid
  31303. 20:12:46level somewhere in that range. The hard
  31304. 20:12:48ones are not something that you're going
  31305. 20:12:50to get in the kind of more entry level
  31306. 20:12:52range. These are questions that you
  31307. 20:12:53might see in kind of a more advanced SQL
  31308. 20:12:56technical interview. I've been on the
  31309. 20:12:57interview side where I've interviewed
  31310. 20:12:59for a ton of data analyst positions. I
  31311. 20:13:00was also a hiring manager and then even
  31312. 20:13:02before that I was on a hiring team where
  31313. 20:13:04we conducted a ton of SQL technical
  31314. 20:13:06interviews. And so the questions that
  31315. 20:13:07we're going to look at today are very
  31316. 20:13:08very similar to ones that I have seen in
  31317. 20:13:10the real world or even given myself to
  31318. 20:13:12interviewees. With that being said,
  31319. 20:13:14let's jump on my screen and take a look.
  31320. 20:13:15All right, so we're here on
  31321. 20:13:16analystbuilder.com. We're going to go
  31322. 20:13:18over here to the questions tab. We're
  31323. 20:13:20going to filter to the free ones and
  31324. 20:13:22then we'll go to the hard ones. Now,
  31325. 20:13:26there are a lot more hard ones here on
  31326. 20:13:28Analyst Builder, but under the free tab,
  31327. 20:13:31uh we only have three. Looks like I
  31328. 20:13:33didn't uh get this one right, but we
  31329. 20:13:35have that one today. So, we'll see if I
  31330. 20:13:37get this one right today. You can go try
  31331. 20:13:38out these questions completely for free,
  31332. 20:13:40and we're going to be taking a look at
  31333. 20:13:42temperature fluctuations and Kelly's
  31334. 20:13:43Third Purchase. And then there's another
  31335. 20:13:45one called Cake Vers Pie, which I think
  31336. 20:13:46may be the hardest of these three. So,
  31337. 20:13:49you might want to go ahead and try to
  31338. 20:13:51take that one and see if you can get it.
  31339. 20:13:53Now, this is Kelly's third purchase.
  31340. 20:13:54We'll start with that one and then we'll
  31341. 20:13:56do temperature fluctuations. Uh, we'll
  31342. 20:13:58see how quickly I can do these two
  31343. 20:13:59because these are hard, but I think we
  31344. 20:14:02can do it. So, let's look at Kelly's
  31345. 20:14:05third purchase. It says, "At Kelly's Ice
  31346. 20:14:07Cream Shop, Kelly gives a 33% discount
  31347. 20:14:09on each customer's third purchase. Write
  31348. 20:14:11a query to select the third transaction
  31349. 20:14:13for each customer that received that
  31350. 20:14:15discount. Output the customer ID,
  31351. 20:14:17transaction ID, amount, and the amount
  31352. 20:14:20after the discount as discounted amount.
  31353. 20:14:23Order the output on customer ID in
  31354. 20:14:25ascending order. Note transaction IDs
  31355. 20:14:27occur sequentially. The lowest
  31356. 20:14:29transaction ID is the earliest ID. Now,
  31357. 20:14:33that's really important. We'll have to
  31358. 20:14:35remember that. Now before we jump in
  31359. 20:14:36anything, let's um let's go look at the
  31360. 20:14:39data, but then let's start making some
  31361. 20:14:40notes. So we have a customer ID, we have
  31362. 20:14:44the transaction ID, and the amount that
  31363. 20:14:47they spent. Now, this is the amount that
  31364. 20:14:49eventually we'll need to use to
  31365. 20:14:51calculate
  31366. 20:14:53the end uh uh amount that they paid with
  31367. 20:14:56the discount. So they get 33% off
  31368. 20:14:59whatever this number is on their third
  31369. 20:15:01purchase if that if you're tracking
  31370. 20:15:03that. So, what we need to do, and let's
  31371. 20:15:06start making some notes. One, we're
  31372. 20:15:07going to need to apply a discount. So,
  31373. 20:15:10that's going to be 33%.
  31374. 20:15:13We have to identify though the person's
  31375. 20:15:16third purchase. So, when they come in
  31376. 20:15:18three times on that third purchase, they
  31377. 20:15:21then get to get that discount. So, how
  31378. 20:15:24can we do that? Well, I I'm almost
  31379. 20:15:26certain just looking at this data
  31380. 20:15:28because we have 101 for a customer ID.
  31381. 20:15:301001
  31382. 20:15:321001 what we can do is we need to order
  31383. 20:15:36this transaction ID and then give it
  31384. 20:15:38some type of rank now because each
  31385. 20:15:41transaction ID should be unique and
  31386. 20:15:43we'll double check that but it should be
  31387. 20:15:44unique we should just be able to use row
  31388. 20:15:47number but we could also use rank or
  31389. 20:15:49dense rank um but they should give the
  31390. 20:15:52exact out same output for each of them
  31391. 20:15:55it shouldn't matter so I think using
  31392. 20:15:56just row number um and then filter ing
  31393. 20:16:01when it equals
  31394. 20:16:03three. So, we're going to apply a row
  31395. 20:16:06number based off the customer ID and the
  31396. 20:16:08transaction ID. And then for each
  31397. 20:16:11customer, we'll give it a row number.
  31398. 20:16:13And then when it's three, which is the
  31399. 20:16:15third transaction, that's the one we
  31400. 20:16:17give the discount to. Um, in our output,
  31401. 20:16:21let's look at what our output is going
  31402. 20:16:23to be. Our output is going to be, let's
  31403. 20:16:27take a look. Select the third
  31404. 20:16:28transaction. Output customer ID,
  31405. 20:16:30transaction ID, amount. So all columns,
  31406. 20:16:34all columns
  31407. 20:16:36with uh and I'll just copy this
  31408. 20:16:39discounted amount.
  31409. 20:16:41So really everything with just that new
  31410. 20:16:43column. And then we need to order by the
  31411. 20:16:47customer
  31412. 20:16:49ID.
  31413. 20:16:50So we got a lot to do. Uh this this
  31414. 20:16:54definitely doesn't look like of course
  31415. 20:16:55is a difficult question. is a hard one
  31416. 20:16:57but it doesn't look like a super
  31417. 20:16:59straightforward one. So the first thing
  31418. 20:17:01that we need to do is we have to
  31419. 20:17:04identify this row number because we
  31420. 20:17:07cannot apply the discount until we know
  31421. 20:17:10which data to apply it to the output in
  31422. 20:17:13the order by will come at the very end.
  31423. 20:17:15So let's look at this. Let's do um let's
  31424. 20:17:18do a comma here. We'll come down here.
  31425. 20:17:21Let's do row number. Now this is a
  31426. 20:17:23window function. It's it, you know, if
  31427. 20:17:25you haven't used these before or you
  31428. 20:17:27haven't taken like my full course and
  31429. 20:17:28and you know, worked through these
  31430. 20:17:30things, row number uh is a window
  31431. 20:17:32function that's going to apply to a
  31432. 20:17:34window or kind of like a group by is is
  31433. 20:17:37what I compare it to. When you group by,
  31434. 20:17:39all of those customer IDs with 101 are
  31435. 20:17:42going to be grouped into one row. With
  31436. 20:17:44uh a window function, they aren't going
  31437. 20:17:46to be grouped into one row. they'll just
  31438. 20:17:48be in a window where you'll see each row
  31439. 20:17:50individually and you can apply something
  31440. 20:17:52to each row instead of grouping it and
  31441. 20:17:56aggregating the data. So, it's really
  31442. 20:17:58unique um and really useful. So, we're
  31443. 20:18:00going to do row number and what we need
  31444. 20:18:02to do this is over the transaction ID
  31445. 20:18:06and we need to order by order by
  31446. 20:18:09transaction ID and that's going to be
  31447. 20:18:11ascending. So, the earliest one it says
  31448. 20:18:13lowest transaction ID is the earliest.
  31449. 20:18:15So, we need to start with the earliest,
  31450. 20:18:17then go to the highest and pick the
  31451. 20:18:18third one. So, let's just run this.
  31452. 20:18:22And I need to do this over. I said row
  31453. 20:18:24number. I didn't write that right at
  31454. 20:18:26all. So, we'll do over and then we write
  31455. 20:18:28it. So, we're doing we're applying this
  31456. 20:18:31row number. The over is the keyword that
  31457. 20:18:33we use to specify that this is what we
  31458. 20:18:36are doing it on. And so now we have
  31459. 20:18:39this. And we can't just do this because
  31460. 20:18:43it's applying the row number
  31461. 20:18:44appropriately based off of only the
  31462. 20:18:47transaction IDs from from lowest to
  31463. 20:18:49highest. Here's the thing though. We
  31464. 20:18:51have to do it per each customer. So it's
  31465. 20:18:53each customer's third. So we have to use
  31466. 20:18:55partition by before the order by. Now
  31467. 20:18:58partition by is going to separate it out
  31468. 20:19:01by the customer ID. It's kind of that's
  31469. 20:19:03kind of like the grouping part. Um,
  31470. 20:19:06and so we'll use partition by customer
  31471. 20:19:10ID. And why did I copy that? By customer
  31472. 20:19:13ID. And now let's run this. And now when
  31473. 20:19:17we come down, it should say 1001 101.
  31474. 20:19:22And notice that we have this um row
  31475. 20:19:25number applying at the customer ID
  31476. 20:19:27level. And then when it gets to the last
  31477. 20:19:30customer ID and it goes to the next one,
  31478. 20:19:32it restarts. So now this is that third
  31479. 20:19:35person's transaction 1001 and then at
  31480. 20:19:3710002 this is the third transaction. Now
  31481. 20:19:41here's the tricky part about trying to
  31482. 20:19:44then use this row number is I cannot
  31483. 20:19:47come down here and say where and let's
  31484. 20:19:50label this. We'll say as row_num.
  31485. 20:19:54Let's run that. Uh whoops because I have
  31486. 20:19:57this as blank. Let's comment that out
  31487. 20:20:00real quick. So I have this row num but I
  31488. 20:20:05cannot say where row num is equal to
  31489. 20:20:09three. Let's try it. So it's going to
  31490. 20:20:12say unknown column. It doesn't
  31491. 20:20:14understand that that's a column. And you
  31492. 20:20:16may be thinking well you know in
  31493. 20:20:18aggregations with group by you can use
  31494. 20:20:19the having statement. Well let's try the
  31495. 20:20:21having. And let's run this. It says the
  31496. 20:20:25window function is allowed only in the
  31497. 20:20:26select list and order by clause. We
  31498. 20:20:29cannot use in the having. So what we
  31499. 20:20:31need to do is we need to actually make
  31500. 20:20:33this as uh its own little output is what
  31501. 20:20:37I'll say. Now we can do that in two
  31502. 20:20:39different ways. We can use a CTE and we
  31503. 20:20:41can use common table expression to kind
  31504. 20:20:43of store this data down here how it is
  31505. 20:20:46and then we can query off it later or we
  31506. 20:20:48can put it in a subquery. Or if you know
  31507. 20:20:51we wanted to get really advanced and
  31508. 20:20:53we're using um actual MySQL database, we
  31509. 20:20:56could use something like a temporary
  31510. 20:20:58table or a view or something. We could
  31511. 20:21:01do other things, but for here let's wrap
  31512. 20:21:04all of this in a um let me come right
  31513. 20:21:09here. Let's wrap all this in
  31514. 20:21:12a subquery. And when you have uh a
  31515. 20:21:16subquery in a from statement, you have
  31516. 20:21:19to label it. So you have to give it a
  31517. 20:21:20name. So we're just going to call as row
  31518. 20:21:22numbers.
  31519. 20:21:24And let's select everything. And what
  31520. 20:21:27this is doing is we're selecting
  31521. 20:21:29everything from this data right down
  31522. 20:21:33here. This table that we've essentially
  31523. 20:21:35created. So what we're going to do is
  31524. 20:21:37we're going to select everything. Now
  31525. 20:21:40what we need to do is we need to say
  31526. 20:21:43where row num is equal to three. And
  31527. 20:21:48let's run this. So now we have each
  31528. 20:21:51person's
  31529. 20:21:52row num three. This is the third
  31530. 20:21:54person's transaction. Now this is really
  31531. 20:21:57good. So what we need to do next is we
  31532. 20:21:59need to then calculate this amount. So
  31533. 20:22:02it gets a 33% discount now. So let's
  31534. 20:22:05select the columns that we actually want
  31535. 20:22:07in our output. We need customer ID. We
  31536. 20:22:11need transaction
  31537. 20:22:13ID. We need the amount. Now we need to
  31538. 20:22:17calculate the discounted amount.
  31539. 20:22:19Remember we have to label this last one.
  31540. 20:22:22Um we'll say as discounted amount. So
  31541. 20:22:25this next column is going to be this
  31542. 20:22:26calculation. Now we have to give a 33%
  31543. 20:22:30discount. So we can't say amount times
  31544. 20:22:34let me bring this down like this. We
  31545. 20:22:38cannot say amount times 0.33. Let's run
  31546. 20:22:43this and let me see. I just spelled
  31547. 20:22:46transaction ID wrong. Transaction
  31548. 20:22:50ID. That's it. Always gets me. Um, this
  31549. 20:22:54is actually a This is 33% of this
  31550. 20:22:58number. That's what this is. Now, 33% of
  31551. 20:23:02this number is not a 33% discount. We're
  31552. 20:23:05giving them a 67% discount. What we want
  31553. 20:23:08is 67%
  31554. 20:23:11of the amount. Let's run this. This
  31555. 20:23:15right here is 33% off the total amount.
  31556. 20:23:18It's a discount. So instead of paying
  31557. 20:23:20$94, this person only had to pay 62.98.
  31558. 20:23:25Now the last thing we need to do, the
  31559. 20:23:27very last thing is order by customer ID.
  31560. 20:23:30And it looks like it already is, but I'm
  31561. 20:23:33going to do it anyways. We'll do order
  31562. 20:23:35by customer ID ascending. And let's run
  31563. 20:23:40this. This should be our final output.
  31564. 20:23:44And you know, it took a little bit of
  31565. 20:23:46work to get there. We had to use this
  31566. 20:23:47subquery, but I'm pretty sure this is
  31567. 20:23:48right. Let's go ahead and check this
  31568. 20:23:51answer.
  31569. 20:23:52And there we go. Our solution is
  31570. 20:23:54correct. Now, remember, there's other
  31571. 20:23:56ways to write this. There isn't just one
  31572. 20:23:59way. Um, this is kind of the difficult
  31573. 20:24:01part about hard interviews or like
  31574. 20:24:03senior level data analyst interviews for
  31575. 20:24:05for SQL um technical interviews. The
  31576. 20:24:08difficult thing is there's not only one
  31577. 20:24:09way to answer it. And so it starts
  31578. 20:24:12getting down to okay, what's the best
  31579. 20:24:13way to solve it? Walk through your
  31580. 20:24:16thought process. So everything that I
  31581. 20:24:18just did where I walked through and I
  31582. 20:24:20said, okay, I could use any of these,
  31583. 20:24:22but row number makes the most sense for
  31584. 20:24:24this data, understanding the difference
  31585. 20:24:26between those and why I'm choosing one
  31586. 20:24:28over the other um is really helpful for
  31587. 20:24:31the interviewer to understand and gauge
  31588. 20:24:33kind of your skill level. That's why I
  31589. 20:24:35recommend you write it out well, but
  31590. 20:24:37also talk about it. The thought process
  31591. 20:24:39is kind of the most important part. Now,
  31592. 20:24:41if you tried this question, you could
  31593. 20:24:43not get it or you couldn't solve it, you
  31594. 20:24:45can always get a hint, um, you can take
  31595. 20:24:47a look at the expected output or you can
  31596. 20:24:50go up to the video explanation where I
  31597. 20:24:51walk through this entire question or
  31598. 20:24:54just go look at the solution and let's
  31599. 20:24:55see if I wrote it the same way. Well, I
  31600. 20:24:57called it Rn for row number, but this is
  31601. 20:24:59essentially the same although I wrote
  31602. 20:25:01out the column names. It's essentially
  31603. 20:25:03the same, but you could have done a CTE
  31604. 20:25:05uh with this as well. But that is how
  31605. 20:25:07you would solve this Kelly's third
  31606. 20:25:09purchase. I will leave a link in the
  31607. 20:25:11description if you want to try that one
  31608. 20:25:12out. Now, let's go up here. Let's go to
  31609. 20:25:15temperature fluctuations. So, this
  31610. 20:25:17question says, write a query to find all
  31611. 20:25:19dates with higher temperatures compared
  31612. 20:25:21to the previous dates. Yesterday, order
  31613. 20:25:25dates in ascending order. Okay, let's
  31614. 20:25:28look at the data. So, we have our date
  31615. 20:25:30over here and the temperature. So, it
  31616. 20:25:32looks like for example this one, this is
  31617. 20:25:34the 2nd of January.
  31618. 20:25:36This temperature was 70. The previous
  31619. 20:25:39days was 65. So, we want to identify
  31620. 20:25:42this date. And I think it's just the
  31621. 20:25:44date um to find all the dates with
  31622. 20:25:46higher temperatures. It looks like our
  31623. 20:25:48output is just going to be the dates.
  31624. 20:25:51And I'll write that real quick. Um
  31625. 20:25:52output
  31626. 20:25:54just date column.
  31627. 20:25:57Now, how are we going to do this? How
  31628. 20:25:58are we going to compare this? Uh
  31629. 20:26:01initially, there are two things that I
  31630. 20:26:03think we could do. One, we could use a
  31631. 20:26:05window function. We could use a lag uh a
  31632. 20:26:08lag function on this which would look at
  31633. 20:26:11the previous rows data. So if we ordered
  31634. 20:26:13on the date which it already looks like
  31635. 20:26:15it's ordered, we can use the lag
  31636. 20:26:17function to look at the previous value.
  31637. 20:26:19So here is 70. Then we use the lag
  31638. 20:26:21function. It would pull over 65 over
  31639. 20:26:23here. That would perfectly fine uh way
  31640. 20:26:25to do it. The other way we could do it
  31641. 20:26:27is we could do a self join. So we could
  31642. 20:26:30tie the table to itself, but instead of
  31643. 20:26:32doing it where the date is equal to the
  31644. 20:26:34date, we say the date minus one. That's
  31645. 20:26:37another way that we could solve this. So
  31646. 20:26:39you can go ahead and try whichever way
  31647. 20:26:40you would like to. I think I prefer the
  31648. 20:26:43self join. Um I just think the last one
  31649. 20:26:47we did uh a row number which is a window
  31650. 20:26:50function. So I don't want to do another
  31651. 20:26:51window function, right? Although you
  31652. 20:26:53could solve this with a window function.
  31653. 20:26:54Um I'm going to try a self join. So
  31654. 20:26:57let's pull this over. Um, I think I'm
  31655. 20:26:59going to do a self join but on the
  31656. 20:27:04previous day where there's a one day
  31657. 20:27:05difference. So where the day is one day
  31658. 20:27:09off is what I'll say. Um, then we can
  31659. 20:27:13use that to compare. So use the
  31660. 20:27:17temperatures
  31661. 20:27:20to say where one is higher than the
  31662. 20:27:22other.
  31663. 20:27:25And that should make more sense uh in
  31664. 20:27:27just a second when we start writing it
  31665. 20:27:28out. But now we also need to order by
  31666. 20:27:31dates ascending. That's it. So we have
  31667. 20:27:34our data down here. And in order to do a
  31668. 20:27:38self join, we're just going to say um
  31669. 20:27:40I'm going to say inner join, but we can
  31670. 20:27:42do if there's a different type of join
  31671. 20:27:43you want to do, you can also do that.
  31672. 20:27:45But I'm going to say on temperatures and
  31673. 20:27:47we need to label these differently. So
  31674. 20:27:49we'll do T1 for temperatures one and
  31675. 20:27:52then T2. So now it's like we have this
  31676. 20:27:54table over here which is temperatures.
  31677. 20:27:56We have this table over here that's
  31678. 20:27:57temperatures. And we're going to join
  31679. 20:27:59them together. Now what are we going to
  31680. 20:28:01Oh, let's do T2. Now what are we joining
  31681. 20:28:04these together on? Um we're going to be
  31682. 20:28:07joining this on the dates. Now there's a
  31683. 20:28:10few different ways that we can write
  31684. 20:28:11this, but there is a function called
  31685. 20:28:13date diff where we can take one date and
  31686. 20:28:17compare it to a different date and make
  31687. 20:28:18sure it's one day different.
  31688. 20:28:21So, let's go ahead and take a look at
  31689. 20:28:23that. Let's do um a join on and we'll do
  31690. 20:28:27date diff and then we'll do t1.
  31691. 20:28:32And it's autopop populating it for us.
  31692. 20:28:35But date diff, t2 dot and then we'll say
  31693. 20:28:39date right there. And it should be a one
  31694. 20:28:42day difference. Let's try this. Let's
  31695. 20:28:44run this.
  31696. 20:28:47And the reason why it's not pulling up
  31697. 20:28:48is because we have all the same uh
  31698. 20:28:51column names. Now, when it has the same
  31699. 20:28:54column name, it's just showing up as
  31700. 20:28:57just one. One is overlaying the other.
  31701. 20:28:59So, what we're going to do is T1.ATE,
  31702. 20:29:03T1.
  31703. 20:29:07And let's get rid of that. Then, we're
  31704. 20:29:09going to label these other ones
  31705. 20:29:10different. So, we'll do T2.
  31706. 20:29:13as date 2 and then we'll copy this
  31707. 20:29:20and we'll do t2 temperature as
  31708. 20:29:24temperature 2. Now let's run this and
  31709. 20:29:27let's see what happens. So we have uh
  31710. 20:29:31this date compared to the previous date
  31711. 20:29:34this date compared to the previous date.
  31712. 20:29:36So 3 versus 2 and let's keep going. 4 3
  31713. 20:29:415 4 6 to 5. And so every single date has
  31714. 20:29:45the previous date. Now what we can do is
  31715. 20:29:48we can compare this temperature to this
  31716. 20:29:51temperature. Now we can do that in a
  31717. 20:29:53wear statement or we could just do it in
  31718. 20:29:55the join. We can make it a conditional
  31719. 20:29:57uh part of the condition in the join.
  31720. 20:30:00Maybe I'll write out both. But let's say
  31721. 20:30:01and we'll do T1 dot uh T1.
  31722. 20:30:09Is greater than T2.
  31723. 20:30:13So let's run this. So now we have 70
  31724. 20:30:17compared to 65. And it looks like the
  31725. 20:30:20other one wasn't as high. So the third
  31726. 20:30:22day is gone. 58 compared to 55.
  31727. 20:30:2590 compared to 58. 82 compared to 70. 88
  31728. 20:30:29compared to 82. These are all of our
  31729. 20:30:31dates right here in this column that
  31730. 20:30:34this temperature was higher than the
  31731. 20:30:36previous day's temperature. And so what
  31732. 20:30:39we should be able to do is just get rid
  31733. 20:30:42of all these columns and just take the
  31734. 20:30:45date. And let's run this. And there we
  31735. 20:30:48go. And all we have to do now is order
  31736. 20:30:50by. And I think it's already correct,
  31737. 20:30:54but I'm just going to I always like to
  31738. 20:30:57write it out if it's asking us to do it.
  31739. 20:30:59take do this in ascending
  31740. 20:31:01and so let's run this. Yeah, in
  31741. 20:31:04ascending order. I didn't write that. Oh
  31742. 20:31:06yeah, here I did. I wrote it right here.
  31743. 20:31:07So now this looks correct to me. Let's
  31744. 20:31:10go ahead and check our answer. And there
  31745. 20:31:12we go. Our solution is correct. Now
  31746. 20:31:14again, there's multiple different ways
  31747. 20:31:16to solve this. Genuinely off the top of
  31748. 20:31:18my head, I could think of two, probably
  31749. 20:31:19another one, another third option. Um,
  31750. 20:31:22just off the top of my head, because
  31751. 20:31:23I've been using my SQL for a while,
  31752. 20:31:25walking through that in your interview,
  31753. 20:31:27saying, "I think I could do it in this
  31754. 20:31:28way or this way, but here's why I'm
  31755. 20:31:30choosing this way." That really tells an
  31756. 20:31:33interviewer, "This guy knows what he's
  31757. 20:31:35talking about." Or, "Girl, this person
  31758. 20:31:37knows what they're talking about. They
  31759. 20:31:39understand it. They get it. I can trust
  31760. 20:31:41that this person will know how to do the
  31761. 20:31:43work that we're going to give them if we
  31762. 20:31:45hire them." You want to give them a lot
  31763. 20:31:47of confidence. That's all I'm going to
  31764. 20:31:48say. Now, if you don't know how to do
  31765. 20:31:50this or you've never done something like
  31766. 20:31:51this before, that's what this platform
  31767. 20:31:53is for. Um, so that when you get into
  31768. 20:31:55those interviews or you know you want to
  31769. 20:31:57learn and go take a course, when you get
  31770. 20:31:59into those interviews, you can
  31771. 20:32:00confidently say, I know this skill. Uh,
  31772. 20:32:02and so if you had trouble with that one,
  31773. 20:32:04you can always go to hints. You can
  31774. 20:32:06always go to the expected output video
  31775. 20:32:08solution solution. Um, let's see how I
  31776. 20:32:11solved it here. Oh, I solved it the
  31777. 20:32:12exact same, but I could I could have
  31778. 20:32:14solved it a different way. I think the
  31779. 20:32:15lag function would have done just as
  31780. 20:32:18well. Uh it may have been simpler
  31781. 20:32:20actually. So this is the one that I
  31782. 20:32:23used, but honestly the lag function in a
  31783. 20:32:25window function may even be better. So
  31784. 20:32:28we solved this Kelly's third purchase.
  31785. 20:32:30We solved this temperature fluctuations.
  31786. 20:32:33I will leave links in the description
  31787. 20:32:34for both of those. Go ahead and try
  31788. 20:32:36those out yourself. And again, even back
  31789. 20:32:39in the question section, there's this
  31790. 20:32:40cake versus pie, uh, which is probably
  31791. 20:32:43the most difficult of the hard ones, uh,
  31792. 20:32:45under the free tier. Now, if you go back
  31793. 20:32:48under the, you know, there's a, uh,
  31794. 20:32:50where you can pay for a subscription
  31795. 20:32:51under those, there's like 20 hard
  31796. 20:32:53questions, and they're all very unique,
  31797. 20:32:55very different, focusing on data
  31798. 20:32:56cleaning, window functions, uh,
  31799. 20:32:58different types of joins, and they're
  31800. 20:32:59all really unique uh, and fun to do. But
  31801. 20:33:02this cake versus pie one is really
  31802. 20:33:04interesting. I want um I want you guys
  31803. 20:33:06to go try this one. I'll leave this one
  31804. 20:33:08in the description as well. This really
  31805. 20:33:10interesting, difficult question. So,
  31806. 20:33:11those were our two hard SQL interview
  31807. 20:33:13questions. Uh they were pretty
  31808. 20:33:15challenging. You know, window function
  31809. 20:33:16and then self join. Two things that are
  31810. 20:33:18a little bit more complex than you'll
  31811. 20:33:20see in easy and medium questions. Uh in
  31812. 20:33:22the next lesson, we'll be solving a very
  31813. 20:33:24hard question. So, if you have not check
  31814. 20:33:26out analyst builder.com, it's one of the
  31815. 20:33:28best platform for data analysts. I
  31816. 20:33:29created all the content on there, all
  31817. 20:33:31the courses, all the questions, and we
  31818. 20:33:33have so much more coming to the
  31819. 20:33:34platform. If you like this video, be
  31820. 20:33:36sure to like and subscribe below, and I
  31821. 20:33:37will see you in the next video.
  31822. 20:33:46[music]
  31823. 20:33:51What's going on everybody? Welcome back
  31824. 20:33:52to another video. Today, we're going to
  31825. 20:33:54be solving a very hard SQL technical
  31826. 20:33:56interview question.
  31827. 20:34:03Now, if you've been following along with
  31828. 20:34:04the entire series, we had videos on
  31829. 20:34:06easy, medium, and hard SQL technical
  31830. 20:34:08interview questions, and we solved two
  31831. 20:34:10questions in each of those videos. But
  31832. 20:34:12we are on to the very hard questions.
  31833. 20:34:15These very hard questions are in fact
  31834. 20:34:16very difficult. So, I'm only going to be
  31835. 20:34:18doing one, although there's multiple on
  31836. 20:34:20the platform that you can try, but I'm
  31837. 20:34:22just going to be doing one because it's
  31838. 20:34:23going to take a long time to solve it.
  31839. 20:34:25Now, practicing these questions is meant
  31840. 20:34:26to help you learn as well as feel
  31841. 20:34:27comfortable and get ready for these
  31842. 20:34:29technical interviews that you're going
  31843. 20:34:30to get as a data analyst. The easy and
  31844. 20:34:33medium questions are more geared toward
  31845. 20:34:34entrylevel beginners or maybe even
  31846. 20:34:36mid-level for the medium questions. The
  31847. 20:34:38hard questions are geared more toward
  31848. 20:34:40mid-level or senior level data analysts.
  31849. 20:34:42And then there's the very hard. I don't
  31850. 20:34:44think that you're going to get a
  31851. 20:34:46technical interview this difficult. I
  31852. 20:34:47know I haven't, nor have I ever given
  31853. 20:34:49one, even though I've given tons of
  31854. 20:34:51technical interviews before. Um, I've
  31855. 20:34:54never gotten a question this hard. These
  31856. 20:34:55are more of a challenge. Really a
  31857. 20:34:58challenge of can you figure this out?
  31858. 20:35:00Uh, because it's pretty difficult. So, I
  31859. 20:35:02hope that you find this really
  31860. 20:35:03interesting. I want you to try it out.
  31861. 20:35:05But with that being said, let's jump
  31862. 20:35:06onto my screen. All right. So, we're
  31863. 20:35:08here on Analyst Builder. Let's go over
  31864. 20:35:09to the questions page. Let's filter down
  31865. 20:35:12to very hard. Now, I will note these are
  31866. 20:35:16not under the free tier. If you go to
  31867. 20:35:17the free, the very very hard ones are
  31868. 20:35:20not under the free tier. So, if you want
  31869. 20:35:21to try these, these are the very hard
  31870. 20:35:23ones. We have consecutive visits,
  31871. 20:35:25Twitter addiction, employee hierarchy,
  31872. 20:35:27biggest spenders, complex address, Uber
  31873. 20:35:30cancellation rates. Now, today we're
  31874. 20:35:32going to be trying this complex address.
  31875. 20:35:34But if you want to try out any of these
  31876. 20:35:36other ones, head over to
  31877. 20:35:37analybuilder.com. They are super super
  31878. 20:35:39fun. But let's try out this complex
  31879. 20:35:42address question. It says, "You are
  31880. 20:35:44given a database containing customer
  31881. 20:35:46addresses. Write a query to break out
  31882. 20:35:48the address column into separate columns
  31883. 20:35:50for street, city, state, and postal
  31884. 20:35:53code. Note, some addresses may have
  31885. 20:35:55additional unit or suite information.
  31886. 20:35:58For example, sweet 5A or unit B, which
  31887. 20:36:01should not be included as part of the
  31888. 20:36:03street. So, let's go down here. Let's
  31889. 20:36:05look at the addresses.
  31890. 20:36:07We have 123 Main Street, sweet 5A. So,
  31891. 20:36:10that's for example, that sweet 5A should
  31892. 20:36:12not be included, it says. Then we have
  31893. 20:36:14New York. That's the city. Uh, I'm
  31894. 20:36:17guessing that's New York City. Then it's
  31895. 20:36:19New York. Uh, then 1 2 3 4 5. Then the
  31896. 20:36:22same thing. Minneapolis is the city.
  31897. 20:36:25Then we have the state. And we have the
  31898. 20:36:26zip code. I think that's all we need to
  31899. 20:36:28Yeah, the postal code. So, let's start
  31900. 20:36:31making some notes here. So, we have to
  31901. 20:36:34the output needs to be uh street and I
  31902. 20:36:38should just copy this street all the way
  31903. 20:36:42down to postal code.
  31904. 20:36:45There we go. So that's what our output
  31905. 20:36:47needs to be. There's nothing on
  31906. 20:36:48ordering. Uh I think the most difficult
  31907. 20:36:51part is going to be just breaking it
  31908. 20:36:54out. So breaking everything out. Now how
  31909. 20:36:57are we going to do this? There's um one
  31910. 20:36:59main way that I would be doing this and
  31911. 20:37:01this is using substring. Now I've done
  31912. 20:37:04this a thousand times in my real job.
  31913. 20:37:07This is an extremely realistic thing.
  31914. 20:37:10Happens all the time. data comes in just
  31915. 20:37:12like this or sometimes separated by
  31916. 20:37:14commas or just spaces and you have to
  31917. 20:37:16figure that out, right? So, this is
  31918. 20:37:19interesting because this is separated by
  31919. 20:37:20no it's just a space. These are
  31920. 20:37:22separated by these dashes. Um, and then
  31921. 20:37:26we can't include this 5A. So, I'm going
  31922. 20:37:28to use substring and we'll see if this
  31923. 20:37:31works. Um, but with this we can choose
  31924. 20:37:34our delimiter and that's really
  31925. 20:37:36important. So we can say whether it's a
  31926. 20:37:37space, whether it's a a dash or
  31927. 20:37:41something like that. But we also have to
  31928. 20:37:42note I'll just write note right here.
  31929. 20:37:46Can't include things like sweet or unit.
  31930. 20:37:50So we have to remove that somehow. Um
  31931. 20:37:54let's go ahead and pull up the data over
  31932. 20:37:56here
  31933. 20:37:58and let's take a look. And I wanted to
  31934. 20:37:59do this in my SQL. Now you can do this
  31935. 20:38:01in Python. You can do this in Microsoft
  31936. 20:38:05SQL. I had started out writing this in
  31937. 20:38:08postgra SQL which uh the syntax is
  31938. 20:38:11actually a little bit potentially maybe
  31939. 20:38:13a little bit different actually it's
  31940. 20:38:14different in Microsoft SQL server I
  31941. 20:38:16believe postgrace SQL the substring is
  31942. 20:38:18the same don't quote me on that but
  31943. 20:38:20we're going to be using my SQL because
  31944. 20:38:21I've been using that throughout the
  31945. 20:38:22entire series
  31946. 20:38:24but if you want to you can use Python my
  31947. 20:38:27SQL Postgra SQL Microsoft SQL Server
  31948. 20:38:30whichever one you feel comfortable using
  31949. 20:38:33now let's run this so I'm going to keep
  31950. 20:38:35everything here, but I'm going to add to
  31951. 20:38:38it so we can confirm that the it's
  31952. 20:38:41accurate. Like our output is correct. So
  31953. 20:38:43that's why I'm going to keep the
  31954. 20:38:44everything there. Now, we're going to
  31955. 20:38:46use this substring. And the first one
  31956. 20:38:49that we have to figure out is um this
  31957. 20:38:53one right here. Now, it should be fairly
  31958. 20:38:56easy with something like one that does
  31959. 20:38:59not include sweet 5A. And for example,
  31960. 20:39:02we would just do substring and we have
  31961. 20:39:05to pass through some parameters. The
  31962. 20:39:07first one that we need to pass through
  31963. 20:39:08is just the string. Now this entire
  31964. 20:39:10string is kept in address. So when I say
  31965. 20:39:13we're passing through the string, we're
  31966. 20:39:15passing through a column where it has
  31967. 20:39:17multiple rows with strings in it. That's
  31968. 20:39:20all that's all I'm saying. The next
  31969. 20:39:22parameter is our delimiter. A delimter
  31970. 20:39:24is something that how are we separating
  31971. 20:39:26this out from itself? So I'm going to
  31972. 20:39:29put in quotes I'm going to put a dash.
  31973. 20:39:33And then the next parameter is where are
  31974. 20:39:35we starting? So are we looking at the
  31975. 20:39:38first delimiter, the second delimiter,
  31976. 20:39:40the third, fourth, fifth? Because this
  31977. 20:39:41one has multiple delimiters. This one
  31978. 20:39:43has one right here and it has one over
  31979. 20:39:45here. So if I put a one here,
  31980. 20:39:48um, we get null. And that's because I
  31981. 20:39:51wrote substring. We actually need
  31982. 20:39:53substring_index.
  31983. 20:39:57Uh, I'm thinking of Python. In Python,
  31984. 20:40:00I'd be using substring. In my SQL, I
  31985. 20:40:02need substring index.
  31986. 20:40:04There we go. So, now we're doing this on
  31987. 20:40:06the first delimter right here. But if I
  31988. 20:40:08change this to two, now we're looking at
  31989. 20:40:11this delimiter. So, that's the first
  31990. 20:40:14delimiter. Second delimiter. So, we only
  31991. 20:40:17want the first delimiter. But here's the
  31992. 20:40:20issue with this. We have And there's a
  31993. 20:40:22unit right here. So we have one that has
  31994. 20:40:24unit and we have one that's sweet 5A.
  31995. 20:40:28Here's what we need to do. We have to
  31996. 20:40:32get rid of it if it has a sweet 5A or if
  31997. 20:40:35it has unit B. So we'll need a case
  31998. 20:40:38statement for this. Um what we'll write
  31999. 20:40:40is we'll write case
  32000. 20:40:43and this will be our else. So if it has
  32001. 20:40:46auite in it or it has a unit in it, we
  32002. 20:40:50will use the substring index on it. But
  32003. 20:40:52if it doesn't, we're just going to treat
  32004. 20:40:54it as normal. This is like our normal
  32005. 20:40:56one. So, I'm going to say, and we'll do
  32006. 20:40:58it right here. I'll have to format this
  32007. 20:41:01in a little bit, but we'll say when when
  32008. 20:41:03the address is like, and now we're
  32009. 20:41:07looking for a pattern. We're going to
  32010. 20:41:08search does this pattern exist in this?
  32011. 20:41:12Now, uh, it's possible in some instances
  32012. 20:41:16if you're using like a million rows of
  32013. 20:41:18data, suite could be in like one two
  32014. 20:41:21three Sweet Street. I've never seen that
  32015. 20:41:24before. Um, I don't think we need to
  32016. 20:41:26take that into account today, but that
  32017. 20:41:28might be something to consider in a in a
  32018. 20:41:30real world example, but this is a real
  32019. 20:41:32world example, but we're just going to
  32020. 20:41:34include sweet. And I'm going to include
  32021. 20:41:36and I'm going to use these um
  32022. 20:41:39these wild cards. So this means anything
  32023. 20:41:42can come before this, anything can come
  32024. 20:41:44after this. It just has to have a space
  32025. 20:41:47suite. Now you don't have to add the
  32026. 20:41:50that you could do it just like that. It
  32027. 20:41:53makes more sense to me because we
  32028. 20:41:55actually need to remove that in the
  32029. 20:41:57future. And I'll explain that in a
  32030. 20:41:58little bit. But when that happens,
  32031. 20:42:01when there is a suite in there, what do
  32032. 20:42:03we want to do? Well, we need to use
  32033. 20:42:05substring index on it. But we cannot use
  32034. 20:42:09the dash. The dash has got us in trouble
  32035. 20:42:12last time. It kept the sweet 5A in
  32036. 20:42:14there. What we need to do is we need to
  32037. 20:42:16use this suite as our delimiter. So then
  32038. 20:42:20when it gets to that delimiter, it's not
  32039. 20:42:21included, right? So then we come over
  32040. 20:42:24here, we put the suite in there. Let's
  32041. 20:42:26run it. And I got a syntax error. And
  32042. 20:42:29that's because we need an end. And we
  32043. 20:42:32need and we can label it as well. But
  32044. 20:42:34this will be our street. Uh we have to
  32045. 20:42:36have an end to signify that the case is
  32046. 20:42:39done. I'm pretty sure that's the issue.
  32047. 20:42:41There we go. And that fixed it. That's
  32048. 20:42:44because like the delimter with the dash,
  32049. 20:42:47when it got to the dash, it took
  32050. 20:42:49everything before it. So now if we find
  32051. 20:42:51a suite, we're using that space suite as
  32052. 20:42:55the delimiter. Now, if we put this as
  32053. 20:42:58the delimiter, you may not be able to
  32054. 20:43:00see it, but there should be a space
  32055. 20:43:03right here, and that might cause dirty
  32056. 20:43:05data. I'm going to actually I'm going to
  32057. 20:43:06keep it like that. We'll see if my
  32058. 20:43:08hypothesis uh is correct. Now, we're
  32059. 20:43:11going to do the exact same thing
  32060. 20:43:14except now we're looking for which one
  32061. 20:43:16was it? Unit. So, if it includes sweet 5
  32062. 20:43:20A or unit B, those are the examples. We
  32063. 20:43:22need to get rid of that and we'll use
  32064. 20:43:25unit. And let's run it.
  32065. 20:43:28And there we go. So, this looks perfect.
  32066. 20:43:31This looks exactly like what we should
  32067. 20:43:33be getting in our output. So now uh
  32068. 20:43:37Whoops. Now we need to come here down to
  32069. 20:43:38the street. So now we have the street,
  32070. 20:43:41but we need to get next we need the
  32071. 20:43:44city. So the city is right after the
  32072. 20:43:48street. But here's the thing. It's in
  32073. 20:43:51the middle. And if you've ever worked
  32074. 20:43:52with data like this, it's a little bit
  32075. 20:43:54tricky because uh a delimiter only goes
  32076. 20:43:58to one point, right? So what we can do
  32077. 20:44:01is use a double uh substring index. So
  32078. 20:44:06we're collecting the substring index and
  32079. 20:44:08then uh within that text of that
  32080. 20:44:10substring index we do another substring
  32081. 20:44:12index. So I think that's what we need to
  32082. 20:44:14do here. So let's come down here and we
  32083. 20:44:17can just copy this because it's already
  32084. 20:44:20written up for us. Um and let's run
  32085. 20:44:23this. Now what if we say two here? Let's
  32086. 20:44:27run this. Um we can do it this way and
  32087. 20:44:31then go backward we can do a minus. So
  32088. 20:44:34in substring index instead of a positive
  32089. 20:44:37one looking forward that's starting from
  32090. 20:44:39um the left hand side of the string and
  32091. 20:44:42looking this way for the first one we
  32092. 20:44:44can do negative which starts from the
  32093. 20:44:45right hand side and looks this way. So
  32094. 20:44:48left to right when it's positive right
  32095. 20:44:50to left when it's negative. So then we
  32096. 20:44:52can wrap this as a substring index.
  32097. 20:44:56And now this whole thing right here is
  32098. 20:44:59our string, which is this. This is our
  32099. 20:45:01string. So now we're going to look
  32100. 20:45:03backward. We're going to do minus one.
  32101. 20:45:06Um, actually our our delimiter first is
  32102. 20:45:09a dash because we're looking to this
  32103. 20:45:11dash. And then we need to go to negative
  32104. 20:45:14one. And let's try this out. And there
  32105. 20:45:18we go. New York, Minneapolis, Goldsboro,
  32106. 20:45:20Maples, Flower Town. So this looks
  32107. 20:45:24perfect. So, let's keep that exactly how
  32108. 20:45:27we have it. Now, for the next one that
  32109. 20:45:29we need, uh, and I'm going to label this
  32110. 20:45:31as city.
  32111. 20:45:34Now, we're going to copy this whole
  32112. 20:45:36thing, bring it right down here. We'll
  32113. 20:45:38do this as state. Now,
  32114. 20:45:42obviously, this isn't going to be our
  32115. 20:45:43answer, but we can run it. So, here's
  32116. 20:45:47what we need to do. Before we took this
  32117. 20:45:49whole string and we got here and then we
  32118. 20:45:52went backward to this delimiter and
  32119. 20:45:55selected New York. What we now need to
  32120. 20:45:57do is we need to go we need to select
  32121. 20:46:01this New York Minneapolis. Now there's a
  32122. 20:46:03space here and so what we should do is
  32123. 20:46:05we should go backward to this index
  32124. 20:46:09right there. I think we need to do that
  32125. 20:46:10first. So we'll use that as our our
  32126. 20:46:14starting place.
  32127. 20:46:17And so we'll do negative one. Um,
  32128. 20:46:20yeah. So I'll just do it. So we'll go
  32129. 20:46:22negative one, but then we need to go
  32130. 20:46:23forward. So this is going to be our
  32131. 20:46:25string right here. New York 1 2 3 0 5.
  32132. 20:46:27So then we need to go forward. And our
  32133. 20:46:29delimiter should be a space.
  32134. 20:46:32Let's do a space right here. Let's run
  32135. 20:46:34this. And there we go. We have New York,
  32136. 20:46:37Minneapolis, North Carolina,
  32137. 20:46:39Massachusetts, I think, and Florida. So
  32138. 20:46:42that's our state. And we have one more,
  32139. 20:46:44and that's going to be our very last
  32140. 20:46:46one. Now, this one should actually be a
  32141. 20:46:47little bit simpler because we're just
  32142. 20:46:49starting at the very end. It's not in
  32143. 20:46:51the middle, which is a little bit
  32144. 20:46:54tricky, right? So, we're going to come
  32145. 20:46:55in here. We're going to say as, and this
  32146. 20:46:57is postal code. I really want to stick
  32147. 20:47:00to exactly what they told us to call
  32148. 20:47:02them. I don't want to go changing it.
  32149. 20:47:06So, now we're looking for a space
  32150. 20:47:07delimiter, but we're looking backward
  32151. 20:47:10negative 1. So, we're starting from the
  32152. 20:47:12right hand side and going to the first
  32153. 20:47:14space. And that should give us that 1 2
  32154. 20:47:163 4 5. Let's run this. And there we go.
  32155. 20:47:21Now I'm going to get rid of everything.
  32156. 20:47:25And let me actually come up here. I'm
  32157. 20:47:26going to get rid of everything.
  32158. 20:47:28And let's run this. So now we have the
  32159. 20:47:31street, city, state, and postal code.
  32160. 20:47:33This all looks correct. I don't know. I
  32161. 20:47:37genuinely don't know if I check this
  32162. 20:47:39answer if it's going to be correct or
  32163. 20:47:40not. My hypothesis, what I think is
  32164. 20:47:42going to happen is is is not going to be
  32165. 20:47:45correct because I think somewhere in our
  32166. 20:47:47output, we have some spaces that we
  32167. 20:47:49can't see. For example, this suite, if
  32168. 20:47:53we're using just the suite and not the
  32169. 20:47:55space suite, I think we have an extra
  32170. 20:47:57space at the end of this one right here.
  32171. 20:48:00So, it goes sweet space, which I don't
  32172. 20:48:03think is correct. And it shouldn't you
  32173. 20:48:05shouldn't have that in actual output in
  32174. 20:48:07a real database. You don't want uh uh
  32175. 20:48:09leading or trailing spaces. That's dirty
  32176. 20:48:12data. So, let's try checking it. And
  32177. 20:48:14there we go. Our answer is wrong. Let's
  32178. 20:48:17try just fixing this and seeing if
  32179. 20:48:19that's it. If not, it could also be one
  32180. 20:48:22of these. But let's try this one now. Uh
  32181. 20:48:25there we go. So, that is that was the
  32182. 20:48:27exact issue. And it's really hard to
  32183. 20:48:28catch. If you're not looking for it, you
  32184. 20:48:31may not catch it because it is a little
  32185. 20:48:33bit tricky. Um, but that is I let me see
  32186. 20:48:38if I added this in as a hint.
  32187. 20:48:41Maybe I did, maybe I didn't. But that is
  32188. 20:48:43something that you need to account for
  32189. 20:48:44in real data. So, um, I know that there
  32190. 20:48:48were people in the Discord, if you
  32191. 20:48:50haven't joined Analyst Builder and tried
  32192. 20:48:51out these questions, um, we have a we
  32193. 20:48:53have a Discord with like 2,000 people in
  32194. 20:48:55it. And this question when people have
  32195. 20:48:57been trying to solve it, have been
  32196. 20:48:58really having issues with this exact
  32197. 20:49:00thing. Is I it looks correct, but it's
  32198. 20:49:02not correct. um that is a real world
  32199. 20:49:06solution, a real world issue. And so
  32200. 20:49:08that is how you solve this question. Now
  32201. 20:49:12you know I have a whole video
  32202. 20:49:13explanation on how to do this. Um as
  32203. 20:49:16well as you can just come down here.
  32204. 20:49:17Let's look at the solution. So yeah,
  32205. 20:49:19this is exactly how I wrote it. Um there
  32206. 20:49:22are other ways to write this actually.
  32207. 20:49:24But that is how you can solve it. Now
  32208. 20:49:27remember, you can come in here even in
  32209. 20:49:30the in the questions and go to the
  32210. 20:49:32difficulty and you can take a look. You
  32211. 20:49:34can check out all these other questions
  32212. 20:49:37um and see what they look like and what
  32213. 20:49:40the questions are. These are really
  32214. 20:49:41tough. U for example, this Uber
  32215. 20:49:44cancellation rates is a really
  32216. 20:49:45interesting one. Find the cancellation
  32217. 20:49:47rates of requests with unbanned users.
  32218. 20:49:49Both client and driver must not be
  32219. 20:49:51banned each day between 2023, 1223, and
  32220. 20:49:561225. Round the cancellation rates to
  32221. 20:49:58two decimal points. So, this is another
  32222. 20:50:00really interesting question. Um, and
  32223. 20:50:03there's actually two tables here. I'm
  32224. 20:50:05not doing this one today, uh, but these
  32225. 20:50:08are more questions. I'll do more of
  32226. 20:50:10these videos in the future just because
  32227. 20:50:12I really love them. They're super fun.
  32228. 20:50:14Um, but if you want to try that question
  32229. 20:50:16out, I will leave a link in the
  32230. 20:50:18description. You can go ahead and check
  32231. 20:50:19that out. If you have not tried out
  32232. 20:50:20Analyst Builder already, I highly
  32233. 20:50:22recommend it. I created all the content
  32234. 20:50:24myself. All the questions, all the
  32235. 20:50:26courses are all done by me. So, if you
  32236. 20:50:27like my YouTube channel, you will love
  32237. 20:50:29Analyst Builder. All premium, really
  32238. 20:50:31high uh quality content. So, go ahead
  32239. 20:50:33and try that out. Thank you guys so much
  32240. 20:50:36for watching. I really appreciate it. If
  32241. 20:50:38you like this video, be sure to like and
  32242. 20:50:39subscribe below, and I'll see you in the
  32243. 20:50:41next video.
  32244. 20:50:54What's going on everybody? Welcome back
  32245. 20:50:55to another video. Today we're going to
  32246. 20:50:57be starting our Azure series.
  32247. 20:51:04Now, if you don't know, Azure is a
  32248. 20:51:06cloud-based platform owned by Microsoft.
  32249. 20:51:08Azure is one of the biggest cloud
  32250. 20:51:10platform and has millions of users all
  32251. 20:51:11around the world. I myself use it for
  32252. 20:51:14many years and I absolutely love Azure.
  32253. 20:51:15I think Azure is a fantastic cloud
  32254. 20:51:17platform and that's why we're going to
  32255. 20:51:18be starting to learn it. I think knowing
  32256. 20:51:20a cloud-based platform is an essential
  32257. 20:51:22skill today for any data analyst, data
  32258. 20:51:24scientist, data engineer out there. So,
  32259. 20:51:25that's what this entire series is going
  32260. 20:51:26to be for. We're going to get our
  32261. 20:51:27account set up. We'll look at things
  32262. 20:51:29like account storage, SQL databases, uh
  32263. 20:51:31even some things like data pipelines.
  32264. 20:51:33So, using Azure data factory and Azure
  32265. 20:51:35Synapse Analytics, these resources and
  32266. 20:51:37tools within Azure are ones you're
  32267. 20:51:39absolutely going to see. And so these
  32268. 20:51:40are the ones that we're going to be
  32269. 20:51:41focusing on in this lesson. We're just
  32270. 20:51:42going to be getting everything set up.
  32271. 20:51:44So we're going to be creating a
  32272. 20:51:45Microsoft account. We're going to be
  32273. 20:51:46creating an Azure account. And then
  32274. 20:51:47we'll be doing a walkthrough of the UI
  32275. 20:51:49just so you can kind of see it and get
  32276. 20:51:51familiar with it. So with all that being
  32277. 20:51:52said, let's jump on my screen and take a
  32278. 20:51:54look. We're going to start right here on
  32279. 20:51:56the azure.microsoft.com/free
  32280. 20:51:59over here. Now this is going to be a
  32281. 20:52:00little bit different if you're in a
  32282. 20:52:01different country, but this is for uh me
  32283. 20:52:04here in the US. But I'll have this link
  32284. 20:52:06in the description so that you can come
  32285. 20:52:08to it. you can create your account and
  32286. 20:52:10then we'll get into all the uh UI and
  32287. 20:52:12how everything looks once we actually
  32288. 20:52:14set up our account. Now, before we
  32289. 20:52:15actually create it, just go down here.
  32290. 20:52:18Here are some of the things that you're
  32291. 20:52:18going to get when you create your
  32292. 20:52:20account. You're going to get uh popular
  32293. 20:52:21services free for 12 months, which is
  32294. 20:52:24really, really great. Um 55 services
  32295. 20:52:26that you're always going to be free. And
  32296. 20:52:27then we're going to get this credit
  32297. 20:52:28right here. Now, this credit is really
  32298. 20:52:29important because some of the things
  32299. 20:52:30that we're going to be looking at in
  32300. 20:52:32this series are not things that are
  32301. 20:52:34completely free all the time. So, uh,
  32302. 20:52:36we're going to be using some of this
  32303. 20:52:38credit throughout this series. So, you
  32304. 20:52:39want to make sure you can get that. You
  32305. 20:52:40just need to create a new account, and
  32306. 20:52:42that's what we're going to be doing. And
  32307. 20:52:43then we don't have to use our money. We
  32308. 20:52:44can use Azure's money, and we will all
  32309. 20:52:47thank them for that. Let's come over
  32310. 20:52:48here. We're going to click on start
  32311. 20:52:50free. So, we're going to start our free
  32312. 20:52:52trial. Now, if you already have an
  32313. 20:52:53account, you can use it. If not, we're
  32314. 20:52:56going to click on use another account.
  32315. 20:52:58Now, again, for this, you can sign in
  32316. 20:52:59with things like GitHub. You can sign in
  32317. 20:53:01with a previous account. If you do not
  32318. 20:53:03have an account, I'm just going to show
  32319. 20:53:04you how to create one really quickly,
  32320. 20:53:06and that's what we'll use going forward.
  32321. 20:53:08If you already have an account, if
  32322. 20:53:09you're already signed in, go ahead and
  32323. 20:53:10skip a little bit forward, maybe like a
  32324. 20:53:12minute or so, and we should be done
  32325. 20:53:13creating this account. But let's go
  32326. 20:53:14ahead and see how we can do one. We're
  32327. 20:53:16going to go to create one. We're going
  32328. 20:53:18to call this uh Alex the analyst
  32329. 20:53:22atoutlook.com.
  32330. 20:53:25And there we go. So, we have Outlook or
  32331. 20:53:26we can do Hotmail. Hotmail feels like
  32332. 20:53:28it's from like the 90s, so I'm going to
  32333. 20:53:29do Outlook. at least feels uh somewhat
  32334. 20:53:31current. Then we need to create our
  32335. 20:53:33password. I don't want any tips. So, I'm
  32336. 20:53:35going to do a password right here. And
  32337. 20:53:37let's go ahead and click next. You're
  32338. 20:53:39going to fill in when you were born. And
  32339. 20:53:41we'll go ahead and click next. And it
  32340. 20:53:43should be creating our account. Looks
  32341. 20:53:44like we need to do a little uh puzzle
  32342. 20:53:46here. Looks like we need to rotate it
  32343. 20:53:48where it's pointing.
  32344. 20:53:51And there we go. So, now we're signed
  32345. 20:53:53into our Microsoft account, but now we
  32346. 20:53:55need to actually create an Azure
  32347. 20:53:56account. And those are two separate
  32348. 20:53:58things. You need two accounts. So, we're
  32349. 20:54:00going to go through. We're going to fill
  32350. 20:54:02in all this information. Your name, your
  32351. 20:54:04phone number, uh your address, and all
  32352. 20:54:06these different things. Then, we're
  32353. 20:54:07going to have to fill out uh our card,
  32354. 20:54:10so a debit card or credit card so that
  32355. 20:54:12we can actually if we go over the $200
  32356. 20:54:14or if we use a service that is not free,
  32357. 20:54:17then it is going to charge us. We won't
  32358. 20:54:19be doing that, thank goodness. But you
  32359. 20:54:21do need to have a card on file in case
  32360. 20:54:22you do that. Let's go ahead and fill out
  32361. 20:54:24all this information. Then, we'll go to
  32362. 20:54:25the next part. All right. So, we just
  32363. 20:54:26created our profile. Now, we need to
  32364. 20:54:28identify our verification by card. One
  32365. 20:54:30thing I will note in the profile, I did
  32366. 20:54:32have to verify my phone number. So, they
  32367. 20:54:34sent me a text. I put in the number and
  32368. 20:54:36there you go. Next thing we need to do
  32369. 20:54:38is we need to put in our debit card. So,
  32370. 20:54:40go ahead and do that. And once we fill
  32371. 20:54:42that out, [clears throat] you're going
  32372. 20:54:42to see this right here, which is a
  32373. 20:54:44little welcome to Microsoft. You can go
  32374. 20:54:46ahead and look through this if you'd
  32375. 20:54:48like. I'm just going to get out of it
  32376. 20:54:49because we don't really need it. Now,
  32377. 20:54:53this is going to be the first thing that
  32378. 20:54:55you see. This is just the homepage of
  32379. 20:54:57Azure. This is where you can access
  32380. 20:54:59different services and resources and
  32381. 20:55:01look at your profile and notifications
  32382. 20:55:02and all these different things. Now, the
  32383. 20:55:04first thing that we're going to do is
  32384. 20:55:05just take a look at some of these
  32385. 20:55:07resources because there are a lot of
  32386. 20:55:10resources within Azure. And so, if we
  32387. 20:55:12come down right here, let's go ahead and
  32388. 20:55:14click into one of these. This is Azure
  32389. 20:55:16Synapse Analytics. If we want to uh
  32390. 20:55:18actually use Azure Synapse Analytics, we
  32391. 20:55:21need to create a Synapse workspace. then
  32392. 20:55:24we can start using this resource and
  32393. 20:55:26start using this application and all we
  32394. 20:55:28would have to do is create this. So we'd
  32395. 20:55:29come in here to create synapse
  32396. 20:55:31workspace. We would start filling out
  32397. 20:55:33all these things and then we would
  32398. 20:55:34actually have access to that resource.
  32399. 20:55:37And so this one specifically is one that
  32400. 20:55:38we will be looking at in this series. Uh
  32401. 20:55:41let's go down and just really quickly
  32402. 20:55:43take a look at some of these. We're
  32403. 20:55:44going to be looking at data factory. So
  32404. 20:55:46creating workflows and data pipelines.
  32405. 20:55:48We will be using Azure Synapse
  32406. 20:55:50Analytics. And if we go down to
  32407. 20:55:52databases, we'll take a look at SQL
  32408. 20:55:54databases as well as maybe one or two
  32409. 20:55:56others because knowing how to use
  32410. 20:55:58databases uh with the resources within
  32411. 20:56:01Azure is actually quite important. And
  32412. 20:56:02then if we go down to storage way down
  32413. 20:56:06here, let's keep going. We go into
  32414. 20:56:09storage, we will be looking at storage
  32415. 20:56:11accounts, and that's actually where you
  32416. 20:56:13can access something like a data lake.
  32417. 20:56:15And so this can be pretty intimidating
  32418. 20:56:17just looking at this because there's so
  32419. 20:56:18many different things. But in this
  32420. 20:56:20series, we'll really focus in on the
  32421. 20:56:22things that I think you need to know
  32422. 20:56:23that you're definitely going to be using
  32423. 20:56:25as a data professional or especially a
  32424. 20:56:27data analyst. But you know, even things
  32425. 20:56:29like uh let's come back up here.
  32426. 20:56:33Even things like data factories are used
  32427. 20:56:35by data engineers, database developers,
  32428. 20:56:36data scientists, it's everybody. And so
  32429. 20:56:39knowing how to use these tools uh within
  32430. 20:56:41Azure extremely important. So that's
  32431. 20:56:43what we're going to be focusing on in
  32432. 20:56:44the next several lessons. We'll be
  32433. 20:56:46getting into specific resources within
  32434. 20:56:48Azure and how to use them. That is all
  32435. 20:56:50we're going to take a look at in this
  32436. 20:56:51lesson because we're just getting set
  32437. 20:56:52up, creating the accounts, looking at
  32438. 20:56:54some of kind of the user interface of
  32439. 20:56:56how Azure actually looks. And in the
  32440. 20:56:58next several lessons, we'll be diving
  32441. 20:56:59in, getting hands-on experience with a
  32442. 20:57:01lot of these tools. Thank you guys so
  32443. 20:57:03much for watching. I really appreciate
  32444. 20:57:04it. If you have not checked it out
  32445. 20:57:06already, I have a full course on AWS and
  32446. 20:57:08Azure on analystbuilder.com. Be sure to
  32447. 20:57:11go check it out. I'll leave a link in
  32448. 20:57:12the description. If you like this video,
  32449. 20:57:14be sure to like and subscribe, and I
  32450. 20:57:16will see you in the [music] next video.
  32451. 20:57:28[music]
  32452. 20:57:30What's going on everybody? Welcome back
  32453. 20:57:31to another video. Today we're going to
  32454. 20:57:33be taking a look at account storage in
  32455. 20:57:35Azure.
  32456. 20:57:38>> [music]
  32457. 20:57:41>> Now, account storage is super important
  32458. 20:57:43within Azure. This is where a lot of
  32459. 20:57:45companies are going to store a lot of
  32460. 20:57:46their data. Using account storage in
  32461. 20:57:48Azure is a super flexible way to store
  32462. 20:57:50your data. It can store just about
  32463. 20:57:51anything and you can even upgrade it
  32464. 20:57:53into a data lakeink. And so, we'll be
  32465. 20:57:54taking a look at all these things in
  32466. 20:57:56this lesson just to get you familiar
  32467. 20:57:57with how to use account storage because
  32468. 20:57:59you absolutely will be using that within
  32469. 20:58:01Azure. Without further ado, let's jump
  32470. 20:58:02on my screen and take a look. So, let's
  32471. 20:58:04start by taking a look at our resources.
  32472. 20:58:06Right here in storage, we have our
  32473. 20:58:08storage accounts. Now, as you can see,
  32474. 20:58:10there's lots of different options for
  32475. 20:58:13storage, but by far the one that you're
  32476. 20:58:15probably going to use the most is
  32477. 20:58:17storage accounts. Now, we do have right
  32478. 20:58:20over here, you'll notice data lakeink
  32479. 20:58:21storage gen 1. If we click into this and
  32480. 20:58:24let's say we wanted to create a data
  32481. 20:58:26lakeink, it says right up here, Azure
  32482. 20:58:29data lakeink storage gen 1 will be
  32483. 20:58:31retired on February 29th of 2024. We
  32484. 20:58:33recommend that you migrate your Azure
  32485. 20:58:34data lakeink storage gen 1 to Azure data
  32486. 20:58:38lakeink storage gen 2 and that is
  32487. 20:58:39located in the storage account. So let's
  32488. 20:58:42come back here. We're going to go right
  32489. 20:58:44into storage accounts and let's really
  32490. 20:58:47quickly set up a storage account. Now
  32491. 20:58:50this is some helpful information if
  32492. 20:58:53you've never used a storage account
  32493. 20:58:54before. It says you can store about 500
  32494. 20:58:56terabytes. It has general purpose
  32495. 20:58:58storage use for object stores. No SQL
  32496. 20:59:01data store. uh you can define and use
  32497. 20:59:03queries for message processing and you
  32498. 20:59:05can also set up file shares. At the very
  32499. 20:59:07end we have blob storage accounts for
  32500. 20:59:09hot and cool access tiers. These are all
  32501. 20:59:11things that we'll look at uh in this
  32502. 20:59:13lesson. And so that is just kind of a
  32503. 20:59:15preview of a lot of the things that
  32504. 20:59:16we're going to be looking at. So let's
  32505. 20:59:18go ahead and create our storage account.
  32506. 20:59:20Now this is a brand new account uh as we
  32507. 20:59:22set it up in the last lesson. So I'm
  32508. 20:59:24going to be walking through this with
  32509. 20:59:25you as if I have a brand new account.
  32510. 20:59:28Now, you have to have your subscription,
  32511. 20:59:30which if you're using the free tier,
  32512. 20:59:31you'll have a free Azure subscription,
  32513. 20:59:33but we have to have a resource group.
  32514. 20:59:36Now, we haven't created a resource
  32515. 20:59:37group. Let's go ahead and create a new
  32516. 20:59:39one. And we'll just call this one Alex
  32517. 20:59:41the analyst. And we'll click okay. Next,
  32518. 20:59:44we need to specify a storage account
  32519. 20:59:46name. We'll call this one Alex the
  32520. 20:59:48Analyst storage. I'm guessing that's
  32521. 20:59:51unique. Uh the storage account name has
  32522. 20:59:53to be unique across all of Azure. So if
  32523. 20:59:56you type in something kind of generic,
  32524. 20:59:58usually it will already have been taken.
  32525. 21:00:00So you have to do something pretty
  32526. 21:00:01specific. Now this part and the next
  32527. 21:00:04part uh these are pretty important. This
  32528. 21:00:06region says choose the Azure region
  32529. 21:00:08that's right for you and your customers.
  32530. 21:00:10Not all storage account configurations
  32531. 21:00:12are available in all regions. Now if
  32532. 21:00:14you're just setting this up for
  32533. 21:00:15yourself, just to store some data on the
  32534. 21:00:17cloud or you have a little app that
  32535. 21:00:18you're creating or something like that,
  32536. 21:00:20it's very easy. You're just going to
  32537. 21:00:22select your local region. And for me,
  32538. 21:00:25that's US East. But what if you have a
  32539. 21:00:28company or a product or an app that's
  32540. 21:00:30being used by people all around the
  32541. 21:00:33world? For example, you have a client-f
  32542. 21:00:35facing app that they're using and
  32543. 21:00:36they're going in and they're uh
  32544. 21:00:38retrieving data from some type of
  32545. 21:00:40storage account. Or maybe they're
  32546. 21:00:41running a query on your website of data
  32547. 21:00:43that's stored in a storage account. And
  32548. 21:00:46what's happening is is it's stored
  32549. 21:00:47locally to you, but they're way over
  32550. 21:00:50here in uh let's say they're in central
  32551. 21:00:53India. And so in order to get from
  32552. 21:00:55central India to the US, it's going to
  32553. 21:00:57take a lot longer to retrieve that data.
  32554. 21:00:59And so it could take 5 10 15 20 seconds
  32555. 21:01:02for it to get to them in India versus if
  32556. 21:01:05it's just locally in US East. And so you
  32557. 21:01:08need to know where your customers or
  32558. 21:01:10where your clients are located who are
  32559. 21:01:12going to be using this. Now, just for
  32560. 21:01:13this lesson, we're going to keep it in
  32561. 21:01:15East US because that's where I am
  32562. 21:01:16located. Uh but that is something you
  32563. 21:01:19really need to consider, especially as
  32564. 21:01:20you get more advanced uh with using
  32565. 21:01:22Azure. But, you know, just for the
  32566. 21:01:24basics, you know, you don't really need
  32567. 21:01:26to be thinking about that. I just want
  32568. 21:01:28to walk you through my thought process
  32569. 21:01:29as we're going through this. Next, we
  32570. 21:01:31have to specify our performance. This is
  32571. 21:01:33just going to determine how quickly and
  32572. 21:01:35how easily you can retrieve your data.
  32573. 21:01:37We're just going to go with standard,
  32574. 21:01:38but premium would just allow you to
  32575. 21:01:39retrieve that data even quicker. Next,
  32576. 21:01:41we have redundancy. Now, redundancy is
  32577. 21:01:44important, and it's one of the benefits
  32578. 21:01:45of the cloud, which is if a server goes
  32579. 21:01:48out that's storing your data, they're
  32580. 21:01:50going to have a backup of that data
  32581. 21:01:52somewhere else. And you can specify
  32582. 21:01:54where that is going to be located. You
  32583. 21:01:55can either do it a locally redundant
  32584. 21:01:58storage, a geo redundant storage, a zone
  32585. 21:02:00redundant storage, or a geozone
  32586. 21:02:02redundant storage. And so if your data
  32587. 21:02:03is super important, it is critical to
  32588. 21:02:06what your website does, it is critical
  32589. 21:02:08to your clients, if it was deleted by
  32590. 21:02:10accident in any way or destroyed in any
  32591. 21:02:12way, your whole company would collapse.
  32592. 21:02:14You're going to choose this one down
  32593. 21:02:15here. But if it's just some local files
  32594. 21:02:17that you're uploading for someone to
  32595. 21:02:19pick up, uh, and it's not that
  32596. 21:02:20important, you're going to do something
  32597. 21:02:21like locally redundant storage. And so
  32598. 21:02:23that that's what we'll choose. Uh, just
  32599. 21:02:25something to consider though. Now, there
  32600. 21:02:27are other things you can do in advanced
  32601. 21:02:30networking, data protection, encryption,
  32602. 21:02:32tags, and all these different things.
  32603. 21:02:34But if I'm being honest, 99% of the
  32604. 21:02:36time, you're never going to use any of
  32605. 21:02:38these unless you really, really, really
  32606. 21:02:40know what you're doing or that's your
  32607. 21:02:42job. you're some type of database
  32608. 21:02:43administrator creating these storage
  32609. 21:02:44accounts for people on your team. Most
  32610. 21:02:46likely, you're never doing that. So,
  32611. 21:02:48let's go down here. We're going to click
  32612. 21:02:50create and it's going to say we have our
  32613. 21:02:52deployment in progress. So, it's going
  32614. 21:02:54to start creating the resources needed
  32615. 21:02:55for that storage account. And then we're
  32616. 21:02:58going to actually get into the storage
  32617. 21:02:59account and start using it. And just
  32618. 21:03:00like that, took about 10 seconds. It
  32619. 21:03:03says that your deployment is complete.
  32620. 21:03:05We don't need to go to the resource up
  32621. 21:03:07here. We're going to go to the resource
  32622. 21:03:08right here.
  32623. 21:03:10Now what we're looking at is the user
  32624. 21:03:12interface for this specific storage
  32625. 21:03:14account. So we have Alex the analyst
  32626. 21:03:16storage. If we go back to all services,
  32627. 21:03:19we come into storage accounts. You can
  32628. 21:03:21now see that we have one. We don't have
  32629. 21:03:23to just have that uh boilerplate text
  32630. 21:03:26and then create. If we want to create
  32631. 21:03:27another one, we'll come right up here.
  32632. 21:03:29But we can come into the storage account
  32633. 21:03:31and we can look at this overview. So
  32634. 21:03:33this is just some of the information on
  32635. 21:03:35the location, the subscription, uh the
  32636. 21:03:38subscription ID, the type of
  32637. 21:03:39performance, the replication or
  32638. 21:03:41redundancy, and a few other things as
  32639. 21:03:44well. Now, there's a ton of things on
  32640. 21:03:46this sidebar on this left hand side. We
  32641. 21:03:49have things like activity log, tags,
  32642. 21:03:51diagnosis, solve problems, access, data
  32643. 21:03:54migration, events, storage browser,
  32644. 21:03:55storage, mover, and all these different
  32645. 21:03:57options. It's kind of overwhelming, but
  32646. 21:03:58I know just from experience that you're
  32647. 21:04:00not going to use almost any of these. In
  32648. 21:04:02fact, things like monitoring are
  32649. 21:04:04typically used like something like logs
  32650. 21:04:06are typically used by it if there's an
  32651. 21:04:08issue. Most likely, you're not going to
  32652. 21:04:10be coming in here and taking a look at
  32653. 21:04:12all these things or creating uh
  32654. 21:04:14different alerts. You may be working
  32655. 21:04:16with metrics if you're in the IT
  32656. 21:04:18department. But again, a lot of this
  32657. 21:04:20stuff you're not going to be working
  32658. 21:04:21with specifically. Most of the time,
  32659. 21:04:23we're going to be here in this storage
  32660. 21:04:25browser. And this is where the data is
  32661. 21:04:27actually uploaded, stored, and accessed.
  32662. 21:04:30So if you come in here, let's come up
  32663. 21:04:32here to a blob container. Let's say we
  32664. 21:04:35want to create a blob container just to
  32665. 21:04:36store a bunch of data. Maybe it's for a
  32666. 21:04:38client or an application or whatever. We
  32667. 21:04:41just want to be able to store that data
  32668. 21:04:42in the cloud. And this kind of the
  32669. 21:04:43simplest version of being able to use
  32670. 21:04:45the storage browser or just storage in
  32671. 21:04:48general. So what we can do is we can add
  32672. 21:04:51a container. Now we're going to name
  32673. 21:04:53this container. We'll call this uh ATA
  32674. 21:04:56container. There we go. And if we come
  32675. 21:04:58down here, we do have an advanced tab.
  32676. 21:05:00You're most likely not going to use it
  32677. 21:05:02because this is uh deals with
  32678. 21:05:04encryption. And just this is completely,
  32679. 21:05:07you know, as a sidebar above and beyond
  32680. 21:05:09what you probably need to know. But when
  32681. 21:05:11you start trying to access data later on
  32682. 21:05:13in different applications, whether it's
  32683. 21:05:14a SQL database or you're using it in
  32684. 21:05:16PowerBI or whatever you're using uh this
  32685. 21:05:18data for, if you have it encrypted,
  32686. 21:05:20you're going to have to have a way to
  32687. 21:05:21unencrypt it within Azure. And so it is
  32688. 21:05:24an additional level of security, but it
  32689. 21:05:26makes it a little bit more difficult to
  32690. 21:05:27access that data later on if it's not
  32691. 21:05:30super sensitive data. So just something
  32692. 21:05:32to think about. Let's go ahead and
  32693. 21:05:34create this. And now we have this ATA
  32694. 21:05:37container. So we're doing great over
  32695. 21:05:39here. So we've already created a storage
  32696. 21:05:41account. We've gone into the storage
  32697. 21:05:42browser. We've created a container. And
  32698. 21:05:45these blob containers are amazing. I've
  32699. 21:05:47used them thousands of times for so many
  32700. 21:05:50different things. And blob containers
  32701. 21:05:52are really just used for anything.
  32702. 21:05:54Anything you need, you can use and you
  32703. 21:05:56can dump inside of a blob container,
  32704. 21:05:58whether it's structured,
  32705. 21:05:59semi-structured, or unstructured data.
  32706. 21:06:01And so let's see how that actually
  32707. 21:06:02works. Let's go into this. And we have
  32708. 21:06:04nothing in here. And we want to upload
  32709. 21:06:07some data. So let's come up here to
  32710. 21:06:09upload. We're going to go and browse for
  32711. 21:06:10some files. So in here we have a bunch
  32712. 21:06:13of different files. We have a SQL text
  32713. 21:06:16file, a PNG which is just an image. Uh a
  32714. 21:06:19Jupyter notebook file and a CSV. All of
  32715. 21:06:21these are completely different. None of
  32716. 21:06:23these are similar almost any way. And so
  32717. 21:06:26what we're going to do is we're going to
  32718. 21:06:26select all these. We're going to open
  32719. 21:06:28these up and we can upload these. But
  32720. 21:06:31really quickly, let's come in here and
  32721. 21:06:33take a look at some of these advanced
  32722. 21:06:35options because this part actually is
  32723. 21:06:38something that you might use. The really
  32724. 21:06:40the most important one in here is this
  32725. 21:06:42access tier. If we hover over it, it's
  32726. 21:06:45this piece that's kind of important. It
  32727. 21:06:46says optimize storage costs by placing
  32728. 21:06:48your data in the appropriate access
  32729. 21:06:51tier. And you can come over here and
  32730. 21:06:53look at all the access tiers if you'd
  32731. 21:06:54like. But let's take a look at what
  32732. 21:06:56these access tiers look like and what
  32733. 21:06:57they actually do. We have four options.
  32734. 21:07:00We have hot, cool, cold, and archive.
  32735. 21:07:02Now, this refers to how the data is
  32736. 21:07:04actually going to be stored in the blob
  32737. 21:07:06storage. If it is hot, that means that
  32738. 21:07:09you can just retrieve it anytime you
  32739. 21:07:11want right away within milliseconds.
  32740. 21:07:13It's just going to be ready to go and
  32741. 21:07:14it's going to be there for you. But if
  32742. 21:07:16you go with an option like cool or cold,
  32743. 21:07:19it's not going to be there hot and ready
  32744. 21:07:21just to be able to pick up and use that
  32745. 21:07:23data. It's going to be sitting in a data
  32746. 21:07:24store where if you want to retrieve it,
  32747. 21:07:26you may have to wait a little bit. And
  32748. 21:07:28so these options are actually a lot more
  32749. 21:07:30cost-effective because if you're not
  32750. 21:07:32using that data actively, you can just
  32751. 21:07:34plop it in there as a data store where
  32752. 21:07:36you're not using it for any application
  32753. 21:07:37or any project and you have the data
  32754. 21:07:40stored securely but you don't have to
  32755. 21:07:41pay a ton of money for it. Whereas if
  32756. 21:07:43you store it in hot, it's going to cost
  32757. 21:07:45more money to store that. Lastly is
  32758. 21:07:47archive. And archive means you most
  32759. 21:07:50likely won't ever use it. This is a
  32760. 21:07:52contract that was signed uh six years
  32761. 21:07:54ago. you need it on file, but most
  32762. 21:07:56likely you're never going to use this.
  32763. 21:07:58If you do, you're willing to wait 5 or
  32764. 21:08:0010 minutes cuz it's not going to be an
  32765. 21:08:02emergency to get that data or that file
  32766. 21:08:04or whatever it is. And so these are the
  32767. 21:08:07different tiers that you can use. Now,
  32768. 21:08:09we'll just use hot because that is the
  32769. 21:08:11default option. But if you have a use
  32770. 21:08:13case where it's not important that that
  32771. 21:08:15data is quickly accessible, you don't
  32772. 21:08:17need it right away, then these other
  32773. 21:08:19options are going to be a lot cheaper.
  32774. 21:08:21So, let's come down here. We're going to
  32775. 21:08:23go ahead and upload these files. And
  32776. 21:08:26there we go. Then what we're going to do
  32777. 21:08:27is we're going to actually upload one
  32778. 21:08:29more. And this is going to be for a
  32779. 21:08:30future lesson when we actually access
  32780. 21:08:33some of this data. We're going to browse
  32781. 21:08:34for files. And we're going to select CSV
  32782. 21:08:36file 2. I just made a copy of this. And
  32783. 21:08:38all we're going to do is we're going to
  32784. 21:08:39open this up. And for this, we're going
  32785. 21:08:42to choose uh you can do any of these
  32786. 21:08:44honestly, but let's put it in archive
  32787. 21:08:46just to be have the most dramatic
  32788. 21:08:47effect. Let's go ahead and upload this.
  32789. 21:08:50And as you can see here in this access
  32790. 21:08:52tier, we have hot inferred inferred
  32791. 21:08:53inferred and then we have archive. And
  32792. 21:08:55so later on in a future lesson when we
  32793. 21:08:58try to access some of this data, we're
  32794. 21:09:00going to try to access both of these and
  32795. 21:09:01you'll see what actually happens when
  32796. 21:09:04you have data stored in archive or cool
  32797. 21:09:06or cold. It's quite similar. We'll see
  32798. 21:09:08how these are retrieved. Now the next
  32799. 21:09:10thing I want to take a look at is right
  32800. 21:09:12over here under settings. Now under
  32801. 21:09:14settings, you'll see this data lakeink
  32802. 21:09:16gen 2 upgrade. Let's go ahead and click
  32803. 21:09:18on this. It says that you can upgrade to
  32804. 21:09:21a storage account with Azure Data Link
  32805. 21:09:23Gen 2 capabilities. So, if you need
  32806. 21:09:25things like data analytics and big data
  32807. 21:09:27storage, you should consider upgrading
  32808. 21:09:29to Azure Data Link Gen 2. Now, we're not
  32809. 21:09:32diving into data links within Azure. I
  32810. 21:09:34may do that in a future lesson, but this
  32811. 21:09:37is where you can access to create a data
  32812. 21:09:39lakeink. You can upgrade your storage
  32813. 21:09:41account into a data lakeink. They used
  32814. 21:09:43to have a completely separate data
  32815. 21:09:44lakeink gen 1 which is what we just
  32816. 21:09:46looked at earlier but now this is all
  32817. 21:09:48located within the storage account. So
  32818. 21:09:49you just upgrade from this location then
  32819. 21:09:52you'll have those data lakeink
  32820. 21:09:53capabilities. So that's just something
  32821. 21:09:54that I wanted to mention while we're
  32822. 21:09:56here. Now the last thing that I actually
  32823. 21:09:58want to look at within the storage
  32824. 21:10:00account is actually the IM which is the
  32825. 21:10:02access control. Now, within here, you're
  32826. 21:10:05going to have complete access to this
  32827. 21:10:07because if you come over here and view
  32828. 21:10:08your access, you can see that you're
  32829. 21:10:10going to have grants full access to
  32830. 21:10:12manage everything. And if you come over
  32831. 21:10:14here, you can read it more. You you have
  32832. 21:10:15access to everything cuz you created it.
  32833. 21:10:18But what if we want other people to have
  32834. 21:10:20access to this? Cuz right now, this is a
  32835. 21:10:23private account. Nobody else can access
  32836. 21:10:25this. If you want other people to have
  32837. 21:10:27access to this, you're just going to go
  32838. 21:10:28to add. You can add a role assignment or
  32839. 21:10:30a co-administrator.
  32840. 21:10:32Let's just say we're going to add a role
  32841. 21:10:33assignment. You can say this person has
  32842. 21:10:36the ability to read, but you can't make
  32843. 21:10:38any changes. So, I'm going to click on
  32844. 21:10:40this one. Then I'm going to come up here
  32845. 21:10:41to members. Now, right now, I am the
  32846. 21:10:44only person in my Azure account. So, if
  32847. 21:10:47I wanted to add somebody, let's say Bob.
  32848. 21:10:50If I wanted to add Bob, he'd have to be
  32849. 21:10:52have an Azure account. But I would click
  32850. 21:10:53on Bob and I'd say, okay, I'm going to
  32851. 21:10:54give Bob this access. I'm going to
  32852. 21:10:56select him and we're going to give him
  32853. 21:10:58just the read access. We don't want him
  32854. 21:11:00to, you know, delete all of our files by
  32855. 21:11:02accident. He's not the brightest uh bulb
  32856. 21:11:04of the bunch. So, we're just going to
  32857. 21:11:06give him that access. Review and assign.
  32858. 21:11:10And we'll go ahead and add that role
  32859. 21:11:12assignment. Now, you can see that my
  32860. 21:11:14access I am an owner, but I'm also a
  32861. 21:11:16reader. And so, that is how you grant
  32862. 21:11:17access to storage accounts. You can also
  32863. 21:11:20create roles, deny assignments, uh
  32864. 21:11:22create classic administrators, but
  32865. 21:11:24typically this is done by a database
  32866. 21:11:26administrator, but it is something that
  32867. 21:11:29is extremely extremely frustrating about
  32868. 21:11:31Azure just in general because any single
  32869. 21:11:34tiny thing you want to do within Azure,
  32870. 21:11:36you're going to have to request access.
  32871. 21:11:37And so when you're first getting started
  32872. 21:11:38up at a company, they're going to give
  32873. 21:11:40you a lot of the base access. They're
  32874. 21:11:42going to, you know, create your
  32875. 21:11:43accounts. They're going to give you some
  32876. 21:11:44access to PowerBI or the data lake or a
  32877. 21:11:47SQL database. But whenever you want to
  32878. 21:11:49use anything outside of that, you have
  32879. 21:11:51to request IM access. And so that's just
  32880. 21:11:53something I want you to be aware of
  32881. 21:11:55because if you want access to specific
  32882. 21:11:58storage accounts, you're saying, "Oh,
  32883. 21:11:59this team, you know, wants me to work on
  32884. 21:12:01their data or use something with their
  32885. 21:12:03data, but I don't have access to it."
  32886. 21:12:05That's because you weren't given access
  32887. 21:12:06to it. You just have to request it or go
  32888. 21:12:08to your database administrator, whoever
  32889. 21:12:10runs that, to ask for permission. And so
  32890. 21:12:12that's kind of the nuts and bolts of
  32891. 21:12:14what most people are going to use
  32892. 21:12:16storage accounts for. There are things
  32893. 21:12:18like fileshares, cues, tables. Honestly,
  32894. 21:12:20I you don't use them that much and so
  32895. 21:12:22I'm not going to dive into it. These
  32896. 21:12:24blob containers within storage accounts,
  32897. 21:12:26the data lake, which uh is an
  32898. 21:12:28upgradeable option, these are kind of
  32899. 21:12:29the more important things. And so
  32900. 21:12:31knowing how to store, where to store,
  32901. 21:12:33and all these uh different options is
  32902. 21:12:35very important. And so we'll be coming
  32903. 21:12:37back to some of this data or putting in
  32904. 21:12:39new data for different lessons when we
  32905. 21:12:42actually start accessing data within a
  32906. 21:12:44storage account. So, I hope that that
  32907. 21:12:45was helpful. If you have not already, I
  32908. 21:12:47have a full course on Azure and AWS over
  32909. 21:12:49on analysts.com. I will leave a link in
  32910. 21:12:52the description if you want to check it
  32911. 21:12:53out. If you like this video, be sure to
  32912. 21:12:55like and subscribe. I will see you in
  32913. 21:12:57the next video.
  32914. 21:13:11What's going on everybody? Welcome back
  32915. 21:13:12to another video. But today we're going
  32916. 21:13:14to be taking a look at SQL databases in
  32917. 21:13:16Azure. [music]
  32918. 21:13:22By now I think you all know how much I
  32919. 21:13:24love SQL. I think it's one of the best
  32920. 21:13:25skills for any data professional to
  32921. 21:13:27have. But using it in the cloud is a
  32922. 21:13:29little bit different than using it on
  32923. 21:13:31your local computer. So in this lesson
  32924. 21:13:32we're going to see how you can use a SQL
  32925. 21:13:34database in Azure. Without further ado,
  32926. 21:13:36let's jump on my screen and take a look.
  32927. 21:13:37All right. So the first thing that we're
  32928. 21:13:39going to do is we're going to come right
  32929. 21:13:40in here into databases under the
  32930. 21:13:42resources. Now we have a lot of
  32931. 21:13:44different options in here and there's a
  32932. 21:13:45ton of different databases that you can
  32933. 21:13:48choose from and it kind of depends on
  32934. 21:13:49what your company does. I'm only going
  32935. 21:13:52to be showing you the SQL databases but
  32936. 21:13:53other popular ones are things like using
  32937. 21:13:55my SQL or Postgrace SQL with flexible
  32938. 21:13:58servers as well as things like Azure
  32939. 21:14:00Cosmos DB. They all have different use
  32940. 21:14:02cases and they all have different ways
  32941. 21:14:04uh that they are implemented. But by far
  32942. 21:14:07the most common or the one that I've
  32943. 21:14:08used the most in my career is SQL
  32944. 21:14:11databases. So let's come right in here
  32945. 21:14:13and what we need to do is we need to
  32946. 21:14:15create a SQL database and let's click on
  32947. 21:14:18create SQL database and let's actually
  32948. 21:14:20create it and then we'll see how we can
  32949. 21:14:21use it. So what we're going to do is
  32950. 21:14:23come right down here to subscription. We
  32951. 21:14:25have to select our resource group which
  32952. 21:14:27you should have already created. Let's
  32953. 21:14:29create a database name. Let's call this
  32954. 21:14:31Alex the analyst DB for database. Now we
  32955. 21:14:36have to select a server but we haven't
  32956. 21:14:37created a server. So we need to create a
  32957. 21:14:39new server. And again I'm going to call
  32958. 21:14:41this uh we'll do ATA for Alex the
  32959. 21:14:43analyst. I'll call this server. It looks
  32960. 21:14:46like this needs to be lowercase. Let's
  32961. 21:14:48do ATA server. And then we'll do YT at
  32962. 21:14:50the end. Have to make it unique. There
  32963. 21:14:52we go. All right. We're overcoming some
  32964. 21:14:53hurdles here. Next we have to choose an
  32965. 21:14:56authentication method. We can use the
  32966. 21:14:58Microsoft Entra only authentication SQL
  32967. 21:15:01and the entra authentication or just SQL
  32968. 21:15:03authentication. Now what that means is
  32969. 21:15:05is if you come in here and set your uh
  32970. 21:15:07Microsoft Entra admin you can set it as
  32971. 21:15:09yourself and that does help if you're
  32972. 21:15:12already signed into Azure going to be
  32973. 21:15:14using it within Azure. This can be very
  32974. 21:15:16helpful. It's actually kind of the
  32975. 21:15:18default u method. Let's get out of here.
  32976. 21:15:20This is the default method. If you come
  32977. 21:15:22down here though you can also create an
  32978. 21:15:24admin login and a password. Both of
  32979. 21:15:26these have their, you know, place and
  32980. 21:15:28sometimes you need to use both. Um, and
  32981. 21:15:31so just choose the one, the
  32982. 21:15:33authentication method that you want for
  32983. 21:15:34that server. For us, I think we're just
  32984. 21:15:36going to stick with the, uh, Entra
  32985. 21:15:38admin. We can always change that if we
  32986. 21:15:40want to. So, let's go ahead and we're
  32987. 21:15:42going to select ourselves here. We're
  32988. 21:15:44going to select that. And there we go.
  32989. 21:15:46Let's go ahead and click okay. And that
  32990. 21:15:49should create our server. And there it
  32991. 21:15:52goes. And now we need to finish creating
  32992. 21:15:53our SQL database. So, do you want to use
  32993. 21:15:56a SQL elastic pool? If you look at this
  32994. 21:15:59tool tip right here, basically helps you
  32995. 21:16:00manage your resources, but we're not
  32996. 21:16:02going to be looking at the elastic
  32997. 21:16:04pools. For our workload environment,
  32998. 21:16:05we're just going to choose development.
  32999. 21:16:07Production is going to be a lot faster
  33000. 21:16:09because if it's in a production
  33001. 21:16:10environment, you're going to want better
  33002. 21:16:11speed, better compute, all these
  33003. 21:16:13different things. Development is going
  33004. 21:16:14to be a little bit slower. We can also
  33005. 21:16:17choose a cheaper database or a more
  33006. 21:16:20budget friendly database. So, we don't
  33007. 21:16:22have to uh choose what it gives us. We
  33008. 21:16:24can come in here and we can define this.
  33009. 21:16:26So maybe you want to have a provision
  33010. 21:16:28tier instead of serverless, which I
  33011. 21:16:30don't really recommend. Uh serverless is
  33012. 21:16:33uh quite nice for scalability, but we're
  33013. 21:16:35just going to keep it at is. But if you
  33014. 21:16:36want to come in here and change some of
  33015. 21:16:38this configuration, you're free to do
  33016. 21:16:39that. Uh just don't, you know, if you
  33017. 21:16:42don't know what it is, I wouldn't mess
  33018. 21:16:43with it. Let's come back to the create
  33019. 21:16:45SQL databases. And then we have our
  33020. 21:16:47backup storage redundancy. You can
  33021. 21:16:49either do locally, zone, or geo. We're
  33022. 21:16:51just going to stick with our local.
  33023. 21:16:53Let's go ahead to review and create.
  33024. 21:16:56It's going to tell us our cost, which is
  33025. 21:16:58very, very, very low. Um, if you don't
  33026. 21:17:00even have the free $200 that they're
  33027. 21:17:03giving you, which will be uh which can
  33028. 21:17:05be used for this, it's going to cost you
  33029. 21:17:06like a dollar uh for, you know, what
  33030. 21:17:09we're going to be doing or maybe even
  33031. 21:17:10like 10 cents uh if I'm being honest.
  33032. 21:17:12Let's go ahead and create this. It's
  33033. 21:17:14going to take a little bit of time to
  33034. 21:17:16set up all these servers and all the
  33035. 21:17:17databases and all those things. And then
  33036. 21:17:19once it is done, we'll take a look. All
  33037. 21:17:21right, so our deployment is complete.
  33038. 21:17:23You can come in here and look at some of
  33039. 21:17:25the details. We created SQL databases,
  33040. 21:17:27the server, SQL server, SQL server. And
  33041. 21:17:28so all these things are ready to go.
  33042. 21:17:31Let's go ahead and click on go to
  33043. 21:17:33resource.
  33044. 21:17:35And let's exit out of this. All this
  33045. 21:17:38information is just an overview of our
  33046. 21:17:40SQL database. Now, we have down here
  33047. 21:17:44some of the more important things that
  33048. 21:17:45we're going to be taking a look at.
  33049. 21:17:46We're not going to be diving into all of
  33050. 21:17:48them because uh I'm just going to show
  33051. 21:17:49you the most common way. Now we have
  33052. 21:17:52configure access connect application and
  33053. 21:17:54start developing. Now in the real world
  33054. 21:17:58when people are actually using the SQL
  33055. 21:18:00databases and when they are getting in
  33056. 21:18:02here and setting everything up you can
  33057. 21:18:03do this in a few different ways. One is
  33058. 21:18:06you can connect to a MySQL database and
  33059. 21:18:09this is a very common practice where
  33060. 21:18:11they connect it to a database management
  33061. 21:18:12system. It could be MySQL Workbench or a
  33062. 21:18:15ton of others that are out there. And
  33063. 21:18:16you can do that by configuring it and
  33064. 21:18:18you're going to get some of that
  33065. 21:18:19information. You're going to plug it in
  33066. 21:18:20and connect it. What we're going to be
  33067. 21:18:22looking at is not that option, although
  33068. 21:18:24uh that is something that happens often.
  33069. 21:18:27I'm going to show you Azure's tool for
  33070. 21:18:29this and it's going to be open Azure
  33071. 21:18:31Data Studio. So, we're going to open up
  33072. 21:18:32Azure Data Studio. We're going to click
  33073. 21:18:34on this right here. And you're going to
  33074. 21:18:36need to download the Azure Data Studio.
  33075. 21:18:39Now, I already have this. So, I'm going
  33076. 21:18:40to come down here and go to Azure Data
  33077. 21:18:43Studio. And this should resemble a few
  33078. 21:18:46different things. It should resemble a
  33079. 21:18:48little bit of Visual Studio Code and it
  33080. 21:18:50should resemble something like Microsoft
  33081. 21:18:51SQL Server. It's kind of a combination
  33082. 21:18:53of both. You have a search, you have
  33083. 21:18:55some notebooks that you can use,
  33084. 21:18:57different projects, an explorer, source
  33085. 21:18:59control, extensions. It has a ton of
  33086. 21:19:02stuff. And so, this was really popular
  33087. 21:19:03when I was using Azure. Everybody used
  33088. 21:19:05this. um as well as sometimes we
  33089. 21:19:07connected to MySQL databases or uh
  33090. 21:19:09Microsoft SQL Server databases and just
  33091. 21:19:11use those database management systems
  33092. 21:19:13but oftent times we would have
  33093. 21:19:15everything in Azure data studio. So
  33094. 21:19:18let's come right up here. We are going
  33095. 21:19:19to connect. Now we have to specify our
  33096. 21:19:22server name. Let's go back really
  33097. 21:19:24quickly. We're going to come right over
  33098. 21:19:25here.
  33099. 21:19:27We're going to go back to uh this right
  33100. 21:19:29here. We need to select our server. So
  33101. 21:19:31this is our server. It's ATA server YYT.
  33102. 21:19:34Uh we could even come in here into the
  33103. 21:19:36server and we can just uh copy this if
  33104. 21:19:38we want to. But we're going to get that.
  33105. 21:19:40We have our server. We have our Windows
  33106. 21:19:42authentication type. And so it can
  33107. 21:19:44either be a SQL login, a Windows
  33108. 21:19:46authentication, but we chose the
  33109. 21:19:48Microsoft Entra ID. Now, right here,
  33110. 21:19:50it's recognizing the analyst builder at
  33111. 21:19:52Outlook.com. That was for the course
  33112. 21:19:54that I have on analyst builder for AWS
  33113. 21:19:56and Azure. We need to add in our Alex
  33114. 21:19:58the analyst atlook.com. So let's come in
  33115. 21:20:00here and we need to sign into our
  33116. 21:20:02account. So let's go ahead and sign in.
  33117. 21:20:03And there you go. Your account was added
  33118. 21:20:06successfully. Let's go back. And there
  33119. 21:20:08we go. Now we're signed in. And we need
  33120. 21:20:10to select our database. Now, it's not
  33121. 21:20:12popping up the database right away,
  33122. 21:20:14which should be called like Alex the
  33123. 21:20:16Analyst DB or something like that. Let's
  33124. 21:20:18go ahead and try to connect and see what
  33125. 21:20:20happens. It looks like we're getting an
  33126. 21:20:21error here. I think let's actually come
  33127. 21:20:24back here.
  33128. 21:20:26I think our server name is actually this
  33129. 21:20:28one right here. I just chose the actual
  33130. 21:20:31server, but this is the connection that
  33131. 21:20:33we actually need to make. So, uh I'm
  33132. 21:20:35actually quite certain about that. Let's
  33133. 21:20:36go ahead and click on this. And now it's
  33134. 21:20:39saying our connection was denied since
  33135. 21:20:40deny public network access is set to
  33136. 21:20:43yes. So, this is something I was waiting
  33137. 21:20:46to see because we need to configure this
  33138. 21:20:48just a little bit. So, let's come over
  33139. 21:20:50here and we need to go to configure
  33140. 21:20:52access. So, we're going to select
  33141. 21:20:55configure. And it says public network
  33142. 21:20:57access is disabled, but we can enable
  33143. 21:21:00this. And then what we can do is we can
  33144. 21:21:02add in our IP address. So, we're going
  33145. 21:21:04to add in your client IP v4 address. And
  33146. 21:21:08all we have to do is click save. So, now
  33147. 21:21:10it's going to update. And it's going to
  33148. 21:21:11say, okay, you can access this. Let's
  33149. 21:21:13not, you know, get too crazy and too
  33150. 21:21:15wild here. Now, we can go back and we're
  33151. 21:21:19going to select this. And we already
  33152. 21:21:21have that selected. So now you can see
  33153. 21:21:23that we have our two databases. We have
  33154. 21:21:25the master which is the one that you're
  33155. 21:21:26going to get and then we have the one
  33156. 21:21:27that we actually created. So all of that
  33157. 21:21:30to show that you do have to configure a
  33158. 21:21:32few things. Make sure you're doing it
  33159. 21:21:34properly. And now we can come down here
  33160. 21:21:36and we can connect to it. And so now
  33161. 21:21:39right in here we can come into our
  33162. 21:21:41tables. We don't have any tables but we
  33163. 21:21:43can come into these tables and views and
  33164. 21:21:45uh all of these different things. Now we
  33165. 21:21:47can actually use this. So now we are
  33166. 21:21:48connected to our resource. So, we're
  33167. 21:21:50connected to our server and we can
  33168. 21:21:52actually access the databases, create
  33169. 21:21:54them, do all of our querying, all of our
  33170. 21:21:56uh things that we need to do with our
  33171. 21:21:58data and we have all these options on
  33172. 21:22:00the left hand side. Now, this isn't an
  33173. 21:22:02Azure Data Studio tutorial, uh, but
  33174. 21:22:04there's tons of stuff that you can do in
  33175. 21:22:06here. So, if you've used something Azure
  33176. 21:22:08Data Studio or if you've used Microsoft
  33177. 21:22:10SQL Server, this should seem really
  33178. 21:22:12familiar. You should feel right at home.
  33179. 21:22:14Now, I want you to be able to actually
  33180. 21:22:16use this. I don't just want this to be
  33181. 21:22:18something pretty. So I need to show you
  33182. 21:22:19one other thing that you need to do.
  33183. 21:22:21Let's go ahead and try to create a table
  33184. 21:22:24here. Right down here we have this
  33185. 21:22:25script create new table. We can keep it
  33186. 21:22:28new table just with the one column. Uh
  33187. 21:22:30it doesn't really matter. Let's just say
  33188. 21:22:32this is ready to go. Let's go ahead and
  33189. 21:22:34publish these changes.
  33190. 21:22:37Then we're going to come down here and
  33191. 21:22:38we're going to update our database. Now
  33192. 21:22:41we can come over here and we have a new
  33193. 21:22:43table. So we can actually uh open this
  33194. 21:22:45up. We'll select the top 10,00. And of
  33195. 21:22:48course, we don't have any data in it,
  33196. 21:22:49but uh we have a working table. So now
  33197. 21:22:52this table is being stored on a server
  33198. 21:22:54in a cloud. And this is great. So if
  33199. 21:22:57you've ever used something like
  33200. 21:22:58Microsoft SQL Server, you have all these
  33201. 21:22:59tables and databases and all these
  33202. 21:23:00things you're working with. That's how
  33203. 21:23:01it's actually used in the real world,
  33204. 21:23:03except you'd probably see a ton more
  33205. 21:23:05tables. You'd have access to a bunch of
  33206. 21:23:07different servers for different clients
  33207. 21:23:09and different uh data. So that worked
  33208. 21:23:11perfect. And what you can now do is
  33209. 21:23:13let's do CtrlN. just get a new query
  33210. 21:23:16window available. I'm going to paste in
  33211. 21:23:18here just like this. Um, we're already
  33212. 21:23:20selecting our database. We don't have to
  33213. 21:23:22say use this database go. I'm just, you
  33214. 21:23:25know, that's what I'm used to, so I'm
  33215. 21:23:26going to keep it in there uh for any,
  33216. 21:23:28you know, if you have a put this in a
  33217. 21:23:29store procedure or something like that.
  33218. 21:23:30I don't want it to fail out. But this is
  33219. 21:23:32just a super simple table. Um, and we're
  33220. 21:23:34going to go ahead and run this. Looks
  33221. 21:23:36like that should be done. Let's refresh
  33222. 21:23:39or actually refresh this table. And we
  33223. 21:23:41have this products. Let's open this up.
  33224. 21:23:44And now we have data in here. These are
  33225. 21:23:46little under uh underlined in red.
  33226. 21:23:49Sometimes if you do control ctrlalttr,
  33227. 21:23:52it'll refresh it. Or maybe it's control
  33228. 21:23:54shift r. That's okay. It'll get rid of
  33229. 21:23:56it eventually. It just doesn't recognize
  33230. 21:23:57it uh yet, but it will. Um so anyways,
  33231. 21:24:00we have our data in here and now we can
  33232. 21:24:02write regular queries. And so this isn't
  33233. 21:24:05a SQL lesson. I'm not going to show you
  33234. 21:24:06how to write SQL, but I have hundreds of
  33235. 21:24:08other lessons and courses on how to
  33236. 21:24:10learn SQL. And so this is uh kind of the
  33237. 21:24:13nuts and bolts of how you set everything
  33238. 21:24:15up and this is how people actually use
  33239. 21:24:16it. So this shouldn't be too
  33240. 21:24:18intimidating if you know how to use
  33241. 21:24:19MySQL Workbench or Microsoft SQL Server.
  33242. 21:24:22And so uh that is really awesome. Now if
  33243. 21:24:25we come back here, we're just going to
  33244. 21:24:26take a look at a few more things. This
  33245. 21:24:28is just within our server, but we don't
  33246. 21:24:30want to look um at our server. We want
  33247. 21:24:32to go back to our database within our
  33248. 21:24:36SQL database. right here. We already
  33249. 21:24:38looked at a little bit of configuration
  33250. 21:24:39and Azure data studio. Again, remember
  33251. 21:24:42if you need to uh connect it to my SQL
  33252. 21:24:44or something like that. Now, just within
  33253. 21:24:46the SQL database, there are a few other
  33254. 21:24:48things that you can do. One, they have
  33255. 21:24:50something called a query editor um where
  33256. 21:24:52you can come in here and you can query
  33257. 21:24:54off of let's say you have tables you can
  33258. 21:24:57query off of in here. I can assure you
  33259. 21:24:59that almost nobody ever uses this,
  33260. 21:25:01almost ever. Uh this is not really
  33261. 21:25:03something that people use. It's there to
  33262. 21:25:05kind of test connections sometimes. So
  33263. 21:25:08if you're just setting up a new server
  33264. 21:25:09or a new So if you're just setting up a
  33265. 21:25:12new server or new database or whatever
  33266. 21:25:14it is, you can kind of check to make
  33267. 21:25:15sure it's working. But you won't use
  33268. 21:25:17this in your real work. Uh that it's
  33269. 21:25:19just not doesn't make sense. Now let's
  33270. 21:25:21come over here and take a look at this
  33271. 21:25:23lefth hand side. There are some
  33272. 21:25:24interesting things that I want to show
  33273. 21:25:25you. One is this power platform. When
  33274. 21:25:28you start working with a large amount of
  33275. 21:25:30data, you have a server and a database
  33276. 21:25:32set up and you're using it. You have
  33277. 21:25:33tons of real data in there. you're like,
  33278. 21:25:34"Okay, now it's time to connect this."
  33279. 21:25:36Well, you can use things like PowerBI,
  33280. 21:25:38Power Apps, and Power Automate. All
  33281. 21:25:41these things just kind of automatically
  33282. 21:25:42integrate into it. There's also
  33283. 21:25:44integrations, but just knowing how, you
  33284. 21:25:46know, these are actually used. You most
  33285. 21:25:47likely won't use them, but just knowing
  33286. 21:25:49kind of what these are and how they
  33287. 21:25:50work, you most likely won't use these
  33288. 21:25:52too much. For people like you and I,
  33289. 21:25:54PowerBI is something that we'll probably
  33290. 21:25:55use quite a bit. And we most likely
  33291. 21:25:59won't use monitoring too much, but I
  33292. 21:26:02will say I've had to come into the
  33293. 21:26:03monitoring quite a bit over my years to
  33294. 21:26:05debug a bunch of stuff. So if a store
  33295. 21:26:07procedure is failing, if the database is
  33296. 21:26:09failing and you know you need to figure
  33297. 21:26:11it out, you can come into the logs. If
  33298. 21:26:13you need to see how much compute, how
  33299. 21:26:14many resources you're using, you can
  33300. 21:26:16look at the metrics. So there are some
  33301. 21:26:17reasons to come in here. Typically
  33302. 21:26:19though, this is more IT related. this
  33303. 21:26:22isn't as much of what a data analyst
  33304. 21:26:24will typically do unless you work like I
  33305. 21:26:25said in IT where they monitor a lot of
  33306. 21:26:28those things to keep cost down and keep
  33307. 21:26:29things running and you know going
  33308. 21:26:31smoothly. So, I hope that that was
  33309. 21:26:32helpful. I really appreciate you guys
  33310. 21:26:34watching. If you have not already, be
  33311. 21:26:35sure to check out my full AWS and Azure
  33312. 21:26:37course on analystbuilder.com.
  33313. 21:26:40And if you like this video, be sure to
  33314. 21:26:41like and subscribe below. I will see you
  33315. 21:26:43in the next video.
  33316. 21:26:57What's going on everybody? Welcome back
  33317. 21:26:58to another video. Today we're going to
  33318. 21:26:59be taking a look at Azure Data Factory
  33319. 21:27:01in Azure. [music]
  33320. 21:27:08Azure Data Factory is a super cool tool
  33321. 21:27:10within Azure because it allows you to
  33322. 21:27:12create data pipelines and different
  33323. 21:27:13workflows to extract data and clean
  33324. 21:27:15data, transform it, and put it places.
  33325. 21:27:17And so it does a lot of different
  33326. 21:27:18things. It's one of those skills I
  33327. 21:27:20started using when I started getting a
  33328. 21:27:21little bit more advanced in Azure, but I
  33329. 21:27:24don't think you have to wait till you're
  33330. 21:27:25really advanced as an analyst or a data
  33331. 21:27:27scientist or engineer. I think you
  33332. 21:27:28should start learning it now because
  33333. 21:27:30it's a really really great skill to
  33334. 21:27:31know. So with all that being said, let's
  33335. 21:27:33jump on my screen and take a look. All
  33336. 21:27:34right, so let's get started by coming
  33337. 21:27:36right down here to analytics and under
  33338. 21:27:38here we have data factories. Let's go
  33339. 21:27:40ahead and click on it and let's create a
  33340. 21:27:43data factory. So let's come in here. We
  33341. 21:27:45need to give it a name. choose our
  33342. 21:27:47resource group and we'll be rocking and
  33343. 21:27:49rolling. So, let's call this the Alex
  33344. 21:27:51the analyst and we'll do ADF just like
  33345. 21:27:55that. For the region, we're good. And
  33346. 21:27:57for version, we only have one option.
  33347. 21:27:58So, let's go and review and create this.
  33348. 21:28:02Now, as we know, this is going to be uh
  33349. 21:28:03deploying this. It's going to take just
  33350. 21:28:05a minute and then it'll be done and then
  33351. 21:28:07we'll get going. And there we go. That
  33352. 21:28:08literally took maybe 15 seconds. And so,
  33353. 21:28:11uh just set up the data factory version
  33354. 21:28:14two. And let's go to our resource. And
  33355. 21:28:17there we go. Now, this should look uh,
  33356. 21:28:21you know, fairly straightforward. We
  33357. 21:28:22just have some of this information up
  33358. 21:28:24here. We have our launch studio. And
  33359. 21:28:26then down here, we have some of the
  33360. 21:28:28monitoring. So, when you're actually
  33361. 21:28:29running these automated systems,
  33362. 21:28:31pipelines, everything that we're going
  33363. 21:28:33to be doing, um, you have some data on
  33364. 21:28:35it. And you can see some of the, uh,
  33365. 21:28:37data on that. Now, they do have some
  33366. 21:28:39quick starts, tutorials, template,
  33367. 21:28:41galleries, and training modules. go
  33368. 21:28:42ahead and take those cuz I've looked at
  33369. 21:28:44a lot of these and they're really great.
  33370. 21:28:45Uh, but what we're going to be doing in
  33371. 21:28:48uh this lesson, which we're going to
  33372. 21:28:50cover a lot of stuff, is I'm going to
  33373. 21:28:52help get you set up. I'm going to help
  33374. 21:28:53show you how to do different things. And
  33375. 21:28:55there's going to be a lot of stuff that
  33376. 21:28:56we cover. So, I'm going to be moving
  33377. 21:28:58pretty quick, but let's go ahead and
  33378. 21:29:00launch our studio. And here we go. So,
  33379. 21:29:03this is the Azure data factory. There's
  33380. 21:29:06a bunch of different things that we can
  33381. 21:29:07do in here. We can ingest data. We can
  33382. 21:29:09orchestrate. So create codef free data
  33383. 21:29:11pipelines. And we can transform data.
  33384. 21:29:13Now we're going to be looking at a lot
  33385. 21:29:14of this but not all of it. So stick with
  33386. 21:29:17me. The first thing that we are going to
  33387. 21:29:19do is we're going to work on an
  33388. 21:29:20ingestion because being able to pull
  33389. 21:29:23data in is actually a pretty important
  33390. 21:29:25thing to know how to do. We're just
  33391. 21:29:26going to select run once and we're going
  33392. 21:29:28to select next. Now uh there's a lot of
  33393. 21:29:32different places that you can ingest
  33394. 21:29:33data from where your source data is
  33395. 21:29:36stored but for us we are going to select
  33396. 21:29:39the data that we put in the last lesson.
  33397. 21:29:41So in our last lesson we have put some
  33398. 21:29:43data um in a SQL database which this is
  33399. 21:29:46our server right here ATA server YT and
  33400. 21:29:49we have this table right here. So we're
  33401. 21:29:51going to ingest this data and so what
  33402. 21:29:54we're going to do is we're going to come
  33403. 21:29:55over here. We're going to type in uh
  33404. 21:29:57SQL. Should have Azure SQL database
  33405. 21:30:00should be right there. And we don't have
  33406. 21:30:01a connection yet. So let's just select
  33407. 21:30:03our new connection. This is basically
  33408. 21:30:05like connecting to the Azure data studio
  33409. 21:30:08uh before. And so this should seem
  33410. 21:30:10really really familiar. So we have our
  33411. 21:30:12ATA server YT. We have our Alex the
  33412. 21:30:15analyst DB. And so now we should uh for
  33413. 21:30:18our Azure subscription, we have our
  33414. 21:30:19subscription. And let me go back because
  33415. 21:30:21now it's not remembering. Uh so what we
  33416. 21:30:24need to do now is we need to select our
  33417. 21:30:27uh system assigned manage identity. So
  33418. 21:30:30our manage identity is this one right
  33419. 21:30:31here, Alex the analyst adf. Now that's
  33420. 21:30:34going to be really important in just a
  33421. 21:30:35second because this is by far the most
  33422. 21:30:38confusing and you know frustrating part
  33423. 21:30:40of doing this if you've never done this
  33424. 21:30:42before. So let's just say we want to go
  33425. 21:30:44ahead and create this. It was
  33426. 21:30:46successfully created but we're getting
  33427. 21:30:48this connection failed. And if we look
  33428. 21:30:49at this, it says it cannot connect to it
  33429. 21:30:52because basically it cannot open the
  33430. 21:30:54server requested by the login. Now what
  33431. 21:30:57we need to do is we need to edit this
  33432. 21:30:59and we need to do something quite
  33433. 21:31:00important. We need to take this manage
  33434. 21:31:02identity name and we're going to
  33435. 21:31:04actually update our database and make
  33436. 21:31:07sure that this identity name is in there
  33437. 21:31:08so it recognizes it and can connect to
  33438. 21:31:10it. So let's go ahead and copy this and
  33439. 21:31:13let's come right over here. Let make
  33440. 21:31:14sure I have that. There you go. Let's do
  33441. 21:31:16controlN in our Azure Data Studio. Now,
  33442. 21:31:19this right here is the most important
  33443. 21:31:21thing, but we have to put that in a few
  33444. 21:31:23different places. So, I'm going to write
  33445. 21:31:25out all the code and then I'll explain
  33446. 21:31:26it to you and I'll have it to where you
  33447. 21:31:27can just copy and paste it yourself. You
  33448. 21:31:29don't have to write it all out. All
  33449. 21:31:30right. So, I went ahead and wrote
  33450. 21:31:31everything out. What we're doing is
  33451. 21:31:33we're creating a user and that's going
  33452. 21:31:35to be our user for Azure Data Factory
  33453. 21:31:37that we have right here. So, we're
  33454. 21:31:39adding that and then we're altering the
  33455. 21:31:40role to make them a member so we can get
  33456. 21:31:42access. Now, if we run just this, let's
  33457. 21:31:45go ahead and run this. You'll notice
  33458. 21:31:46that we don't have anything in this
  33459. 21:31:49database principles and this database
  33460. 21:31:50role members. This is our uh CIS
  33461. 21:31:53databases. So, we're just checking there
  33462. 21:31:55isn't uh that account in there. So, what
  33463. 21:31:57we now need to run is this top part. And
  33464. 21:31:59again, I'll have this as a copy and
  33465. 21:32:00paste down below. Let's go ahead and run
  33466. 21:32:02this. And looks like it worked. And now,
  33467. 21:32:04let's check these two queries again. And
  33468. 21:32:07there we are. So now we are in both of
  33469. 21:32:10these uh CIS databases or CIS tables
  33470. 21:32:12that we need to be in. So we should be
  33471. 21:32:14good to go. Let's go ahead and go back
  33472. 21:32:17and we're going to come right in here.
  33473. 21:32:20And now that we have all that connected.
  33474. 21:32:23Let's make sure let's see. Let's make
  33475. 21:32:25sure everything's good in here. Let's go
  33476. 21:32:28ahead and test this connection. And
  33477. 21:32:29there we go. You can see that the
  33478. 21:32:31connection is successful. Now, what we
  33479. 21:32:34can do is cancel out of here because now
  33480. 21:32:36this should be working.
  33481. 21:32:39Now, what we need to do next is select
  33482. 21:32:41what data we actually want in the
  33483. 21:32:42output. Let's go ahead and select our
  33484. 21:32:44products. We'll select next. You can
  33485. 21:32:46preview the data if you want, but we
  33486. 21:32:48don't need to do any of that right now.
  33487. 21:32:50Let's go ahead and select next. Now,
  33488. 21:32:51where are we going to place this data?
  33489. 21:32:53Because we have data sitting over here
  33490. 21:32:55in Azure Data Studio right in here that
  33491. 21:32:59we want. And let's say we want to put it
  33492. 21:33:02in the Azure blob storage. Maybe this is
  33493. 21:33:04a report or some type of query that we
  33494. 21:33:07want to send to a client. Uh, and so
  33495. 21:33:09that's what we're going to do to get it
  33496. 21:33:11into the Azure blob storage. We need to
  33497. 21:33:13select our subscription and our account
  33498. 21:33:16storage name. And we'll go down here to
  33499. 21:33:19create. Next, we have to choose our
  33500. 21:33:21folder path. So, let's pull up our
  33501. 21:33:23storage account. We can duplicate this
  33502. 21:33:26over here. And let's come back and let's
  33503. 21:33:29see if we can get it right here. Here's
  33504. 21:33:31our storage account. Let's go to Alex
  33505. 21:33:33the Analyst storage. Let's go to our
  33506. 21:33:35storage browser. We're going to go to
  33507. 21:33:38our blob containers. Now, we should have
  33508. 21:33:40uh one blob container in here. Here we
  33509. 21:33:43go. Ata container. So, we can come back
  33510. 21:33:45here. We're just going to select browse.
  33511. 21:33:46I did all that just to show you where
  33512. 21:33:48the data was coming from. Uh but that's
  33513. 21:33:49in our uh storage account over here. Or
  33514. 21:33:53is it called account storage? Storage
  33515. 21:33:55accounts. If we just uh come in here and
  33516. 21:33:59we say, "Okay, we want a file." That
  33517. 21:34:00doesn't really work cuz we're putting
  33518. 21:34:02data into something. So, we can't put it
  33519. 21:34:04into a different file. We need to select
  33520. 21:34:06a folder that we're going to place it
  33521. 21:34:08into. So, we're going to select the ATA
  33522. 21:34:10container. We're going to select okay.
  33523. 21:34:11For our file name, we'll call this one
  33524. 21:34:13SQL database output. And that should be
  33525. 21:34:17good. Let's go ahead and select next.
  33526. 21:34:20Now, these are the file format settings.
  33527. 21:34:22We need to specify how we actually want
  33528. 21:34:24this data to sit once we move it into
  33529. 21:34:26the blob storage. Now, this is a
  33530. 21:34:28delimited text. You can choose JSON
  33531. 21:34:30files or C files, paret files, whichever
  33532. 21:34:33files you want. So, we're going to do a
  33533. 21:34:34comma delimited file, which is should be
  33534. 21:34:36a CSV. We shouldn't need to add any
  33535. 21:34:38compression onto it. Uh, because this
  33536. 21:34:40isn't a massive amount of data or
  33537. 21:34:42multiple files at all. So, we should be
  33538. 21:34:44able to go ahead and select next. Next,
  33539. 21:34:46we need to specify our task name. Now
  33540. 21:34:49we're going to call this one uh SQL to
  33541. 21:34:53blob
  33542. 21:34:55and we should be good to select next.
  33543. 21:34:57And this is the whole process. So we
  33544. 21:34:59have Azure SQL database going to Azure
  33545. 21:35:02blob storage. Let's go all the way down.
  33546. 21:35:05We'll select next. And this is uh
  33547. 21:35:07creating this. It says our whole
  33548. 21:35:09deployment is complete. It validated the
  33549. 21:35:11copy runtime environment, created the
  33550. 21:35:13data sets, created the pipelines, and
  33551. 21:35:15ran the pipelines. Go ahead and select
  33552. 21:35:17finish. If we come over here to our
  33553. 21:35:19storage, you can see that right here we
  33554. 21:35:21have our SQL database output and uh
  33555. 21:35:25let's see if we can just click into it
  33556. 21:35:27real quick. Let's go ahead and download
  33557. 21:35:28this just to see what it looks like. I'm
  33558. 21:35:30just going to put this in downloads.
  33559. 21:35:32We'll go ahead and save that. If we open
  33560. 21:35:34up this file, uh just ignore those
  33561. 21:35:36pictures of me and my wife on the
  33562. 21:35:37Segway. Um if we open up this file, we
  33563. 21:35:41can open it up as a let's just open up
  33564. 21:35:43in Notepad. And you can see here's our
  33565. 21:35:46data. Now, this isn't in a CSV format.
  33566. 21:35:48Um, and that's okay because it's really
  33567. 21:35:50easy to change it. But it is CSV uh
  33568. 21:35:52separated. So, it was a text file. It
  33569. 21:35:54meant to be I kind of want it to be a
  33570. 21:35:56CSV, but we can very easily uh change
  33571. 21:35:59that if we do CSV here. And now we've
  33572. 21:36:02changed it into a CSV. Let's open it up.
  33573. 21:36:04And there we go. So, uh you can
  33574. 21:36:07definitely change that and we may
  33575. 21:36:09actually look at that at some point in
  33576. 21:36:10this lesson. But very easy to change
  33577. 21:36:12that to a CSV file because it is comma
  33578. 21:36:14separated. Um, so all this looks great.
  33579. 21:36:16This looks really, really good. I don't
  33580. 21:36:18need to save this. Let's go ahead and go
  33581. 21:36:20back. Now, let's go back to Azure Data
  33582. 21:36:22Factory. One thing I want to point out
  33583. 21:36:24really quickly, uh, before we get into
  33584. 21:36:26some other things is, uh, for our recent
  33585. 21:36:29resources, we have our SQL to blob. You
  33586. 21:36:31can find that right over here in this
  33587. 21:36:34author. So, when we go over to author,
  33588. 21:36:37you can find our pipelines and we have
  33589. 21:36:39some data sets as well for our
  33590. 21:36:40destination and our source data set. But
  33591. 21:36:43that's regardless of what we're looking
  33592. 21:36:44at in our pipelines. We built our SQL to
  33593. 21:36:47blob. So if we come over here, this is
  33594. 21:36:49what it's doing. And we can click on
  33595. 21:36:51this and we can see uh kind of what it's
  33596. 21:36:53doing. Down here we have our source
  33597. 21:36:56data. That's where the data is coming
  33598. 21:36:57from. That's our table. You can also
  33599. 21:37:00have it write a query. So you can change
  33600. 21:37:01this to a write a query from that table
  33601. 21:37:04if you want to do some advanced stuff.
  33602. 21:37:06Uh um you know, this data is super
  33603. 21:37:07simple. But if we wanted to just select
  33604. 21:37:09units in stock where it's greater than
  33605. 21:37:11100, right? you can just write the query
  33606. 21:37:13in here, copy it and put it right in
  33607. 21:37:16here and then you can have a query
  33608. 21:37:17instead of pulling over the whole table.
  33609. 21:37:19And so that's actually uh really really
  33610. 21:37:21useful. And so that is all really
  33611. 21:37:23interesting stuff. Now within what we're
  33612. 21:37:25looking at right here, we'll take a look
  33613. 21:37:27at that in just a second. Um but what
  33614. 21:37:29we're going to do is we're going to come
  33615. 21:37:31over here to transform data. Let's go
  33616. 21:37:33ahead and select this. You can see right
  33617. 21:37:35up here we have our SQL to blob. That's
  33618. 21:37:38our pipeline. And we have a bunch of
  33619. 21:37:39stuff. And then we have our data flow
  33620. 21:37:41right down here. Now what our data flow
  33621. 21:37:44is is we're able to take different data
  33622. 21:37:46sources, different things, transform it,
  33623. 21:37:48join it, uh do aggregations, do anything
  33624. 21:37:50we want to it, and then spit it out
  33625. 21:37:51wherever we want. If we want to pull all
  33626. 21:37:53these different files and put into a SQL
  33627. 21:37:55database, we can do that. If we want to
  33628. 21:37:57take a bunch of different data and we
  33629. 21:37:59want to put it into a file, put into
  33630. 21:38:01blob storage, we can do that. Or if you
  33631. 21:38:04want to take multiple tables from a SQL
  33632. 21:38:06database and then put it into a file, we
  33633. 21:38:09can do that. And so it's kind of
  33634. 21:38:11limitless what you can do within here.
  33635. 21:38:13You just have to kind of know how it
  33636. 21:38:14works and and kind of piece everything
  33637. 21:38:16together. So let's start building this
  33638. 21:38:19transformation. Let's come in here and
  33639. 21:38:21we're going to add a data source. Now
  33640. 21:38:24within our data source, we can come down
  33641. 21:38:25here and we need to select a data set.
  33642. 21:38:27Now these are two data sets that we've
  33643. 21:38:29already used. uh these were in the ones
  33644. 21:38:32that we did when we created the SQL to
  33645. 21:38:34blob. Let's say we want to create a new
  33646. 21:38:36data source. If we select a new data
  33647. 21:38:38source, you'll notice all the different
  33648. 21:38:40options for this, right? We have a ton a
  33649. 21:38:42ton a ton of different places and
  33650. 21:38:44applications that we can pull in. Um if
  33651. 21:38:46you just want to scroll down, there's a
  33652. 21:38:48lot. And so there's a lot of different
  33653. 21:38:50things. Now, we're on a free tier, so um
  33654. 21:38:52we may not be able to use some of these,
  33655. 21:38:54but you know, if your company's paying
  33656. 21:38:56for it, you should be able to do it. So
  33657. 21:38:58let's just say we're going to take it
  33658. 21:38:59from Azure blob storage. We're going to
  33659. 21:39:02come right here. Ours is uh a delimited
  33660. 21:39:05text. Let's go to our link service and
  33661. 21:39:08go to our storage. And we need to select
  33662. 21:39:11our data. So let's go to ATA container.
  33663. 21:39:13Let's take this CSV file. CSV. So we
  33664. 21:39:18just came in here. We're just selecting
  33665. 21:39:20our data source. And you'll see we
  33666. 21:39:21select it from our blob storage. And
  33667. 21:39:23there's the path to it. Let's go ahead
  33668. 21:39:25and select okay. And there we go. Now,
  33669. 21:39:28one thing we will want to do as we're
  33670. 21:39:30going throughout this process is to turn
  33671. 21:39:31on data preview. So, we have to turn on
  33672. 21:39:34the debug mode. Debug mode is right up
  33673. 21:39:36here. So, data flow debug. And you can
  33674. 21:39:38let it live for a certain amount of
  33675. 21:39:40time. This does cost money. It's very
  33676. 21:39:42cheap, but uh it's well worth it because
  33677. 21:39:44as you're doing all these different
  33678. 21:39:46things, you're going to want to preview
  33679. 21:39:48the data and see what data looks like as
  33680. 21:39:50a final result before you push it
  33681. 21:39:51somewhere, before you put it into a
  33682. 21:39:53database or a file. So, we're just going
  33683. 21:39:55to wait for just a second while that um
  33684. 21:39:57while that debug session starts and then
  33685. 21:39:59we'll have our data preview available.
  33686. 21:40:01Now, this is taking forever and I don't
  33687. 21:40:03want to wait around forever to keep
  33688. 21:40:04going. Uh it should work at some point
  33689. 21:40:07and maybe we'll see it throughout the
  33690. 21:40:09process, but uh we're just going to keep
  33691. 21:40:11going because if yours is taking as long
  33692. 21:40:13as mine, we don't need to wait on it
  33693. 21:40:14because it's not vital. You don't have
  33694. 21:40:16to have it. Um so, let's come down here.
  33695. 21:40:19What we can do is we can add another
  33696. 21:40:22source if we want to. You don't have to,
  33697. 21:40:25but if you have multiple sources, you
  33698. 21:40:26can add that. Uh so if you wanted to add
  33699. 21:40:28a source down here, you just add uh
  33700. 21:40:30another source. We aren't going to be
  33701. 21:40:32doing that. So we can just delete that.
  33702. 21:40:34Let's click this little button right
  33703. 21:40:36here cuz there we're get a little
  33704. 21:40:38different options than we have been uh
  33705. 21:40:40before. We have a bunch of things that
  33706. 21:40:43we can do to this data. So let's just
  33707. 21:40:46scroll down really quickly. You should
  33708. 21:40:48notice and you should be able to see a
  33709. 21:40:50ton of these and one of the most
  33710. 21:40:52important is actually this destination
  33711. 21:40:54sync destination at the end and we'll
  33712. 21:40:55take a look at in a bit. But we have all
  33713. 21:40:57of these options to actually change and
  33714. 21:41:00transform our data. And so if we want to
  33715. 21:41:02clean the data, if we want to filter the
  33716. 21:41:04data, if we want to aggregate the data,
  33717. 21:41:06uh if we want to pivot the data, there's
  33718. 21:41:07so many different things that you can do
  33719. 21:41:09to it. Now, really quick, uh while we're
  33720. 21:41:11here, I'm just going to show you the
  33721. 21:41:12actual data that we're working with. If
  33722. 21:41:14we open up this file, we have this CSV
  33723. 21:41:16file. Let's go ahead and open it.
  33724. 21:41:19And this is the data that is actually in
  33725. 21:41:22that file that we upload. And there's a
  33726. 21:41:24lot. There's about 32,000
  33727. 21:41:26rows of data. We have things like state
  33728. 21:41:29name, county, city, place, type, etc.
  33729. 21:41:32And so there's a ton of data in here.
  33730. 21:41:34Let's say we just want to filter this
  33731. 21:41:36data. So let's go back. Let's go ahead
  33732. 21:41:38to don't save. I just wanted to show you
  33733. 21:41:39what it looked like. Let's go ahead and
  33734. 21:41:41let's say we want to filter our data. So
  33735. 21:41:43we're going to come down here. We're
  33736. 21:41:44going to go to a row modifier which is
  33737. 21:41:46filter. And so what we need to do is
  33738. 21:41:48come down here and I highly recommend
  33739. 21:41:50opening up the expression builder
  33740. 21:41:52because what we can do is we can say we
  33741. 21:41:54want to filter on one of these columns.
  33742. 21:41:56Now over here in the dataf flow
  33743. 21:41:58expression builder we have our
  33744. 21:41:59expression up here and we have all of
  33745. 21:42:01our elements. So we have things like
  33746. 21:42:03functions, input schemas, parameters,
  33747. 21:42:06cache lookups, dataf flow libraries. 99%
  33748. 21:42:09of the time you're going to be using
  33749. 21:42:11functions and your input schema. So our
  33750. 21:42:13input schema is our table and the
  33751. 21:42:15functions are all the functions that we
  33752. 21:42:17have in here. So we can do one there's
  33753. 21:42:20one called equals.
  33754. 21:42:22Let's do this one right here. So we can
  33755. 21:42:24do equals. You have your expression. You
  33756. 21:42:25can even say over here here's some
  33757. 21:42:27examples that you can do. But what we're
  33758. 21:42:29going to do is we're going to go over
  33759. 21:42:31here the input schema and we'll get rid
  33760. 21:42:34of this. We have something called a
  33761. 21:42:36state name. So if we come up here,
  33762. 21:42:38select in there, select state name. So
  33763. 21:42:40if we do state name and then in here
  33764. 21:42:42let's do Alabama. So what we're saying
  33765. 21:42:45is is we're going to filter where the
  33766. 21:42:47state name is equal to Alabama. That's
  33767. 21:42:50what we're going to do. So we're going
  33768. 21:42:51to save and finish this and that should
  33769. 21:42:54be good to go. Let's see if we have a
  33770. 21:42:55data preview. This hasn't been working
  33771. 21:42:57for me at all. I hope it's working for
  33772. 21:42:58you. It's just taking it abnormally long
  33773. 21:43:01time. Maybe because they're not
  33774. 21:43:02prioritizing uh me as a small account,
  33775. 21:43:05which is understandable, but um you
  33776. 21:43:08know, thanks Azure. So now we have this
  33777. 21:43:10source. We've filtered our data. And now
  33778. 21:43:13and you can do so many different things
  33779. 21:43:15in here. We're just not this isn't a
  33780. 21:43:17full um you know lesson on how to use
  33781. 21:43:20this. Now we need something called a
  33782. 21:43:22sync. Now what the sync is is how you
  33783. 21:43:24can actually save and publish it because
  33784. 21:43:26you can't publish it without a sync. The
  33785. 21:43:28sync is how you can specify where you're
  33786. 21:43:30placing this data. So what we're going
  33787. 21:43:33to do is we can place this anywhere we
  33788. 21:43:35want. We can place this as a new file.
  33789. 21:43:37We can put this in our SQL uh database.
  33790. 21:43:39Now, if we come in here, we're going to
  33791. 21:43:40have several different options here, but
  33792. 21:43:43let's go ahead and select a new one and
  33793. 21:43:47and let's say we want to put it back in
  33794. 21:43:49the blob storage. So, we're cleaning the
  33795. 21:43:51data up and we're going to save it as a
  33796. 21:43:53delimited text file. Let's go ahead and
  33797. 21:43:55select continue. So, now we want to put
  33798. 21:43:58it in our blob storage. Again, we need
  33799. 21:44:00to select our container. Container is
  33800. 21:44:02going to be ATA container. You could set
  33801. 21:44:04up another container if you want. Now, I
  33802. 21:44:07don't think we want to select a file
  33803. 21:44:09name because uh we're choosing the file
  33804. 21:44:11path where we're going to place it. So,
  33805. 21:44:12I think we just need to select okay
  33806. 21:44:14here. Now, there's one last thing that
  33807. 21:44:15we want to do before we actually publish
  33808. 21:44:18all of this. Let's go to settings. And
  33809. 21:44:21we have some options in here, which is a
  33810. 21:44:23file name option. Now, when you're doing
  33811. 21:44:27files in here, you in fact, you should
  33812. 21:44:29probably publish this and just try it
  33813. 21:44:30and see what happens. But often times
  33814. 21:44:32you're going to want this as a single
  33815. 21:44:34file, but it doesn't always happen when
  33816. 21:44:36you're using Azure. Sometimes it'll make
  33817. 21:44:38it 2, three, four, five, six files
  33818. 21:44:40depending on what you're doing. So I
  33819. 21:44:41like to output this as a single file.
  33820. 21:44:44And then we get to output as a single
  33821. 21:44:46file. And we can select the name. So we
  33822. 21:44:47can just put this as we'll do filtered
  33823. 21:44:50data. Uh, and that's it. I'm actually
  33824. 21:44:53not sure if I need to do CSV right here.
  33825. 21:44:56Let's just try it as CSV. Let's go ahead
  33826. 21:44:57and try to publish this. It looks like
  33827. 21:44:59it says the file name option output to
  33828. 21:45:00single file requires single partition be
  33829. 21:45:03selected in the partition type. So if we
  33830. 21:45:05come over here I think it's in optimize
  33831. 21:45:07for the partition option. You can use
  33832. 21:45:09current partitioning but we need to
  33833. 21:45:11select single partitioning. It now says
  33834. 21:45:13it is fixed. We can close that and let's
  33835. 21:45:16go ahead and publish all. So what we are
  33836. 21:45:19going to do is we're going to review
  33837. 21:45:20this. We have our different data sets.
  33838. 21:45:22Um and then we have our data flow. So
  33839. 21:45:25our data flow we're going to go ahead
  33840. 21:45:26and publish. These are all changes that
  33841. 21:45:28we've made uh throughout this process.
  33842. 21:45:31It's going to deploy those and then it's
  33843. 21:45:32going to uh run this data flow one and
  33844. 21:45:35then we should see a new data set uh
  33845. 21:45:37which is filtered based off of our
  33846. 21:45:39source data. We should see that in our
  33847. 21:45:42storage account. We should be able to
  33848. 21:45:44come right up here and it looks like uh
  33849. 21:45:47all those things are completed. Now I
  33850. 21:45:49forgot we're actually not going to see
  33851. 21:45:51this uh because it didn't actually run.
  33852. 21:45:53It just saved as a data flow. We need to
  33853. 21:45:55come up here and we need to create a new
  33854. 21:45:57pipeline. So let's come up here, create
  33855. 21:45:59a new pipeline. And what we're going to
  33856. 21:46:02do is we're going to go down to our data
  33857. 21:46:04flow. We're just going to drag this
  33858. 21:46:06over. So this is our data flow. And we
  33859. 21:46:08can name this anything we want. We can
  33860. 21:46:10say uh transform.
  33861. 21:46:13I need to spell that right. Uh transform
  33862. 21:46:17data. Let's just call it this. And then
  33863. 21:46:19we need to add a trigger. So we're going
  33864. 21:46:22to go ahead and say trigger now. And
  33865. 21:46:23that should run that data flow that we
  33866. 21:46:25created. So let's go ahead and trigger
  33867. 21:46:27now. And actually we need to publish it
  33868. 21:46:30first. So let's go ahead and publish
  33869. 21:46:31all. We'll publish this. And that
  33870. 21:46:35publishing is completed. And now we can
  33871. 21:46:37trigger it. So now we're going to say
  33872. 21:46:39okay. And it's going to start running.
  33873. 21:46:41And so this is one of the things just to
  33874. 21:46:43kind of understand about building data
  33875. 21:46:44flows and pipelines is that the pipeline
  33876. 21:46:47you can do a lot of different things in
  33877. 21:46:49it, but you're mostly chaining together
  33878. 21:46:51different data flows. When you actually
  33879. 21:46:52get in the data flow, you're chaining
  33880. 21:46:54together all the different combinations
  33881. 21:46:56that you want to do with different data
  33882. 21:46:58sets and transformations and data
  33883. 21:46:59cleaning and all these different things
  33884. 21:47:01and then you put it into a pipeline. And
  33885. 21:47:04that pipeline when it runs, which I
  33886. 21:47:06think it's still running, when it runs,
  33887. 21:47:08it runs that data flow that you created.
  33888. 21:47:11And so these data flows can get really
  33889. 21:47:13complex and you can chain multiple data
  33890. 21:47:14flows together. You can say once this
  33891. 21:47:16data flow is done running, then do this.
  33892. 21:47:18Once this data flow is done running, do
  33893. 21:47:20this next data flow. And so there's a
  33894. 21:47:22lot of different things that you can
  33895. 21:47:23chain together. And it's pretty awesome.
  33896. 21:47:26So we're just going to wait on this for
  33897. 21:47:27just a second. And when it is complete,
  33898. 21:47:30we'll take a look at the output. And
  33899. 21:47:32there you can see that it succeeded.
  33900. 21:47:35Let's come over here and take a look.
  33901. 21:47:37Let's go ahead and refresh this. Let's
  33902. 21:47:39go to our blob container.
  33903. 21:47:41And there we go. We have our filtered
  33904. 21:47:43data.csv.
  33905. 21:47:45So you can go ahead and check that out.
  33906. 21:47:46Uh so those two things are working
  33907. 21:47:49great. Let's go back home really quick.
  33908. 21:47:52So we've worked on ingestion, we worked
  33909. 21:47:54on data transformation, and lastly we
  33910. 21:47:56have this orchestrate. And let's just
  33911. 21:47:58come in here really quickly and take a
  33912. 21:48:00look at how this looks. So as I was
  33913. 21:48:02telling you before, we have these uh
  33914. 21:48:04different pipelines that we've created.
  33915. 21:48:06We've created a few extras that don't do
  33916. 21:48:07anything. Um but what we can do is
  33917. 21:48:10within this we can orchestrate this by
  33918. 21:48:12taking multiple different pipelines,
  33919. 21:48:14multiple workflows, multiple data sets
  33920. 21:48:17and orchestrating all of it into an
  33921. 21:48:20actual full pipeline. Now with that, and
  33922. 21:48:22we're not actually going to be uh doing
  33923. 21:48:23that right now, but with that, you can
  33924. 21:48:25see that we have a ton of options right
  33925. 21:48:28here. And in fact, you can take data
  33926. 21:48:30from a ton of different places. You can
  33927. 21:48:32copy data, you can do a Spark job
  33928. 21:48:34function or even an Azure function. And
  33929. 21:48:36you can customize so many different
  33930. 21:48:38things and take data from so many
  33931. 21:48:39different places and you can use so many
  33932. 21:48:41resources within Azure to do just about
  33933. 21:48:44anything you want. And so uh and I don't
  33934. 21:48:46say that you know as in like you can
  33935. 21:48:48actually do anything but just look at
  33936. 21:48:50all these options. There are so many
  33937. 21:48:51things uh that you can do. And so I've
  33938. 21:48:55just given you a brief kind of
  33939. 21:48:56introduction to ingesting data uh and
  33940. 21:48:59transforming data. And then to build
  33941. 21:49:01these out you just kind of combine those
  33942. 21:49:03things together. So you say okay I want
  33943. 21:49:05this uh pipeline right here and then if
  33944. 21:49:08that works then we want to you know
  33945. 21:49:10transfer it over here and actually we
  33946. 21:49:12need to do something like this on
  33947. 21:49:14success and so you can say if this works
  33948. 21:49:16then on the success of that we'll do
  33949. 21:49:19this and then just for an example we can
  33950. 21:49:21say um we'll add this down here and
  33951. 21:49:23we'll say if it fails we'll do this one
  33952. 21:49:26and so this is just a demonstration of
  33953. 21:49:28how this looks. This isn't actually what
  33954. 21:49:30you should do by any means. Um, but you
  33955. 21:49:33can give it some different instructions.
  33956. 21:49:35You can say if this successfully works,
  33957. 21:49:37if this pipeline works, then go do this
  33958. 21:49:39piece. And then if this works, go do
  33959. 21:49:41this piece. Oftent times you're going to
  33960. 21:49:43chain these together. And this is the
  33961. 21:49:44full orchestration of Azure Data Factory
  33962. 21:49:46that we're not looking at in this
  33963. 21:49:48lesson, but you can imagine uh you're
  33964. 21:49:50taking data from a client. So the client
  33965. 21:49:52drops data into a specific location. You
  33966. 21:49:54ingest that data. So you have a data
  33967. 21:49:56ingestion data flow. Once that data gets
  33968. 21:49:59in, then maybe you have one for
  33969. 21:50:01transforming your data. So if the data
  33970. 21:50:03adjusts properly, then you're going to
  33971. 21:50:04come up here and you're going to
  33972. 21:50:06transform the data. Then you'll have
  33973. 21:50:08another one afterwards. You'll be over
  33974. 21:50:09here and you'll say once it's
  33975. 21:50:10transformed and then we're going to send
  33976. 21:50:12an email to me who is the person who
  33977. 21:50:14owns that and saying, "Hey, this
  33978. 21:50:16ingestion process worked or this data
  33979. 21:50:18pipeline worked." And so you can get
  33980. 21:50:19really advanced. You can also keep it
  33981. 21:50:21really simple. And in my time as a data
  33982. 21:50:23analyst, I worked with a ton of data
  33983. 21:50:24engineers and data scientists and
  33984. 21:50:27database developers who use this all the
  33985. 21:50:29time. So I get in there and I get to
  33986. 21:50:31mess around with it quite a bit. And
  33987. 21:50:32oftent times it was mostly keeping it
  33988. 21:50:34kind of simple. You're ingesting data,
  33989. 21:50:36you're transforming the data, and you're
  33990. 21:50:37placing it in somewhere. There were some
  33991. 21:50:39use cases where we did a lot more
  33992. 21:50:40advanced stuff, but this is the meat and
  33993. 21:50:42potatoes of it. So play around with
  33994. 21:50:43this, mess around with it, try to get
  33995. 21:50:45these different things to work, try to
  33996. 21:50:47create a full endto-end project. I think
  33997. 21:50:49that'd be really cool. And maybe I'll do
  33998. 21:50:51that in a future video. So that is in
  33999. 21:50:54general what ADF kind of is. That's the
  34000. 21:50:57meat and potatoes of Azure Data Factory.
  34001. 21:50:59And I hope you're able to follow along
  34002. 21:51:00and really understand that so you can
  34003. 21:51:02start building on top of that and trying
  34004. 21:51:04out your own stuff. If you found that
  34005. 21:51:06helpful, be sure to check out my full
  34006. 21:51:07Azure and AWS course on
  34007. 21:51:09analystbuilder.com.
  34008. 21:51:11And if you haven't already, be sure to
  34009. 21:51:12like and subscribe below. And I will see
  34010. 21:51:14you in the next video. [music]
  34011. 21:51:27What's going on everybody? Welcome back
  34012. 21:51:28to another video. Today we're going to
  34013. 21:51:30be taking a look at Azure Synapse
  34014. 21:51:31Analytics in Azure.
  34015. 21:51:36[music]
  34016. 21:51:38Now Azure Synapse Analytics is meant to
  34017. 21:51:40be this all-in-one place to go for all
  34018. 21:51:42your data analyst needs. It's going to
  34019. 21:51:44have ETL. It's going to have workflows.
  34020. 21:51:45It's going to be able to query data. So,
  34021. 21:51:47it has a lot going for it. So, we're
  34022. 21:51:49going to be taking a look at that and
  34023. 21:51:51I'll talk a little bit about the
  34024. 21:51:52comparisons between Azure Synapse
  34025. 21:51:54Analytics and a few of the other
  34026. 21:51:55resources and tools within Azure. So,
  34027. 21:51:57with all that being said, let's jump on
  34028. 21:51:58my screen and take a look. All right, so
  34029. 21:52:00let's go down to our analytics tab.
  34030. 21:52:02Let's go over to Azure Synapse Analytics
  34031. 21:52:06and let's create a Synapse workspace. As
  34032. 21:52:08you know, we need to select our
  34033. 21:52:10subscription and our resource group and
  34034. 21:52:12we need to name this. So we'll call this
  34035. 21:52:14Alex the analyst and this is called uh
  34036. 21:52:17oh wait I need to make them all
  34037. 21:52:19lowercase. So we'll do Alex the analyst
  34038. 21:52:22ASA Azure Synapse Analytics. That should
  34039. 21:52:25be good. Now the next thing that we need
  34040. 21:52:27to do is select a data lakeink storage
  34041. 21:52:29gen 2 when we are using Azure Synapse
  34042. 21:52:32Analytics. We are using a data lakeink.
  34043. 21:52:34So we need to create an account name for
  34044. 21:52:36this. So we'll do Alex the analyst ASA.
  34045. 21:52:40That should work. Then we need a file
  34046. 21:52:43system. Now we don't have one. So we're
  34047. 21:52:45going to create the Alex the analyst FS
  34048. 21:52:48and let's select okay. Now it says right
  34049. 21:52:51here assign myself the storage blob data
  34050. 21:52:53contributor role for the data lakeink
  34051. 21:52:55storage gen 2 account to interactively
  34052. 21:52:57query it in the workspace. So we're
  34053. 21:52:59making oursel the person who is the main
  34054. 21:53:01contributor so we can actually use this
  34055. 21:53:03data lakeink gen 2 that we're using.
  34056. 21:53:05Let's go ahead to review and create. It
  34057. 21:53:08is going to cost us cuz we're using a
  34058. 21:53:09serverless SQL per terabyte. It's going
  34059. 21:53:11to cost about 5 USD for that and that's
  34060. 21:53:14not a big uh cost for us. So, we're
  34061. 21:53:16going to go ahead and create that and
  34062. 21:53:17that should be covered under your 200.
  34063. 21:53:19If you had the free $200 uh credit, that
  34064. 21:53:22should be covered under that as well.
  34065. 21:53:23All right, so that was deployed uh
  34066. 21:53:26successfully. If you look in here, we
  34067. 21:53:27did a few different things or it did a
  34068. 21:53:29few different things. One, it created a
  34069. 21:53:30new storage account for us and that's
  34070. 21:53:32going to be our data lake. Next, it
  34071. 21:53:34created our Synapse workspace. So, we
  34072. 21:53:36have the new storage account and we have
  34073. 21:53:37a new workspace. So let's go to this
  34074. 21:53:39resource group here and let's actually
  34075. 21:53:41come into our Synapse workspace and you
  34076. 21:53:44can see a lot of our information up here
  34077. 21:53:46but then the most important part which
  34078. 21:53:48is open Synapse Studio. So let's go
  34079. 21:53:50ahead and open this up. Then we need to
  34080. 21:53:52go ahead and sign in here. Now let's
  34081. 21:53:54just take a look at some of the things
  34082. 21:53:56that's in here because this should seem
  34083. 21:53:59pretty reminiscent of Azure Data
  34084. 21:54:02Factory. And I say that because in our
  34085. 21:54:04last lesson we looked at Azure Data
  34086. 21:54:06Factory and we had a lot of these
  34087. 21:54:07different things. We had things where we
  34088. 21:54:08can ingest data. We could transform data
  34089. 21:54:11and then we can place it somewhere. And
  34090. 21:54:12believe it or not, you're able to do
  34091. 21:54:14that within Azure Synapse Analytics as
  34092. 21:54:16well. Not only that, within Azure
  34093. 21:54:18Synapse Analytics, we're going to be
  34094. 21:54:20able to explore our data and analyze it
  34095. 21:54:23as well. You can come in here and see
  34096. 21:54:24how all that works, but this is going to
  34097. 21:54:26act very much like an Azure Data Studio.
  34098. 21:54:29If you remember from our SQL databases
  34099. 21:54:31video, we looked at Azure Data Studio
  34100. 21:54:33and how that works and how you can
  34101. 21:54:35actually access the data. And we'll be
  34102. 21:54:37coming back to uh some of these things
  34103. 21:54:39in a little bit. So, we're going to keep
  34104. 21:54:41this up. Let's come over here and let's
  34105. 21:54:43take a look at our data. Right now, we
  34106. 21:54:45have no data in here. So, let's come in
  34107. 21:54:48here. Now, if we connect to a SQL
  34108. 21:54:49database, we're actually creating a SQL
  34109. 21:54:51database or a lake database, but we
  34110. 21:54:53don't need that. We're going to connect
  34111. 21:54:54to external data. In here, we can
  34112. 21:54:56connect to our Azure blob storage. So,
  34113. 21:54:58we're going to go ahead and say
  34114. 21:55:00continue, and we're just going to bring
  34115. 21:55:02in some of our data that we've been
  34116. 21:55:04working with. So, we're going to go to
  34117. 21:55:05the Alex analyst storage. This is where
  34118. 21:55:08we have some uh data in here and we need
  34119. 21:55:10to select our subscription right there.
  34120. 21:55:13There we go. We'll go ahead and create
  34121. 21:55:15that. So, now if we come over here in
  34122. 21:55:17our workspace, if we go over here to
  34123. 21:55:19linked, we have our uh blob storage.
  34124. 21:55:22Then we have our data link. Now within
  34125. 21:55:24our data lakeink uh we don't have any uh
  34126. 21:55:27data but if we come up here to the blob
  34127. 21:55:29storage and so as you can see here we
  34128. 21:55:32have all of our data that we have in
  34129. 21:55:34that blob storage. If we wanted to
  34130. 21:55:36access one of those we can do something
  34131. 21:55:38like select new script. We do a new
  34132. 21:55:41notebook where we can load to a data
  34133. 21:55:42frame or a spark table. We can create a
  34134. 21:55:45data flow. We can take that as a source.
  34135. 21:55:47We can transform the data and we can
  34136. 21:55:48load the data to somewhere else. So
  34137. 21:55:50there's a lot of things that we can do
  34138. 21:55:52with this data. One other thing I want
  34139. 21:55:54to show you just with the data section
  34140. 21:55:56is we have these browse galleries. And
  34141. 21:55:59within here, there's a ton of real and
  34142. 21:56:02really unique data that we can uh use
  34143. 21:56:05and we can look at. For example, let's
  34144. 21:56:06come over here to New York City uh
  34145. 21:56:08safety data. Let's go ahead and click
  34146. 21:56:10continue. There's a bunch of data in
  34147. 21:56:12here. We're going to add this data set.
  34148. 21:56:14It's going to take just a second, but it
  34149. 21:56:16looks like it was created in this sample
  34150. 21:56:18data sets uh in Azure blob storage. If
  34151. 21:56:21we come over here, we can click on city
  34152. 21:56:23safety New York. Let's go ahead and
  34153. 21:56:25right click on it, select top 100 rows,
  34154. 21:56:28and we'll go ahead and run this. As you
  34155. 21:56:30can see down below, we're just looking
  34156. 21:56:31at, you know, data. So, this is how we
  34157. 21:56:34can run it with SQL. And with this, we
  34158. 21:56:37can do just about anything we want,
  34159. 21:56:38right? If we wanted to do some type of
  34160. 21:56:40group by or joins or anything we want to
  34161. 21:56:43do, you can do it. Uh, this is going to
  34162. 21:56:45be by default SQL Server. Um, so you can
  34163. 21:56:48do a lot of things uh that you want to
  34164. 21:56:50do in there, but let's just say we
  34165. 21:56:51wanted to group by category
  34166. 21:56:55um and subcategory.
  34167. 21:56:58And then up here, we'll select the top.
  34168. 21:57:01We'll just do all of it, but we'll do
  34169. 21:57:03select category and subcategory.
  34170. 21:57:07And then we'll just do let's do a count
  34171. 21:57:10of the subcategory.
  34172. 21:57:13We're just going to get a count of it.
  34173. 21:57:14Let's go ahead and run this. And let's
  34174. 21:57:17take a look. Okay, it looks like our
  34175. 21:57:20output is correct. Uh I was getting
  34176. 21:57:21worried at first when I saw the nulls at
  34177. 21:57:23the beginning, but we could probably uh
  34178. 21:57:25clean this up a little bit, but we don't
  34179. 21:57:27need to. Okay, we're just taking a look
  34180. 21:57:29at what Azure Synapse Analytics can do.
  34181. 21:57:31So this is where we can query data. We
  34182. 21:57:34can also save this. We can publish this.
  34183. 21:57:36And now that's been saved. So if I came
  34184. 21:57:38over here to the develop, you can see we
  34185. 21:57:40have SQL script one. Now we just got to
  34186. 21:57:42change the name of this if we want to
  34187. 21:57:44change it to something else. We can come
  34188. 21:57:45over here. We can say rename. We can sol
  34189. 21:57:48say this is the uh was this New York
  34190. 21:57:50City. We'll say group by uh category.
  34191. 21:57:54We'll just select okay. And there we go.
  34192. 21:57:56So now we've saved that script. And so
  34193. 21:57:57that's really important. That's really
  34194. 21:57:59really useful. One other thing that we
  34195. 21:58:01can do down here is we can also look at
  34196. 21:58:04this as a chart. Now, this data in and
  34197. 21:58:06of itself isn't very helpful as a line
  34198. 21:58:08chart, but if we did a bar chart for the
  34199. 21:58:11category column was the category and
  34200. 21:58:13maybe we just want to select the top 10.
  34201. 21:58:18We'll order by let's do the count of
  34202. 21:58:22subcategory.
  34203. 21:58:24Let's try running this again and we can
  34204. 21:58:25go look at the table really quickly. And
  34205. 21:58:29I need to do this descending. Whoops.
  34206. 21:58:31All right, let's run this again. All
  34207. 21:58:33right. So, there's the day that we want.
  34208. 21:58:35Let's go back to this chart. Uh, again,
  34209. 21:58:38this isn't a good visualization. We
  34210. 21:58:40would do something like a bar chart. Uh,
  34211. 21:58:42we would have the category here, and
  34212. 21:58:44that'll be fine. But you can customize
  34213. 21:58:46this a little bit more if you'd like to.
  34214. 21:58:48Um, but we're able to look at little
  34215. 21:58:50visualizations in our output when we're
  34216. 21:58:52working with the SQL scripts. If we want
  34217. 21:58:54to, we can save that as an image. And
  34218. 21:58:56that would be great. Again, we can
  34219. 21:58:58publish this and we can save this and we
  34220. 21:59:01are good to go. Now the next thing that
  34221. 21:59:04we can do, let's go back to our data.
  34222. 21:59:06Next thing we can do is we can also
  34223. 21:59:09create a notebook. So let's load this
  34224. 21:59:11into a data frame. And you're going to
  34225. 21:59:13notice this looks a little bit
  34226. 21:59:14different. Now before we can actually
  34227. 21:59:16run this, we have to create or attach a
  34228. 21:59:19spark pool. We don't have one. So we're
  34229. 21:59:21going to go create one uh really
  34230. 21:59:22quickly. And we'll just call this uh ATA
  34231. 21:59:26pool. There we go. We're going to go
  34232. 21:59:28back down to review and create. going to
  34233. 21:59:32create this.
  34234. 21:59:34That was successfully deployed. So, our
  34235. 21:59:36uh pool is ready to go. So, let's go
  34236. 21:59:38back here. We're going to go to our ATA
  34237. 21:59:41pool and we're going to choose spice
  34238. 21:59:43spark. That's the one I've almost always
  34239. 21:59:45used. You can also use SQL in here. Now
  34240. 21:59:48um SQL in uh Azure Synapse Analytics or
  34241. 21:59:51in other tools maybe like data bricks
  34242. 21:59:53and other things like that they don't
  34243. 21:59:55always have a SQL option but now it's
  34244. 21:59:56being added a lot more but I used to
  34245. 21:59:59have to use Scola and Pispark and all
  34246. 22:00:01sorts of things but now if you know SQL
  34247. 22:00:02you can do that in here too. Um so
  34248. 22:00:04you're good to go. We're going to this
  34249. 22:00:05is Pispark though. So we're going to go
  34250. 22:00:07ahead and run this. And right here we're
  34251. 22:00:09running into an issue. Your Spark job
  34252. 22:00:10requested 24 vores. However, the
  34253. 22:00:11workspace has a 12 core limit and that's
  34254. 22:00:14because we need to message Azure support
  34255. 22:00:16and request more. Um, and unfortunately
  34256. 22:00:19for this video, we're not going to do
  34257. 22:00:21that. So, let's get a smaller data set.
  34258. 22:00:23So, we're going to come back here to our
  34259. 22:00:25storage and let's add a new file.
  34260. 22:00:30It's going to be this products file
  34261. 22:00:32right here. Let's go ahead and upload
  34262. 22:00:34this. And there we go. Now, we can go
  34263. 22:00:37back here. We're take a look within our
  34264. 22:00:40container. And we have this
  34265. 22:00:42products.csv. So let's right click on
  34266. 22:00:44this. Let's go to new notebook. You can
  34267. 22:00:46load to dataf frame or spark table.
  34268. 22:00:48Whichever one we're going to load this
  34269. 22:00:50to a spark table. Let's choose our pool.
  34270. 22:00:54And we're using Python. So now let's go
  34271. 22:00:56ahead and try to run this. Now this
  34272. 22:00:57didn't work. It says either the cores of
  34273. 22:00:59the memory of the driver executes
  34274. 22:01:00exceeded the spark pool node size. So
  34275. 22:01:03for this what we're going to do is we're
  34276. 22:01:04going to come back here. We're going to
  34277. 22:01:06edit this. We're going to make it just
  34278. 22:01:07the smallest one possible because we're
  34279. 22:01:10just exceeding uh what we are working
  34280. 22:01:13with right here. So now that's updated.
  34281. 22:01:15Let's go back.
  34282. 22:01:17Let's come right here. All right. And we
  34283. 22:01:20got our output. Took a while, but that's
  34284. 22:01:22cuz we're using a really small pool over
  34285. 22:01:25here. Now, if you use a larger pool,
  34286. 22:01:28it'll go a lot faster. Uh so if you
  34287. 22:01:31select a ton more nodes and uh you get a
  34288. 22:01:34larger node size just in general, it's
  34289. 22:01:36going to go a lot faster. And so right
  34290. 22:01:38now, oops, let's get out of here. Right
  34291. 22:01:41now, uh before when we tried it with
  34292. 22:01:44this one, it wasn't working because our
  34293. 22:01:46node sizes were just too large for what
  34294. 22:01:49they're allowing us to have. We have to
  34295. 22:01:50again ask them to increase that. But
  34296. 22:01:52again, that's mostly for really large
  34297. 22:01:55data sets. For this one, we have a
  34298. 22:01:57really tiny data set. and we get our
  34299. 22:01:59data right down here. And so everything
  34300. 22:02:02is working properly. But what we can do,
  34301. 22:02:04which is really neat because this is a
  34302. 22:02:06notebook, is we can come down here, we
  34303. 22:02:08can write more code. So if you use
  34304. 22:02:09something like a Jupyter notebook or
  34305. 22:02:10there's tons of other notebooks out
  34306. 22:02:12there that are really great. Um, if you
  34307. 22:02:13use a notebook, you know, you have some
  34308. 22:02:15code up here. You can put code down
  34309. 22:02:17here. You can also put markdown. And so
  34310. 22:02:19you can add in, you know, any title that
  34311. 22:02:21you want to uh add in here. You can say
  34312. 22:02:24this is a title. I'll go ahead and run
  34313. 22:02:27this. And another really cool thing
  34314. 22:02:29about using a notebook, especially
  34315. 22:02:31within here, is that you don't just have
  34316. 22:02:33to use Python. If you uh for some reason
  34317. 22:02:36you say, okay, I want to use SQL, you
  34318. 22:02:38can do that using this magic command,
  34319. 22:02:40and you can says SQL and then you can
  34320. 22:02:43just write SQL like normal. So you can
  34321. 22:02:45select everything. We'll come right down
  34322. 22:02:47here. We'll say from and right now it's
  34323. 22:02:49called dataf frame. But I don't know if
  34324. 22:02:52that's actually going to work. Let's go
  34325. 22:02:53ahead and run this. And that's not going
  34326. 22:02:55to work because it's not uh in a table.
  34327. 22:02:58So we can do dataf frame dot and we can
  34328. 22:03:00say create and there's this option for
  34329. 22:03:03create or replace temp view and then we
  34330. 22:03:06can name it whatever we want. So we can
  34331. 22:03:08say this dataf frame to table. So we'll
  34332. 22:03:10call this uh that right there. Let's go
  34333. 22:03:12ahead and run this and then we'll come
  34334. 22:03:14down here and replace that right here.
  34335. 22:03:17Now we can run this and we just created
  34336. 22:03:20it into a temporary view. And now we can
  34337. 22:03:22run this just like we're running SQL.
  34338. 22:03:24And so there's lots of options that you
  34339. 22:03:26can do with this. Um I have a hundred
  34340. 22:03:29tutorials on using Jupyter notebooks and
  34341. 22:03:31how to use uh Python. It's very similar
  34342. 22:03:33within this. And so it's really neat to
  34343. 22:03:36be able to combine the two uh languages.
  34344. 22:03:38I guess if you want to call SQL a
  34345. 22:03:40programming language, it's technically
  34346. 22:03:42not. Um but we have Pispark, so we can
  34347. 22:03:44use Python and we have this as well. And
  34348. 22:03:47so lots of options, lots of really good
  34349. 22:03:50stuff in here. And so that's a big part
  34350. 22:03:51of working with data within Azure
  34351. 22:03:54Synapse Analytics. Now if we come down
  34352. 22:03:57here to integrate, we can create now
  34353. 22:03:59pipelines, link connections and copy
  34354. 22:04:02data tool. Not using them, but we can
  34355. 22:04:04use these things. And this is very very
  34356. 22:04:07similar to Azure data factory. There are
  34357. 22:04:09also some really good uh options in here
  34358. 22:04:12if you want to kind of copy these. Let's
  34359. 22:04:15say right over here it says bulk copy
  34360. 22:04:16from files to database. If you want to
  34361. 22:04:18do that, you can come in here, click
  34362. 22:04:22continue, and then you can use this. So
  34363. 22:04:24you can open this pipeline. You can say
  34364. 22:04:26this is what I'm looking for. And you
  34365. 22:04:28select your link service and your other
  34366. 22:04:30link service. You open the pipeline, it
  34367. 22:04:32creates that pipeline for you. So just
  34368. 22:04:35something to be aware of. I think that's
  34369. 22:04:37really awesome. And in fact, I've used
  34370. 22:04:39these uh many times. Let's go ahead and
  34371. 22:04:41click back. So there's tons and tons of
  34372. 22:04:44just sample things where if you are
  34373. 22:04:46doing one of these, let's say you want
  34374. 22:04:47to create a system that deletes files
  34375. 22:04:49older than 30 days. There you go. And so
  34376. 22:04:51there's tons of things in here that you
  34377. 22:04:53can use. Um as well as there's different
  34378. 22:04:55SQL scripts you can use, different
  34379. 22:04:57notebooks, different data sets. These
  34380. 22:04:59are all free things that you can use
  34381. 22:05:01within Azure Synapse Analytics. But
  34382. 22:05:04let's get out of here. Let's go ahead
  34383. 22:05:06and close this out. So let's say we do
  34384. 22:05:08actually want to use something in
  34385. 22:05:09integrate. Let's uh use this copy data
  34386. 22:05:12tool. And this should look extremely
  34387. 22:05:15extremely familiar if you use the Azure
  34388. 22:05:18data factory uh if you took that lesson.
  34389. 22:05:21Now, we're just going to copy it from
  34390. 22:05:22blob storage.
  34391. 22:05:24We'll go to next. We'll go to browse and
  34392. 22:05:28we'll just select a file.
  34393. 22:05:31So, we're going to come in here. We have
  34394. 22:05:32our products uh data. So, we're going to
  34395. 22:05:35take that products data. We're going to
  34396. 22:05:37select next. and it wants to know what
  34397. 22:05:39our file format is. Right now, we have
  34398. 22:05:40it kind of as a CSV and we don't need
  34399. 22:05:43any compression. So, we're going to go
  34400. 22:05:44ahead and keep it as is. And we need to
  34401. 22:05:46select our destination. Now, we can put
  34402. 22:05:48this in almost any place we want. In
  34403. 22:05:51fact, Azure uh SQL database would be a
  34404. 22:05:53perfectly good spot for it. We're just
  34405. 22:05:55demonstrating how to move one thing to
  34406. 22:05:58another. So, I'm going to select Azure
  34407. 22:05:59blob storage. We're just going to place
  34408. 22:06:01it in the exact same one, exact same
  34409. 22:06:03container. We're going to make some uh
  34410. 22:06:05weird copy of this. Let's go ahead and
  34411. 22:06:07click okay. And we need to select the
  34412. 22:06:10file name. Now the file name is going to
  34413. 22:06:12be products_copied.
  34414. 22:06:14It's all we're going to do. CSV. Uh so
  34415. 22:06:18now we'll select next. We'll select
  34416. 22:06:20next. And our task name is going to be
  34417. 22:06:22copy data. We'll do underscore. So copy
  34418. 22:06:25data. And we'll select next. And we're
  34419. 22:06:27going to select next. Now I'm not going
  34420. 22:06:30to deep dive into the transformation and
  34421. 22:06:32the pipelines and all those things
  34422. 22:06:33because that's what we did in Azure data
  34423. 22:06:35factory and in Azure Synapse Analytics.
  34424. 22:06:38It's very very similar. Now you can see
  34425. 22:06:40here we have this pipeline built. We can
  34426. 22:06:42come right over here and this pipeline
  34427. 22:06:44is ready to go. All we have to do is we
  34428. 22:06:47have to publish it and then add a
  34429. 22:06:49trigger. So let's go ahead and publish
  34430. 22:06:51all. We're going to go ahead and publish
  34431. 22:06:55this. Now that we've published it, we
  34432. 22:06:56can add this trigger. We're going to say
  34433. 22:06:58trigger now. We're going to click okay.
  34434. 22:07:01So, as we looked at in Azure Data
  34435. 22:07:03Factory, once we publish it, it saves
  34436. 22:07:05it. We can add this trigger. We can run
  34437. 22:07:07it to trigger it now to actually
  34438. 22:07:09activate that process. And now, it's
  34439. 22:07:11going to copy that data over. Now, that
  34440. 22:07:13should take a little bit of time, but we
  34441. 22:07:15can view that pipeline running. And it
  34442. 22:07:17looks like it just succeeded. We can go
  34443. 22:07:20back to our storage account. We're going
  34444. 22:07:22to refresh our storage uh really
  34445. 22:07:26quickly. go back to our blob containers
  34446. 22:07:29and there you can see we have
  34447. 22:07:30products_copied.csv.
  34448. 22:07:33So even within Azure Synapse Analytics
  34449. 22:07:36we can create these workflows and these
  34450. 22:07:38pipelines. So let's go back over here
  34451. 22:07:41back to the integrate. So this integrate
  34452. 22:07:44allows us to do just about almost
  34453. 22:07:46everything that we were doing within
  34454. 22:07:48Azure data factory. It is a little bit
  34455. 22:07:50more limiting but we copied some data.
  34456. 22:07:53That's what we worked with. And there's
  34457. 22:07:54a bunch of other things in here as well.
  34458. 22:07:56You can create full data pipelines
  34459. 22:07:58within Azure Synapse Analytics just like
  34460. 22:08:01you can Azure Data Factory. But within
  34461. 22:08:04Azure Synapse Analytics, we can also use
  34462. 22:08:06the data. So we can take a look at the
  34463. 22:08:08data and we can uh run queries on it and
  34464. 22:08:11we can create different notebooks as
  34465. 22:08:13well. And this is really awesome stuff
  34466. 22:08:15that we're able to do. So Azure Synapse
  34467. 22:08:17Analytics is really meant for a more
  34468. 22:08:19mature data team. They're using large
  34469. 22:08:22amounts of data. Again, this sits on top
  34470. 22:08:24of a data lake. So you're creating all
  34471. 22:08:26these pipelines, you're working with all
  34472. 22:08:27these different data sets and you're
  34473. 22:08:29querying the data, you're using the
  34474. 22:08:30data, you're transforming the data.
  34475. 22:08:32That's what this is really really for.
  34476. 22:08:34And so if we come back over here to the
  34477. 22:08:36home, you can see that we ingested some
  34478. 22:08:39data. We explored and analyzed some
  34479. 22:08:41data. We also have visualized data. Now,
  34480. 22:08:44if we click in here, we can connect to
  34481. 22:08:46PowerBI. We don't have an actual
  34482. 22:08:48workspace for PowerBI set up, so we
  34483. 22:08:51can't do that. But this is meant to be
  34484. 22:08:53something that you're supposed to do.
  34485. 22:08:55You're supposed to be able to ingest it,
  34486. 22:08:56explore it, and then visualize it all in
  34487. 22:08:59one place. So, it makes the work for
  34488. 22:09:01data analysts or even data scientists
  34489. 22:09:03quite easy. If you have kind of a
  34490. 22:09:05smaller team or depending on your team,
  34491. 22:09:07what data and tools you use, you may be
  34492. 22:09:09able to do most of your work within
  34493. 22:09:11Azure Synapse Analytics. Again, just
  34494. 22:09:13depending on uh, you know, how
  34495. 22:09:15everything's configured. But if you have
  34496. 22:09:16a lot more complex systems, a lot larger
  34497. 22:09:19data sets coming from a lot of different
  34498. 22:09:21data sources, you may need to go branch
  34499. 22:09:24out and use some of these other tools
  34500. 22:09:25like SQL databases. Azure data factory
  34501. 22:09:27as standalone tools, but sometimes
  34502. 22:09:30you're able to get it all within Azure
  34503. 22:09:32Synapse Analytics, all your ingestion,
  34504. 22:09:34your data analysis, and your data
  34505. 22:09:36visualization all in one place. And so
  34506. 22:09:38it's a really powerful tool, and this is
  34507. 22:09:40one that I used for quite a while. And
  34508. 22:09:42so, uh, just coming in here, this is
  34509. 22:09:45really bringing me back to one of my
  34510. 22:09:46previous data analyst jobs where we were
  34511. 22:09:48in here all the time. Now, one thing to
  34512. 22:09:50note, and I didn't really mention this,
  34513. 22:09:52is that this is actually a workspace.
  34514. 22:09:54And so, uh, we have this workspace that
  34515. 22:09:57you can then share and you can
  34516. 22:09:59collaborate with people on. And so, if
  34517. 22:10:01you're over here in a notebook and
  34518. 22:10:02you're trying to run it, it's not
  34519. 22:10:04working or, you know, whatever it is.
  34520. 22:10:06Um, we can run these run this one real
  34521. 22:10:08quick. It'll take a second. Um, we can
  34522. 22:10:10run these and you can collaborate with
  34523. 22:10:13other people and they can see your code.
  34524. 22:10:14So then you can, you know, publish this
  34525. 22:10:16and you can save this and all these
  34526. 22:10:18different things and other people can
  34527. 22:10:20view this. And so it's kind of more of a
  34528. 22:10:21collaborative environment as well, which
  34529. 22:10:24is really nice. So get in here, mess
  34530. 22:10:26around with it a little bit. This is
  34531. 22:10:28kind of just a little crash course on
  34532. 22:10:30how to get up and running and some of
  34533. 22:10:31the features of Azure Synapse Analytics.
  34534. 22:10:35And this is a really great tool to know
  34535. 22:10:36how to use. And I hope that that was
  34536. 22:10:38helpful. I hope you got kind of a good
  34537. 22:10:40overview of how Azure Synapse actually
  34538. 22:10:42works. If you have not already, be sure
  34539. 22:10:44to check out my full course on Azure and
  34540. 22:10:46AWS on analybuilder.com. Be sure to like
  34541. 22:10:48and subscribe below and I will see you
  34542. 22:10:50in the next video.
  34543. 22:10:53[music]
  34544. 22:11:04What's going on everybody? Welcome back
  34545. 22:11:05to another video. Today we're going to
  34546. 22:11:06be starting our AWS series.
  34547. 22:11:14Now AWS to me always seemed really
  34548. 22:11:16complicated compared to Azure because I
  34549. 22:11:18started with Azure and I knew it really
  34550. 22:11:20well. And so when I started using AWS,
  34551. 22:11:23it just seemed like a whole another
  34552. 22:11:24world. So if you've already gone through
  34553. 22:11:25my Azure series, that's really good
  34554. 22:11:27because I'm going to reference it quite
  34555. 22:11:28a bit to make some comparisons, but we
  34556. 22:11:30still will be focusing mainly on the AWS
  34557. 22:11:33portion of it. In this series, we'll be
  34558. 22:11:34getting everything set up. We're looking
  34559. 22:11:36at S3 buckets, Amazon Athena, Glue, Glue
  34560. 22:11:39Data Brew, and Quicksite. And so that's
  34561. 22:11:41a lot of different tools within AWS. And
  34562. 22:11:43these are ones that I think are really,
  34563. 22:11:44really important to know how to use. In
  34564. 22:11:46this video, we're going to be creating
  34565. 22:11:47an account and doing a walkthrough of
  34566. 22:11:48the user interface. So without further
  34567. 22:11:50ado, let's jump on my screen and get
  34568. 22:11:52started. All right, so what we're going
  34569. 22:11:53to be doing is creating an AWS account,
  34570. 22:11:55looking at the UI within AWS, just
  34571. 22:11:57getting familiar with it before we jump
  34572. 22:11:59into some of the tools within AWS. Now,
  34573. 22:12:02here I'll have this link down in the
  34574. 22:12:04description. we are going to get started
  34575. 22:12:06for free. So let's come right here and
  34576. 22:12:08what we want is the AWS free tier. With
  34577. 22:12:11the free tier, we get a lot of things
  34578. 22:12:13within AWS completely for free. Of
  34579. 22:12:15course, there are some things that are
  34580. 22:12:16not underneath the umbrella of the free
  34581. 22:12:18tier and so we won't be using those, but
  34582. 22:12:21we will be able to do everything in this
  34583. 22:12:22series with just the free account. So
  34584. 22:12:25let's go ahead and create our free
  34585. 22:12:27account.
  34586. 22:12:28We need to sign up for AWS. Let's go
  34587. 22:12:31ahead and verify this email address. So,
  34588. 22:12:33I'm going to use my Alex
  34589. 22:12:34theanalystytgmail.com
  34590. 22:12:38and my account name is going to be Alex
  34591. 22:12:41thean analyst. We'll do AWS. I got the
  34592. 22:12:45code. I'm going put it in here and
  34593. 22:12:47verify this. Now, we need to select our
  34594. 22:12:49password. So, I'm going to put my
  34595. 22:12:50password in right here.
  34596. 22:12:54There we go. Let's go ahead and click
  34597. 22:12:56continue. Now, within this free tier, we
  34598. 22:12:58get a few different things. one uh the
  34599. 22:13:01free services that were within AWS,
  34600. 22:13:03they're never going to expire. You'll
  34601. 22:13:04get them free always, which is really
  34602. 22:13:06great. Um we also get 12 months free for
  34603. 22:13:09certain services, and we'll look at that
  34604. 22:13:10in just a little bit. And these things
  34605. 22:13:12activate from when our trial actually
  34606. 22:13:14starts. So, let's go ahead and fill out
  34607. 22:13:17all this information, and then we will
  34608. 22:13:20continue. Now, if we do use any
  34609. 22:13:22services, we have to have billing on
  34610. 22:13:24hand in case we use something that is
  34611. 22:13:26not free or we go above the free tier.
  34612. 22:13:29And so you have to input some type of
  34613. 22:13:30credit or debit card number just in case
  34614. 22:13:32you do that. Within what we're doing, we
  34615. 22:13:34shouldn't be doing that or if we do,
  34616. 22:13:35it'll cost like 10 cents. And so it
  34617. 22:13:37should be super super cheap. So go ahead
  34618. 22:13:39and fill in your information here. Next,
  34619. 22:13:41we need to confirm our identity. I'm
  34620. 22:13:43going to have it send me a text message
  34621. 22:13:45so that I can uh fill this out. So go
  34622. 22:13:48ahead and do that as well. All right,
  34623. 22:13:50we're going to go ahead and select
  34624. 22:13:51continue. And now we need to sign up for
  34625. 22:13:53a support plan. Now, we're using a free
  34626. 22:13:55account, so we don't really need
  34627. 22:13:57support. Now, if you are just you're
  34628. 22:13:59feeling wild, uh, and you want to get
  34629. 22:14:01something like developer support, you
  34630. 22:14:02can. If you're encountering issues, um,
  34631. 22:14:05or if you're using AWS for business,
  34632. 22:14:07maybe you want business support. Uh, you
  34633. 22:14:09know what? Go for it. I'm not going to
  34634. 22:14:10stop you. But we're going to be using,
  34635. 22:14:12uh, the free support because, uh, I
  34636. 22:14:14don't want to pay for it. So, let's go
  34637. 22:14:16ahead and complete our sign up. And just
  34638. 22:14:18like that, we have created our AWS
  34639. 22:14:21account. Let's go to the AWS management
  34640. 22:14:23console. Now, we are actually going to
  34641. 22:14:25sign in with our account. Now, we are a
  34642. 22:14:27root user. So, we're going to come in
  34643. 22:14:29here. We're going to put in our email
  34644. 22:14:30address and sign in. All right, we are
  34645. 22:14:32all signed in. Let's go ahead and click
  34646. 22:14:35next. Done and done and done and get rid
  34647. 22:14:38of all this stuff. Now, this is our
  34648. 22:14:39console home. You'll notice that it's
  34649. 22:14:42very, very blank. We don't have anything
  34650. 22:14:43that we've recently visited. We don't
  34651. 22:14:45have any applications running. We don't
  34652. 22:14:47have any cost uh going either. And so
  34653. 22:14:50once we actually start using some of
  34654. 22:14:52these services when we get into glue and
  34655. 22:14:54start automating things you know you
  34656. 22:14:56might have a cost but it should be under
  34657. 22:14:57the free tier but you will have a cost
  34658. 22:15:00when we start using databases and
  34659. 22:15:02instances and all these different
  34660. 22:15:03things. These things are compute and
  34661. 22:15:06resources that AWS offers. So we'll be
  34662. 22:15:08able to see and monitor a lot of those
  34663. 22:15:10things within this home console right
  34664. 22:15:13here. You can also customize this
  34665. 22:15:15console home if you want to. So, if you
  34666. 22:15:17want to come in here and add widgets,
  34667. 22:15:18you can add different metrics or
  34668. 22:15:20different things that you want in here,
  34669. 22:15:22but we're not going to be doing that in
  34670. 22:15:23this lesson. So, let's take a look at
  34671. 22:15:25this UI really quick. On this lefth hand
  34672. 22:15:27side, we have services. If we come here,
  34673. 22:15:30this is all the services that AWS
  34674. 22:15:32offers. And I'm just going to kind of
  34675. 22:15:34slowly scroll down. We have compute,
  34676. 22:15:36containers, storage, databases, machine
  34677. 22:15:39learning. Let's keep going down a little
  34678. 22:15:41bit. We have analytics. For this series,
  34679. 22:15:44we're going to be focusing on things in
  34680. 22:15:45this analytics tab. So, right in here,
  34681. 22:15:48we're also going to be looking at some
  34682. 22:15:50stuff in the databases and then of
  34683. 22:15:53course S3 for S3 buckets. And this is
  34684. 22:15:56where you can access all the resources
  34685. 22:15:58and all the services within AWS. Another
  34686. 22:16:01thing to note is this right up here,
  34687. 22:16:03which is our region. Now, I'm in US
  34688. 22:16:06East, but make sure you have the
  34689. 22:16:08appropriate one that you're using. the
  34690. 22:16:10region actually is uh pretty important
  34691. 22:16:13if you choose one that's really far
  34692. 22:16:14away. You're going to have some latency
  34693. 22:16:16and some delays on retrieving data or
  34694. 22:16:18using different services. And so make
  34695. 22:16:20sure this is the correct one for you.
  34696. 22:16:23Lastly, if we come over here, you can
  34697. 22:16:25notice in your account we have account
  34698. 22:16:26organization service quotas, billing and
  34699. 22:16:28cost management and security
  34700. 22:16:30credentials. The two that I think are
  34701. 22:16:32really important is account and billing
  34702. 22:16:34and cost management. If we go over to
  34703. 22:16:36billing, this is an actual service uh
  34704. 22:16:39within AWS. You can look at all of your
  34705. 22:16:42costs. And so, as you start using these
  34706. 22:16:44different services, you're going to want
  34707. 22:16:46to come in here and make sure you're
  34708. 22:16:47not, you know, spending too much money.
  34709. 22:16:49Just as an example, we use AWS for
  34710. 22:16:51Analyst Builder. And so, in here, we
  34711. 22:16:53track all of our costs, all of our
  34712. 22:16:55bills, everything associated with AWS
  34713. 22:16:58for our platform. And so in here we
  34714. 22:17:00track a lot of stuff and we have
  34715. 22:17:01different metrics and different flags
  34716. 22:17:03that we uh have in case we go over a
  34717. 22:17:05certain amount or if something isn't
  34718. 22:17:07working. And so we monitor uh you can
  34719. 22:17:09create monitoring stuff. You can monitor
  34720. 22:17:11a lot of stuff in this billing and cost
  34721. 22:17:13management home uh which also was really
  34722. 22:17:15important when I was a manager and we
  34723. 22:17:17were using AWS. And then lastly, of
  34724. 22:17:19course, we have our account within here.
  34725. 22:17:21There's a ton of stuff like bills,
  34726. 22:17:23payments, you know, if you want to
  34727. 22:17:24change your credit card and all these
  34728. 22:17:26different things. This is a really good
  34729. 22:17:27place to come and just be familiar with.
  34730. 22:17:29So, let's just go back to the services
  34731. 22:17:30real quick while we close out and we'll
  34732. 22:17:33go to all services and view all
  34733. 22:17:35services. So, this is what we're going
  34734. 22:17:37to be focusing on in the next several
  34735. 22:17:38lessons. We're going to be looking at
  34736. 22:17:40things like S3 storage. Let's come down
  34737. 22:17:43here. I think we're going to be looking
  34738. 22:17:44at Athena, AWS Glue, Data Brew, AWS
  34739. 22:17:47Glue, and a few others as well. So,
  34740. 22:17:49we're going to be in here. We're going
  34741. 22:17:50to be learning a ton of stuff about AWS.
  34742. 22:17:53And hopefully by the end of the series,
  34743. 22:17:54you'll be really familiar with AWS, feel
  34744. 22:17:56really confident putting it on your
  34745. 22:17:58resume and actually knowing how to use
  34746. 22:18:00it. So, I hope that this was helpful
  34747. 22:18:01getting everything set up. If you have
  34748. 22:18:03not already, be sure to check out my
  34749. 22:18:04full AWS and Azure course on
  34750. 22:18:06analystbuilder.com.
  34751. 22:18:08And if you like this video, be sure to
  34752. 22:18:09like and subscribe. I will see you in
  34753. 22:18:11the next video. [music]
  34754. 22:18:17>> [music]
  34755. 22:18:24>> What's going on everybody? Welcome back
  34756. 22:18:26to another video. Today we're going to
  34757. 22:18:27be taking a look at S3 buckets in AWS.
  34758. 22:18:35Now S3 buckets are super flexible ways
  34759. 22:18:38of storing your data within AWS and they
  34760. 22:18:40kind of connect to all the other data
  34761. 22:18:42aspects of AWS as well. So, if you have
  34762. 22:18:44data sitting in an S3 bucket, you can
  34763. 22:18:46connect it to a SQL database, you can
  34764. 22:18:47connect it to a data visualization tool
  34765. 22:18:49or an ETL tool or a ton of other things.
  34766. 22:18:52So, we're going to be diving into how to
  34767. 22:18:53set up your S3 bucket, how you can
  34768. 22:18:54actually use it. We're going to upload
  34769. 22:18:56some data and we'll talk about little
  34770. 22:18:57tips and little nuances of using S3
  34771. 22:18:59buckets that I've learned over the
  34772. 22:19:00years. So, with that being said, let's
  34773. 22:19:01jump onto my screen and take a look. All
  34774. 22:19:03right, so let's get started by coming
  34775. 22:19:04into our services. We're going to go
  34776. 22:19:06down to storage and we're going to click
  34777. 22:19:07on S3. Now, you'll notice we have S3
  34778. 22:19:10Glacier over here. And I'll briefly
  34779. 22:19:13mention this uh a little bit in this
  34780. 22:19:16video because it is worth noting. But
  34781. 22:19:18let's come over here to S3. So this is
  34782. 22:19:21kind of the homepage for Amazon S3.
  34783. 22:19:24We'll take a look at a few things in
  34784. 22:19:26here really quickly. They do have this
  34785. 22:19:28little video here which if you're just
  34786. 22:19:30using S3, you should look at. Now you
  34787. 22:19:32may be wondering what does S3 stand for?
  34788. 22:19:34It stands for simple storage service.
  34789. 22:19:37It's meant to be a really simple way to
  34790. 22:19:38store just about anything in the cloud.
  34791. 22:19:40You can store essentially any type of
  34792. 22:19:42file whether it's structured,
  34793. 22:19:43semi-structured, unstructured, it could
  34794. 22:19:45be almost anything. And so let's take a
  34795. 22:19:47look at some of the things in here. It
  34796. 22:19:48says store and retrieve any amount of
  34797. 22:19:50data from anywhere. Amazon S3 is an
  34798. 22:19:52object storage service that offers
  34799. 22:19:54industryleading scalability, data
  34800. 22:19:56availability, security, and performance.
  34801. 22:19:59Let's come down here and take a look at
  34802. 22:20:00some of the benefits and features. You
  34803. 22:20:02can read through all of these things,
  34804. 22:20:04and they're all really good. I'll read
  34805. 22:20:05through this one in a little bit, but it
  34806. 22:20:06says data performance and durability,
  34807. 22:20:08security compliance and auditing,
  34808. 22:20:10granular data control, and flexible
  34809. 22:20:12storage options. So, right down here, it
  34810. 22:20:14says save cost without sacrificing
  34811. 22:20:16performance. Store data across a wide
  34812. 22:20:17range of cost-effective storage classes
  34813. 22:20:19and support different data access levels
  34814. 22:20:21that are all designed for specific use
  34815. 22:20:23cases. Now, in this lesson, we're going
  34816. 22:20:25to be taking a look at some of this,
  34817. 22:20:26which is their storage classes, cuz
  34818. 22:20:28these are quite important and they do
  34819. 22:20:30affect the cost that it's going to take
  34820. 22:20:32in order to store your data because uh
  34821. 22:20:35it's not free. Uh storing your data in
  34822. 22:20:37the cloud is not free. You can also look
  34823. 22:20:39at some of their use cases as well as
  34824. 22:20:42some of their case studies if you would
  34825. 22:20:44like. Now, let's actually get into it.
  34826. 22:20:47We're going to come in here and we are
  34827. 22:20:48going to create our very first S3
  34828. 22:20:50bucket. So, I'll click on create bucket.
  34829. 22:20:51The first thing that we need to do is do
  34830. 22:20:53some more of our general configuration.
  34831. 22:20:55We're going to keep this a general
  34832. 22:20:57purpose. And we need to give it a name.
  34833. 22:20:59So, I'm just going to call this one Alex
  34834. 22:21:01the analyst bucket. And if we had a
  34835. 22:21:05pre-existing bucket, we've already
  34836. 22:21:07configured it with uh different
  34837. 22:21:08configurations. We can just select that
  34838. 22:21:10bucket and it'll copy over all the uh
  34839. 22:21:12things that we want. The next thing we
  34840. 22:21:14need to do is need to come right down
  34841. 22:21:16here for object ownership. You can have
  34842. 22:21:18ACL's disabled or ACL's enabled. If we
  34843. 22:21:21go with the recommended route, it means
  34844. 22:21:23that all the objects in this bucket are
  34845. 22:21:25owned by this account, your account that
  34846. 22:21:26you created. But if you do it where it's
  34847. 22:21:29enabled, it says objects in this bucket
  34848. 22:21:31can be owned by other AWS accounts. So
  34849. 22:21:33with this one, it's just a little bit
  34850. 22:21:35more secure because you're not saying
  34851. 22:21:36other people can own it, which means
  34852. 22:21:38they can delete it or change it in any
  34853. 22:21:40way. Next, we're going to come down here
  34854. 22:21:41to block public access for this bucket.
  34855. 22:21:44Now, this part is actually very
  34856. 22:21:47interesting because I've had a lot of
  34857. 22:21:49use cases where you just want to block
  34858. 22:21:51all public access, but if you start
  34859. 22:21:53really getting into AWS and you start
  34860. 22:21:55using a bunch of different tools and
  34861. 22:21:57things, sometimes you need to get rid of
  34862. 22:21:58it. Um, and you need to come in and not
  34863. 22:22:01only that, there's much more advanced
  34864. 22:22:03things in order to grant different
  34865. 22:22:05bucket policies or create different
  34866. 22:22:06bucket policies. And, um, we most likely
  34867. 22:22:09won't get into all that in this lesson,
  34868. 22:22:11but it can get quite advanced. And so
  34869. 22:22:12this piece is pretty deceivingly simple.
  34870. 22:22:15Um, but we're just going to keep it as
  34871. 22:22:17we block all public access, but as you
  34872. 22:22:19uh start opening it up to different
  34873. 22:22:21services within AWS, you may want to
  34874. 22:22:23turn this off so that you can have
  34875. 22:22:25different services hitting off of your
  34876. 22:22:26S3 bucket or the data within your S3
  34877. 22:22:28bucket. So, we're just going to keep
  34878. 22:22:30this as uh all public access off. I'm
  34879. 22:22:32just giving you lots of extra
  34880. 22:22:34information while we're in here. Some of
  34881. 22:22:35my thoughts. Next, we're going to do
  34882. 22:22:37bucket versioning. We don't need to have
  34883. 22:22:38any type of versioning or version
  34884. 22:22:40control within our bucket. What this
  34885. 22:22:42means is keeping multiple variants of an
  34886. 22:22:44object in the same bucket. It's used to
  34887. 22:22:45preserve, retrieve, and restore every
  34888. 22:22:47version of every object stored in your
  34889. 22:22:49S3 bucket. And that is of course going
  34890. 22:22:51to cost a little bit extra. So we don't
  34891. 22:22:53uh need that at all. Next, you can add
  34892. 22:22:56tags. And tags are helpful if you have a
  34893. 22:22:59lot of different buckets and you maybe
  34894. 22:23:01it's per client. You have some type of
  34895. 22:23:03tag for a specific client. Perfectly
  34896. 22:23:05normal. Uh next we have default
  34897. 22:23:08encryption. Now encryption in general is
  34898. 22:23:11really interesting within the cloud.
  34899. 22:23:12I've run into lots of use cases where
  34900. 22:23:15it's been really difficult to work with.
  34901. 22:23:17If you want to pull data into certain
  34902. 22:23:18services, you have to decrypt it uh
  34903. 22:23:20because you've encrypted it in one area.
  34904. 22:23:22And so if it's in the S3 bucket and it's
  34905. 22:23:24encrypted, uh especially with kind of
  34906. 22:23:26more advanced options, it can be
  34907. 22:23:28somewhat difficult. And so just
  34908. 22:23:29something to take into consideration if
  34909. 22:23:31you want to kind of up your encryption.
  34910. 22:23:33But for most use cases, you're just
  34911. 22:23:35going to use the server side encryption
  34912. 22:23:36with Amazon S3 managed keys with the
  34913. 22:23:39bucket key enabled. Next, let's come
  34914. 22:23:41down here to advanced settings. There's
  34915. 22:23:44only one thing in here that we need to
  34916. 22:23:45look at, which is the object lock. And
  34917. 22:23:47remember, everything that you put inside
  34918. 22:23:49of an S3 bucket is an object. Now, if we
  34919. 22:23:52just read this right here, it says
  34920. 22:23:53storage objects use a write once, read
  34921. 22:23:55many, which is a worm model. And this
  34922. 22:23:57helps prevent objects from being deleted
  34923. 22:23:59or overwritten for a fixed amount of
  34924. 22:24:01time or indefinitely. So, if you want to
  34925. 22:24:03drop a file in there and you know you're
  34926. 22:24:04going to need it, you don't want it to
  34927. 22:24:06be deleted for any amount of time, you
  34928. 22:24:08can lock that and you can have an object
  34929. 22:24:10lock on that object. It can never be
  34930. 22:24:12deleted. We of course do not need that.
  34931. 22:24:14So, we're going to keep that disabled.
  34932. 22:24:16And now we're ready to create our very
  34933. 22:24:18first bucket. I clicked on create
  34934. 22:24:20bucket. Uh looks like we can't use
  34935. 22:24:22uppercase and I actually knew that. Uh
  34936. 22:24:24let's fix this. Now, this does have to
  34937. 22:24:27be unique. This is global. So, it says
  34938. 22:24:29right here you have to use a unique
  34939. 22:24:30name. You can't just use like Alex. Uh,
  34940. 22:24:32someone's probably already chosen that.
  34941. 22:24:34Let's go ahead and create our bucket.
  34942. 22:24:36And now you can see right in here we
  34943. 22:24:37have our very first bucket. Very
  34944. 22:24:40exciting. Let's click into our first
  34945. 22:24:42bucket, our only bucket. Let's go ahead
  34946. 22:24:44and click into here. And we have a few
  34947. 22:24:46different things in here. We have our
  34948. 22:24:47objects, and that's going to be any
  34949. 22:24:49files that we upload into this bucket.
  34950. 22:24:51And within this, we can create tons of
  34951. 22:24:53folders and subfolders and sub
  34952. 22:24:55subfolders and all these different
  34953. 22:24:56things. We also have properties. So this
  34954. 22:25:00gives you a little bit of information on
  34955. 22:25:02how you actually created this. You have
  34956. 22:25:04permissions. So if you want to grant uh
  34957. 22:25:06access to it. I talked a little bit
  34958. 22:25:08about this which is a bucket policy. So
  34959. 22:25:11if we turn off this all public access
  34960. 22:25:13and we turn on this or we allow this
  34961. 22:25:15bucket policy, we can create our own
  34962. 22:25:17bucket policy and that's written in JSON
  34963. 22:25:19and we can create our own bucket policy
  34964. 22:25:21for public access to this specific
  34965. 22:25:24bucket. That gets a little bit more
  34966. 22:25:26advanced, but it is really fun. I've uh
  34967. 22:25:28done that quite a bit. You have metrics
  34968. 22:25:30on this bucket. You can manage this
  34969. 22:25:32bucket and you can create access points
  34970. 22:25:34to this bucket. So, there's a lot of
  34971. 22:25:36things just within a single S3 bucket
  34972. 22:25:38that you can do. But the most popular
  34973. 22:25:41one that you're going to be using is
  34974. 22:25:42this one right here, which is just
  34975. 22:25:44adding, creating, and deleting, and
  34976. 22:25:46using objects in general. So, let's go
  34977. 22:25:48ahead and upload our very first file.
  34978. 22:25:51We're going to go over here to add
  34979. 22:25:52files, but you could add a folder if you
  34980. 22:25:54have a whole folder, but we're just
  34981. 22:25:55going to add one file. And within my
  34982. 22:25:56sample files here, we have a bunch of
  34983. 22:25:58very real healthcare data. It's not
  34984. 22:26:01real. Uh it's just completely fake data.
  34985. 22:26:03Now, what we're going to do is we're
  34986. 22:26:04going to upload one. Then we're going to
  34987. 22:26:05come back. We're upload another one in a
  34988. 22:26:07different way. And I'm going to
  34989. 22:26:08demonstrate that and uh explain that in
  34990. 22:26:10a little bit. Now, what we're going to
  34991. 22:26:11do is we're going to select this file.
  34992. 22:26:13We're going to open this up. And now we
  34993. 22:26:15have this real healthcare data 1.csv.
  34994. 22:26:18And that's what we're going to be
  34995. 22:26:19uploading. Now, let's come down here. We
  34996. 22:26:22have our destination. This is telling us
  34997. 22:26:23where we're actually placing this. We
  34998. 22:26:26have our permissions and of course we
  34999. 22:26:28have uh bucket enforced and so if we
  35000. 22:26:30wanted to grant access to other accounts
  35001. 22:26:32we need to change some of our access
  35002. 22:26:34policies. But lastly we have properties
  35003. 22:26:37and this piece is really interesting.
  35004. 22:26:39This is our storage class. This is how
  35005. 22:26:41uh Amazon S3 is actually going to store
  35006. 22:26:43your data. Now I highly recommend going
  35007. 22:26:45in to learn more and looking at their
  35008. 22:26:47Amazon S3 pricing because it's very
  35009. 22:26:49fascinating how they do this. Um, and
  35010. 22:26:51it's also really important that you
  35011. 22:26:52understand the differences between these
  35012. 22:26:54different options that we have. By
  35013. 22:26:56default, we have standard, and it's
  35014. 22:26:59designed for frequently accessed data
  35015. 22:27:01within milliseconds for access. So, if
  35016. 22:27:03you're going to be using this data,
  35017. 22:27:04you're going to be hitting off of it for
  35018. 22:27:05different applications, services, uh,
  35019. 22:27:08visualizations, whatever you're using it
  35020. 22:27:09for, you're going to want to be able to
  35021. 22:27:11access that pretty quickly. And so, this
  35022. 22:27:13is a great option. If you need it even
  35023. 22:27:15faster, you have S3 Express one zone,
  35024. 22:27:18which is singledigit millisecond
  35025. 22:27:20response times for the most frequent
  35026. 22:27:22access data. Now, I don't think it talks
  35027. 22:27:24about cost in here, uh, but you can use
  35028. 22:27:28a calculator, and this is going to be
  35029. 22:27:29costly, right? It's going to cost more
  35030. 22:27:31to get faster and lower latency
  35031. 22:27:34responses to your data. Now, if we come
  35032. 22:27:36down here, you'll notice we have this
  35033. 22:27:38glacier tier. Now, if we went back to
  35034. 22:27:40our resources, remember we talked about
  35035. 22:27:42S3 Glacier. I was going to mention that.
  35036. 22:27:44Well, you can use these different
  35037. 22:27:47glaciers which allows you to store it
  35038. 22:27:50for long periods of time at a much lower
  35039. 22:27:52cost, but it stores it a little bit
  35040. 22:27:54differently. This one specifically is
  35041. 22:27:56instant retrieval. It's very similar to
  35042. 22:27:59almost standard, but you're kind of
  35043. 22:28:00storing it for a long long time. You may
  35044. 22:28:03not need it for 10 years, but when you
  35045. 22:28:04do need it, you need it right away,
  35046. 22:28:06which is not a lot of use cases if
  35047. 22:28:08you're using Glacier. But then you have
  35048. 22:28:09something like Glacier Deep Archive.
  35049. 22:28:11This is longived archive data accessed
  35050. 22:28:14less than once a year with retrieval of
  35051. 22:28:16hours. And so this is going to be data
  35052. 22:28:18that you don't need it right away. Uh
  35053. 22:28:20you just want to be able to store it and
  35054. 22:28:22have the security of putting it in the
  35055. 22:28:24cloud, but you may not use that for
  35056. 22:28:26years. And when you do need it, you
  35057. 22:28:27know, you're just you're okay with
  35058. 22:28:28waiting a little bit. It's going to cost
  35059. 22:28:30almost nothing to store. It's very very
  35060. 22:28:32very little. And oftent times if you're
  35061. 22:28:34doing something like this, you may even
  35062. 22:28:36put backups of databases. You may put
  35063. 22:28:38backups of entire code bases in here.
  35064. 22:28:41things that you may never use again. Um,
  35065. 22:28:43and there's lots of different use cases
  35066. 22:28:45as well. So, I just wanted to walk
  35067. 22:28:47through that with this file. We're going
  35068. 22:28:48to do standard. And on the next file we
  35069. 22:28:50do, we're going to do Glacier deep
  35070. 22:28:52archive. And just look at the difference
  35071. 22:28:54here. Now, let's come down. Uh, we don't
  35072. 22:28:56need encryption. We don't need any type
  35073. 22:28:59of check sums, tags, or metadata. That
  35074. 22:29:02stuff is almost uh never used or very
  35075. 22:29:04very infrequently. So, we've uploaded
  35076. 22:29:06this file. Let's go ahead and go to our
  35077. 22:29:08destination. You can see that now we
  35078. 22:29:10have an object in our bucket which is
  35079. 22:29:13fantastic. You can even come over here
  35080. 22:29:15and you can see the storage class is
  35081. 22:29:18standard. Now let's go in. We're going
  35082. 22:29:20to upload one more but now we're going
  35083. 22:29:22to upload it as a different storage
  35084. 22:29:24class. So let's go to upload. Let's go
  35085. 22:29:26to add files. Let's go to healthcare
  35086. 22:29:28data 2. We're going to open that up. The
  35087. 22:29:31only thing we're going to change is now
  35088. 22:29:33we're going to go down to the deep
  35089. 22:29:35archive and we're going to go ahead and
  35090. 22:29:38upload this. Easy peasy. And there we
  35091. 22:29:42have two files. Now we have one in
  35092. 22:29:45standard, one in Glacier deep archive.
  35093. 22:29:47Let's go into the first one. If we want
  35094. 22:29:48to use this in any way, it's almost
  35095. 22:29:51instantly retrievable. We can download
  35096. 22:29:53this. Uh we have a bunch of object
  35097. 22:29:55options. So we can download it. We can
  35098. 22:29:58copy it. We can move it. We can change
  35099. 22:30:00the storage class. We do a bunch of
  35100. 22:30:01different things. But let's come back
  35101. 22:30:04and we're going to go to that file too.
  35102. 22:30:07Let's go ahead in here. Notice right
  35103. 22:30:09here we're getting a totally different
  35104. 22:30:11uh message. It says the object is
  35105. 22:30:13starting Glacier deep archive storage
  35106. 22:30:15class. In order to access it, you must
  35107. 22:30:16first restore it. So you have to
  35108. 22:30:19initiate a restore right over here. And
  35109. 22:30:22it can take 30 minutes to several hours.
  35110. 22:30:24Notice we cannot download this. We also
  35111. 22:30:27can't really do anything with it until
  35112. 22:30:30we actually initiate that restore and it
  35113. 22:30:32is restored for us to be able to access
  35114. 22:30:34it. And that's just something that I
  35115. 22:30:36think is worth noting about storing
  35116. 22:30:38things in S3. There are different
  35117. 22:30:39storage classes depending on your use
  35118. 22:30:41case and what you're using. That's ADA
  35119. 22:30:434. And of course, you should look at the
  35120. 22:30:45S3 pricing for both of these cuz this
  35121. 22:30:47one is going to cost more than this one.
  35122. 22:30:50Now, there are costs associated with
  35123. 22:30:52restoring it, but if you're restoring it
  35124. 22:30:54once per year or maybe once every 5
  35125. 22:30:56years, it's going to be significantly
  35126. 22:30:58less than your standard storage class.
  35127. 22:31:00Now, this is kind of the meat and
  35128. 22:31:01potatoes of using S3. Of course, you can
  35129. 22:31:04create folders and subfolders. And in
  35130. 22:31:06fact, when we get into some other
  35131. 22:31:08lessons, especially things like glue, uh
  35132. 22:31:10having folders, subfolders, and
  35133. 22:31:12different things like that is actually
  35134. 22:31:14really important because we have
  35135. 22:31:15something called a glue crawler. You
  35136. 22:31:17know, a crawl through your folders and
  35137. 22:31:19subfolders and retrieve certain data.
  35138. 22:31:21And so having a folder structure
  35139. 22:31:23actually becomes more important in those
  35140. 22:31:25lessons, but we'll of course get to that
  35141. 22:31:27when we actually start looking at it.
  35142. 22:31:29One other thing to mention, and this is
  35143. 22:31:30just uh kind of a neat addition that
  35144. 22:31:32they have in here. If we go into this
  35145. 22:31:34file and we go down to query with S3
  35146. 22:31:37select, you can access this data and
  35147. 22:31:40take a look at it. And so, uh, let's say
  35148. 22:31:42we have, uh, our CSV here. It's comma
  35149. 22:31:45separated. We can query this data using
  35150. 22:31:48SQL. And so, let's just run this with
  35151. 22:31:50the limit five on there. We'll run our
  35152. 22:31:52SQL query. We have our query results
  35153. 22:31:55right down here. We can have it
  35154. 22:31:56formatted and it looks like a little
  35155. 22:31:58table. So, we can come in here. we can
  35156. 22:32:00look at uh this data down here and just
  35157. 22:32:03see what's in there. And so that might
  35158. 22:32:04be useful to you. Now, in the next
  35159. 22:32:07lesson that we're going to be having,
  35160. 22:32:08we're going to use Amazon Athena, which
  35161. 22:32:10is basically a tool to query off of S3
  35162. 22:32:13buckets. That's its primary use. And so,
  35163. 22:32:16most of the time, I honestly am not
  35164. 22:32:18using this almost ever, but you can even
  35165. 22:32:19see right here it says Amazon Athena.
  35166. 22:32:22That's what we're going to be looking at
  35167. 22:32:23in the next lesson. We'll be seeing how
  35168. 22:32:24Amazon Athena works, how you can query
  35169. 22:32:26data, kind of set up a pseudo database
  35170. 22:32:29like structure. I'll talk about the pros
  35171. 22:32:31and cons of Amazon Athena versus other
  35172. 22:32:34tools because Amazon Athena is not for
  35173. 22:32:36every use case. So, I hope that that was
  35174. 22:32:39helpful. I hope you enjoyed it. If you
  35175. 22:32:40have not, I have a full AWS and Azure
  35176. 22:32:43course on analystbuilder.com. Be sure to
  35177. 22:32:44check it out. If you like this video, be
  35178. 22:32:46sure to like and subscribe below. I will
  35179. 22:32:48see you in the next video.
  35180. 22:32:51>> [music]
  35181. 22:33:02>> What's going on everybody? Welcome back
  35182. 22:33:03to another video. Today we're going to
  35183. 22:33:05be taking a look at Amazon Athena in
  35184. 22:33:07AWS.
  35185. 22:33:11[music]
  35186. 22:33:13Now Athena is a tool that allows you to
  35187. 22:33:15query data in your S3 bucket without
  35188. 22:33:18having to put that data into some type
  35189. 22:33:20of database. you're just querying it
  35190. 22:33:21directly. So let's say you just got a
  35191. 22:33:23big file from a client, you put it in an
  35192. 22:33:25S3 bucket, but you don't want to
  35193. 22:33:26actually create a table and take the
  35194. 22:33:28time to do all that whole process. You
  35195. 22:33:30just want to take a look at the data.
  35196. 22:33:31You just want to query it really
  35197. 22:33:32quickly. Well, Athena allows you to do
  35198. 22:33:34that. And so if that's the case, it can
  35199. 22:33:36save you a lot of time and money. And so
  35200. 22:33:37this is a really great tool that a lot
  35201. 22:33:39of companies use. We'll talk a lot more
  35202. 22:33:41about Athena in just a second. So let's
  35203. 22:33:43jump on my screen and take a look. All
  35204. 22:33:44right, so let's come into services and
  35205. 22:33:46we're going to go all the way down to
  35206. 22:33:47the analytics tab and we're going to go
  35207. 22:33:49into Athena. Now, before we jump into
  35208. 22:33:51actually querying data and setting
  35209. 22:33:53everything up, let's take a look at some
  35210. 22:33:54of the information they have on Amazon
  35211. 22:33:56Athena. This right here, this start
  35212. 22:33:59quering data instantly is probably one
  35213. 22:34:01of the uh biggest pieces of why you
  35214. 22:34:04would use Amazon Athena. And I'll talk a
  35215. 22:34:06little bit about a little later on about
  35216. 22:34:08who this is for, why you'd want to use
  35217. 22:34:10this versus other tools uh within AWS.
  35218. 22:34:13But Amazon Athena is an interactive
  35219. 22:34:15query service that makes it easy to
  35220. 22:34:17analyze data in Amazon S3 and other
  35221. 22:34:20federated data sources using standard
  35222. 22:34:22SQL. So primarily though for you and I
  35223. 22:34:25most likely you're going to be using
  35224. 22:34:27this just to hit off of an Amazon S3
  35225. 22:34:29bucket. You can even see how it works
  35226. 22:34:30right down here. It says point to your
  35227. 22:34:32data source. You're going to use Amazon
  35228. 22:34:34Athena. You're going to query it and you
  35229. 22:34:36can analyze those results down here in
  35230. 22:34:40the benefits that are right here. You
  35231. 22:34:42have start querying now. Oh, it's
  35232. 22:34:43powerful, cost effective, fast. All of
  35233. 22:34:45these things are great. Honestly,
  35234. 22:34:47powerful, cost effective, and fast could
  35235. 22:34:49be a ton of different tools in AWS. But
  35236. 22:34:51this piece right here is quite unique to
  35237. 22:34:53it in the fact that you can query it as
  35238. 22:34:55it just sits in an S3. You don't have to
  35239. 22:34:57bring that data over into a database and
  35240. 22:35:00actually store it in the database. You
  35241. 22:35:01can keep it in your S3 bucket and still
  35242. 22:35:04query off of it. And so that is uh kind
  35243. 22:35:06of the real use case and the real reason
  35244. 22:35:09why you would want Amazon Athena just to
  35245. 22:35:10look at data uh within an S3 bucket. Now
  35246. 22:35:13we do have two options here. Query your
  35247. 22:35:14data with Trino SQL or analyze your data
  35248. 22:35:17using PIS spark and spark SQL. We are
  35249. 22:35:19just going to be looking at the Trino
  35250. 22:35:21SQL in this lesson but of course you can
  35251. 22:35:23use PIS spark and spark SQL as well.
  35252. 22:35:26Let's go ahead and launch our query
  35253. 22:35:27editor. And this is what you should see.
  35254. 22:35:30Now it says uh we need to edit some of
  35255. 22:35:33our settings. And I'll explain that in
  35256. 22:35:35just a little bit. Um, but over here on
  35257. 22:35:37the lefth hand side, we have our data.
  35258. 22:35:40So we have our data source, we have our
  35259. 22:35:42database, we have tables and views, and
  35260. 22:35:45then we have where we query our data,
  35261. 22:35:47and then down here where our results
  35262. 22:35:49will be. So there's a lot of stuff just
  35263. 22:35:52in here, but this is um not super crazy
  35264. 22:35:55advanced. Uh if you've used anything
  35265. 22:35:57like MySQL or if you've used Microsoft
  35266. 22:35:59SQL Server or anything like that, this
  35267. 22:36:01is like a really I don't want to say
  35268. 22:36:02dumbed down version that's not super uh
  35269. 22:36:05kind to say, but it's it's a really
  35270. 22:36:07simplified version of it. It's not very
  35271. 22:36:10uh difficult to understand. You can also
  35272. 22:36:12save your queries in recent and saved
  35273. 22:36:15queries. And of course, we have some
  35274. 22:36:17settings over here. Now, we're going to
  35275. 22:36:19see how we can set up our database,
  35276. 22:36:21create a table or two, see how all that
  35277. 22:36:23works with actually hitting off of data
  35278. 22:36:25within our S3 bucket and we will have to
  35279. 22:36:28fix this piece which is you have to set
  35280. 22:36:30up a query result location in Amazon S3.
  35281. 22:36:33That's for your results or your metadata
  35282. 22:36:36and uh that piece becomes quite
  35283. 22:36:38important later on. So, let's come down
  35284. 22:36:40here. We have our data source. This is
  35285. 22:36:41going to be our AWS data catalog. Now,
  35286. 22:36:44we haven't covered this in a previous
  35287. 22:36:45lesson, but you have something called a
  35288. 22:36:49data catalog, and we're going to look a
  35289. 22:36:50lot at that actually in either the next
  35290. 22:36:53lesson or the lesson after that when we
  35291. 22:36:54look at uh AWS Glue and Glue Data Brew.
  35292. 22:36:58But that's how they kind of organize it.
  35293. 22:36:59And so, we're not going to be messing
  35294. 22:37:00with that uh here. But we have to choose
  35295. 22:37:03a database. And notice we don't have any
  35296. 22:37:05database. So, what we need to do is we
  35297. 22:37:07need to start pulling in data. And when
  35298. 22:37:09we're pulling in that data, we'll be
  35299. 22:37:10able to create a database. Now, right
  35300. 22:37:13here we have create. You can create a
  35301. 22:37:14table from a data source or create with
  35302. 22:37:16SQL. So, if you want to go the
  35303. 22:37:18oldfashioned way where you're creating a
  35304. 22:37:19table like this and you can and you can
  35305. 22:37:22specify the column, the column types or
  35306. 22:37:25data types, the location, all these
  35307. 22:37:27things, you can do that. Uh, but we're
  35308. 22:37:29not going to be doing that. We are going
  35309. 22:37:31to be doing it with S3 bucket data. Now,
  35310. 22:37:34we also have AWS Glue Crawler. Now, I'm
  35311. 22:37:37just going to open this up really quick.
  35312. 22:37:39We will be doing this when we get to
  35313. 22:37:41glue. Uh when we start looking at glue
  35314. 22:37:43because crawlers are great. Crawlers
  35315. 22:37:45allow you to specify the data source and
  35316. 22:37:47it pulls it in and infers based off of
  35317. 22:37:50the column names and and the data types
  35318. 22:37:52that are in there. It builds the table
  35319. 22:37:54for you and it's very helpful and it
  35320. 22:37:56kind of helps automate it as well. We're
  35321. 22:37:58not going to be doing that. Uh you can
  35322. 22:38:00look at crawlers here, but we're not
  35323. 22:38:02going to be doing that in this lesson.
  35324. 22:38:04So this is what crawlers are and that's
  35325. 22:38:06within AWS Glue, but we're not we're not
  35326. 22:38:08going to be looking at that in this
  35327. 22:38:09lesson. So what we are going to be doing
  35328. 22:38:11is just creating it from an S3 bucket
  35329. 22:38:13data. Now we need to call this table
  35330. 22:38:15something. So let's call this healthcare
  35331. 22:38:18and I need to spell health right. Uh
  35332. 22:38:20healthcare data. I I'm having trouble
  35333. 22:38:22spelling. Let's go down to the database
  35334. 22:38:25configuration. Now we don't have a
  35335. 22:38:27database. So we need to create a
  35336. 22:38:29database. And this is super easy. Um
  35337. 22:38:31this is actually the table name. Let's
  35338. 22:38:33call this um patient data because I want
  35339. 22:38:36to call the uh the database healthcare
  35340. 22:38:39data. So I'll call this one healthcare
  35341. 22:38:41data. I spelled that much better that
  35342. 22:38:42time. So we've specified here's what our
  35343. 22:38:45table is going to be called. Here's what
  35344. 22:38:47our database is going to be called. Now
  35345. 22:38:49we need to specify our data set. And
  35346. 22:38:51this is a kind of an odd part and you'll
  35347. 22:38:53see that in just a little bit. Let's
  35348. 22:38:55come in here and we have our Alex the
  35349. 22:38:57analyst bucket. Let's go ahead and click
  35350. 22:38:58into it. Notice though within this
  35351. 22:39:01bucket we have two data sets. I I really
  35352. 22:39:03only want this one if I'm being honest.
  35353. 22:39:05I just want this one. But you can't do
  35354. 22:39:08that. Uh not within Athena and within
  35355. 22:39:10other parts of AWS as well. This is just
  35356. 22:39:12a a kind of one of those nuances uh
  35357. 22:39:15within it. We have to specify a file
  35358. 22:39:17path, not a file itself. So we have to
  35359. 22:39:20choose the entire folder. Let's choose
  35360. 22:39:23this. Let's come down here to the data
  35361. 22:39:26format. Now this data format that's in
  35362. 22:39:29here is a CSV. So we're going to come in
  35363. 22:39:32here with an Apache Hive and we're going
  35364. 22:39:34to specify that is a CSV file. Of
  35365. 22:39:36course, we want the delimiter which is
  35366. 22:39:38right down here to be a comma. So we
  35367. 22:39:40should be good to go. But because we are
  35368. 22:39:43not using a crawler, we have to manually
  35369. 22:39:45enter these column details. So I'm going
  35370. 22:39:48to come down here. We are going to pull
  35371. 22:39:50up this file. Let's zoom in a little
  35372. 22:39:52bit. These are uh everything that we
  35373. 22:39:55have. Now we can there is an option in
  35374. 22:39:57here actually. We can copy all of this
  35375. 22:40:00and we'll come in here to add bulk
  35376. 22:40:02columns and you can do it like this and
  35377. 22:40:04then you can put in the data type and
  35378. 22:40:07that's perfectly fine if you want to do
  35379. 22:40:08that. Uh but we're not going to be doing
  35380. 22:40:10that. I'm going to actually pull this
  35381. 22:40:12up. We will bring this over to the side
  35382. 22:40:17right here. And there we go. So now we
  35383. 22:40:20can see it. So we have our first column.
  35384. 22:40:22It's going to be uh patient
  35385. 22:40:25ID. It doesn't have to be the exact same
  35386. 22:40:27as over here in the file. Now, this file
  35387. 22:40:29type is just numeric. So, we can come in
  35388. 22:40:31here and we'll choose integer right
  35389. 22:40:34here. And that's all we need to specify.
  35390. 22:40:37Now, we have several other columns. So,
  35391. 22:40:39let's just kind of bulk place them in
  35392. 22:40:41here. We have name, we have age,
  35393. 22:40:45we have diagnosis,
  35394. 22:40:48and we have treatment. Let's see if
  35395. 22:40:50there's anything else in here. I think
  35396. 22:40:52we have files. Yeah, one more. So let's
  35397. 22:40:54add in files. And just to show you, we
  35398. 22:40:58can do name underscore. Is this their
  35399. 22:41:00full name? Yeah, full name. So we'll do
  35400. 22:41:03full underscore name. And we're doing
  35401. 22:41:06that just to demonstrate that doesn't
  35402. 22:41:07have to copy this exactly. Um but for
  35403. 22:41:10the full name, this should be string or
  35404. 22:41:12text. So we could use char. We could use
  35405. 22:41:15uh string. See if there's any other ones
  35406. 22:41:17that we could use. Probably those two.
  35407. 22:41:18We'll call this one string. For age, it
  35408. 22:41:21should be integer as well. for diagnosis
  35409. 22:41:25treatment those are both string so we'll
  35410. 22:41:28do string and string and then for files
  35411. 22:41:32this one is integer as well we can make
  35412. 22:41:36this a little bit larger now there's a
  35413. 22:41:38bunch of different things that we can
  35414. 22:41:39specify different types of compression
  35415. 22:41:42if you have compression so if you're
  35416. 22:41:43using a zip file or anything like that
  35417. 22:41:46you can specify uh that it's sitting in
  35418. 22:41:48it there is partitioning as well and
  35419. 22:41:50this is a little bit more advanced this
  35420. 22:41:52is a way that you can group specific
  35421. 22:41:54information together, but this is not
  35422. 22:41:56something that we need to worry about,
  35423. 22:41:58especially with our simple data set.
  35424. 22:42:00There also is bucketing. This is a way
  35425. 22:42:02to bucket multiple columns together. And
  35426. 22:42:05then it's stored in a way that when you
  35427. 22:42:06try to retrieve it, it's retrieved a lot
  35428. 22:42:08faster and easier. Again, this is a bit
  35429. 22:42:11more complicated and a little bit
  35430. 22:42:12advanced. So, we're not going to be
  35431. 22:42:13taking a look at that at the moment.
  35432. 22:42:15Let's go ahead and create this table.
  35433. 22:42:18Now, we're getting this error that says
  35434. 22:42:20no output location provided. Now, output
  35435. 22:42:22location is required either through the
  35436. 22:42:24work group result configuration setting
  35437. 22:42:26or as an API input. So, let's go fix
  35438. 22:42:29this really quickly. We're going to
  35439. 22:42:31actually I don't want to have to redo
  35440. 22:42:32all this. So, let's actually duplicate
  35441. 22:42:34this. Let's go into our query editor and
  35442. 22:42:38we need to go into this work group. So,
  35443. 22:42:40let's come over here. Let's go into our
  35444. 22:42:42workg groupoups and this is our primary
  35445. 22:42:44work group. Let's come in here and we
  35446. 22:42:47need to come over to edit. Now within
  35447. 22:42:50this we had chosen uh Athena SQL and if
  35448. 22:42:53we come down we have this query result
  35449. 22:42:55configuration. We have to specify this
  35450. 22:42:58so that our output and our metadata is
  35451. 22:43:02put somewhere. So let's go ahead and
  35452. 22:43:04browse this. Now just like when we chose
  35453. 22:43:06our file we cannot specify like a file
  35454. 22:43:10to put it in. We have to specify a file
  35455. 22:43:12path. Now we're going to specify that
  35456. 22:43:14this is our path but this is not the
  35457. 22:43:16best way to do it. I'm doing this for
  35458. 22:43:18demonstration purposes only. Uh we'll go
  35459. 22:43:20back and do it the right way in a little
  35460. 22:43:22bit. So this is where we're going to put
  35461. 22:43:23our output, our results, metadata, all
  35462. 22:43:25that stuff. Let's go ahead and choose
  35463. 22:43:27this.
  35464. 22:43:29And uh you can add life cycle uh
  35465. 22:43:32configuration as well as assign a bucket
  35466. 22:43:34owner and some encryption, but we don't
  35467. 22:43:36need to do that. Let's save these
  35468. 22:43:38changes and let's go back
  35469. 22:43:42and let's go and create this table.
  35470. 22:43:46So, it created this for us. The query
  35471. 22:43:48was successful. Let's refresh this. And
  35472. 22:43:51it's giving us a default database.
  35473. 22:43:53That's actually not the one that we put
  35474. 22:43:55it in. We put it into healthcare. So,
  35475. 22:43:57let's go over to healthcare. And there
  35476. 22:43:59is our patient data. You can see we have
  35477. 22:44:01patient ID, full name, age, diagnosis,
  35478. 22:44:03treatment, files with the associated
  35479. 22:44:06data types. And what we can do, whoops.
  35480. 22:44:08What we can do is we can come right over
  35481. 22:44:10here and let's say we want to preview
  35482. 22:44:13this table. So that is completed. Let's
  35483. 22:44:16go down here. And the data looks pretty
  35484. 22:44:18good. We have this one file uh because
  35485. 22:44:20we have two files. It's reading in that
  35486. 22:44:23second file uh column names, but we have
  35487. 22:44:27some data in there. And that's really
  35488. 22:44:28really good. Now, we're limiting this to
  35489. 22:44:3010. And let's get rid of this. But
  35490. 22:44:33actually uh before we do that, I'm going
  35491. 22:44:34to keep it the same because before we do
  35492. 22:44:36that, we need to go look at the
  35493. 22:44:39ramifications of what we actually did
  35494. 22:44:41because uh unfortunately it's not a good
  35495. 22:44:44thing what we did. Let's go to our S3
  35496. 22:44:46bucket and let's see what data is in
  35497. 22:44:49this Alexi Analyst bucket here. Now you
  35498. 22:44:52can see we have a bunch of stuff. It's
  35499. 22:44:54not just our two files anymore. Now we
  35500. 22:44:56have a text file, a text file, metadata,
  35501. 22:44:59CSV. This is our output and some extra
  35502. 22:45:01stuff as well as the metadata. And
  35503. 22:45:03what's going to happen if we come over
  35504. 22:45:06here and we try to query all of our
  35505. 22:45:08data. Let's go ahead and run this.
  35506. 22:45:11Now, you'll notice that we're pulling in
  35507. 22:45:13a lot of bad bad data. This has
  35508. 22:45:16completely ruined our query and this is
  35509. 22:45:18kind of defeated the purpose of setting
  35510. 22:45:20up using Amazon Athena. What we need is
  35511. 22:45:24we need a separate folder location
  35512. 22:45:26within our S3 bucket to dump all this
  35513. 22:45:28stuff. Otherwise, you'll notice it's
  35514. 22:45:30just going to keep growing. We're just
  35515. 22:45:31going to have more metadata, more CSV,
  35516. 22:45:33more text files. That is not a good
  35517. 22:45:35thing. So, here's what we're going to
  35518. 22:45:37do. We're going to create a folder.
  35519. 22:45:39We're going to call this one uh metadata
  35520. 22:45:42healthcare. I think I spelled that
  35521. 22:45:44right. And we're going to create this
  35522. 22:45:45folder. Now, I'm going to take all of
  35523. 22:45:48these things and I'm going to delete
  35524. 22:45:51them. So, let's go ahead and delete all
  35525. 22:45:53these files. And we have to specify
  35526. 22:45:55this. I'm going to do a little cheat.
  35527. 22:45:56I'm going to copy and paste this. There
  35528. 22:45:59we go. Let's delete our objects.
  35529. 22:46:01And those were deleted. And now you can
  35530. 22:46:03see we just have our uh real healthcare
  35531. 22:46:06data here. And we have our metadata
  35532. 22:46:09healthcare up here. Now what we need to
  35533. 22:46:12do is we have to go back. We're going to
  35534. 22:46:14go over to our work group and we're
  35535. 22:46:15going to specify the new metadata folder
  35536. 22:46:19that we're going to be placing this in.
  35537. 22:46:20So let's go back down to settings.
  35538. 22:46:23Actually, it's in the query result
  35539. 22:46:24configuration. Let's go to browse. We're
  35540. 22:46:27going to go in here and we're now we're
  35541. 22:46:28going to specify the metadata healthcare
  35542. 22:46:31folder. So, let's go ahead and specify
  35543. 22:46:33that. Let's save our changes and we'll
  35544. 22:46:36go back to our query editor. Now, when
  35545. 22:46:40we run this, let's go ahead and run this
  35546. 22:46:41again. Now, we have our output. Our data
  35547. 22:46:45is in there. Let's come up here. Let's
  35548. 22:46:47refresh this.
  35549. 22:46:50The data is not in here anymore. Now,
  35550. 22:46:52it's in this metadata healthcare. And
  35551. 22:46:54that's great, right? Let's come back
  35552. 22:46:56here and let's run this once again.
  35553. 22:47:00Let's come down and you're going to
  35554. 22:47:02notice something uh peculiar is what
  35555. 22:47:04I'll call it. What's peculiar is the
  35556. 22:47:06fact that now we have the same metadata.
  35557. 22:47:09Now, why is this why is this happening?
  35558. 22:47:11And why am I showing you this in the
  35559. 22:47:13first place? It's because when you are
  35560. 22:47:16specifying a file path, you are not only
  35561. 22:47:18specifying a file path, you're
  35562. 22:47:20specifying the folders and the
  35563. 22:47:22subfolders. So when we come in here and
  35564. 22:47:25we look at this bucket, if we just
  35565. 22:47:28specify that we're pulling all the data
  35566. 22:47:30out of this bucket, then we're pulling
  35567. 22:47:32not just this data, we're pulling a
  35568. 22:47:34folder within a subfolder. And so now
  35569. 22:47:37we're pulling this data as well. So we
  35570. 22:47:39need to if we want to keep it all in one
  35571. 22:47:41bucket, which we can, we need to create
  35572. 22:47:44a new folder called our patient
  35573. 22:47:47data. So we're going to click on our
  35574. 22:47:50file. We're going to click move and we
  35575. 22:47:54need to specify our destination. So,
  35576. 22:47:55we're just going to put this in the
  35577. 22:47:57patient data. So, let's go ahead and
  35578. 22:47:59choose this and let's move it. And we're
  35579. 22:48:02going to close this out. Now, uh you'll
  35580. 22:48:05notice that this data is a Glacier deep
  35581. 22:48:09archive. So, we cannot move this and we
  35582. 22:48:11cannot query it. And that's also
  35583. 22:48:12something that I wanted to mention while
  35584. 22:48:14we were here. I somewhat forgot this.
  35585. 22:48:16The data that we are pulling in uh this
  35586. 22:48:19data down here is only from one file. We
  35587. 22:48:22don't have two files of data in here.
  35588. 22:48:24The only data that we have or that we
  35589. 22:48:26were pulling in was from this real
  35590. 22:48:28healthcare data one. We were able to hit
  35591. 22:48:30off of that data cuz the storage class
  35592. 22:48:32is standard. But because when we set
  35593. 22:48:35this up, this was a Glacier deep
  35594. 22:48:38archive, we cannot query off of that
  35595. 22:48:40data. And so what we're going to do is
  35596. 22:48:42I'm going to come back up here to
  35597. 22:48:43patient data. I'm going to go to upload.
  35598. 22:48:46So, we have more than one file in here.
  35599. 22:48:48Let's go ahead and add a file. I'm going
  35600. 22:48:49to specify this number two, but now
  35601. 22:48:52we're just going to keep it as is. We're
  35602. 22:48:54not going to Oh, if we go to down to
  35603. 22:48:56properties, we're just going to keep it
  35604. 22:48:57as standard. So, let's go ahead and
  35605. 22:48:59upload this. There we go. Let's close
  35606. 22:49:02this out. Now, the data that we're
  35607. 22:49:05hitting off of is right here. So, we're
  35608. 22:49:08not hitting off of this file path. Now,
  35609. 22:49:11we're going to be hitting off of this
  35610. 22:49:12patient data. So let's go back. What we
  35611. 22:49:15need to do now is we need to come back
  35612. 22:49:17up here and we need to create a new
  35613. 22:49:20table. So this new one, we're going to
  35614. 22:49:22do create new table. This is going to be
  35615. 22:49:23uh patient data 2 and we're going to
  35616. 22:49:27choose our healthcare data. Now our data
  35617. 22:49:31set is going to be different. So we're
  35618. 22:49:33going to go into the Alex analyst
  35619. 22:49:35bucket, but now we're going to specify
  35620. 22:49:36patient data. Now, this is important
  35621. 22:49:39because there are no folders and
  35622. 22:49:42subfolders underneath patient data. It's
  35623. 22:49:45just this one folder with our two files
  35624. 22:49:47in it. When we actually run this and we
  35625. 22:49:49query off of this data, it's going to go
  35626. 22:49:52all the metadata is going to go into
  35627. 22:49:53here, but will not mess up our data
  35628. 22:49:56source. And that is very important to
  35629. 22:49:58understand. Now, often times, just as
  35630. 22:50:01you know, a little bit of side note,
  35631. 22:50:03often times when you're working with
  35632. 22:50:04this, you can either set it up like this
  35633. 22:50:05or sometimes people and departments will
  35634. 22:50:08create entire separate buckets just for
  35635. 22:50:10their metadata. So, they can store all
  35636. 22:50:11their metadata in it and then they can
  35637. 22:50:12often they just delete it or whatever.
  35638. 22:50:14So, let's go back here. We're going to
  35639. 22:50:16recreate this. We're going to go to
  35640. 22:50:18Apache Hive and we'll do uh CSV. Note,
  35641. 22:50:22if you do iceberg or delta lake or lake
  35642. 22:50:25formation governed table, these ones
  35643. 22:50:27don't have options for a CSV anyways. So
  35644. 22:50:30that's why we're not looking at it. Um,
  35645. 22:50:32but for Apache Hive, they do have our
  35646. 22:50:35CSV option, which is common delimited.
  35647. 22:50:38Now, we need to go through and we need
  35648. 22:50:39to specify our columns. Again, I'm going
  35649. 22:50:41to skip this because you can just do
  35650. 22:50:43this yourself. But we're just going to
  35651. 22:50:44do this and then we're going to create
  35652. 22:50:45our table. All right, let's go down.
  35653. 22:50:47We're going to go ahead and create this
  35654. 22:50:49table. Query was successful. Let's go
  35655. 22:50:52back to our healthcare data and let's
  35656. 22:50:54refresh this. So now we have our patient
  35657. 22:50:57data 2. Let's go ahead and preview this
  35658. 22:51:00table.
  35659. 22:51:01And this is looking good. Let's get rid
  35660. 22:51:04of this limiter. So let's come over
  35661. 22:51:06here. Let's run this. Now you notice we
  35662. 22:51:09have 42 results which is because we have
  35663. 22:51:13uh one right here. This is from file.
  35664. 22:51:16It's actually file two and this is file
  35665. 22:51:17one but I got that wrong. Uh, but we
  35666. 22:51:19have both files in here that we're
  35667. 22:51:21hitting off of. So, within our S3
  35668. 22:51:23bucket, we have two files of exact data
  35669. 22:51:25and it's creating a union between these.
  35670. 22:51:27It's reading in both of these files and
  35671. 22:51:29it's giving us our output. And of
  35672. 22:51:31course, we have this right here, which
  35673. 22:51:33we don't want. So, we can always filter
  35674. 22:51:35that out. Uh, whoops. Let's come up
  35675. 22:51:37here. Let's say uh where let's do
  35676. 22:51:41patient
  35677. 22:51:43ID. There we go. We'll do is not null.
  35678. 22:51:48And we'll run this. And now this looks
  35679. 22:51:52really good. And so now we're querying
  35680. 22:51:54off of our data and we're not getting
  35681. 22:51:55any of that metadata issues that we were
  35682. 22:51:58experiencing. We come back here in our
  35683. 22:52:00metadata. It's storing all of this. And
  35684. 22:52:03most of this is going to be pretty
  35685. 22:52:04useless to most people. And so often
  35686. 22:52:06times you'll have uh some type of event
  35687. 22:52:08or something in place to delete this
  35688. 22:52:10because you don't want to store this
  35689. 22:52:12long term or most people won't. There
  35690. 22:52:13may be some use cases too, but most of
  35691. 22:52:15the time you're going to get rid of
  35692. 22:52:16this. And so this is Amazon Athena. Now
  35693. 22:52:19you can also create views. If you want
  35694. 22:52:21to tie a bunch of tables together and
  35695. 22:52:23create a view, you can do that. And of
  35696. 22:52:25course this is SQL. So you can write uh
  35697. 22:52:28you know SQL statements like you
  35698. 22:52:30normally would with any SQL environment
  35699. 22:52:32or SQL editor. And so if we want to
  35700. 22:52:34filter, if we want to join uh we can do
  35701. 22:52:37a lot of those things. And so this is a
  35702. 22:52:39fully functioning uh quer editor. Now if
  35703. 22:52:41we come down there are some other things
  35704. 22:52:43that we have. We can copy this data. We
  35705. 22:52:46can download these results. We can clear
  35706. 22:52:49this whole thing. We can also create a
  35707. 22:52:51table from this query or a view from
  35708. 22:52:53this query which is really useful. We
  35709. 22:52:55can also come up here if we want to save
  35710. 22:52:57one of our queries. We'll come over here
  35711. 22:52:59to query five and we're going to save
  35712. 22:53:01as. And we'll call this one uh filter on
  35713. 22:53:06nullles. It's a terrible description.
  35714. 22:53:07We're just going to save that. So we
  35715. 22:53:09have this filter on nulls. And if we
  35716. 22:53:10ever want to reference this again, we
  35717. 22:53:12can uh come back here and we can pull up
  35718. 22:53:15this query and we'll have it available.
  35719. 22:53:18Now, if we come over here on this
  35720. 22:53:19left-hand side, you'll notice we have a
  35721. 22:53:22notebook editor and a notebook explorer.
  35722. 22:53:24So, there are options to create
  35723. 22:53:26notebooks and run notebooks as well.
  35724. 22:53:29That's something I would create a whole
  35725. 22:53:30another lesson on because it's not as
  35726. 22:53:32straightforward as using the SQL option.
  35727. 22:53:35But another thing we can do which is
  35728. 22:53:37within jobs right here is we have
  35729. 22:53:39something called workflows. Now
  35730. 22:53:41workflows are how you can create
  35731. 22:53:43different pipelines and different
  35732. 22:53:45orchestrations with your data and with a
  35733. 22:53:48bunch of different tools within AWS.
  35734. 22:53:50This is definitely a little bit more
  35735. 22:53:52advanced and not something that most
  35736. 22:53:54people are going to use within Athena.
  35737. 22:53:56For a lot of orchestration data flows,
  35738. 22:53:57data pipelines, you're going to be using
  35739. 22:53:59Glue. And so within Glue, we'll be
  35740. 22:54:01taking a look at how we can, you know,
  35741. 22:54:03set everything like this up. But you can
  35742. 22:54:05come in here and you can take a look at
  35743. 22:54:06a bunch of different ones. You can, you
  35744. 22:54:08know, these are different options. You
  35745. 22:54:10can execute multiple queries, query
  35746. 22:54:11large data sets, keep data uh up to
  35747. 22:54:14date, and you can come in here and
  35748. 22:54:16there's lots of different uh things that
  35749. 22:54:17you can do, but again, we're not going
  35750. 22:54:20to be covering it, but go ahead and take
  35751. 22:54:21a look and see if you want to try it
  35752. 22:54:22out. It can get a little bit
  35753. 22:54:24complicated, a little bit complex. These
  35754. 22:54:26are things that people do all the time
  35755. 22:54:27in AWS, especially people like data
  35756. 22:54:30engineers, database developers,
  35757. 22:54:31analytics engineers, people like that.
  35758. 22:54:33And so when we get to Glue, we'll look
  35759. 22:54:35at how to create different workflows,
  35760. 22:54:37data pipelines, uh, and all that stuff.
  35761. 22:54:39So with all that being said, this is the
  35762. 22:54:42meat and potatoes of Athena. Now, who is
  35763. 22:54:45this for exactly? When I was using
  35764. 22:54:48Amazon Athena, it was mostly to query
  35765. 22:54:50data really quickly. A client was giving
  35766. 22:54:52me a file, put it into an S3 bucket so I
  35767. 22:54:54could start querying off of it, and that
  35768. 22:54:56was it. uh most of the time we didn't
  35769. 22:54:58have a full scale production environment
  35770. 22:55:01over on this lefth hand side here with
  35771. 22:55:03tables and views and databases um we
  35772. 22:55:05kept the data separate of course for
  35773. 22:55:07different clients and different projects
  35774. 22:55:09but this was not our primary place to go
  35775. 22:55:12I have consulted and worked with other
  35776. 22:55:14teams where I come in and they're like
  35777. 22:55:16hey here's where we're trying to get
  35778. 22:55:17we're trying to get to this place and
  35779. 22:55:19I'm like okay show me your current you
  35780. 22:55:20know setup how you're working with your
  35781. 22:55:22data how your data flows work and
  35782. 22:55:23everything like that and they'll come in
  35783. 22:55:24and they're like we're only using Amazon
  35784. 22:55:26Athena for quering data and creating
  35785. 22:55:28workflows and automations. If you want
  35786. 22:55:30to be able to scale to a much larger
  35787. 22:55:32scale, this won't work. There are
  35788. 22:55:34several limitations within Amazon
  35789. 22:55:36Athena. As you try to scale, as you try
  35790. 22:55:39to add more data sources, as you try to
  35791. 22:55:41automate all these things, it gets very
  35792. 22:55:43difficult to do within Amazon Athena.
  35793. 22:55:45And so that's when you need to start
  35794. 22:55:46creating different databases like using
  35795. 22:55:48something like RDS or another type of
  35796. 22:55:50SQL server where you can store your
  35797. 22:55:52data, just not within Amazon Athena.
  35798. 22:55:55hitting off of S3 buckets as your main
  35799. 22:55:58uh main way to create kind of your
  35800. 22:56:01database is not optimal by any means.
  35801. 22:56:04And so they might work for kind of a
  35802. 22:56:05smaller company who's just trying to hit
  35803. 22:56:07off some data, but it doesn't work at
  35804. 22:56:09scale very well. So Amazon Athena is
  35805. 22:56:11really good for getting quick insights
  35806. 22:56:13into your data. It's really good when
  35807. 22:56:15you have a ton of data stored in S3 and
  35808. 22:56:17you just want to get simple insights
  35809. 22:56:19into it, want to do simple joins,
  35810. 22:56:21aggregations, and you're not trying to
  35811. 22:56:23do anything too complex with it. This is
  35812. 22:56:25a great place to go because it's
  35813. 22:56:27actually very cheap compared to other
  35814. 22:56:29resources and tools within AWS. This
  35815. 22:56:31really shouldn't be used as a full-scale
  35816. 22:56:33database, especially as your company
  35817. 22:56:35gets larger. You run into a lot of
  35818. 22:56:37roadblocks, a lot of issues, and I've
  35819. 22:56:39seen that firsthand. And so, it's just
  35820. 22:56:40not something I'm going to recommend.
  35821. 22:56:42But Amazon Athena definitely has its
  35822. 22:56:44place and that's why we're looking at it
  35823. 22:56:45because you most likely if you're using
  35824. 22:56:47AWS, you're working as a data scientist,
  35825. 22:56:50data analyst, business analyst, you'll
  35826. 22:56:51use Amazon Athena. A lot of companies
  35827. 22:56:54have it. A lot of companies will use it.
  35828. 22:56:55And so I hope that this was helpful. I
  35829. 22:56:57hope you're able to get up and running,
  35830. 22:56:58understand some of the nuances,
  35831. 22:57:00especially with the folder paths. I
  35832. 22:57:02always found that a little bit confusing
  35833. 22:57:03until I just used it more. but
  35834. 22:57:05understanding how to uh put your tables
  35835. 22:57:08in to the healthcare in here um and
  35836. 22:57:10actually get that uh metadata folders
  35837. 22:57:12working as well. If you liked it, be
  35838. 22:57:14sure to check out my full AWS and Azure
  35839. 22:57:16course on analyst builder.com. And if
  35840. 22:57:18you like the video, be sure to like and
  35841. 22:57:20subscribe. And I will see you in the
  35842. 22:57:21next video.
  35843. 22:57:35What's going on everybody? Welcome back
  35844. 22:57:36to another video. Today we're going to
  35845. 22:57:38be taking a look at Glue and Glue datab.
  35846. 22:57:44[music]
  35847. 22:57:47Now, within the Glue umbrella, which
  35848. 22:57:48includes Glue data brew, it's mostly for
  35849. 22:57:51building pipelines and creating ETL
  35850. 22:57:52processes. This is how you get data from
  35851. 22:57:54one place to another. You can extract
  35852. 22:57:56data, transform data, load the data, and
  35853. 22:57:58do a ton of other things with it. So, in
  35854. 22:58:00this video, we're going to take a look
  35855. 22:58:01at both Glue and Glue Data Brew because
  35856. 22:58:03they're slightly different and they have
  35857. 22:58:04different purposes. So, without further
  35858. 22:58:06ado, let's jump on my screen and take a
  35859. 22:58:07look. All right, let's go down here.
  35860. 22:58:09We're go down to analytics. Now, we're
  35861. 22:58:11going to be taking a look at both AWS
  35862. 22:58:14Glue Data Brew and AWS Glue. Now, we're
  35863. 22:58:17going to start with Data Brew because I
  35864. 22:58:18think it's a little bit more
  35865. 22:58:19userfriendly. There's some nice
  35866. 22:58:21animations. The UI is really uh a little
  35867. 22:58:23bit, I would say, easier to understand.
  35868. 22:58:26And this is often a place where you'll
  35869. 22:58:28come for a lot of your transformations.
  35870. 22:58:29So, let's come in here and you can go
  35871. 22:58:31ahead and take a look at a lot of stuff
  35872. 22:58:33in here. On this right hand side, we
  35873. 22:58:35have data sets, projects, recipes, uh
  35874. 22:58:38jobs, and we'll take a look at a few of
  35875. 22:58:39those while we're in here. And you can
  35876. 22:58:42look at some of the benefits as well.
  35877. 22:58:45And uh Glue Data Brew is awesome. It's
  35878. 22:58:47very much a more visual way to prepare
  35879. 22:58:50your data. It even says it's a visual
  35880. 22:58:52data preparation tool. And so it's a way
  35881. 22:58:54to visualize how your data is changing
  35882. 22:58:56and you can see how it's changing. We
  35883. 22:58:58are not going to just create a project.
  35884. 22:59:00We're going to create a sample project.
  35885. 22:59:01And this is going to give us some sample
  35886. 22:59:03data. We're going to work with it. We're
  35887. 22:59:04going to be cleaning it up, transforming
  35888. 22:59:06it a little bit, and then we'll see how
  35889. 22:59:07we can automate that as well. So let's
  35890. 22:59:09go ahead and create our sample project.
  35891. 22:59:11Let's go ahead and select popular baby
  35892. 22:59:13names in 2020. And then we have to go
  35893. 22:59:16down here and choose a RO name. Now we
  35894. 22:59:19haven't talked a lot about IM roles uh
  35895. 22:59:22within AWS, but for certain things like
  35896. 22:59:25glue data brew glue and a few other
  35897. 22:59:27things you need IM access. So you can
  35898. 22:59:29say create new IM ro and that's what
  35899. 22:59:31we're going to do. Let's go down here
  35900. 22:59:33and we need to actually create um a new
  35901. 22:59:36role for AWS Glue Brew Service. So, it's
  35902. 22:59:40going to create and I'll explain that in
  35903. 22:59:42just a little bit. We'll call this one
  35904. 22:59:43Alex the analyst and I'll call it data
  35905. 22:59:47brew. Let's go ahead and create this
  35906. 22:59:50project. Now, this needs to set up our
  35907. 22:59:53session. It's provisioning some compute
  35908. 22:59:55and getting our session ready, getting
  35909. 22:59:56our data ready, all of these things in
  35910. 22:59:58order to use data brew. But while we're
  35911. 23:00:01in here and while we're waiting for this
  35912. 23:00:02to uh be ready, I want to talk a little
  35913. 23:00:04bit about the UI. So over here we have
  35914. 23:00:07something called a recipe. Now the
  35915. 23:00:09recipe is for when we actually use all
  35916. 23:00:12of these things and we apply different
  35917. 23:00:13changes to the data set, we make any
  35918. 23:00:16transformations, whether we join the
  35919. 23:00:17data, we group the data, we pivot the
  35920. 23:00:19data, it's going to say, okay, you did
  35921. 23:00:21this and then this and then this and
  35922. 23:00:22then this. And you can come in here and
  35923. 23:00:24you can edit this. And so you can say,
  35924. 23:00:26oh, I don't want to actually group it.
  35925. 23:00:27Let me get rid of that. And that'll be
  35926. 23:00:29really easy to do and I'll show you that
  35927. 23:00:30in a little bit. But then we can also
  35928. 23:00:33save this recipe. We can just say, "Oh,
  35929. 23:00:35I want to save this for a future data
  35930. 23:00:37set." Or if you want to use that recipe
  35931. 23:00:39on, you know, if you're bringing in
  35932. 23:00:40multiple uh data sets of the same exact
  35933. 23:00:43data or you have multiple uh data sets
  35934. 23:00:45coming in that are all the same, then
  35935. 23:00:47you may use the same recipe on all of
  35936. 23:00:49them to transform that data consistently
  35937. 23:00:51every single time. Looks like our data
  35938. 23:00:53is done or our session is ready. But
  35939. 23:00:55let's look at this top area. So, this is
  35940. 23:00:57where we can make all of our
  35941. 23:00:58transformations. We can filter, we can
  35942. 23:01:00sort, we can come in here and we can
  35943. 23:01:02click on the clean. And you'll notice
  35944. 23:01:04there are tons of different options in
  35945. 23:01:06here. A lot of ones that you should be
  35946. 23:01:08pretty familiar with if you've ever
  35947. 23:01:09cleaned data before or if you've ever
  35948. 23:01:11done any of my projects in my SQL or
  35949. 23:01:13Excel or Tableau or uh you know, Python
  35950. 23:01:16and all these different ones on data
  35951. 23:01:17cleaning. And these are a lot of really
  35952. 23:01:20popular things in order to clean the
  35953. 23:01:22data. So there's clean, extract, uh you
  35954. 23:01:25can look at duplicates, outliers, you
  35955. 23:01:27can merge your data, you can perform
  35956. 23:01:29functions, you can apply different
  35957. 23:01:31functions to your data. We also have
  35958. 23:01:34things like pivot, group, join, union,
  35959. 23:01:36and others. And there's just a ton in
  35960. 23:01:38here. Now, what we're going to do is
  35961. 23:01:40first we're going to look at our data,
  35962. 23:01:42and then we're going to go through and
  35963. 23:01:44we're going to do a few changes to it so
  35964. 23:01:46you can see how the recipes work and
  35965. 23:01:48then we'll save our recipe. So let's
  35966. 23:01:50come in here. This is a new data set to
  35967. 23:01:52both of us. This is our uh baby names
  35968. 23:01:54data. So we have count, we have gender,
  35969. 23:01:58we have the ID, we have the name, and
  35970. 23:02:00then the year. And so this is pretty
  35971. 23:02:02interesting information. Let's see if
  35972. 23:02:03it's all uh 1880. This looks like just a
  35973. 23:02:06small sample of the data. And we can
  35974. 23:02:09come in here and we can also uh take a
  35975. 23:02:11look at what kind of data types they
  35976. 23:02:13assigned to this data as well. Now, what
  35977. 23:02:15we're going to do is something quite
  35978. 23:02:17simple. We just want to look at the male
  35979. 23:02:20names and we want to take a look at the
  35980. 23:02:22most popular male names per year. So
  35981. 23:02:25that's going to require a bit of
  35982. 23:02:26grouping. So we're going to have to
  35983. 23:02:27group on both the year and the name and
  35984. 23:02:30then we're have to filter based off of
  35985. 23:02:32the gender. Now one other thing to note
  35986. 23:02:35is that right now we're just working
  35987. 23:02:36with a sample of the data. when we
  35988. 23:02:39actually get to the final process and we
  35989. 23:02:41actually create this data cleaning
  35990. 23:02:43process. We can apply this to the entire
  35991. 23:02:46data set or we can apply it to the
  35992. 23:02:47sample. So right now we're just going to
  35993. 23:02:49be working with this sample, but we'll
  35994. 23:02:52of course be using the full data set
  35995. 23:02:54later on. And you can even come up here
  35996. 23:02:56and you can look at this. You can say
  35997. 23:02:57first n rows, last n rows, and random.
  35998. 23:03:01Now, right now we're just looking at the
  35999. 23:03:02first n rows, the first 500 rows of our
  36000. 23:03:05data set. And that may not be a perfect
  36001. 23:03:07sample size. It actually may be better
  36002. 23:03:10to pull random rows because what if we
  36003. 23:03:12have male or female or other things.
  36004. 23:03:15Right now it just looks like we have
  36005. 23:03:16female in our sample and that may not be
  36006. 23:03:19representative of the entire data set.
  36007. 23:03:21So let's come here to random rows. Let's
  36008. 23:03:23choose 500. We're going to load this
  36009. 23:03:25sample. And as you can see we do we do
  36010. 23:03:27have males in here. And so I'm really
  36011. 23:03:29glad we did that because now we kind of
  36012. 23:03:31have a better representation of our
  36013. 23:03:34data. And so I think what we need to do
  36014. 23:03:36let's bring over our recipe. I think
  36015. 23:03:37what we need to do or what we're going
  36016. 23:03:39to do is one, I want to filter where the
  36017. 23:03:42gender is equal to male. Then we're
  36018. 23:03:45going to come over here and we're going
  36019. 23:03:46to try to find the most common name per
  36020. 23:03:48year. Or maybe we'll just group by the
  36021. 23:03:50year and the name and do a count on the
  36022. 23:03:52name. I think that would be really
  36023. 23:03:53interesting. So we're really
  36024. 23:03:54transforming it quite a bit. So what
  36025. 23:03:57we're going to do is we're going to
  36026. 23:03:58filter on this gender. So we're going to
  36027. 23:04:00go over here to filter and we're going
  36028. 23:04:02to go down to by condition. Now we want
  36029. 23:04:04to say where gender is equal to male. So
  36030. 23:04:07you can either do contains and we can do
  36031. 23:04:09contains an M or we can say it is
  36032. 23:04:11exactly. Either one of these will be
  36033. 23:04:14perfectly fine. We're going to do that
  36034. 23:04:16on gender right here. So we have 300
  36035. 23:04:19females, 200 males. We don't want the
  36036. 23:04:21females, so we can get rid of that one.
  36037. 23:04:23We're going to only keep the males. We
  36038. 23:04:25can also enter a value in here. Uh but
  36039. 23:04:27we don't need to do that. And so now
  36040. 23:04:29this is ready to go. We're going to go
  36041. 23:04:30down and we can either preview changes,
  36042. 23:04:32but we're just going to go ahead and
  36043. 23:04:33apply this. And as you can see right
  36044. 23:04:35here in our recipe, it says under our
  36045. 23:04:38applied steps, we have filter values by
  36046. 23:04:40gender. We can either edit this or we
  36047. 23:04:42can delete this. So, at any time if we
  36048. 23:04:44want to change any of this, uh, we can
  36049. 23:04:46do that. But, as you can see in our
  36050. 23:04:48preview in our sample, we now only have
  36051. 23:04:50200 rows and it's all filtered by males.
  36052. 23:04:54Now, what we can do is we're going to
  36053. 23:04:56group this data. We want to do it based
  36054. 23:04:58off of the year and the name. So, let's
  36055. 23:05:00come up here. We're going to group and
  36056. 23:05:03we need to select our columns. So, we're
  36057. 23:05:05going to start with the year and we're
  36058. 23:05:07going to group by the year. And then
  36059. 23:05:08we're going to select the name as well.
  36060. 23:05:11And we'll come down here and we'll say
  36061. 23:05:13group by. But we also wanted and you'll
  36062. 23:05:16notice we also wanted to aggregate these
  36063. 23:05:19values. So, we want the count. So, what
  36064. 23:05:21we're going to do is we're going to come
  36065. 23:05:22in here and we're going to say based off
  36066. 23:05:24of the name, we want a count of the
  36067. 23:05:27names for that year and name. So, we're
  36068. 23:05:28going to do a count here. And so, for
  36069. 23:05:31this new column, you can call it the
  36070. 23:05:32name count, and that'll be perfectly
  36071. 23:05:34fine. This is uh just like an example
  36072. 23:05:36down here. But it shouldn't be a string.
  36073. 23:05:39This should be an integer. And so, if we
  36074. 23:05:41come down here, let's see. There should
  36075. 23:05:43be some that have multiple um higher
  36076. 23:05:45than one,
  36077. 23:05:47at least not in our preview. But still,
  36078. 23:05:50we're working on a sample here. So,
  36079. 23:05:51let's go ahead and finish this. And now
  36080. 23:05:54we have our data right here. Now, again,
  36081. 23:05:57this is only working off the 200 rows.
  36082. 23:05:59We could have 100,000, 50,000 uh in our
  36083. 23:06:02data. But we grouped off of the year and
  36084. 23:06:06then we grouped off of the name and then
  36085. 23:06:07we got a count of the name. Now, what we
  36086. 23:06:10need to do is I also want to filter or
  36087. 23:06:12sorry, sort on this year and we can do
  36088. 23:06:15that uh just by sorting here manually.
  36089. 23:06:18So we can come over here and it's just
  36090. 23:06:19going to do this within our uh window.
  36091. 23:06:22But I actually want to apply a sort to
  36092. 23:06:24here. So I want to do this ascending. So
  36093. 23:06:27the smallest year to the largest year.
  36094. 23:06:29We'll do this based off of the year.
  36095. 23:06:31Then we'll come down here. We'll click
  36096. 23:06:33apply. And now we have our years over
  36097. 23:06:35here in ascending from smallest all the
  36098. 23:06:38way down to largest. So now that we've
  36099. 23:06:40applied all of our steps and really
  36100. 23:06:42transform our data on our sample data
  36101. 23:06:44set, let's go ahead and save this
  36102. 23:06:45recipe. We're going to go ahead and
  36103. 23:06:47publish this. So you can add some notes
  36104. 23:06:49if you would like. We're going to
  36105. 23:06:50publish this. And so now we've saved
  36106. 23:06:52that recipe. And in fact, if we come
  36107. 23:06:54over here to recipes, you can see that
  36108. 23:06:56we've saved this. So we have that
  36109. 23:06:58available. If we go back to our
  36110. 23:07:00projects, we can come up here and we can
  36111. 23:07:02create this job. So we're going to call
  36112. 23:07:05this one the uh name aggregator. This is
  36113. 23:07:09the data set associated with it. And we
  36114. 23:07:12can choose our output. So, where do we
  36115. 23:07:14want this output to be? Let's put it in
  36116. 23:07:16S3. Uh, we can keep it right here. Let's
  36117. 23:07:19go to our S3 location. And let's just
  36118. 23:07:22put it in the Alex the analyst bucket.
  36119. 23:07:24Let's select that. And we have some
  36120. 23:07:26additional options down here. So, we
  36121. 23:07:28have some advanced settings. One, the
  36122. 23:07:30maximum number of units. So, that's to
  36123. 23:07:32do with how many nodes you want on this
  36124. 23:07:34job when it actually runs. You can
  36125. 23:07:37specify if it times out or how many
  36126. 23:07:38times you want it to retry it. This one
  36127. 23:07:41is probably the more important one is if
  36128. 23:07:42you want to schedule this right here. So
  36129. 23:07:45you can come in here and you can create
  36130. 23:07:46a new schedule and you can specify I
  36131. 23:07:48want this recurring every and this says
  36132. 23:07:501 hour but maybe you want it recurring
  36133. 23:07:52or doing on a specific time of the month
  36134. 23:07:55and you want to automate this and run
  36135. 23:07:58this maybe every week or every month and
  36136. 23:08:00get an output of the data that you have.
  36137. 23:08:03So this can be really really useful. You
  36138. 23:08:06can add tags for permissions. We just
  36139. 23:08:08need to specify our role and we can
  36140. 23:08:10create and run this job. This is going
  36141. 23:08:13to take a little bit to run because it's
  36142. 23:08:15going to be working in a much larger
  36143. 23:08:16data set. But in a little bit, it's
  36144. 23:08:18going to run this entire job. It's going
  36145. 23:08:20to output our CSV into our S3 bucket.
  36146. 23:08:24And then we're going to go and take a
  36147. 23:08:26look at it. So, let's go over here to
  36148. 23:08:28jobs and see its status is still
  36149. 23:08:31running. Let's wait for just a little
  36150. 23:08:33bit. And it's going to be doing that on
  36151. 23:08:35the entire uh project. that's not just
  36152. 23:08:37going to be doing that on the sample.
  36153. 23:08:39It's using the uh full data set. And so
  36154. 23:08:41let's wait for this to be done and then
  36155. 23:08:42let's go look at our output. As you can
  36156. 23:08:44see, it succeeded. It took about 2
  36157. 23:08:47minutes. It finished up very quickly or
  36158. 23:08:49just a second ago. Let's come up here to
  36159. 23:08:50our S3 bucket and it should be right in
  36160. 23:08:54here. So let's go ahead and refresh
  36161. 23:08:56this. And now you can see we have this
  36162. 23:08:57new folder name aggregator. Let's click
  36163. 23:08:59in it. And now we have all of these
  36164. 23:09:02CSVs. Now, this is to be expected
  36165. 23:09:04because this is the default option
  36166. 23:09:06within Glue Data Brew. I personally do
  36167. 23:09:09not like this. I want a single CSV
  36168. 23:09:11output as I'm sure most of you do. Let's
  36169. 23:09:13come back up here to our jobs and let's
  36170. 23:09:15go into this name aggregator. Let's come
  36171. 23:09:17over here and we're going to select edit
  36172. 23:09:19job. And now we have right here. This is
  36173. 23:09:22our uh job that we just created. Now,
  36174. 23:09:25what we need to do is get rid of this.
  36175. 23:09:27So we need to go to settings because
  36176. 23:09:28right now for file partitioning we have
  36177. 23:09:32file output options autogenerate files
  36178. 23:09:35default file output setting that
  36179. 23:09:36generates multiple files. This usually
  36180. 23:09:39results in the fastest job runtime which
  36181. 23:09:41can be important uh for some use cases
  36182. 23:09:44especially as you scale your company or
  36183. 23:09:46your business or your department. You
  36184. 23:09:48know these things do matter a lot but
  36185. 23:09:50for what we're doing we want a single
  36186. 23:09:52file output. We also have an option out
  36187. 23:09:55here for our file storage where we can
  36188. 23:09:57create a new folder for each run or
  36189. 23:09:59replace output files for each job run.
  36190. 23:10:02We'll keep it the create, but depending
  36191. 23:10:04on what you're doing, uh you may want to
  36192. 23:10:06replace it as well. Let's go ahead and
  36193. 23:10:08save this. Then we're going to come down
  36194. 23:10:10here and we're going to save it as well.
  36195. 23:10:13And now we need to actually run this. So
  36196. 23:10:15now we're going to click run job and
  36197. 23:10:17we're going to run the same one except
  36198. 23:10:19as a single file output. Let's go ahead
  36199. 23:10:21and run this. Now it's going to be
  36200. 23:10:22running. It's going to take a little bit
  36201. 23:10:24longer than the minute 37 seconds, but
  36202. 23:10:26hopefully not by a lot. So, let's wait
  36203. 23:10:28just a little bit and then we will see
  36204. 23:10:30what it looks like in our S3 bucket. All
  36205. 23:10:32right, this succeeded and somehow took
  36206. 23:10:34less time. Uh, so AWS is just messing
  36207. 23:10:37with us right now. They're lying to us
  36208. 23:10:38completely. Let's go back to our bucket.
  36209. 23:10:41We're going to come back just to the
  36210. 23:10:43bucket. Let's go ahead and refresh this.
  36211. 23:10:45There's our next one. I think this is
  36212. 23:10:48the second one. Uh they have different
  36213. 23:10:50names obviously because we didn't
  36214. 23:10:52overwrite. Let's come into here. And now
  36215. 23:10:54we have our CSV. You can go ahead and
  36216. 23:10:56download that. And in fact, I'm not just
  36217. 23:10:58going to tell you to download it. I'll
  36218. 23:10:59download it, too. So, let's come in
  36219. 23:11:00here. Let's go and download this. All
  36220. 23:11:02right. Let's open this up. And let's
  36221. 23:11:04take a look. So, let's come over here.
  36222. 23:11:07Let's filter this real quick cuz there's
  36223. 23:11:09a lot in here, I'm assuming. Let's come
  36224. 23:11:12over. And it looks like there's only one
  36225. 23:11:14only most common name per year. Uh,
  36226. 23:11:17apparently I completely misunderstood
  36227. 23:11:18the data. Uh, this is probably what they
  36228. 23:11:21did was they took they told us the most
  36229. 23:11:23common year or the most common name per
  36230. 23:11:25year. Um, and I just wasn't thinking
  36231. 23:11:27about it. So, I think we misunderstood
  36232. 23:11:28the assignment. Actually, you know what?
  36233. 23:11:30I'll take the blame. I'll take the
  36234. 23:11:32blame. I misunderstood the assignment.
  36235. 23:11:33But, we do have 25,779
  36236. 23:11:36rows. Uh, and so, you know, just a
  36237. 23:11:38little example of how to use it.
  36238. 23:11:41Although I'm not an expert on that data
  36239. 23:11:42set. So, uh I take full blame for that.
  36240. 23:11:45But you can see the process that we took
  36241. 23:11:47on how to clean the data, change the
  36242. 23:11:48data, and get a correct CSV output.
  36243. 23:11:51Let's go back over to AWS. Let's go back
  36244. 23:11:53to our analyst bucket, and we'll stick
  36245. 23:11:56right here for just a second. Now, one
  36246. 23:11:58thing to note, and this is something
  36247. 23:12:00that you may, some people may have
  36248. 23:12:02encountered when they were trying to run
  36249. 23:12:04this job. It's it may say, oh, you don't
  36250. 23:12:06have access or the ability to do that.
  36251. 23:12:08You may have gotten an error in some
  36252. 23:12:10way.
  36253. 23:12:11What you may need to do, and this is
  36254. 23:12:13something that uh my friend Cassoon over
  36255. 23:12:15at Analyst Builder, he helped me
  36256. 23:12:17understand, is that sometimes AWS
  36257. 23:12:20doesn't give you full functionality
  36258. 23:12:21until you have certain services running
  36259. 23:12:23like an EC2 instance. Now, we're not
  36260. 23:12:25covering EC2 instances in this series,
  36261. 23:12:28but you may need to come in here into
  36262. 23:12:30the EC2 and you can just go to services,
  36263. 23:12:32go make sure to go to EC2, you may need
  36264. 23:12:35to just launch an instance and just
  36265. 23:12:37launch it. And what happened after I
  36266. 23:12:39launched it was it sent me an email and
  36267. 23:12:41said, "Hey, you now have full
  36268. 23:12:42functionality for different things. It's
  36269. 23:12:44super easy. You just come in here, make
  36270. 23:12:46sure you select your uh pair. You can
  36271. 23:12:47just say you don't want one, and then
  36272. 23:12:49you launch an instance." And that's it.
  36273. 23:12:51And after that, you'll hopefully within
  36274. 23:12:53a few minutes or, you know, within the
  36275. 23:12:54day, you'll get an email saying you have
  36276. 23:12:56full functionality. You may need to do
  36277. 23:12:58this. That's just something I want to
  36278. 23:12:59make mention of because I know I
  36279. 23:13:02encountered that when I first did it.
  36280. 23:13:04Now, I had never encountered this before
  36281. 23:13:06because I've used it in a workplace
  36282. 23:13:08where somebody already had all this
  36283. 23:13:10stuff set up, right? We this was a fully
  36284. 23:13:12functioning production and development
  36285. 23:13:13environment and so I didn't have to
  36286. 23:13:15worry about this. But this is a
  36287. 23:13:16completely new account. And so this is a
  36288. 23:13:18free instance. You know, you don't have
  36289. 23:13:20to spend money on this because you get
  36290. 23:13:22two EC2 free tier offers and you can use
  36291. 23:13:25those and it should uh be good to go.
  36292. 23:13:27And you need to do that for what we're
  36293. 23:13:28about to do in just a second. Um, but
  36294. 23:13:31just wanted to mention this. So that is
  36295. 23:13:34how you can use glue datab. Uh and of
  36296. 23:13:38course I want you to get in here. I want
  36297. 23:13:39you to take a look at a bunch of this
  36298. 23:13:41other stuff. You can create rules as
  36299. 23:13:43well for invalidating your data and you
  36300. 23:13:45can send yourself emails. Uh if you know
  36301. 23:13:47it doesn't look good. You can come in
  36302. 23:13:49here and look at all your data sets that
  36303. 23:13:51you have. This is the one that we were
  36304. 23:13:52using the data set national baby names.
  36305. 23:13:54And of course you can always connect to
  36306. 23:13:56new data sets. So if you want to come in
  36307. 23:13:58here, you want to pull data out of an S3
  36308. 23:14:00bucket or from Redshift or you know
  36309. 23:14:03other options within AWS, you can do
  36310. 23:14:05that. So all really really good stuff.
  36311. 23:14:07Now let's go back. We're going to go to
  36312. 23:14:09all services and let's click up here. We
  36313. 23:14:12are going to go all the way down to
  36314. 23:14:15Glue. Now here's what I'll say about
  36315. 23:14:17Glue before we even click into it. Glue
  36316. 23:14:18data brew is very visual. I think it's
  36317. 23:14:20actually fairly easy to use uh compared
  36318. 23:14:24to glue. Glue, I think, is a little bit
  36319. 23:14:26more complicated. Um, not entirely, but
  36320. 23:14:29it is. Um, and so let's look at glue
  36321. 23:14:32really quickly. Now, over on this lefth
  36322. 23:14:34hand side, we have a ton of different
  36323. 23:14:36stuff. Um, and we're not going to be
  36324. 23:14:37looking at everything in here. I'm going
  36325. 23:14:39to look at kind of the more important
  36326. 23:14:41things, but we have something like a
  36327. 23:14:42data catalog. And this we looked at in
  36328. 23:14:44our lesson with Amazon Athena. They have
  36329. 23:14:47the data catalog to set up your
  36330. 23:14:49databases and tables and your schemas.
  36331. 23:14:51And we had crawlers. Now, this is the
  36332. 23:14:53first thing that we're going to look at
  36333. 23:14:54within Glue because this is how you can
  36334. 23:14:56kind of automate pulling in data,
  36335. 23:14:59getting the data types, and pulling in
  36336. 23:15:00that data. And so, it's really useful.
  36337. 23:15:02The next is creating ETL jobs. So, those
  36338. 23:15:05are the two things that we'll be looking
  36339. 23:15:06at in this lesson. There's a ton of
  36340. 23:15:09other things that it does. So, be sure
  36341. 23:15:12to get in here and just check everything
  36342. 23:15:13out because uh Glue does a lot of
  36343. 23:15:16different stuff, and I'm just not
  36344. 23:15:17covering everything, of course, because,
  36345. 23:15:19you know, this would be a 10-hour uh
  36346. 23:15:20lesson. So we have a few different
  36347. 23:15:22things. One, you can prepare your
  36348. 23:15:24account for AWS Glue. Here's your
  36349. 23:15:26catalog for your data sets. And then
  36350. 23:15:28here's how you move and transform your
  36351. 23:15:30data. And so what we're going to do is
  36352. 23:15:32we will need to set up ROS and users.
  36353. 23:15:34We're just not going to do it right now,
  36354. 23:15:35but we will need to set that up. And I'm
  36355. 23:15:36actually going to show you some of the
  36356. 23:15:38IM uh you know on the back in the IM uh
  36357. 23:15:42resource how that actually looks. But
  36358. 23:15:44let's come over here to crawlers.
  36359. 23:15:46And we don't have any crawlers created,
  36360. 23:15:48but we need to. Let's create a crawler.
  36361. 23:15:52And let's create this. And we'll call
  36362. 23:15:54this the uh Alex the analyst crawler
  36363. 23:15:58example. Let's go ahead and click next.
  36364. 23:16:02Now, we need to specify our data source.
  36365. 23:16:04Now, just let me back up one second. You
  36366. 23:16:07know, we want to pull in data to be able
  36367. 23:16:08to use it in different services, and we
  36368. 23:16:10want to do it kind of automatically,
  36369. 23:16:12like I mentioned. And so let's say we're
  36370. 23:16:13pulling in data and we want to put it
  36371. 23:16:14into a database or we want to pull in
  36372. 23:16:16data and we want to put it into Athena.
  36373. 23:16:18These are things that we can automate.
  36374. 23:16:20And so uh we want to specify a data
  36375. 23:16:23source here. So let's go ahead and add a
  36376. 23:16:25data source. We have our S3 bucket.
  36377. 23:16:28That's what we want to do. And this is
  36378. 23:16:29data that we used in previous lessons.
  36379. 23:16:31So if you didn't take those lessons, be
  36380. 23:16:33sure to go and do that. So we're going
  36381. 23:16:35to browse this data. Let's go into the
  36382. 23:16:37Alex analyst bucket. We're going to go
  36383. 23:16:38into patient data. We can specify single
  36384. 23:16:43files but let me just tell you it won't
  36385. 23:16:45work. Um and you know that's just
  36386. 23:16:47because of how the folder system works
  36387. 23:16:49within glue. So we need to specify the
  36388. 23:16:52entire patient data folder. Let's go
  36389. 23:16:55ahead and choose this. And now we have
  36390. 23:16:57on subsequent crawler runs crawl all
  36391. 23:16:59subfolders subfolders only. If you add
  36392. 23:17:01new subfolders to your folder then based
  36393. 23:17:04off of an event. So an event would be
  36394. 23:17:06like something triggering and then you
  36395. 23:17:08uh it runs based off of that. So, we're
  36396. 23:17:10just going to do crawl all subfolders.
  36397. 23:17:12Let's add this data source. Let's go
  36398. 23:17:14ahead and click next. Now, this is the
  36399. 23:17:17part where we need to select an IM RO.
  36400. 23:17:18We don't have one. So, let's go ahead
  36401. 23:17:20and create a new IM roll. I'm going to
  36402. 23:17:22call this Alex glue crawler roll. You
  36403. 23:17:27can call this anything. Let's go ahead
  36404. 23:17:29and create this.
  36405. 23:17:31And it says it successfully created it.
  36406. 23:17:33Let's go ahead and view this.
  36407. 23:17:38So now we're in a totally different part
  36408. 23:17:40of AWS. This is the identity and access
  36409. 23:17:43management. That's our IM. So right here
  36410. 23:17:46we created an IM role. This is the Alex
  36411. 23:17:48group.
  36412. 23:17:50This is the Alex Glue crawler role. And
  36413. 23:17:53then down here we have the permissions
  36414. 23:17:55policies. So right here this is going to
  36415. 23:17:58be giving us access to I believe the S3
  36416. 23:18:00bucket. We can come in here and actually
  36417. 23:18:02look at the policy. So the permissions
  36418. 23:18:04are read and write on a specific uh data
  36419. 23:18:08source and that's going to be our bucket
  36420. 23:18:10with the patient data and I think we can
  36421. 23:18:12come up here to policy versions. Look
  36422. 23:18:16right here and so this is what it looks
  36423. 23:18:18like inside of it. Now this is in JSON
  36424. 23:18:20and you can actually customize these and
  36425. 23:18:22I'm not going to go into all how to do
  36426. 23:18:24that but sometimes you need to depending
  36427. 23:18:26on the data the data source if it's
  36428. 23:18:28encrypted if it's not um what
  36429. 23:18:30permissions you want it to do. But what
  36430. 23:18:32this is doing is it's allowing us to get
  36431. 23:18:34an object and put an object in this
  36432. 23:18:36specific resource. So that's our patient
  36433. 23:18:38data and that star is just a wild card
  36434. 23:18:40to say anything in that file path. So if
  36435. 23:18:42we go back and let's come back to this
  36436. 23:18:44role. We also have this AWS glue service
  36437. 23:18:47role. Now this one right here we created
  36438. 23:18:50when we created the crawler to specify
  36439. 23:18:53the file path of the data set. This is
  36440. 23:18:55AWS manage. This is one that AWS creates
  36441. 23:18:58themselves and we can look at all the
  36442. 23:19:00things. Let me scroll down. We can look
  36443. 23:19:02at all the things that it does uh for
  36444. 23:19:04that AWS Glue service role. Gives us
  36445. 23:19:07access to a ton of things for EC2
  36446. 23:19:08instances, S3, everything within Glue.
  36447. 23:19:11And we can come down here and take a
  36448. 23:19:14look at the buckets, the access to S3 as
  36449. 23:19:17well as a bunch of other stuff. And so
  36450. 23:19:19this is what the IM roles look like. And
  36451. 23:19:21you can create custom policies uh if you
  36452. 23:19:24want to. And you can give access to
  36453. 23:19:26different things. And so again, we're
  36454. 23:19:28not covering this entirely in this
  36455. 23:19:30lesson because this is not a lesson on
  36456. 23:19:32IM roles, but I think it is interesting
  36457. 23:19:34and worth uh worth knowing. So we've
  36458. 23:19:36created our role. Let's go down over
  36459. 23:19:38here. Let's click next. And now we need
  36460. 23:19:41to specify where we're going to be
  36461. 23:19:43putting this. So we're going to put this
  36462. 23:19:45data in our healthcare data. So this is
  36463. 23:19:48our healthcare data. Again, we already
  36464. 23:19:50had created this database back in our
  36465. 23:19:52Amazon Athena. And we have the option to
  36466. 23:19:55uh create a table name prefix or use the
  36467. 23:19:58maximum table threshold for the prefix.
  36468. 23:20:01Let's just say uh crawler. There we go.
  36469. 23:20:04And now we have this crawler schedule
  36470. 23:20:05down here. Now you can do it on demand
  36471. 23:20:07or you can specify whether you want a
  36472. 23:20:10specific day of the month, whether
  36473. 23:20:11weekly, daily, monthly, whatever you
  36474. 23:20:13need. You can create this uh
  36475. 23:20:16scheduleuler in order to run this
  36476. 23:20:18crawler. Let's go ahead and click next.
  36477. 23:20:20And let's just review this real quick.
  36478. 23:20:21This is everything that we chose. We're
  36479. 23:20:23going to go ahead and create our
  36480. 23:20:25crawler. So now it says one crawler was
  36481. 23:20:27successfully created. It's this one
  36482. 23:20:29right here, Alex Analyst crawler
  36483. 23:20:30example. And uh it has not run yet. So
  36484. 23:20:34we've have no crawler runs. But let's go
  36485. 23:20:36ahead and run this crawler. So now we're
  36486. 23:20:38going to start the crawler. It's going
  36487. 23:20:39to start up this that we just created to
  36488. 23:20:41pull in that patient data. And once it
  36489. 23:20:44is completed, we're going to go take a
  36490. 23:20:46look at it in Amazon Athena like we
  36491. 23:20:48looked at in a previous lesson. So right
  36492. 23:20:50down here it says it's running. So once
  36493. 23:20:52that's done running, we're going to take
  36494. 23:20:53a look at that data. All right, it says
  36495. 23:20:54that was completed. Now we can come back
  36496. 23:20:58here to the data catalog connections.
  36497. 23:21:00Let's go ahead and refresh this.
  36498. 23:21:03You can see we have our crawler that's
  36499. 23:21:05our uh prefix that we used and we have
  36500. 23:21:08patient data. This patient data and
  36501. 23:21:10patient data 2 were data cataloges and
  36502. 23:21:12part of our data catalog are tables that
  36503. 23:21:15we created in Amazon Athena. Now let's
  36504. 23:21:18come up here. Let's just duplicate this
  36505. 23:21:20really quickly. We're going to go back
  36506. 23:21:22to Amazon Athena. Let's see if it's
  36507. 23:21:24right here. So, here we go. We have
  36508. 23:21:26Athena.
  36509. 23:21:27And now we can access that data right
  36510. 23:21:30here. So, now if we want to, I can say,
  36511. 23:21:32uh, let's just preview the table.
  36512. 23:21:35It's running. And we have our data in
  36513. 23:21:38here. And so, this is perfect. Um, if
  36514. 23:21:40you remember, we had our patient data
  36515. 23:21:42and patient data 2. We manually entered
  36516. 23:21:45that data to pull that in. And that was
  36517. 23:21:47not super fun. So when we created it, we
  36518. 23:21:49did it from an S3 uh bucket data. But
  36519. 23:21:52with the AWS glue crawler, we can do
  36520. 23:21:54this automatically and then it'll
  36521. 23:21:56refresh our data and we can create this
  36522. 23:21:58uh without having to manually do this
  36523. 23:22:00every time we get a new data source,
  36524. 23:22:02which let me tell you, when you start
  36525. 23:22:03getting into a production environment or
  36526. 23:22:05a development environment, whichever one
  36527. 23:22:06you're in, when you have to start
  36528. 23:22:08bringing in lots of data and the data is
  36529. 23:22:10coming in daily or weekly or monthly,
  36530. 23:22:12you do not want to have to manually do
  36531. 23:22:14this. It takes up so much time. It is
  36532. 23:22:16much better to automate this with an AWS
  36533. 23:22:18glue crawler. So that's during that
  36534. 23:22:20scheduling part right in here and we
  36535. 23:22:23come over to crawlers. We come in here.
  36536. 23:22:26This is just on demand, but we can edit
  36537. 23:22:29this and we come down here and we can
  36538. 23:22:31schedule it down here if we want to. But
  36539. 23:22:34you can also now we have it on demand.
  36540. 23:22:36So anytime we want to run it, we can
  36541. 23:22:37also just run it on demand. Um so it's,
  36542. 23:22:40you know, really really great to have
  36543. 23:22:42and use. So that's how we use crawlers.
  36544. 23:22:44And crawlers are amazing. Oftentimes, if
  36545. 23:22:47you're using this in your work, you're
  36546. 23:22:48going to have tons of them, like 50 to
  36547. 23:22:50100 of them um running, and you'll be
  36548. 23:22:53scheduling them, and some of them will
  36549. 23:22:54break because a data set changed or
  36550. 23:22:56whatever. Um and so this is a really
  36551. 23:22:59great thing to test out, try with
  36552. 23:23:01different data sets, uh and really get
  36553. 23:23:03familiar with it because crawlers are
  36554. 23:23:04amazing. Let's go down here. Let's go to
  36555. 23:23:07ETL jobs. So, this is the last thing
  36556. 23:23:10that we're going to be taking a look at
  36557. 23:23:11in this lesson. There is of course more
  36558. 23:23:13to AWS glue, but this is kind of like
  36559. 23:23:16the two most important things I would
  36560. 23:23:18say. So, let's go over here to a visual
  36561. 23:23:21ETL. And what we're going to do is we're
  36562. 23:23:23going to build out I don't think I have
  36563. 23:23:25an unsaved job. We're going to build out
  36564. 23:23:27um our very first ETL job within AWS
  36565. 23:23:31Glue. Now, what we have here, and I'll
  36566. 23:23:33talk a little bit more about this in a
  36567. 23:23:35little bit. We have parent node, and we
  36568. 23:23:37have uh the child node. I think it's
  36569. 23:23:40node if that's the right term, but we
  36570. 23:23:41have parent and child uh different nodes
  36571. 23:23:44that we have in here and we need to make
  36572. 23:23:46sure we chain them properly. Now,
  36573. 23:23:48luckily we have this ETL visual tool and
  36574. 23:23:50that's what we're in right now is be
  36575. 23:23:52able to see what we're doing when we're
  36576. 23:23:54in here. Now, let's come over here and
  36577. 23:23:56let's go back to our sources because we
  36578. 23:23:58have to have a source to start out with.
  36579. 23:24:00So, let's go to Amazon S3 and we're
  36580. 23:24:03going to click into this Amazon S3. So,
  36581. 23:24:06we're going to pull data from our Amazon
  36582. 23:24:09S3 bucket. We need to specify our
  36583. 23:24:11location and we can either make it
  36584. 23:24:13recursive or not recursive and I'll
  36585. 23:24:15explain that in just a second. Now,
  36586. 23:24:17let's come in here. We'll go into our
  36587. 23:24:18bucket. We'll go into our patient data.
  36588. 23:24:21Now, let's specify just this first file
  36589. 23:24:23here. We really don't need recursive
  36590. 23:24:25because I don't have any sub
  36591. 23:24:26directories. So, we can turn that off or
  36592. 23:24:28you can keep it on. We also have a data
  36593. 23:24:31format. The our data format is not uh no
  36594. 23:24:34format. We have a CSV format which is
  36595. 23:24:36commaepparated.
  36596. 23:24:38Now what it's kind of prompting us to do
  36597. 23:24:40down here and I highly recommend doing
  36598. 23:24:42it is getting a data preview. So we can
  36599. 23:24:44see the data as we're transforming it
  36600. 23:24:45and changing it. So I am going to come
  36601. 23:24:48in here and I am going to specify this
  36602. 23:24:50role that we had created earlier. And
  36603. 23:24:52we're going to start this session. This
  36604. 23:24:54could take just a little bit of time but
  36605. 23:24:55we're going to get a data preview down
  36606. 23:24:57right here at the bottom. And now our
  36607. 23:24:59data preview is ready. We're looking at
  36608. 23:25:02uh this file right here. Next, what
  36609. 23:25:03we're going to do is we're going to come
  36610. 23:25:05over here to add a node and we're going
  36611. 23:25:06to go to transform and we're going to
  36612. 23:25:09join. Now, we have to specify
  36613. 23:25:13uh a few things here. One, we can name
  36614. 23:25:15this. So, it's just called a join. Next,
  36615. 23:25:17our node parent, and this is what I was
  36616. 23:25:19talking about before with the parents.
  36617. 23:25:22So, this parent is our first data
  36618. 23:25:24source, which is just called Amazon S3,
  36619. 23:25:26which we could change. We can come in
  36620. 23:25:28here. We can call this uh patient data
  36621. 23:25:31one. We can call this patient data 1.
  36622. 23:25:33Then we'll come down here and go to the
  36623. 23:25:35join. And notice if you come in in here,
  36624. 23:25:37we only have one data source. So we need
  36625. 23:25:40to specify a second data source. So
  36626. 23:25:43let's come back out here. Let's come up.
  36627. 23:25:45Let's go back to our sources and we'll
  36628. 23:25:47pull in our second one. I'm actually
  36629. 23:25:50going to change uh this view really
  36630. 23:25:52quickly. I like it going left to right,
  36631. 23:25:54but some people like it going up to
  36632. 23:25:56down. Um, you can just do that using
  36633. 23:25:58this button right here, which is the
  36634. 23:25:59direction, but I like this direction a
  36635. 23:26:01little better. So, we're going to come
  36636. 23:26:02into this bucket. Let's call this
  36637. 23:26:04patient data 2. And let's specify
  36638. 23:26:09our other patient data, which is our
  36639. 23:26:10second, which is number two, which
  36640. 23:26:12actually says file one in it, but you
  36641. 23:26:14know, just ignore that. Okay. Um, we are
  36642. 23:26:18going to do that right there. We already
  36643. 23:26:19have our preview. And now we need to go
  36644. 23:26:21back to our join and specify these are
  36645. 23:26:24the two things that we are joining
  36646. 23:26:26together. Now if we do uh an inner join,
  36647. 23:26:29it's not going to work cuz these data
  36648. 23:26:30sets are extremely uh familiar. In fact,
  36649. 23:26:33if we come in here and look at the data,
  36650. 23:26:35there aren't any patient datas to join
  36651. 23:26:37on or patient IDs to join on. Um they're
  36652. 23:26:40all unique. And so what we're going to
  36653. 23:26:41do is we should actually be doing a
  36654. 23:26:44union here. Let's actually get rid of
  36655. 23:26:45this. You know what? That was my
  36656. 23:26:47mistake. Let's go to transform.
  36657. 23:26:50Let's come down. Let's find a union or
  36658. 23:26:52let me search for it. So, I'm going to
  36659. 23:26:54do a union. So, we're going to do a
  36660. 23:26:55union right here. There we go. And let's
  36661. 23:26:59go into our union. And we're going to
  36662. 23:27:00specify our parent nodes. We have boom
  36663. 23:27:02and boom. That's one and two. And it's
  36664. 23:27:04going to be working on this data
  36665. 23:27:06preview. There we go. Let's scroll down
  36666. 23:27:08a little bit. And now they're all in
  36667. 23:27:10there, which is perfect. That's exactly
  36668. 23:27:12what we want. File one and file two,
  36669. 23:27:14which is actually file one and file two.
  36670. 23:27:16So, we are good to go. This is looking
  36671. 23:27:18really, really good. Let's come back
  36672. 23:27:20here and let's take a look at what comes
  36673. 23:27:24next. So, we've uh created our sources.
  36674. 23:27:27We had two data sources. Let me pull
  36675. 23:27:28this over here. And I can't pull this
  36676. 23:27:31over anymore. Um, but we have our data
  36677. 23:27:33sources. And again, you can pull this
  36678. 23:27:35data in from anywhere. We've done one
  36679. 23:27:37transformation. Now, we can do other
  36680. 23:27:40transformations as well. We can even
  36681. 23:27:42write a SQL query. We can look at uh
  36682. 23:27:44filling in missing values if we need to.
  36683. 23:27:46We can aggregate our data, drop
  36684. 23:27:49duplicates. These are a lot of the
  36685. 23:27:50different things that we looked at in
  36686. 23:27:51Glue Data Brew. Um, and there's even
  36687. 23:27:53more options uh in here as well that are
  36688. 23:27:56kind of unique to Glue. But lastly, what
  36689. 23:27:59we need to do is then we need to specify
  36690. 23:28:01our target location. Where do we
  36691. 23:28:04actually want this data to go? And so we
  36692. 23:28:06can put it into things like an Azure uh
  36693. 23:28:09SQL database. It could go into
  36694. 23:28:11Snowflake. and go into a SQL server,
  36695. 23:28:13Postgrace, MySQL, Redshift, or we can
  36696. 23:28:15just put it back in an S3 bucket, which
  36697. 23:28:17is by far uh the most simplest thing you
  36698. 23:28:19can do. We could also take this data and
  36699. 23:28:22put into the glue data catalog. And so,
  36700. 23:28:24if we want to use this in Athena, we
  36701. 23:28:26have a much, you know, bigger process
  36702. 23:28:27and then we want to put it into or query
  36703. 23:28:30that data in Athena, we can do that. So,
  36704. 23:28:32there's a lot of different places and
  36705. 23:28:34things that we can do. Let's just come
  36706. 23:28:36back and put it into an S3 bucket
  36707. 23:28:38because that is going to be the simplest
  36708. 23:28:40thing to do. So we have our process and
  36709. 23:28:42there at the very end we're going to put
  36710. 23:28:44it into a CSV file. We don't need any
  36711. 23:28:47type of compression here but uh we do
  36712. 23:28:50have an option data catalog update
  36713. 23:28:52options. Let me zoom in while we're
  36714. 23:28:54here. We have our data catalog update
  36715. 23:28:56options. So we can create a table in the
  36716. 23:28:58data catalog on subsequent runs update
  36717. 23:29:00the schema and add new partitions or we
  36718. 23:29:02can create a table in data catalog and
  36719. 23:29:04on subsequent runs keep existing schema
  36720. 23:29:06and add new partitions. So, I'm going to
  36721. 23:29:08click on this one right here. And we'll
  36722. 23:29:10specify our database. That's going to be
  36723. 23:29:11our healthcare data. Our table name,
  36724. 23:29:14we'll call this one uh the ETL. I'll do
  36725. 23:29:17underscore patient data. And then we'll
  36726. 23:29:20come up here for our S3 target location.
  36727. 23:29:23So, we're going to come back. We'll just
  36728. 23:29:24place it in the Alex the analyst bucket.
  36729. 23:29:27Let's go ahead and choose this. And we
  36730. 23:29:29have a fully functioning ETL process. We
  36731. 23:29:32took two data sets, we union them
  36732. 23:29:34together, and then we have our output.
  36733. 23:29:36And of course, we can see every step of
  36734. 23:29:38the way what we're doing here. Now, if
  36735. 23:29:40we wanted to uh because we already have
  36736. 23:29:42this full process, right? If we wanted
  36737. 23:29:45to, what if we wanted to add in an extra
  36738. 23:29:47part? Let's say we wanted to come in
  36739. 23:29:49here and we wanted to transform this
  36740. 23:29:51union. Let's do an aggregation. So, we
  36741. 23:29:53wanted to perform an aggregation on
  36742. 23:29:55this. So, let's go to aggregation.
  36743. 23:29:58Now, this doesn't look right. Right. We
  36744. 23:30:00can't union it and then aggregate it and
  36745. 23:30:04also send it out. Well, we can, but it
  36746. 23:30:07doesn't really make sense for what we're
  36747. 23:30:08doing. So, what we're going to do is
  36748. 23:30:10let's say we want to union on maybe a
  36749. 23:30:12diagnosis and look at the average age or
  36750. 23:30:15maybe a treatment. Uh, could be
  36751. 23:30:16anything. But let's come down here.
  36752. 23:30:19Let's click on this aggregate. What we
  36753. 23:30:22want to do is we want to put it where
  36754. 23:30:24this is its parent. And then for the S3,
  36755. 23:30:26the new parent for this is going to be
  36756. 23:30:28the aggregation. So, this is correct
  36757. 23:30:31because you can see we have this line
  36758. 23:30:32flowing here. This part is correct. we
  36759. 23:30:34will need to aggregate it in just a
  36760. 23:30:36second. But we need to come up here and
  36761. 23:30:38we need to change this parent node to
  36762. 23:30:40the aggregate and then get rid of the
  36763. 23:30:43union. And so now we've changed our
  36764. 23:30:47workflow here. We've changed the ETL
  36765. 23:30:49process. So now we need to go to
  36766. 23:30:50aggregate. Now we're going to come over
  36767. 23:30:52here and we need to be able to aggregate
  36768. 23:30:54our data. So we have to uh select the
  36769. 23:30:56fields to group by and we have to
  36770. 23:30:58perform our aggregation on a specific
  36771. 23:31:00column. But when we come in here, notice
  36772. 23:31:04all of these are string. We have string,
  36773. 23:31:06string, string, string, and string. And
  36774. 23:31:09that's not correct. Uh that's actually
  36775. 23:31:11incorrect. What we need to do is we need
  36776. 23:31:14to come in here and after this union, we
  36777. 23:31:17need to add an additional step. That's
  36778. 23:31:18going to be our change schema. And then
  36779. 23:31:22we'll select this aggregate real quick.
  36780. 23:31:24And we're going to put it on the change
  36781. 23:31:26schema. There we go. So we're just
  36782. 23:31:28adding multiple steps here, but we need
  36783. 23:31:30to specify what our data actually is.
  36784. 23:31:32And we can see when we make the change
  36785. 23:31:34what'll happen. So we can keep this or
  36786. 23:31:36we can make this an integer. The uh name
  36787. 23:31:39is going to be a string. The age needs
  36788. 23:31:41to be an integer as well. We have string
  36789. 23:31:44for both of these. And then a file needs
  36790. 23:31:46to be an integer. And so this is looking
  36791. 23:31:49really really good. Everything should be
  36792. 23:31:52working properly. We shouldn't have any
  36793. 23:31:54mistakes. Um, often times it'll, you
  36794. 23:31:56know, show all blanks if you're doing
  36795. 23:31:58something wrong. So now we can come over
  36796. 23:32:01here to our aggregation and say we
  36797. 23:32:03wanted to do this based off of the
  36798. 23:32:06diagnosis. Then we come down to here.
  36799. 23:32:08This is the um aggregation. Which field
  36800. 23:32:10do we want to aggregate on? It's going
  36801. 23:32:12to be on age. And we'll just do let's do
  36802. 23:32:15an average. Just keeping it simple. So
  36803. 23:32:18now this is good. And we can even take a
  36804. 23:32:20look at this right here. So this is our
  36805. 23:32:24data that we're going to be outputting
  36806. 23:32:26into a CSV file. And then for our data
  36807. 23:32:30target, we've already specified
  36808. 23:32:32everything that we need. And of course
  36809. 23:32:34creating the data catalog as well. So
  36810. 23:32:37this is ready to go. Let's go ahead and
  36811. 23:32:40uh let's go over to job details just
  36812. 23:32:41really quick. We want to change this.
  36813. 23:32:43We're going to say uh first ETL. There
  36814. 23:32:46we go. We can come down here and there's
  36815. 23:32:49a few different things that you can
  36816. 23:32:50change if you want. You can change the
  36817. 23:32:53type of job that it's going to be. You
  36818. 23:32:55can change the glue version, the
  36819. 23:32:56language, the worker type, bunch of
  36820. 23:32:59different stuff in here, but I don't
  36821. 23:33:00recommend uh you doing any of that if
  36822. 23:33:03I'm being honest. The other thing while
  36823. 23:33:05we're in here, and I'm just going to
  36824. 23:33:07mention this, although I'm not going to
  36825. 23:33:08show this to you uh because this gets
  36826. 23:33:10quite complicated. I do cover this in
  36827. 23:33:12the AWS and Azure course on Analyst
  36828. 23:33:14Builder, but it gets a little bit
  36829. 23:33:16complicated in here. But this is the
  36830. 23:33:18code that's being generated from your
  36831. 23:33:20visual. So this visual is actually
  36832. 23:33:22writing uh to AP py file. Now you can
  36833. 23:33:25get in here and change a lot of things.
  36834. 23:33:28Um and actually it's helpful if you want
  36835. 23:33:31certain functionalities to get in here
  36836. 23:33:32and change these things, but we're not
  36837. 23:33:34going to be doing that in this lesson. I
  36838. 23:33:36just wanted to show this to you. If you
  36839. 23:33:37want to edit the script, you won't be
  36840. 23:33:39able to use the visual ETL anymore cuz
  36841. 23:33:41that's for kind of simpler visual things
  36842. 23:33:44where you're doing it exactly how they
  36843. 23:33:46have it kind of made for you. But if you
  36844. 23:33:48want to go and start doing custom
  36845. 23:33:49things, which you can do, and it's
  36846. 23:33:50pretty awesome, you're just going to
  36847. 23:33:52have to confirm this, and then you won't
  36848. 23:33:53be able to use the visual anymore. So,
  36849. 23:33:55just be warned. Uh that is uh that is
  36850. 23:33:58something. So, job has not been saved.
  36851. 23:34:00Let's go ahead and save this. This is
  36852. 23:34:02our first ETL. We successfully created
  36853. 23:34:04this. And now, we need to run this. So,
  36854. 23:34:06let's go ahead and run this. Let's go to
  36855. 23:34:08our run details. This process is
  36856. 23:34:11running, and we had multiple steps of
  36857. 23:34:12our first ETL uh job that we created.
  36858. 23:34:15Now we're going to let it run and then
  36859. 23:34:16when it's done running we'll take a look
  36860. 23:34:18at the output. It looks like our run
  36861. 23:34:20failed this happens. Let's see what
  36862. 23:34:23actually occurs. It says an error
  36863. 23:34:24occurred when calling the py write
  36864. 23:34:27dynamic frame access denied. Um so let's
  36865. 23:34:31go back. Uh let's go to visual. Let's go
  36866. 23:34:35see which role we actually took. Or
  36867. 23:34:38maybe uh that's in a different place cuz
  36868. 23:34:40maybe we need to go to the im and give
  36869. 23:34:42uh different uh different options here.
  36870. 23:34:44And here we go. So now we have this AWS
  36871. 23:34:46uh glue service ro. Let's come over
  36872. 23:34:48here. Let's go in and actually look at
  36873. 23:34:51this glue crawler ro. Maybe we'll give
  36874. 23:34:53it admin privileges uh just for this
  36875. 23:34:55example, though you probably wouldn't do
  36876. 23:34:57that in real life. But let's go over to
  36877. 23:35:00uh let's go let's go to the EC2 cuz we
  36878. 23:35:02don't need that one. Let's go to the IM.
  36879. 23:35:05So let's go back to all services. It
  36880. 23:35:08should be right over here. Yep. In the
  36881. 23:35:10security identity compliance.
  36882. 23:35:12Let's click into here. Let's go to our
  36883. 23:35:16rolls.
  36884. 23:35:18And it should be this Alex glue crawler
  36885. 23:35:20roll. Let's make sure that's the right
  36886. 23:35:21one. Alex glue crawler roll. So, let's
  36887. 23:35:23go into this Alex glue craw crawler
  36888. 23:35:25roll. It's tough to say. Um, it is
  36889. 23:35:27possible that we didn't have the correct
  36890. 23:35:29access. So, let's go into I guess we we
  36891. 23:35:32are getting um we're getting a lesson in
  36892. 23:35:34a little bit in IM. We're going to
  36893. 23:35:35attach a policy to this. We're just
  36894. 23:35:37going to give our guy straight up admin
  36895. 23:35:38access. So, we're going to say uh admin.
  36896. 23:35:40Now, there's a bunch of different admins
  36897. 23:35:42in here. There should be one just says
  36898. 23:35:44admin full access. Maybe it's this one.
  36899. 23:35:47Yeah, it's allow everything. So, this is
  36900. 23:35:48the one we're looking for. So, we're
  36901. 23:35:50just going to attach this policy to this
  36902. 23:35:53person. I think it was an S3 uh thing. I
  36903. 23:35:56think we just didn't have access to the
  36904. 23:35:58correct bucket or something. Um I'm not
  36905. 23:36:01100% sure, but this is saved. It was
  36906. 23:36:03attached to the RO. Let's go and try to
  36907. 23:36:05run this again. So, let's go. Um
  36908. 23:36:09there's our visual, but we can just run
  36909. 23:36:11this again. Then we'll go to runs and
  36910. 23:36:14hopefully this will not fail again. If
  36911. 23:36:16it does, we'll try to work through it,
  36912. 23:36:18right? These things happen. This is very
  36913. 23:36:20common. So, let's go ahead and give it a
  36914. 23:36:22go and see if this one works this time.
  36915. 23:36:24And just like that, we figured it out.
  36916. 23:36:27We always do. It succeeded. Um so, it's
  36917. 23:36:29just a permission issue. And uh believe
  36918. 23:36:32it or not, that is extremely extremely
  36919. 23:36:34common. Um so, that succeeded. Let's go
  36920. 23:36:37over here to our query editor. Let's go
  36921. 23:36:39ahead and refresh this. We have our ETL
  36922. 23:36:42patient data. Let's go ahead and preview
  36923. 23:36:45this table.
  36924. 23:36:47Now, it's being separated by commas. It
  36925. 23:36:49didn't uh doesn't look like it separated
  36926. 23:36:51out exactly how we wanted or maybe we
  36927. 23:36:53did it wrong. Uh I'm not sure, but it's
  36928. 23:36:57in there. It's just not in the right
  36929. 23:36:59format. So, that's something you can
  36930. 23:37:00definitely fix. Let's go over to our
  36931. 23:37:02bucket. Let's go right here and refresh
  36932. 23:37:05this. If we come down here, we have a
  36933. 23:37:08ton of these really tiny files, like 21
  36934. 23:37:11bytes. Uh, really, really tiny. Let's go
  36935. 23:37:14down to the bottom. This unsave. Let's
  36936. 23:37:17see what this is. We have these CSVs in
  36937. 23:37:19here. Let me let's go into this really
  36938. 23:37:22quick and let's download this and let's
  36939. 23:37:25open this up. And so, this is our
  36940. 23:37:28original data its. So, this is part of
  36941. 23:37:30the original uh data set. This is not
  36942. 23:37:33part of our actual output.
  36943. 23:37:35Let's go back.
  36944. 23:37:40If we come down here, let's take a look
  36945. 23:37:42at any of these. This is just part of
  36946. 23:37:44the run object. And so that is not a
  36947. 23:37:47file.
  36948. 23:37:49And let's scroll down. So we're getting
  36949. 23:37:50this really weird output. Let's actually
  36950. 23:37:52go back. Let's go back to our visual.
  36951. 23:37:57And so for the format, we chose CSV,
  36952. 23:38:00which should be fine. uh we have
  36953. 23:38:03compression type as none but maybe we
  36954. 23:38:05need a compression type and then we
  36955. 23:38:07putting this in the healthcare data and
  36956. 23:38:09so maybe we don't want the CSV type or
  36957. 23:38:11maybe we need some type of compression
  36958. 23:38:13maybe we need to zip this up so let's
  36959. 23:38:16try doing this in something like a
  36960. 23:38:18parquet file really great file maybe we
  36961. 23:38:21want to put in a snappy compression
  36962. 23:38:23feeling wild um I'm going to keep it
  36963. 23:38:25like this just for now let's try it but
  36964. 23:38:28it looks like we need to aggregate this
  36965. 23:38:30properly and so let's Go back in here.
  36966. 23:38:32Let's choose diagnosis. I guess it
  36967. 23:38:34forgot what we were doing over here.
  36968. 23:38:36We'll do age aggregate function is
  36969. 23:38:39average. And now that's working again.
  36970. 23:38:41So let's go over here. Let's uh try a
  36971. 23:38:44parquet file. Let's save this. And then
  36972. 23:38:47we are going to run this. Let's come
  36973. 23:38:49over here to run details and let's let
  36974. 23:38:52that run and see what happens. It looks
  36975. 23:38:54like this one failed. Let's come back
  36976. 23:38:55over here.
  36977. 23:38:57Looks like we may need some compression.
  36978. 23:38:59Let's go back to our visual.
  36979. 23:39:01Let's add snappy compression. Although
  36980. 23:39:04I'm not a fan. Let's go ahead and save
  36981. 23:39:06this
  36982. 23:39:08and let's run this and let's try again.
  36983. 23:39:13All right, this one succeeded. Let's go
  36984. 23:39:15down here. Let's click refresh really
  36985. 23:39:17quick.
  36986. 23:39:19Go down to our patient data. Actually,
  36987. 23:39:22we have it right here. Let's go ahead
  36988. 23:39:23and run again.
  36989. 23:39:25Let's go down. Still doing the same
  36990. 23:39:27thing. Let's go to our S3 bucket. I
  36991. 23:39:30should have cleaned this up first
  36992. 23:39:31because that's just going to keep
  36993. 23:39:32getting messy. But if we scroll down,
  36994. 23:39:35now we have all these parquet files.
  36995. 23:39:38Now, this is still a lot better than
  36996. 23:39:39what we had because now we can pull in
  36997. 23:39:41these parquet files and we can join them
  36998. 23:39:44together. And that's just kind of a
  36999. 23:39:45typical run with an ETL job. Um, and so
  37000. 23:39:48this is actually a lot lot better. If we
  37001. 23:39:51want it all in one file, unfortunately,
  37002. 23:39:54there is not a very easy way to do this.
  37003. 23:39:56We can come in here and go to Amazon S3.
  37004. 23:40:00There's not really a great way or an
  37005. 23:40:02easy way to be able to do this. And so
  37006. 23:40:04what you need to do if if you want it
  37007. 23:40:05all in one file or you want it in a
  37008. 23:40:07specific format, you have to script it
  37009. 23:40:08out yourself. Um, again, it's not crazy
  37010. 23:40:11hard to do once you've gotten in here
  37011. 23:40:13and you kind of understand a little bit.
  37012. 23:40:14But if you want to be able to do some of
  37013. 23:40:16these custom things within using ETL,
  37014. 23:40:18this is how you do it. Um, within the
  37015. 23:40:20visual, it kind of limits you. So this
  37016. 23:40:22would still be good. this type of ETL
  37017. 23:40:25process um would still be perfectly fine
  37018. 23:40:27because it's just going to append all of
  37019. 23:40:29this uh data if you're putting into a
  37020. 23:40:31database or something like that. That'd
  37021. 23:40:33be perfectly fine. And so not as clean
  37022. 23:40:35of an output as data brew was when we
  37023. 23:40:38were working with these ones up here,
  37024. 23:40:41but we are able to do different things
  37025. 23:40:42that data brew isn't able to do within
  37026. 23:40:45Glue Studio. And so this is how you use
  37027. 23:40:47it. This is how you create these ETL
  37028. 23:40:48jobs. Sometimes you got to get in and
  37029. 23:40:50you have to customize a little bit to
  37030. 23:40:51get the exact output that you want or
  37031. 23:40:54are looking for. Um, but I'm going to
  37032. 23:40:55have to come in here. I'm going to clean
  37033. 23:40:57this up. Uh, because this is a mess now,
  37034. 23:41:00but this is how you use uh, glue and
  37035. 23:41:03glue data brew. Once you get in here and
  37036. 23:41:04start trying it out and messing with all
  37037. 23:41:06this stuff, you'll understand, right? As
  37038. 23:41:08you start using it more, this is not
  37039. 23:41:10uncommon. This actually happens all the
  37040. 23:41:12time and is not a bad thing if you know
  37041. 23:41:13how to use the data correctly. Now, like
  37042. 23:41:15I said, there is a ton more to AWS Glue
  37043. 23:41:18than just these two things, although
  37044. 23:41:21those are kind of uh some of the bigger
  37045. 23:41:22things that I wanted you to know how to
  37046. 23:41:24use, but there are things like workflows
  37047. 23:41:26and triggers and things like schemas.
  37048. 23:41:30And these are of course the most popular
  37049. 23:41:31ones. So, make sure to know these ones
  37050. 23:41:33and we covered some of them in this
  37051. 23:41:34lesson. But Glue is very expansive and
  37052. 23:41:37you're going to use it for a lot of
  37053. 23:41:38different things. Now, if you're a data
  37054. 23:41:39analyst and you're working on something
  37055. 23:41:41like a data collection team, uh, which
  37056. 23:41:43is something that I worked on for many
  37057. 23:41:44years, then you might be getting in here
  37058. 23:41:46and using this quite a bit. But if
  37059. 23:41:48you're just a data analyst and you're
  37060. 23:41:49waiting for the data engineer or
  37061. 23:41:51database developer or whoever's, you
  37062. 23:41:52know, bringing in this data, if you're
  37063. 23:41:54waiting for them to bring in the data,
  37064. 23:41:55most likely you're not going to get in
  37065. 23:41:57here that much. You might inform them.
  37066. 23:41:59You might say, "Hey, I was looking at
  37067. 23:42:01the data. Uh, the data looks bad or
  37068. 23:42:03there was something wrong with it." So,
  37069. 23:42:04you're looking for quality issues
  37070. 23:42:06immediately. Then you'd relay that to a
  37071. 23:42:08data engineer and say, "Hey, could you
  37072. 23:42:09go and check out that job that brought
  37073. 23:42:11in that data and then they would go and
  37074. 23:42:13check it." That's typically how you know
  37075. 23:42:15that would actually work. So, just
  37076. 23:42:16something to be aware of uh with Glue.
  37077. 23:42:19But, uh, Glue, Glue datab
  37078. 23:42:23crawlers, as well as ETL, all stuff that
  37079. 23:42:25I recommend you testing out, trying out,
  37080. 23:42:27figuring out how it all fits together
  37081. 23:42:29and works. With all that being said,
  37082. 23:42:30that is the end of the lesson. If you
  37083. 23:42:32haven't already, be sure to check out my
  37084. 23:42:33AWS and Azure course on Analyst Builder.
  37085. 23:42:36I go a lot more in depth into Glue and
  37086. 23:42:39everything in it. We even create some
  37087. 23:42:40custom scripts in here to put it all in
  37088. 23:42:43one file, which is really uh useful to
  37089. 23:42:45know how to do. So, if you're curious
  37090. 23:42:46about how to do that, be sure to check
  37091. 23:42:48out that course. If you have not, be
  37092. 23:42:50sure to like and subscribe below, and I
  37093. 23:42:52will see you in the next video.
  37094. 23:42:55[music]
  37095. 23:43:00>> [music]
  37096. 23:43:05>> What's going on everybody? Welcome back
  37097. 23:43:07to another video. Today we're going to
  37098. 23:43:08be taking a look at Quicksite in AWS.
  37099. 23:43:11[music]
  37100. 23:43:17Now Quicksite is AWS's data
  37101. 23:43:19visualization [music]
  37102. 23:43:19tool. And so a lot of companies when
  37103. 23:43:21they get into AWS's ecosystem, they have
  37104. 23:43:24really simple needs for their data
  37105. 23:43:25visualization and they just use the
  37106. 23:43:27internal tool which is QuickSite. It's
  37107. 23:43:29not the most robust tool you've ever
  37108. 23:43:30seen in your life, but we're going to
  37109. 23:43:32take a look and see how it actually
  37110. 23:43:33works and I'll make a lot of comparisons
  37111. 23:43:35to things like PowerBI and Tableau which
  37112. 23:43:37are really popular data visualization
  37113. 23:43:39tools. So without further ado, let's
  37114. 23:43:41jump on my screen and take a look. I'll
  37115. 23:43:42scroll down. Let's go to analytics. And
  37116. 23:43:45under the analytics, we have Quicksite
  37117. 23:43:47right here. Now, in order to get started
  37118. 23:43:49with Quicksite, we actually have to
  37119. 23:43:51create an account. So, we have to sign
  37120. 23:43:53up for Quicksite. So, let's go ahead and
  37121. 23:43:55say sign up for Quicksite. For the
  37122. 23:43:56authentication method, we just want to
  37123. 23:43:58use the IM federated identities. You can
  37124. 23:44:01uh use some of these other ones if you'd
  37125. 23:44:03like. Be sure to specify your region.
  37126. 23:44:05Make sure you fill out your account
  37127. 23:44:06info. And then down here, you can uh use
  37128. 23:44:10an existing role or you can just use the
  37129. 23:44:11quicksite manage role. Highly recommend
  37130. 23:44:13just using default, much easier. and
  37131. 23:44:15allow access and autodiscocovery for
  37132. 23:44:18these resources. So, if you want them to
  37133. 23:44:21be able to use your S3 buckets, be sure
  37134. 23:44:23to click on your S3 bucket and we can
  37135. 23:44:24say uh here's the bucket we want. Uh,
  37136. 23:44:27you know, maybe I'll just choose both of
  37137. 23:44:28them, but here are the buckets that we
  37138. 23:44:30want you to be able to access as well as
  37139. 23:44:32all these other things as well. And then
  37140. 23:44:34we'll come down here and we don't want
  37141. 23:44:37pageionated reports. And then we'll
  37142. 23:44:38click finish. So, now it's creating our
  37143. 23:44:40account and then we'll get access in
  37144. 23:44:42just a second. All right, that took
  37145. 23:44:44about 10 seconds. This is the name that
  37146. 23:44:45I gave uh our account for Quicksite. And
  37147. 23:44:49let's go ahead and go to Quicksite. This
  37148. 23:44:51is what's new in Quicksite. Let's go
  37149. 23:44:52ahead and close out of that. Now, this
  37150. 23:44:55is the UI for Quicksite. Now, just
  37151. 23:44:58before we get into, you know, creating
  37152. 23:45:00stuff and building stuff and all these
  37153. 23:45:02different things. I just want to talk
  37154. 23:45:03about Quicksite in general. This is
  37155. 23:45:05AWS's tool for data visualization. And
  37156. 23:45:08of course, there are other options.
  37157. 23:45:10There's PowerBI, there's Looker, there's
  37158. 23:45:12uh Tableau, there's lots of different
  37159. 23:45:14options and all those are perfectly
  37160. 23:45:16acceptable. And in fact, in some
  37161. 23:45:18instances, they may be better for some
  37162. 23:45:20things, but within AWS's ecosystem, this
  37163. 23:45:23is their BI data visualization tool. And
  37164. 23:45:26so, because it's already integrated into
  37165. 23:45:27all their services, it does make it a
  37166. 23:45:29little bit easier to use than some of
  37167. 23:45:30the other ones. Um, and that's what
  37168. 23:45:32they're hoping for. They're hoping you
  37169. 23:45:34use their services and stay in their
  37170. 23:45:35ecosystem. So you don't have to go
  37171. 23:45:37anywhere else for any service ever
  37172. 23:45:39because AWS wants your money and your
  37173. 23:45:40business of course. Now within Quicksite
  37174. 23:45:42you can share reports, you can create
  37175. 23:45:44folders that you can uh share with
  37176. 23:45:46customers and clients. You can create
  37177. 23:45:48dashboards. You can of course create
  37178. 23:45:49stories. We have analysis data sets and
  37179. 23:45:53topics. And then over here we have some
  37180. 23:45:55sample analysis. So these are different
  37181. 23:45:58um things that they've already created
  37182. 23:46:00visualizations for. But the first thing
  37183. 23:46:02I want to show you is right over here in
  37184. 23:46:05data sets. Now these are the data sets
  37185. 23:46:07that we already have access to. Sales
  37186. 23:46:09pipeline. Uh let's just click in on one.
  37187. 23:46:12We get a very slight overview of kind of
  37188. 23:46:14what this data looks like. We can
  37189. 23:46:16refresh this data. And so if we're
  37190. 23:46:18connected to a data source, we can
  37191. 23:46:20refresh this or we can schedule this.
  37192. 23:46:22And then we can look at permissions and
  37193. 23:46:24usage for people who have access uh to
  37194. 23:46:27this data and how they can use it as
  37195. 23:46:29well. So just some interesting things
  37196. 23:46:31within data sets. If we want a new data
  37197. 23:46:33set, we just come in here and we specify
  37198. 23:46:35where we want to pull in our data.
  37199. 23:46:37Whether it's an S3 bucket or we want to
  37200. 23:46:39upload a file or it's coming in from
  37201. 23:46:41Athena. There's a lot of different
  37202. 23:46:42places uh that we can pull it in. There
  37203. 23:46:45is something up here I just want to
  37204. 23:46:46note. We're not actually going to be
  37205. 23:46:47pulling in any data for this. We're
  37206. 23:46:49going to be using one of their samples
  37207. 23:46:50just for demonstration purposes. But
  37208. 23:46:52there's something called SPICE in here.
  37209. 23:46:54Spice actually stands for superfast
  37210. 23:46:56parallel in-memory calculation engine.
  37211. 23:46:59and it's used to do things really
  37212. 23:47:01quickly in Quicksite. But for example,
  37213. 23:47:03let's just say we were uh uploading a
  37214. 23:47:05file. We can choose uh SQL database
  37215. 23:47:09output. I don't even know what's in that
  37216. 23:47:10file. Let's see what the preview says.
  37217. 23:47:12Okay, we have some products. This is our
  37218. 23:47:14products file. But let's say we select
  37219. 23:47:16next. We want to bring in uh this file.
  37220. 23:47:19It's going to import it into SPICE. And
  37221. 23:47:22so that's going to cost money. That's
  37222. 23:47:23going to put it into their super fast
  37223. 23:47:24parallel in-memory calculation engine.
  37224. 23:47:27and then you were going to pay for that
  37225. 23:47:29service. Now, that isn't always the
  37226. 23:47:30case. We don't have to uh we're not
  37227. 23:47:33going to do that. We're not we're going
  37228. 23:47:34to cancel that import. But you don't
  37229. 23:47:35always have to do that, especially if
  37230. 23:47:37you have other types of data connections
  37231. 23:47:38to like my SQL or Postgre SQL. You may
  37232. 23:47:40not need that. But just be aware of what
  37233. 23:47:42that is cuz that does cost money. Let's
  37234. 23:47:45go up here to quicksite. We're going to
  37235. 23:47:46come on back and let's take a look at
  37236. 23:47:48some of these samples that they have.
  37237. 23:47:50Let's go into this sales pipeline
  37238. 23:47:52analysis. So right now we're working
  37239. 23:47:54with sample data and we're not going to
  37240. 23:47:56be doing a full project in here in
  37241. 23:47:59Quicksite. Really what we're doing is
  37242. 23:48:00just seeing how it works and how
  37243. 23:48:02everything is built out and how you can
  37244. 23:48:04customize and build out your own
  37245. 23:48:06dashboards analysis as well. So if you
  37246. 23:48:08come in here you can see that we have
  37247. 23:48:09different types of visualizations very
  37248. 23:48:12standard types of visualizations uh for
  37249. 23:48:14any BI tool. And if we click into one of
  37250. 23:48:17these, let's say we're clicking into
  37251. 23:48:18this one, you'll see we have an x-axis,
  37252. 23:48:21a value, and a color. On the lefth hand
  37253. 23:48:24side, we also have all of our fields.
  37254. 23:48:26And you can see whether it's a dimension
  37255. 23:48:28or if it is a measure. Next, you can see
  37256. 23:48:30that up here we have our data set. This
  37257. 23:48:32is the data that we are using. And right
  37258. 23:48:35over here is the type of visualization
  37259. 23:48:37chart. Now, this should look really
  37260. 23:48:39familiar if you're familiar with Tableau
  37261. 23:48:41or PowerBI, both of which I have series
  37262. 23:48:43on YouTube. These are different types of
  37263. 23:48:45visualizations that you probably have
  37264. 23:48:47seen. And so if we wanted to uh change
  37265. 23:48:50this, we can click on a different type
  37266. 23:48:52of chart and it's going to visualize
  37267. 23:48:54that data based off of that visual type.
  37268. 23:48:57It's not going to be extremely extremely
  37269. 23:48:59useful. These are ones that I would use
  37270. 23:49:01all the time is just clicking on one of
  37271. 23:49:03these and then filling in the x-axis,
  37272. 23:49:06the value, the color, and all of these
  37273. 23:49:08different things that it's prompting you
  37274. 23:49:09to provide. Another thing you'll notice
  37275. 23:49:11is we have different sheets up here. So
  37276. 23:49:13within this analysis, we can add new
  37277. 23:49:15sheets. So we'll make this uh
  37278. 23:49:17interactive. And now we have a blank
  37279. 23:49:19sheet here that we can build our
  37280. 23:49:21visualizations off of. Let's say we
  37281. 23:49:22wanted some type of doughut chart in
  37282. 23:49:24here. We have our doughut chart. And
  37283. 23:49:26it's going to uh prompt us to fill in
  37284. 23:49:28what it actually needs. So we need a
  37285. 23:49:30value. Then we need a group slashcolor.
  37286. 23:49:33So let's say we want the uh region to be
  37287. 23:49:36our group and color. And for the value,
  37288. 23:49:39we'll do the weighted uh revenue right
  37289. 23:49:42here. And we're going to do the sum.
  37290. 23:49:44That should work. And so now you can see
  37291. 23:49:46that this is interactive. You can go
  37292. 23:49:47ahead and click on this. You can click
  37293. 23:49:49into these different options. You can
  37294. 23:49:51change these colors. Let's say we want
  37295. 23:49:52to make this one uh black. There we go.
  37296. 23:49:55And there's other options up here like
  37297. 23:49:57format this uh visualization or if we
  37298. 23:50:00want to maximize it or minimize it. And
  37299. 23:50:02if we want to add any more
  37300. 23:50:03visualizations, we just click add and we
  37301. 23:50:06can add it right over here. And so
  37302. 23:50:08everything in here is quite
  37303. 23:50:09customizable. And you can rename these
  37304. 23:50:11sheets. Let's call this one uh sum by
  37305. 23:50:14region.
  37306. 23:50:16Call it whatever we want. This is just
  37307. 23:50:17for this one uh visualization. But
  37308. 23:50:19everything is in here is quite
  37309. 23:50:20customizable. Now once we have our
  37310. 23:50:22visualizations, we have this properties
  37311. 23:50:24right over here. And we can change a lot
  37312. 23:50:26of the titles, subtitles. If it's a
  37313. 23:50:29doughnut chart, we can make it large,
  37314. 23:50:31small, medium. We can show the total
  37315. 23:50:33versus not showing the total. So
  37316. 23:50:35everything in here is very, very
  37317. 23:50:37customizable. And we can specify if we
  37318. 23:50:39want the data labels and the legend on.
  37319. 23:50:42So if we don't want the legend, we can
  37320. 23:50:44turn it off and on. Or if we don't want
  37321. 23:50:45the data labels, we can turn those off
  37322. 23:50:47and on as well. We also have over here
  37323. 23:50:50an interactions tab. So if you want to
  37324. 23:50:52customize some of these interactions or
  37325. 23:50:55if you want to customize some of these
  37326. 23:50:56tool tips, you can also do that as well,
  37327. 23:50:58which happens when you hover over it. So
  37328. 23:51:01right here on this right hand side, it's
  37329. 23:51:02giving us the uh field for region and
  37330. 23:51:05the weighted. And you'll notice when we
  37331. 23:51:07hover over it, you can see it's the US
  37332. 23:51:09with the weighted revenue. So we can
  37333. 23:51:10specify what we want in here. Maybe we
  37334. 23:51:12want to um add something else. Maybe we
  37335. 23:51:15want to add the date doesn't make sense
  37336. 23:51:17for here, but maybe the uh segment.
  37337. 23:51:20Let's go ahead and do that. And we hover
  37338. 23:51:21over it. You can see there's a count of
  37339. 23:51:24the segment which is 12,824
  37340. 23:51:26for this data set. So you can customize
  37341. 23:51:28these tool tips as well. Now when we're
  37342. 23:51:30done with our visualizations, we can
  37343. 23:51:32come over here to file and we can
  37344. 23:51:35publish this and save as analysis. So
  37345. 23:51:37just saving is going to save it for you
  37346. 23:51:39to pick up later and do whatever you
  37347. 23:51:41want with it. But let's say we want to
  37348. 23:51:43publish this. Publishing this dashboard,
  37349. 23:51:45we're just going to call this uh sample
  37350. 23:51:47dashboard is going to make it available
  37351. 23:51:49to everyone. So let's go ahead and
  37352. 23:51:51publish this dashboard. So now we have
  37353. 23:51:53uh this first sheet that was created by
  37354. 23:51:55them, but then we have the second one
  37355. 23:51:57that was created by us. Now once we've
  37356. 23:52:00published it, we can then come over here
  37357. 23:52:02and we can share this. So we can share
  37358. 23:52:05this dashboard and we can come in here
  37359. 23:52:07and we can choose anyone who has access
  37360. 23:52:09to Quicksite. We can say I want to share
  37361. 23:52:11this with my colleague or the customer
  37362. 23:52:12or whoever it is and I want to use this.
  37363. 23:52:15The other thing that we can do is we can
  37364. 23:52:17copy this embed code. What you can do is
  37365. 23:52:19you can say hey I want to embed this on
  37366. 23:52:21my website or on this platform and I
  37367. 23:52:23want to uh show this visualization. You
  37368. 23:52:26can embed that using the code uh from
  37369. 23:52:29this right here. We also can copy this
  37370. 23:52:31link. And so we'll copy the link. Come
  37371. 23:52:34right over here.
  37372. 23:52:38And now we have access to this
  37373. 23:52:40dashboard. So anybody who has access to
  37374. 23:52:41it can just use it as a link and that's
  37375. 23:52:44really helpful as well. But what I
  37376. 23:52:45thought was really interesting uh within
  37377. 23:52:47all this is the embedding code. Because
  37378. 23:52:49not every BI tool is embeddible but
  37379. 23:52:52quicksite because of course it's with
  37380. 23:52:53AWS it's all internetbased. It's not you
  37381. 23:52:56know local to your computer. It's very
  37382. 23:52:57embeddible into almost you know anything
  37383. 23:52:59you want to put it into. So let's go
  37384. 23:53:01back to our sample dashboard. We'll go
  37385. 23:53:03back to Quicksite. So that's our
  37386. 23:53:05different analysis, but let's go over to
  37387. 23:53:07our dashboards. When we actually
  37388. 23:53:09published our analysis, it went right in
  37389. 23:53:12here to our dashboard. So now this is a
  37390. 23:53:14completed dashboard. We would again
  37391. 23:53:16share with our internal teams or our
  37392. 23:53:18customers. We also can create data
  37393. 23:53:20stories. This is something you do need
  37394. 23:53:22to upgrade in order to receive access to
  37395. 23:53:24this. But this is very very similar to
  37396. 23:53:27data stories in something like Tableau.
  37397. 23:53:29If you've watched my Tableau series,
  37398. 23:53:30it's very very similar. you can watch
  37399. 23:53:32this uh video as well. But you create
  37400. 23:53:34these little stories and you can add
  37401. 23:53:36narrative and you know why the data is
  37402. 23:53:38doing what it's doing and what impact
  37403. 23:53:39that has and it's pretty good. I
  37404. 23:53:41personally don't use data stories all
  37405. 23:53:43that much. I mostly would create a lot
  37406. 23:53:45of KPI metric dashboards and stuff like
  37407. 23:53:48that but you know there are use cases
  37408. 23:53:50for data stories of course. Lastly we
  37409. 23:53:52have these folders. Let's go ahead and
  37410. 23:53:55create a new folder. We call this one
  37411. 23:53:57Alex the analyst folder. Once that
  37412. 23:53:59folder is created, we can come back to
  37413. 23:54:02our dashboard. We can right click on
  37414. 23:54:04this and say add to folder. Then we need
  37415. 23:54:06to specify our folder. So we'll go to my
  37416. 23:54:08folders and we'll add this. And so now
  37417. 23:54:12within my folder, if I click in here, I
  37418. 23:54:14have this dashboard. Now, this is really
  37419. 23:54:17just an organizational tool for the most
  37420. 23:54:19part. But when you start using this in a
  37421. 23:54:21production environment, you're going to
  37422. 23:54:22have a ton of different dashboards. And
  37423. 23:54:24so you can come in here and create
  37424. 23:54:25different ones for different customers,
  37425. 23:54:27different clients, internal teams so
  37426. 23:54:29that you can organize all these
  37427. 23:54:31different dashboards and data stories
  37428. 23:54:32and whatnot. So you have it all in one
  37429. 23:54:34place. And so again, that's just super
  37430. 23:54:36usable, really userfriendly. Now, this
  37431. 23:54:39is really all we're going to cover in
  37432. 23:54:41this video. We're not doing a full
  37433. 23:54:42project in Quicksite. I'm really just
  37434. 23:54:44demonstrating how to use it, some of the
  37435. 23:54:46things that they have in here that I
  37436. 23:54:48think are really interesting, and how
  37437. 23:54:50you can publish and share and do all
  37438. 23:54:51those things within Quicksite. So, I
  37439. 23:54:53hope that that was helpful and if you
  37440. 23:54:54have not already, be sure to check out
  37441. 23:54:55my full Azure and AWS course on
  37442. 23:54:57analystbuilder.com. And if you like this
  37443. 23:54:59video, be sure to like and subscribe
  37444. 23:55:00below and I will see you in the next
  37445. 23:55:02video. What's [music] going on
  37446. 23:55:03everybody? Welcome back to another
  37447. 23:55:05video. Today, we're going to be learning
  37448. 23:55:06data bricks in under two hours.
  37449. 23:55:14Now, for the past 5 weeks, we've been
  37450. 23:55:15diving into data bricks. And in this
  37451. 23:55:17video, we're just putting all that
  37452. 23:55:18together so you can follow along really
  37453. 23:55:19easily. We're going to start by taking a
  37454. 23:55:21quick walkthrough of data bricks and
  37455. 23:55:22seeing everything that it has to offer.
  37456. 23:55:24Then we're going to start importing data
  37457. 23:55:25not just from a flat file but also
  37458. 23:55:27connecting to a data source. Then we're
  37459. 23:55:29going to start using their SQL editor as
  37460. 23:55:30well as their notebooks and visualizing
  37461. 23:55:32data. After this we'll be using their AI
  37462. 23:55:34tools like Genie and their AI assistant.
  37463. 23:55:36And finally we'll be building a full
  37464. 23:55:38project at the end. The best thing about
  37465. 23:55:40all this is it is completely free. Data
  37466. 23:55:41bicks has something called the data
  37467. 23:55:42bicks free edition. I will leave link in
  37468. 23:55:44the description. You can make an account
  37469. 23:55:46by just using your email. That is it. So
  37470. 23:55:48be sure to go and create your free
  37471. 23:55:49account so you can follow along with
  37472. 23:55:51this entire video because we have a lot
  37473. 23:55:52of things that we are going to cover.
  37474. 23:55:54With all that being said, I hope you
  37475. 23:55:55learn a ton because data bicks is a
  37476. 23:55:57fantastic platform. So let's jump right
  37477. 23:55:59into it. Now data bicks is an amazing
  37478. 23:56:01platform. I've been using it for many
  37479. 23:56:02years and it's built on top of Apache
  37480. 23:56:04Spark which means it is very good at
  37481. 23:56:06handling large amounts of data. It's
  37482. 23:56:08designed for entire teams of data
  37483. 23:56:10engineers, data analysts, data
  37484. 23:56:11scientists to work with data
  37485. 23:56:13collaboratively. That means ingesting
  37486. 23:56:14the data, analyzing the data and
  37487. 23:56:16visualizing data all in one place. In
  37488. 23:56:18this lesson, we're going to be diving
  37489. 23:56:20into data bricks and look at some of the
  37490. 23:56:21core functionality and features that
  37491. 23:56:23data bricks free edition has to offer.
  37492. 23:56:25And then in the next several lessons,
  37493. 23:56:26we're going to get really hands-on and
  37494. 23:56:28start digging into these features and
  37495. 23:56:29start building things out. With that
  37496. 23:56:30being said, let's jump on my screen and
  37497. 23:56:32get started. Before we jump into the
  37498. 23:56:34platform itself, I just want to show you
  37499. 23:56:35that this is where you sign up. So, I'm
  37500. 23:56:37going to have this link down below. So,
  37501. 23:56:39you can just click on it. You can create
  37502. 23:56:40an account and you can sign in. There is
  37503. 23:56:42no credit card information that they
  37504. 23:56:44take. You just literally sign in and you
  37505. 23:56:45are good to go. But on this page, you
  37506. 23:56:47can sign up for the free edition or
  37507. 23:56:49login, which we'll log in in just a
  37508. 23:56:50second. But you can also learn a lot
  37509. 23:56:52more about data bicks free edition and
  37510. 23:56:55everything that they have to offer. You
  37511. 23:56:56can see that they have built-in AI
  37512. 23:56:58agents and they have AI builtin and that
  37513. 23:57:00is something that we're going to cover
  37514. 23:57:01in this series. You can also visualize
  37515. 23:57:04your data and create full dashboards.
  37516. 23:57:06And of course, you can interact with
  37517. 23:57:08your data with Python and SQL, either
  37518. 23:57:10through notebooks or, you know, through
  37519. 23:57:11a code editor. Let's go back up and
  37520. 23:57:14let's go and sign up for the free
  37521. 23:57:16edition. All we have to do is log in.
  37522. 23:57:19You can do that with Google, with a
  37523. 23:57:20Microsoft account, or just an email. I'm
  37524. 23:57:22going to sign in with my Google account.
  37525. 23:57:24And all I have to do is say where I'm
  37526. 23:57:25from. So, this is Alex. We have the free
  37527. 23:57:27edition, and I'm from the United States.
  37528. 23:57:29Let's go ahead and click continue. And
  37529. 23:57:31just like that, we are signed up for the
  37530. 23:57:32Data Bricks free edition. It was about
  37531. 23:57:34as seamless as it can possibly be. Now,
  37532. 23:57:37there's a lot to cover. Data Bricks has
  37533. 23:57:39so many different features. They have so
  37534. 23:57:41many different things that you can do
  37535. 23:57:42from building interactive dashboards to
  37536. 23:57:44writing SQL queries and sharing that
  37537. 23:57:45with your team and being able to work
  37538. 23:57:47with your team. You can even build AI
  37539. 23:57:49agents. There is a lot of things that
  37540. 23:57:51you can do. And some of this might be a
  37541. 23:57:52little bit intimidating if you've never
  37542. 23:57:54used a platform like this before. If
  37543. 23:57:56you're used to just working something
  37544. 23:57:57like SQL or R or Tableau, it's a little
  37545. 23:58:00bit more advanced than that. So there's
  37546. 23:58:02a lot of things that they have that are
  37547. 23:58:03all combined into one place. And so
  37548. 23:58:05we're going to walk through a lot of
  37549. 23:58:06these things that you see on this lefth
  37550. 23:58:07hand side to see exactly what you can do
  37551. 23:58:10in data bricks. Now I'm going to start
  37552. 23:58:11at the very top because this is a
  37553. 23:58:14workspace. And a workspace is basically
  37554. 23:58:16the place that you work and you can
  37555. 23:58:18collaborate in as well. So you can give
  37556. 23:58:20your teammates access to your workspace.
  37557. 23:58:22So if you have data in here, if you have
  37558. 23:58:23code in here, if you have
  37559. 23:58:24visualizations, whatever it is, you can
  37560. 23:58:26share that with them and they can get
  37561. 23:58:27access to all of your work. Next, let's
  37562. 23:58:29go to catalog. You can think of catalog
  37563. 23:58:32as like a schema. So if you have a
  37564. 23:58:34schema in a database, you're going to
  37565. 23:58:35have all of your tables and your views
  37566. 23:58:36and your store procedures and everything
  37567. 23:58:38underneath it. And this is very similar.
  37568. 23:58:40So if I go into a workspace or if I go
  37569. 23:58:43down here into the samples, we have
  37570. 23:58:45different databases. And so we can click
  37571. 23:58:47into these databases and we can look at
  37572. 23:58:49all these different tables. And so this
  37573. 23:58:50is where you're going to have access to
  37574. 23:58:51view all of your data and files and
  37575. 23:58:53tables within data bricks. Next, let's
  37576. 23:58:55take a look at jobs and pipelines. This
  37577. 23:58:58is where we start getting into some
  37578. 23:59:00automation. So here we have an ingestion
  37579. 23:59:02pipeline, an ETL pipeline, and a job.
  37580. 23:59:05And each of these does a slightly
  37581. 23:59:07different thing. If you create an
  37582. 23:59:08ingestion pipeline, that's going to be
  37583. 23:59:09like the extraction of the ETL process.
  37584. 23:59:12You're extracting data to bring it in.
  37585. 23:59:14Then we have our ETL pipeline, which is
  37586. 23:59:16the entire process of transforming it,
  37587. 23:59:18loading, and actually putting it into a
  37588. 23:59:19table within data bricks. And then we
  37589. 23:59:22have our jobs that's going to
  37590. 23:59:23orchestrate it. We're going to be able
  37591. 23:59:24to say, here's when we actually run
  37592. 23:59:25these pipelines so that we can time it.
  37593. 23:59:28We can do it, you know, daily, weekly,
  37594. 23:59:29monthly, whenever we want to run these
  37595. 23:59:31pipelines. So, we don't have any
  37596. 23:59:33created, but when we do, they'll be down
  37597. 23:59:35here at the bottom. Next, let's look at
  37598. 23:59:38compute. Now, compute is very simple in
  37599. 23:59:40the free edition because you don't have
  37600. 23:59:42any options here. We just have our
  37601. 23:59:44serverless starter warehouse. This is
  37602. 23:59:46what you get for free with the free
  37603. 23:59:48edition. Now, if you go to the full
  37604. 23:59:50datab bricks product, then you're going
  37605. 23:59:51to be able to kind of customize your
  37606. 23:59:53compute to your needs. But for this free
  37607. 23:59:55edition, we have uh the owner, we have
  37608. 23:59:57the size, which is a 2x small, and then
  37609. 24:00:00we have whether it's active or not. Now,
  37610. 24:00:02right now, we're not running anything.
  37611. 24:00:04We're not looking at any tables. We're
  37612. 24:00:05not running any queries. So, it's not
  37613. 24:00:07active at the moment, but the second
  37614. 24:00:09that we open something up and start
  37615. 24:00:10working with real data, it will activate
  37616. 24:00:12the serverless compute and we'll be able
  37617. 24:00:14to use it for free. One small nuance to
  37618. 24:00:16this is there actually is one other type
  37619. 24:00:17of compute, you just can't see it, and
  37620. 24:00:19that's for when you run Python in a
  37621. 24:00:21notebook. It's called a generic compute.
  37622. 24:00:22It's just for that one specific use
  37623. 24:00:24case. For the most part, you're going to
  37624. 24:00:25be using this serverless compute, but I
  37625. 24:00:27thought it was worth mentioning. Notice
  37626. 24:00:29when I clicked on compute, it also took
  37627. 24:00:31me right down here to the SQL warehouse.
  37628. 24:00:34This is our SQL warehouse that we are
  37629. 24:00:36using. Next, let's go down to the
  37630. 24:00:38marketplace. Now, the marketplace is
  37631. 24:00:40basically just, hey, here's a lot of
  37632. 24:00:42companies that work with us, that we
  37633. 24:00:44partner with, we have connectors to, and
  37634. 24:00:46we have, you know, partnerships with,
  37635. 24:00:47and allows you to work with them a lot
  37636. 24:00:49easier. So, here we go. Partner connect
  37637. 24:00:51integration. So if you want to connect
  37638. 24:00:53to Fiverr, to PowerBI, to Tableau, DBT,
  37639. 24:00:56Prophecy, you can easily connect to
  37640. 24:00:59these. I know at my previous job I
  37641. 24:01:01connected it with PowerBI a lot and so
  37642. 24:01:03these are great connectors where you can
  37643. 24:01:05just kind of search and you can see,
  37644. 24:01:06hey, do they connect to this tool that
  37645. 24:01:08we use and most of the time they do have
  37646. 24:01:10that connector. Now the marketplace has
  37647. 24:01:12other things as well. If we come over
  37648. 24:01:13here to products, we have things like
  37649. 24:01:15tables or files which is data. You can
  37650. 24:01:18also search for models and notebooks and
  37651. 24:01:20all sorts of other things. So you can
  37652. 24:01:22come in here and we can search for
  37653. 24:01:24files. And so these are all free
  37654. 24:01:26resources and files that you can search
  37655. 24:01:28for and use. If you can't find data here
  37656. 24:01:30in the marketplace, you can always just
  37657. 24:01:31go to something like Kaggle and get free
  37658. 24:01:33data and bring that into data bricks as
  37659. 24:01:35well. Now let's come over here and go to
  37660. 24:01:37the SQL editor. You can see we have kind
  37661. 24:01:39of these uh larger overarching sections
  37662. 24:01:42up here, but then we have SQL and then
  37663. 24:01:44we have data engineering. Then we have
  37664. 24:01:46AI and machine learning. Right now we're
  37665. 24:01:48in the SQL section. So, right in here,
  37666. 24:01:50we're able to come in and we're able to
  37667. 24:01:52write SQL just like any other platform.
  37668. 24:01:54The neat thing about this though is that
  37669. 24:01:56they have AI integrated into it. It
  37670. 24:01:58helps a lot with writing some of the
  37671. 24:01:59base queries that you're going to write.
  37672. 24:02:01Now, we're going to have a whole lesson
  37673. 24:02:02on Genie. And so, we're going to dive
  37674. 24:02:04into that and see how you can generate
  37675. 24:02:05code and do a lot of different things
  37676. 24:02:07with Genie, which is their AI system
  37677. 24:02:09within Data Bricks. And Genie just
  37678. 24:02:10allows you to get insights from your
  37679. 24:02:12data just using natural language. But
  37680. 24:02:14you'll be able to write SQL right here
  37681. 24:02:15in this editor as well as have multiple
  37682. 24:02:17tabs and choose what workspace you're
  37683. 24:02:20working with in and choose what
  37684. 24:02:21workspace you are working in. Right now,
  37685. 24:02:23we're just on the default, but if you
  37686. 24:02:24had different workspaces, you'd be able
  37687. 24:02:26to just click on those and select where
  37688. 24:02:28you want your queries to be pointed at.
  37689. 24:02:29Next, let's take a look at our queries.
  37690. 24:02:31So, once we get in and we start
  37691. 24:02:33developing all these queries, we want to
  37692. 24:02:34save them. And organization is a big
  37693. 24:02:36piece of that. I know that I used to
  37694. 24:02:38have like 20 30 different kind of
  37695. 24:02:40queries that I was saving on my file
  37696. 24:02:42explorer back in my old job and then I
  37697. 24:02:44started working in data bricks. I'm like
  37698. 24:02:46hey I can just save those within this
  37699. 24:02:48and then I don't have to email someone
  37700. 24:02:49my query and then they pull it up and
  37701. 24:02:51copy and paste like it's all here within
  37702. 24:02:53data bricks which is really great. Next
  37703. 24:02:55let's go look at dashboards. Now these
  37704. 24:02:58are some sample dashboards and we're
  37705. 24:02:59going to have a whole lesson on
  37706. 24:03:00analyzing and visualizing data within
  37707. 24:03:02data bicks. So we'll be able to build
  37708. 24:03:04something like this. Let's click into
  37709. 24:03:06one of these dashboards right here. It
  37710. 24:03:08says my warehouse is starting. That's
  37711. 24:03:10because it's connecting to the data to
  37712. 24:03:11be able to visualize our data. So, let's
  37713. 24:03:14get rid of this filter really quick. So,
  37714. 24:03:16this is what our dashboard looks like.
  37715. 24:03:18And you're able to create all these
  37716. 24:03:19different visualizations. You're able to
  37717. 24:03:20drill down into the data. And this is
  37718. 24:03:23all connected to data that is already in
  37719. 24:03:25data brick. So, it's all in one place.
  37720. 24:03:27Next, let's go take a look at Genie. And
  37721. 24:03:29they have a whole section just for this.
  37722. 24:03:31And they also have an entire section
  37723. 24:03:33that is just devoted to this warehouse.
  37724. 24:03:36Now this is something that a lot of
  37725. 24:03:37platforms are trying to build to but
  37726. 24:03:39data bricks already has it which is they
  37727. 24:03:41have all the data they have the ability
  37728. 24:03:42to query and analyze and visualize data
  37729. 24:03:44all in one place but being able to use
  37730. 24:03:47AI with it to get a lot of those things
  37731. 24:03:49done faster. And so you can ask it
  37732. 24:03:50questions and it's going to prompt you
  37733. 24:03:52because this is kind of a uh you know
  37734. 24:03:54starter section and you can ask it
  37735. 24:03:56questions and it's going to run these
  37736. 24:03:58queries and it's going to get you that
  37737. 24:03:59information really quickly. In one of
  37738. 24:04:01our future lessons, we're going to be
  37739. 24:04:02diving into just Genie, focused only on
  37740. 24:04:04what it can do, how it helps you analyze
  37741. 24:04:06your data faster, and how it can be
  37742. 24:04:08really useful to you as a user. The next
  37743. 24:04:10thing that we're going to take a look at
  37744. 24:04:11is alerts. Now, an alert is basically
  37745. 24:04:13like a trigger. When a condition is met,
  37746. 24:04:15it's going to do something. And so, you
  37747. 24:04:17can customize these alerts and set these
  37748. 24:04:19conditions, and they'll email you or
  37749. 24:04:20they'll message you when these
  37750. 24:04:22conditions are true. Now, in this
  37751. 24:04:24section up here, this is where we're
  37752. 24:04:25going to be spending the majority of our
  37753. 24:04:27time. There are other things like the
  37754. 24:04:30job runs which is where you can create
  37755. 24:04:32your jobs which is part of these uh jobs
  37756. 24:04:34and pipelines and then of course the
  37757. 24:04:36data ingestion as well which allows you
  37758. 24:04:38to connect to your data. So if you have
  37759. 24:04:40a data source that you want to point at
  37760. 24:04:42maybe it's Google Analytics you can just
  37761. 24:04:44click on this and connect to your data
  37762. 24:04:46or if you just want to upload a file you
  37763. 24:04:48can do that as well. Down here we have
  37764. 24:04:50our AI and machine learning section. So
  37765. 24:04:52you can click on the playground. This is
  37766. 24:04:54another area where you can interact with
  37767. 24:04:55the AI within data bricks and you can
  37768. 24:04:57select some custom parameters as well as
  37769. 24:05:00the prompts that you are using. We can
  37770. 24:05:02also look at experiments. This is where
  37771. 24:05:04you can build out AI agents and machine
  37772. 24:05:06learning models and you can actually
  37773. 24:05:07test them out. And so this is a
  37774. 24:05:08fantastic place where you can actually
  37775. 24:05:09learn how to use a lot of these
  37776. 24:05:11foundational models and you can take the
  37777. 24:05:12data and you can deploy it and you can
  37778. 24:05:14work through these issues and really
  37779. 24:05:15learn hands-on how to work with them.
  37780. 24:05:17Naturally, they're going to have AI
  37781. 24:05:19integrated into all this. So you can
  37782. 24:05:20work with the data bricks assistant to
  37783. 24:05:22get help with all of your coding. So as
  37784. 24:05:24you're going along, if you get stuck,
  37785. 24:05:25you can always get help with your code.
  37786. 24:05:27As I said before though, we are going to
  37787. 24:05:28be spending most of our time right up
  37788. 24:05:30here. Of course, we'll need to ingest
  37789. 24:05:32our data. But after that, we're going to
  37790. 24:05:34be spending a lot of our time
  37791. 24:05:35visualizing, see how we can work with
  37792. 24:05:37our data and how we can use their
  37793. 24:05:38integrated AI to be able to do our work
  37794. 24:05:40faster. At the end of this entire
  37795. 24:05:42series, we'll be building a full project
  37796. 24:05:44using a lot of the things that we're
  37797. 24:05:45going to be looking at in this series. I
  37798. 24:05:47think building and getting hands-on is
  37799. 24:05:48the best way to learn. So, I cannot wait
  37800. 24:05:50to get started on that. There are a lot
  37801. 24:05:52of ways to work with data in data bricks
  37802. 24:05:54and we're going to cover a lot of them
  37803. 24:05:55in this lesson. We're going to upload
  37804. 24:05:57data like a CSV and a JSON file. Then,
  37805. 24:05:59we're going to connect to an external
  37806. 24:06:00data source and we're going to bring
  37807. 24:06:01that data in. Then, we're going to see
  37808. 24:06:03how we can actually use our data working
  37809. 24:06:04in the SQL editor as well as using a
  37810. 24:06:06notebook. The best way to follow along
  37811. 24:06:08is to create a data bicks account. I
  37812. 24:06:09will leave a link in the description.
  37813. 24:06:11It's data bicks free edition, so it is
  37814. 24:06:13completely free. All you have to do is
  37815. 24:06:14create an account and sign in and you'll
  37816. 24:06:16have access to everything. You don't
  37817. 24:06:17have to put in a credit card at all. It
  37818. 24:06:19is completely free which is amazing.
  37819. 24:06:21With all that being said, let's jump on
  37820. 24:06:22my screen and get started. We are
  37821. 24:06:24starting out fresh. We haven't uploaded
  37822. 24:06:26any data or ingested any data into data
  37823. 24:06:28bicks yet. So, you are right where you
  37824. 24:06:30need to be. Now, there's actually a lot
  37825. 24:06:32of different ways you can bring data
  37826. 24:06:34into databicks. Right now, we're in our
  37827. 24:06:36workspace, but let's go over to our
  37828. 24:06:39catalog and let's go into our workspace.
  37829. 24:06:42Let's go into default. Right now, we
  37830. 24:06:44have no data in our default workspace.
  37831. 24:06:47Now, what we're going to do is let's
  37832. 24:06:48click into this default and we're going
  37833. 24:06:51to come right over here and we go to
  37834. 24:06:52create. Now, we have a few different
  37835. 24:06:54options. These two are the only ones
  37836. 24:06:56that are really relevant to what we're
  37837. 24:06:57doing right now. So, let's create a new
  37838. 24:06:59volume here. And I'm just going to call
  37839. 24:07:00this uh YouTube series. And then I'm
  37840. 24:07:04going to go ahead and create this.
  37841. 24:07:08Now, you'll see right over here under
  37842. 24:07:10default, we now have this folder called
  37843. 24:07:12YouTube series. If I click in this
  37844. 24:07:14YouTube series, we can upload to this
  37845. 24:07:18volume. So, we can do that right here.
  37846. 24:07:20We don't have to actually go outside of
  37847. 24:07:22it or go to any of these other options.
  37848. 24:07:24We just click on upload to this volume.
  37849. 24:07:26So, let's go ahead and click browse. And
  37850. 24:07:29I have all these different files. Now, I
  37851. 24:07:31created these. They're very simple
  37852. 24:07:32files. We're not getting crazy in this
  37853. 24:07:34lesson, but I have a customers CSV and a
  37854. 24:07:37customer's JSON. So, one's a CSV file,
  37855. 24:07:40one's a JSON file. I also have orders
  37856. 24:07:42CSV, orders JSON, product CSV, and
  37857. 24:07:45products JSON. We're not going to use
  37858. 24:07:47all these, although I will have all
  37859. 24:07:49these files in a GitHub. You can just
  37860. 24:07:51find them in a link below. So, you can
  37861. 24:07:52download these exact files if you want
  37862. 24:07:54to work alongside me. But let's bring in
  37863. 24:07:56the customers CSV. So, I'm going to
  37864. 24:07:58click on this customer CSV. And you can
  37865. 24:08:01see this is the destination path that we
  37866. 24:08:03are using. Let's go ahead and upload
  37867. 24:08:05this file. And very quickly, like in 1
  37868. 24:08:09second it took, we now have our
  37869. 24:08:11customers CSV CSV. Now, I just named it
  37870. 24:08:14that. So, you know, if the CSV wasn't
  37871. 24:08:16there, we'll still be able to see it.
  37872. 24:08:18Let's click into this CSV really
  37873. 24:08:20quickly. We have our customer ID, first
  37874. 24:08:22name, last name, country, and signup
  37875. 24:08:24date. And then you can see our data is
  37876. 24:08:27all separated by a comma. Now, this data
  37877. 24:08:30is just being stored as a file. This
  37878. 24:08:32isn't actually being stored as a table.
  37879. 24:08:34So, you can see it just sits in here as
  37880. 24:08:36a CSV. So, if we go over to our files,
  37881. 24:08:39it's going to sit there as an actual CSV
  37882. 24:08:41file. Now, we can still query off of
  37883. 24:08:44this data just as it is as a file. We
  37884. 24:08:46don't actually have to have this in a
  37885. 24:08:48table format. Let's come right over here
  37886. 24:08:51and let's copy this path. And then we're
  37887. 24:08:54going to go down to our SQL editor and
  37888. 24:08:56let's come over here to a SQL query.
  37889. 24:08:59Now, if we want to access this data, we
  37890. 24:09:02can say select everything and then we'll
  37891. 24:09:05say from and I'm going to put this path
  37892. 24:09:08in here. I should be able to use back
  37893. 24:09:11ticks just like this. And let's try
  37894. 24:09:13running this. And actually, I need to
  37895. 24:09:15put CSV dot right here. Now, let's try
  37896. 24:09:20running this. And as you can see, we
  37897. 24:09:22were able to read in our data without it
  37898. 24:09:25actually being in a table. A CSV file is
  37899. 24:09:28one of the easiest files to work with.
  37900. 24:09:30It's just values that are separated by
  37901. 24:09:31commas. And so when we do this, when we
  37902. 24:09:34say CSV dot and then we provide the
  37903. 24:09:36path, we are reading in this data as if
  37904. 24:09:39it is in a table. Now, if you come from
  37905. 24:09:41just a SQL background, this may seem
  37906. 24:09:43very unintuitive to you. And that's
  37907. 24:09:45okay. Let's go back to our catalog and
  37908. 24:09:48we're going to come over here to
  37909. 24:09:50workspace. We're going to go to default.
  37910. 24:09:52And instead of going into our volume
  37911. 24:09:56right here, we're going to come back to
  37912. 24:09:58our default. And so now we're going to
  37913. 24:10:01create a table. When we go to create a
  37914. 24:10:03table, we're still using our serverless
  37915. 24:10:05starter warehouse here, but now we have
  37916. 24:10:07the ability to connect to a data source
  37917. 24:10:10or to upload a specific file format.
  37918. 24:10:12Let's go ahead and click browse. We just
  37919. 24:10:15uploaded the customers CSV, but let's go
  37920. 24:10:17down to the orders JSON because JSON is
  37921. 24:10:20a totally different format. Let's go
  37922. 24:10:22ahead and open this up. It's going to
  37923. 24:10:24read in that JSON and make it tabular,
  37924. 24:10:27which is fantastic because JSON by
  37925. 24:10:29definition is not a structured format.
  37926. 24:10:31And so being able to read in that data
  37927. 24:10:33really easily and then put it into
  37928. 24:10:35columns and rows is very helpful. So now
  37929. 24:10:39we're going to do a create a new table.
  37930. 24:10:41We can name this table anything we want.
  37931. 24:10:43I'm just going to get rid of this JSON
  37932. 24:10:45because once it reads it in, it's like a
  37933. 24:10:47table anyways. So, we're going to keep
  37934. 24:10:49it as orders here. Then, we're going to
  37935. 24:10:51create this table. Now, you'll notice
  37936. 24:10:53over here under our default, we have
  37937. 24:10:55tables and we have volumes. So, they are
  37938. 24:10:58separated out because they're two
  37939. 24:11:00totally different things. One is going
  37940. 24:11:02to be storing different files in kind of
  37941. 24:11:04a folder format and then one is the
  37942. 24:11:06tables underneath our default workspace.
  37943. 24:11:10So let's come down here to orders and
  37944. 24:11:12that's actually right over here. So now
  37945. 24:11:14under our orders we can see customer ID,
  37946. 24:11:16order date, order ID, product ID,
  37947. 24:11:18quantity, and total amount. We can get a
  37948. 24:11:21little bit of metadata on this file. And
  37949. 24:11:23if we come up here, we can come here and
  37950. 24:11:25just create a query. So let's click on
  37951. 24:11:27create query. It's going to open up a
  37952. 24:11:29new query in here. And now we're just
  37953. 24:11:32selecting everything from our orders
  37954. 24:11:34table. It's already hitting off of our
  37955. 24:11:36default schema in our workspace. So, we
  37956. 24:11:39don't have to start doing, you know,
  37957. 24:11:40workspace
  37958. 24:11:42dot uh default.
  37959. 24:11:45We don't have to have all that. You can
  37960. 24:11:47uh but I'm just going to hit control-z
  37961. 24:11:50here. Let's go ahead and run this. And
  37962. 24:11:52now we can see all of our data in this
  37963. 24:11:54really pretty view. So, so far we've
  37964. 24:11:56ingested a CSV file and we just did that
  37965. 24:11:58as a CSV file. We were still able to
  37966. 24:12:01read that data in which is really
  37967. 24:12:03fantastic. But we're also able to just
  37968. 24:12:05create tables and then read that data in
  37969. 24:12:08like any other SQL database. But now
  37970. 24:12:10let's come over here to data ingestion.
  37971. 24:12:13There's a lot of different ways you can
  37972. 24:12:14access data that is not just sitting in
  37973. 24:12:17a file. Right off the bat we have our
  37974. 24:12:18data bricks connectors. Things like
  37975. 24:12:20Salesforce, Workday, Service Now, Google
  37976. 24:12:22Analytics, Azure SQL Server. These are a
  37977. 24:12:24lot of the things that I've used in my
  37978. 24:12:26actual work. Almost all companies are
  37979. 24:12:28going to have at least one of these. And
  37980. 24:12:29so connecting to that data source,
  37981. 24:12:31bringing it in is really common. We can
  37982. 24:12:32also bring in data from a file like we
  37983. 24:12:34did before or create a table from Amazon
  37984. 24:12:36S3. Then we have our fiverr connectors
  37985. 24:12:39right down at the bottom. I know
  37986. 24:12:41personally I've worked at different
  37987. 24:12:42companies. I've consulted with
  37988. 24:12:43companies. They use Google Drive as like
  37989. 24:12:45their store of information. That's where
  37990. 24:12:46they keep everything. So let's go over
  37991. 24:12:48here to Google Drive and I'm going to
  37992. 24:12:51actually connect this. So I'm going to
  37993. 24:12:52say I want to put it in my workspace.
  37994. 24:12:55Let's go ahead and click next. Really
  37995. 24:12:57quickly, I have a file over here,
  37996. 24:12:59orderscv.csv.
  37997. 24:13:02It's sitting in a Google Drive. So,
  37998. 24:13:04that's what we're going to go and try to
  37999. 24:13:05connect to. Let's go ahead and click
  38000. 24:13:06next. This is my email that I'm using
  38001. 24:13:09for this Google Drive. We're going to
  38002. 24:13:11connect this to Fiverr. Since this is a
  38003. 24:13:13new account for Fiverr, I need to create
  38004. 24:13:15a password. So, I'm going to do that
  38005. 24:13:17really quick. We're going to come right
  38006. 24:13:18down here and we're going to go to
  38007. 24:13:19share. And all we have to do is make
  38008. 24:13:22sure that this is not restricted. So,
  38009. 24:13:23we're going to say anyone with this
  38010. 24:13:25link, which means fiverr as well. And
  38011. 24:13:27then we're going to copy this link and
  38012. 24:13:30put it in our folder URL. Let's go ahead
  38013. 24:13:33and save and test this. And it looks
  38014. 24:13:35like our connection test passed. Let's
  38015. 24:13:36go ahead and click continue. And now
  38016. 24:13:38what we're going to do is sync our data.
  38017. 24:13:40We'll start the initial sync. And it
  38018. 24:13:42should be very quick because I do not
  38019. 24:13:45have much data in this folder. So, it
  38020. 24:13:47looks like our connection was
  38021. 24:13:48successful. Let's come over here to our
  38022. 24:13:50schema. our one file that we have in our
  38023. 24:13:53Google folder is synced up. So, we
  38024. 24:13:55should be good to go. Now, let's come
  38025. 24:13:57back to our data bricks. Let's come
  38026. 24:13:59right over here and we're going to go
  38027. 24:14:01into our catalog. We're going to go into
  38028. 24:14:03our workspace. And now we have default
  38029. 24:14:06and we also have Google Drive. Let's
  38030. 24:14:08click on our Google Drive and we have
  38031. 24:14:10this orders CSV.
  38032. 24:14:13And you'll notice that we now have it in
  38033. 24:14:15here as a table. Let's go ahead and
  38034. 24:14:17create a query for this so we can look
  38035. 24:14:19at our data. So now we have
  38036. 24:14:21workspace.google
  38037. 24:14:22drive. It's connecting to a different
  38038. 24:14:24schema. So we have select everything
  38039. 24:14:25from orders CSV. Let's run this.
  38040. 24:14:29And now we have our data. It also adds
  38041. 24:14:32this in which is five transync which is
  38042. 24:14:35a really really useful column because if
  38043. 24:14:37you're syncing this data consistently,
  38044. 24:14:39you really want to know when that data
  38045. 24:14:41gets put into this table. I promise you
  38046. 24:14:43that's really helpful that they put that
  38047. 24:14:44in there. And then we have all of our
  38048. 24:14:46data that we have. And so that's how we
  38049. 24:14:48can connect to outside data. In this
  38050. 24:14:49case, we use Fiverr, but sometimes
  38051. 24:14:51you'll just do a direct connection
  38052. 24:14:52depending on your data source. Now, this
  38053. 24:14:55SQL editor works like any other SQL
  38054. 24:14:57editor. You're going to be able to make
  38055. 24:14:58joins and aggregations and all sorts of
  38056. 24:15:00different things, but there is a
  38057. 24:15:02different way to interact with your
  38058. 24:15:04data. Let's come right over here. Let's
  38059. 24:15:06go to new. We can also go and use a
  38060. 24:15:08notebook.
  38061. 24:15:10We can add code. We can add text. You
  38062. 24:15:13can also use an AI assistant to help you
  38063. 24:15:15with these things. So, we have markdown
  38064. 24:15:17file right here. And I can say uh this
  38065. 24:15:19is my first text
  38066. 24:15:24right here. And then I have my code down
  38067. 24:15:27here. So I can start writing and typing
  38068. 24:15:28my code. Now I can specify right here
  38069. 24:15:31whether I want it to be SQL, Scala, R or
  38070. 24:15:34Python. So for this notebook, you can
  38071. 24:15:36use any of these. In this cell right
  38072. 24:15:38here, I have Python. But let's add
  38073. 24:15:41another one. And I can use SQL in the
  38074. 24:15:43next one. And then in the next one, I
  38075. 24:15:47could use R. And so you don't have to
  38076. 24:15:49just use one. You can use multiple. Now,
  38077. 24:15:51it depends on what you're doing, whether
  38078. 24:15:53you want to use a SQL editor or you want
  38079. 24:15:55to come in here and use a notebook. When
  38080. 24:15:57I'm just kind of querying data, I'm just
  38081. 24:15:59looking at it. I'm not doing a lot of
  38082. 24:16:00transformations. I don't need a big
  38083. 24:16:02programming language. I'm just quering
  38084. 24:16:03the data. I'm going to be using a SQL,
  38085. 24:16:06you know, editor right here most of the
  38086. 24:16:08time. And I can always save these
  38087. 24:16:09queries and I can pass them along. But
  38088. 24:16:11if I'm really digging in and I need to
  38089. 24:16:13be able to break things out and leave
  38090. 24:16:15notes and I'm going to share this with
  38091. 24:16:16my team, a notebook is kind of the way
  38092. 24:16:18to go. So let's look at SQL really
  38093. 24:16:19quick. We already have a query for this,
  38094. 24:16:21albeit a very simple query. But let's
  38095. 24:16:24come over here and let's run this SQL
  38096. 24:16:28query right here. So let's go ahead and
  38097. 24:16:29run this. And so now if we scroll down,
  38098. 24:16:32we're going to be able to see our data
  38099. 24:16:34just like we did in the SQL editor. But
  38100. 24:16:37now let's go write the same thing but in
  38101. 24:16:39Python. In order to do that, let's come
  38102. 24:16:41up here. And this is already in Python.
  38103. 24:16:43So, we'll just say spark.t.
  38104. 24:16:46And we need to read in uh the
  38105. 24:16:49appropriate table. And all that is is
  38106. 24:16:51orders. And let's go ahead and run this.
  38107. 24:16:54And it is reading it in as a data frame.
  38108. 24:16:57Let's call this uh dataf frame. And
  38109. 24:17:00let's come right down here and we'll say
  38110. 24:17:01display dataf frame. And let's run this.
  38111. 24:17:07And now we're going to get our data in a
  38112. 24:17:09table. Just like before, of course, with
  38113. 24:17:12this, it's going to save this data, but
  38114. 24:17:13you can always come in here and you can
  38115. 24:17:15rename and export it and you can put it
  38116. 24:17:17into Git. You can share this with your
  38117. 24:17:20friends because all your friends really
  38118. 24:17:21care about your notebooks that you are
  38119. 24:17:23writing. Or you can create a new
  38120. 24:17:24notebook and start from scratch. But
  38121. 24:17:27this is a totally different way to
  38122. 24:17:29interact with your data in data bricks.
  38123. 24:17:31This is where most of your work is going
  38124. 24:17:32to be done. It's right here querying
  38125. 24:17:34data, whether it's a SQL query or over
  38126. 24:17:37here in a notebook writing a bunch of
  38127. 24:17:39code. whether it's in Scola or Python or
  38128. 24:17:41R or SQL itself. Now, I hope that was
  38129. 24:17:44really helpful because in the next
  38130. 24:17:45lesson, we're going to be analyzing data
  38131. 24:17:47with SQL and then also building out
  38132. 24:17:48visualizations in data bricks. Now, in
  38133. 24:17:51the last lesson, we looked at the SQL
  38134. 24:17:52editor as well as notebooks. And so,
  38135. 24:17:54what we're going to be doing is we're
  38136. 24:17:55going to be looking at some data. We're
  38137. 24:17:56going to be analyzing that data and then
  38138. 24:17:58we're going to be putting it into a
  38139. 24:17:59dashboard and creating different
  38140. 24:18:00visualizations. This is actually the
  38141. 24:18:02dashboard that we're going to be
  38142. 24:18:03creating in this lesson. And I know what
  38143. 24:18:04you're thinking, Alex, you put the exact
  38144. 24:18:06same visualization twice. That makes no
  38145. 24:18:08sense. but it will make sense once we
  38146. 24:18:10get to it in the lesson. I highly
  38147. 24:18:11recommend following along. All you have
  38148. 24:18:13to do is have a data bricks free edition
  38149. 24:18:15account. I will leave a link in the
  38150. 24:18:17description so you can make that account
  38151. 24:18:18and follow along. With that being said,
  38152. 24:18:20let's jump onto my screen and get
  38153. 24:18:21started. All right, so we're getting
  38154. 24:18:22started right here on the dashboards.
  38155. 24:18:25All we're going to do is we're going to
  38156. 24:18:26come up here and we're going to create
  38157. 24:18:28our own dashboard. So, we get started
  38158. 24:18:30with this blank slate and it has all
  38159. 24:18:32these little arrows and I recommend you
  38160. 24:18:34read through these really quickly, but
  38161. 24:18:35this is how you add filters. This is how
  38162. 24:18:37we get our data which is right up here
  38163. 24:18:39and I'll show you that in just a second.
  38164. 24:18:40And this is how we actually add our
  38165. 24:18:42visualizations to what they're calling
  38166. 24:18:44our canvas. Let's come right up here and
  38167. 24:18:46let's go to our data. Now within our
  38168. 24:18:50data set, we are able to write SQL
  38169. 24:18:52queries. And I will say this is one of
  38170. 24:18:54my personal favorite things about this
  38171. 24:18:56is you can write the query and then you
  38172. 24:18:58can use that query to then create a
  38173. 24:19:00visualization. We're going to do that in
  38174. 24:19:01this lesson because I like being able to
  38175. 24:19:03visualize and kind of see my
  38176. 24:19:04aggregations when I'm doing some type of
  38177. 24:19:06group by in SQL. I like to see what the
  38178. 24:19:08actual output is and you can really
  38179. 24:19:10easily do that in here. You can also
  38180. 24:19:12come down here and you can just come in
  38181. 24:19:14and select some of your data. Now, we
  38182. 24:19:16are actually going to be using a sample
  38183. 24:19:18data set. Everyone should have this data
  38184. 24:19:20set. It's right here called the bake
  38185. 24:19:22house. And so, we can come in here and
  38186. 24:19:24we can also just select one of our data
  38187. 24:19:26sets. When we select this sales
  38188. 24:19:28transaction, it's going to start our
  38189. 24:19:30warehouse. So now it's connected to our
  38190. 24:19:32data and our serverless warehouse is
  38191. 24:19:34running. So now we have access to this
  38192. 24:19:36data. If I come right here, I click on
  38193. 24:19:38these three dots and I can click add to
  38194. 24:19:41dashboard. So I'm going to click add to
  38195. 24:19:42dashboard. It's going to read in this as
  38196. 24:19:45a SQL query. So if we go back up here,
  38197. 24:19:47we now have sales transactions as one of
  38198. 24:19:49our data sets. So we can just come in
  38199. 24:19:52here and write it ourselves or we can
  38200. 24:19:54also come into the catalog and just
  38201. 24:19:55select a data set and have it run it for
  38202. 24:19:57us. Now before we start actually diving
  38203. 24:19:59in and kind of analyzing and visualizing
  38204. 24:20:01this data, there are other ways you can
  38205. 24:20:04actually analyze data. And we looked at
  38206. 24:20:06this in a previous lesson when working
  38207. 24:20:07with data set. But as it pertains to
  38208. 24:20:10connecting it to a dashboard, what we
  38209. 24:20:12can do is let's come right up here and
  38210. 24:20:14let's click on a notebook. Let's say we
  38211. 24:20:16want to run that exact same query. And
  38212. 24:20:18I'll just go back to the dashboard. I'm
  38213. 24:20:21going to rename this really quick. I'm
  38214. 24:20:23going to rename this as our transaction,
  38215. 24:20:26if I can spell this right, dashboard.
  38216. 24:20:28All right. So, if I go to my data, I
  38217. 24:20:30could just copy this. And then I can
  38218. 24:20:32come right over here to the SQL editor,
  38219. 24:20:34and we'll actually have access to uh our
  38220. 24:20:38notebook right over here. So, this is
  38221. 24:20:40just our fresh notebook. We haven't used
  38222. 24:20:42it. I'm just going to make this SQL just
  38223. 24:20:44so it can you can see how easy this is.
  38224. 24:20:46But, we're going to run this exact same
  38225. 24:20:47thing. We're going to get our output
  38226. 24:20:49right down here. Now, let's say this is
  38227. 24:20:51the output that we want. It isn't, but
  38228. 24:20:53this is the output we want. But if we
  38229. 24:20:54come right over here to these three dots
  38230. 24:20:56and we scroll down, I can click add to
  38231. 24:20:58dashboard. So, I'm going to add this to
  38232. 24:21:00my dashboard. I'm going to say add to
  38233. 24:21:02existing dashboard. And when I click on
  38234. 24:21:04this, I'm going to click on the
  38235. 24:21:05transaction dashboard and I'm going to
  38236. 24:21:07import this. This data is then going to
  38237. 24:21:09be imported over as an untitled data
  38238. 24:21:12set. We can rename this. Uh I'm just
  38239. 24:21:14going to say that this is from notebook.
  38240. 24:21:17So this is our data from the notebook.
  38241. 24:21:19It is the exact same query as you can
  38242. 24:21:21see exact same data. But you don't just
  38243. 24:21:24have to create your data from right here
  38244. 24:21:26in the create from SQL or in this
  38245. 24:21:28dashboard tab. Now let's start actually
  38246. 24:21:30working on our dashboard and kind of
  38247. 24:21:32analyzing the data as we go. Let's just
  38248. 24:21:34start by taking a look at our data. So
  38249. 24:21:35we're working in the sales transactions.
  38250. 24:21:37We have transaction ID, customer ID,
  38251. 24:21:39franchise ID. If we scroll over to the
  38252. 24:21:41right hand side, we have the date and
  38253. 24:21:44time that this transaction went through,
  38254. 24:21:46the product that was purchased, the
  38255. 24:21:48quantity, the unit price, total price,
  38256. 24:21:50the way that they paid, and their card
  38257. 24:21:53number. Now, this is not real data, so
  38258. 24:21:55don't try to steal any of this card
  38259. 24:21:56number, but we are going to be using
  38260. 24:21:58this data to create our visualizations.
  38261. 24:22:01Now, typically when I'm analyzing and
  38262. 24:22:02then visualizing data, I have an end
  38263. 24:22:04goal in mind. I know what I'm going to
  38264. 24:22:05be doing with the data, and so I know
  38265. 24:22:07how I need to analyze it. if I need to
  38266. 24:22:09be use a group by or a window function,
  38267. 24:22:11if I need to clean the data or pivot the
  38268. 24:22:13data. These are things that I'll know
  38269. 24:22:14ahead of time. Now, in this lesson,
  38270. 24:22:16we're going to keep it kind of simple,
  38271. 24:22:17just learn how to build these things.
  38272. 24:22:19But in the last lesson in this series,
  38273. 24:22:21we're going to be building a full
  38274. 24:22:22project. It's going to have really messy
  38275. 24:22:24data that we need to dig into. But here,
  38276. 24:22:26we're going to learn a lot of the
  38277. 24:22:27fundamentals. Let's start with that
  38278. 24:22:28first bar chart that we saw earlier on.
  38279. 24:22:31So, we're going to come right here.
  38280. 24:22:32We're going to go create from SQL. And
  38281. 24:22:35let's call this one. Let's rename this
  38282. 24:22:37before we actually write it. We're going
  38283. 24:22:38to call this one product sales
  38284. 24:22:41descending. Now, what this means is is
  38285. 24:22:44we're going to take the product sales.
  38286. 24:22:46So, right over here, we're going to take
  38287. 24:22:48the product and then we're also going to
  38288. 24:22:50look at this total price. So, we're
  38289. 24:22:51going to calculate the sales. This is
  38290. 24:22:53actually going to be quite easy. If you
  38291. 24:22:55know SQL, this should be uh pretty
  38292. 24:22:56straightforward because we're just going
  38293. 24:22:57to be using a group by for this. So, I'm
  38294. 24:22:59going to come right over here and I'm
  38295. 24:23:01going to say I want to take the product.
  38296. 24:23:04So, let's take the product. And I use
  38297. 24:23:05tab for autocomplete here. So, I'm going
  38298. 24:23:07to do uh comma, then I'm going to do the
  38299. 24:23:09sum, and then I'm going to take the sum
  38300. 24:23:11of total price. And again, I'm just
  38301. 24:23:13going to hit tab. So, now that we have
  38302. 24:23:15the product and the sum of total price,
  38303. 24:23:18all we have to do is come right down
  38304. 24:23:19here and say group by and we're going to
  38305. 24:23:21group by the product. And we should also
  38306. 24:23:24order by. So, we're going to order by
  38307. 24:23:26and we'll do total price and we'll do
  38308. 24:23:29that descending. And so, all we're
  38309. 24:23:31doing, and let's run this. All we're
  38310. 24:23:32doing is we're taking the product and
  38311. 24:23:34we're grouping it. And then we're taking
  38312. 24:23:35the sum of all of that total price. And
  38313. 24:23:37I actually need to order by the sum of
  38314. 24:23:40total price. I just took the column
  38315. 24:23:43itself, but in this query, we're using
  38316. 24:23:45the sum of total price. Let's try
  38317. 24:23:47running that one more time. Listen, it
  38318. 24:23:48happens to the best of us. So now we
  38319. 24:23:51have the product right down here, and
  38320. 24:23:53we're ordering it based off the sum of
  38321. 24:23:55this total price. Now I'm going to leave
  38322. 24:23:57this just like this. Although typically
  38323. 24:24:00I would use an alias. I would say as and
  38324. 24:24:03I would say total
  38325. 24:24:05price or something like this, right? But
  38326. 24:24:07I'm not going to do that because I want
  38327. 24:24:09to show you in the dashboard how we can
  38328. 24:24:10easily rename this. We don't have to use
  38329. 24:24:13this column name. So now this data right
  38330. 24:24:15here is ready for us to visualize. We
  38331. 24:24:18can use this. So now let's come over to
  38332. 24:24:21our untitled page and let's title this.
  38333. 24:24:24We're going to say uh dashboard. So
  38334. 24:24:27we're just going to name this dashboard.
  38335. 24:24:28And we can get rid of these global
  38336. 24:24:29filters for now, but we will need that
  38337. 24:24:32in a little bit. Now, you have all these
  38338. 24:24:34options down here at the bottom. We have
  38339. 24:24:36the move, we have add visualization, add
  38340. 24:24:38a text box, add a filter, undo, and
  38341. 24:24:41redo. Now, let's focus on adding a
  38342. 24:24:43visualization first, and we'll worry
  38343. 24:24:45about the text box later because we'll
  38344. 24:24:48give it kind of a header of transaction
  38345. 24:24:50dashboard. You don't have to, but we
  38346. 24:24:52will for this dashboard. Now, when you
  38347. 24:24:54first create a visualization, we're
  38348. 24:24:56going to have this widget on this right
  38349. 24:24:58hand side. This is where you basically
  38350. 24:25:00build out your visualizations. We're
  38351. 24:25:02going to come in here and we're going to
  38352. 24:25:04select the data that we want. We just
  38353. 24:25:06built this product sales descending.
  38354. 24:25:08Let's go ahead and click on this. We do
  38355. 24:25:10want this bar chart, but let's come in
  38356. 24:25:12here and let's look at all these
  38357. 24:25:14different options. There is a lot of
  38358. 24:25:16different types of visualizations that
  38359. 24:25:18we can create, and a lot of these are
  38360. 24:25:20the ones that you'll use 99% of the
  38361. 24:25:22time. So, we're going to click on this
  38362. 24:25:24bar chart. Now, we have to select the
  38363. 24:25:26x-axis and the y-axis. In our chart, the
  38364. 24:25:29axes are like this. We have we have two
  38365. 24:25:31separate axes. And so, we need to select
  38366. 24:25:33what data goes on each of those axes.
  38367. 24:25:36So, let's select our x-axis. For this,
  38368. 24:25:38we're going to do the sum of the total
  38369. 24:25:40price. And then for the yaxis, we're
  38370. 24:25:42going to select the product. Now, this
  38371. 24:25:45looks perfectly fine, right? I'm going
  38372. 24:25:47to uh expand this a little bit just for
  38373. 24:25:49a second. This looks perfectly fine as
  38374. 24:25:52is, but there's a lot of little things
  38375. 24:25:54that we can do to make it a lot better.
  38376. 24:25:57The first thing that I'm noticing is
  38377. 24:25:59that I, you know, I'm having a little
  38378. 24:26:01tough time reading this. I'm saying,
  38379. 24:26:03okay, how much is this one exactly? It's
  38380. 24:26:05a little over 11,000. And if I hover
  38381. 24:26:07over it, it'll tell me the exact number.
  38382. 24:26:09But that's not good for a customer or
  38383. 24:26:11somebody to see. I'm going to add these
  38384. 24:26:13labels. And now we can see it right
  38385. 24:26:16away. So, we don't have to kind of
  38386. 24:26:17guesstimate. we can see the exact
  38387. 24:26:19number. The next thing I'm noticing is
  38388. 24:26:21that it's kind of all over the place. It
  38389. 24:26:23looks like it's in alphabetical order
  38390. 24:26:25here, but if you remember in our data
  38391. 24:26:27back here, we had it in descending order
  38392. 24:26:30based off of the sum of total price. So,
  38393. 24:26:32highest to lowest, that's descending.
  38394. 24:26:34And I want that in our dashboard as
  38395. 24:26:36well. All we have to do is we're going
  38396. 24:26:38to click on this. We're going to go down
  38397. 24:26:40to these three bars right above product.
  38398. 24:26:42And then we're going to click buy Xaxis
  38399. 24:26:45and then right here is the descending.
  38400. 24:26:47So now we've ordered our data from
  38401. 24:26:50highest to lowest. It's no longer
  38402. 24:26:52alphabetical. Now there are some other
  38403. 24:26:53things I want to highlight. We don't
  38404. 24:26:54have to add these, but we absolutely
  38405. 24:26:57can. First, let's add a title. So we're
  38406. 24:26:59just going to call this total price
  38407. 24:27:02by product. Keep it super simple. But we
  38408. 24:27:05can also add a description. For example,
  38409. 24:27:08let's say we wanted to add some context
  38410. 24:27:09to this. Or maybe we wanted to highlight
  38411. 24:27:11that this is our biggest seller. So, we
  38412. 24:27:13can say Golden Gate Ginger is our
  38413. 24:27:16highest
  38414. 24:27:19selling product
  38415. 24:27:21eight years in a row. Now, I'm just
  38416. 24:27:24making this up. Uh, this isn't real.
  38417. 24:27:25This is just as an example, but let's
  38418. 24:27:27say we had some historical data and this
  38419. 24:27:29is now showing, hey, this is still our
  38420. 24:27:31best seller and I just wanted to add
  38421. 24:27:32that as some context. You can definitely
  38422. 24:27:34do that. You don't have to, but you can.
  38423. 24:27:36One other thing is let's take a look at
  38424. 24:27:38these colors because we don't have to
  38425. 24:27:41just keep these colors. We can also use
  38426. 24:27:43a custom color. So they can be you know
  38427. 24:27:45whatever color you think is best for
  38428. 24:27:47your dashboard. We can also click on
  38429. 24:27:49this plus sign and we can create some
  38430. 24:27:51other options. Now if we click on
  38431. 24:27:52product and this is one that I don't
  38432. 24:27:54necessarily recommend. So each product
  38433. 24:27:56is going to get its own color on each
  38434. 24:27:59row. It's a little bit redundant. Now
  38435. 24:28:01let's go back over here. Let's get rid
  38436. 24:28:03of our product and let's select our
  38437. 24:28:06total price. Now we have this gradient
  38438. 24:28:09scale from blue to white. This isn't my
  38439. 24:28:11favorite. I actually prefer if we come
  38440. 24:28:14right up here and let's get the green
  38441. 24:28:17blue. And so this is a great way to
  38442. 24:28:19analyze and visualize at the same time.
  38443. 24:28:21Sometimes you already know what you're
  38444. 24:28:22going to be building out and so you can
  38445. 24:28:24work with the data while you're building
  38446. 24:28:26your dashboard. And now I can very
  38447. 24:28:27easily see I'm like Golden Gate Ginger
  38448. 24:28:29Man that is our product. like we're
  38449. 24:28:31killing it with this product. Uh but
  38450. 24:28:32Richard Oasis, nobody likes that. It's
  38451. 24:28:34doing okay, but it is our worst seller.
  38452. 24:28:37Now, just remember, we use this product
  38453. 24:28:40sales descending and let's go take a
  38454. 24:28:42look at this. This is the only data
  38455. 24:28:45available to us in that visualization.
  38456. 24:28:48Let's come over here and let's look at
  38457. 24:28:51our sales transactions. We have our
  38458. 24:28:54sales transactions right here. This is
  38459. 24:28:55all of our data. And so there are times
  38460. 24:28:58where we don't even need to write a
  38461. 24:29:01custom query for each visualization.
  38462. 24:29:03Let's take a look at this. So let's use
  38463. 24:29:05our sales transactions to create a
  38464. 24:29:07visualization in our dashboard. Let's
  38465. 24:29:09come down here. Let's create our new
  38466. 24:29:11visualization. And the next one that
  38467. 24:29:13we're going to take a look at is payment
  38468. 24:29:15type. So let's change this data set to
  38469. 24:29:17the sales transaction. So now we're
  38470. 24:29:19using two different data sets. Just note
  38471. 24:29:22that for future reference because that
  38472. 24:29:24will come into play. But we're going to
  38473. 24:29:26come down here and let's say we wanted
  38474. 24:29:28to create a pie chart for the angle. And
  38475. 24:29:32I'm just going to come down here. We're
  38476. 24:29:34going to do payment method right here.
  38477. 24:29:36It's going to give us a count. And we
  38478. 24:29:37don't have to do count distinct. In
  38479. 24:29:39fact, uh we probably shouldn't because
  38480. 24:29:41it's just going to if we hover over it,
  38481. 24:29:42you're going to see three because
  38482. 24:29:43there's only three options. But if we do
  38483. 24:29:45a count and hover over it now, it's
  38484. 24:29:473.33,000.
  38485. 24:29:49So now we're going to be able to see how
  38486. 24:29:51many transactions are using each payment
  38487. 24:29:53method. Now, for the color, this one is
  38488. 24:29:56actually really important for a pie
  38489. 24:29:58chart. Let's come in here and we want to
  38490. 24:30:00do this based off of the payment method.
  38491. 24:30:02We want to break it out. So, we have
  38492. 24:30:04this payment method. We have Mastercard,
  38493. 24:30:06AX, and Visa. Again, we can see the
  38494. 24:30:09split based off of the color, but I
  38495. 24:30:11really like labels. I think they're just
  38496. 24:30:13super important. So, I'm going to add
  38497. 24:30:15these labels in right here. Now, this is
  38498. 24:30:16an example where it says count of
  38499. 24:30:18payment method right here on the
  38500. 24:30:20dashboard. I don't like that. I mean,
  38501. 24:30:22that's just by default. It's going to
  38502. 24:30:23take the uh name of it. But I'm going to
  38503. 24:30:25come in here. I'm going to change this
  38504. 24:30:27display name. So, all I'm going to do is
  38505. 24:30:29I'm just going to call this payment
  38506. 24:30:30method breakdown.
  38507. 24:30:33And let's change that. And that looks a
  38508. 24:30:36lot better. It just doesn't seem so I
  38509. 24:30:38just tossed it in there. Seems like you
  38510. 24:30:39intentionally named this dashboard. So,
  38511. 24:30:42we were able to go in to this sales
  38512. 24:30:44transactions that has a lot of different
  38513. 24:30:46fields, a lot of different columns, and
  38514. 24:30:48we're able to just kind of pick out
  38515. 24:30:49which one we want to use. So far, our
  38516. 24:30:51dashboard is looking great. We're just
  38517. 24:30:53going to build one last visualization
  38518. 24:30:55and then we're going to work on
  38519. 24:30:56filtering. So, let's come right down
  38520. 24:30:58here and let's create one last
  38521. 24:31:00visualization. And this is going to be
  38522. 24:31:02our dashboard. So, we're going to come
  38523. 24:31:04in here. We're going to use sales
  38524. 24:31:05transactions again, but this time we
  38525. 24:31:08want to see our transactions over time,
  38526. 24:31:10right? We have this date column and we
  38527. 24:31:12want to use this. Let's use a line
  38528. 24:31:14chart. And if we go back to our data, we
  38529. 24:31:17have this date time. And this is really
  38530. 24:31:19useful. We want to utilize this and see
  38531. 24:31:21how many transactions are we having over
  38532. 24:31:23time. Maybe there's a certain day of the
  38533. 24:31:24week that people are just making a lot
  38534. 24:31:26of transactions. This is really useful
  38535. 24:31:27data for someone to know. So, let's go
  38536. 24:31:30back to our dashboard and let's come
  38537. 24:31:32down here to our x-axis. And for this,
  38538. 24:31:34we want it to be our date column right
  38539. 24:31:37down here. So, we'll choose our date
  38540. 24:31:38time. Now, by default, it's going to
  38541. 24:31:41select monthly, but you can come in here
  38542. 24:31:43and you can transform this. It's going
  38543. 24:31:45to take that datetime column. It's going
  38544. 24:31:47to be able to automatically change it to
  38545. 24:31:49basically anything you want. So, let's
  38546. 24:31:51just choose daily for now, but we can
  38547. 24:31:53change it later on. We just have to
  38548. 24:31:55choose our y-axis. So, let's click on
  38549. 24:31:57our plus sign in order to see our sales
  38550. 24:31:59over time. Let's take a look at our
  38551. 24:32:01quantity. It's going to do the sum of
  38552. 24:32:03quantity here. And if we go back just to
  38553. 24:32:06check on this data, the quantity is the
  38554. 24:32:08actual amount that we sold. So, we sold
  38555. 24:32:10eight, we sold 36, we sold 40. And so,
  38556. 24:32:12it's aggregating that data for us, which
  38557. 24:32:14is really nice. If we come right over
  38558. 24:32:16here, we can hover over this and we can
  38559. 24:32:18kind of see each day and the sum of
  38560. 24:32:22quantity. Now, again, we need to
  38561. 24:32:24transform this a little bit because it's
  38562. 24:32:26just sum of quantity, date, time, um,
  38563. 24:32:29doesn't display the best. We want to
  38564. 24:32:31customize this. We're going to just say
  38565. 24:32:32date to keep it simple. And then for the
  38566. 24:32:34sum of quantity, we're going to say
  38567. 24:32:36quantity sold and keep it just like
  38568. 24:32:39this. for our title because I think this
  38569. 24:32:42one may need one. We'll say quantity of
  38570. 24:32:44sales over time. Right there we go. Now
  38571. 24:32:49we have our dashboard built. It looks
  38572. 24:32:52great. I'm super happy with this. One
  38573. 24:32:54last thing we should add, and this is
  38574. 24:32:56optional. You don't have to do this, but
  38575. 24:32:58I'm going to add this title really
  38576. 24:33:00quick. I'm going to call this our
  38577. 24:33:02transaction. Let me spell that right.
  38578. 24:33:05Transaction dashboard. And I'm going to
  38579. 24:33:08format it just a little bit. I'm going
  38580. 24:33:10to do it like this. I'm going to
  38581. 24:33:13increase the size. Just like that. You
  38582. 24:33:16can change it to be a different color,
  38583. 24:33:18but it just kind of adds a little bit of
  38584. 24:33:21finesse to it, right? We can put that up
  38585. 24:33:24and make this smaller. Um, we can make
  38586. 24:33:26this smaller if we want to go kind of
  38587. 24:33:28that route. But it is up to you. The
  38588. 24:33:31next thing that I want to show you
  38589. 24:33:32though is adding a filter. Now, filters
  38590. 24:33:36are quite important. customers, clients,
  38591. 24:33:38managers, whoever is using this
  38592. 24:33:40dashboard are going to want to filter in
  38593. 24:33:42some way. They're going to want to say,
  38594. 24:33:43"Oh, I want to filter on this product or
  38595. 24:33:44I want to filter on this month or this
  38596. 24:33:46year or whatever it is." And so adding a
  38597. 24:33:49filter is really important. We can add a
  38598. 24:33:51global filter right here. Now, let's
  38599. 24:33:53come over here to our widget because we
  38600. 24:33:55do have the ability to change the type
  38601. 24:33:57of filter. We can select multiple
  38602. 24:33:59values. It could just be a single value.
  38603. 24:34:01Could be a date picker or range picker.
  38604. 24:34:03So, a range of dates instead of just a
  38605. 24:34:05single date. It could be a text entry
  38606. 24:34:07where they're searching for something.
  38607. 24:34:08Maybe it's a product. You can also do a
  38608. 24:34:10range slider. Let's click on this range
  38609. 24:34:13slider and let's come in here. We're
  38610. 24:34:15going to go down to the sales
  38611. 24:34:17transactions and let's go down to the
  38612. 24:34:20quantity. Now, what this means is is
  38613. 24:34:22we've created this global filter on
  38614. 24:34:24quantity. Quantity is a numeric data
  38615. 24:34:27type. So, we have this slider where we
  38616. 24:34:29can basically say, hey, I only want to
  38617. 24:34:30see where the quantity was over a
  38618. 24:34:32certain amount. So we have a picker
  38619. 24:34:34where we can select a range for the
  38620. 24:34:36quantity. Maybe we only want to see the
  38621. 24:34:38transactions that have a quantity
  38622. 24:34:40greater than 30. For example, we would
  38623. 24:34:42be able to do that in this dashboard. We
  38624. 24:34:44can click in here and we can customize
  38625. 24:34:46this. Maybe the minimum is zero and the
  38626. 24:34:48maximum is let's say 100. I'm just going
  38627. 24:34:51to set it for now. Let's come right over
  38628. 24:34:53here and let's say we only want to look
  38629. 24:34:55at it where it's greater than 30. So I'm
  38630. 24:34:58going to click on that. You'll notice
  38631. 24:35:00that this doesn't actually change at
  38632. 24:35:02all, but this one changed and this one
  38633. 24:35:05changed. And let's just highlight that a
  38634. 24:35:08little more. Let's kind of slide this
  38635. 24:35:09around.
  38636. 24:35:12And you'll notice
  38637. 24:35:15that only these ones are changing, but
  38638. 24:35:17this one is not changing. The reason for
  38639. 24:35:19that is the data set that we chose. So,
  38640. 24:35:22let's come back here. Right up here, we
  38641. 24:35:24have the product sales descending. And
  38642. 24:35:27then if you go down here, we have our
  38643. 24:35:29sales transactions and we have our sales
  38644. 24:35:32transactions. But what are we actually
  38645. 24:35:34filtering on? We are filtering on the
  38646. 24:35:36quantity. And if you remember, let's go
  38647. 24:35:38back to our product sales description.
  38648. 24:35:41We don't have the quantity in here at
  38649. 24:35:43all. And so this quantity is not
  38650. 24:35:44connected to this data set. And so when
  38651. 24:35:46we're applying this filter to this
  38652. 24:35:48dashboard, it is not connected to this
  38653. 24:35:51right here. Now, the way that we can fix
  38654. 24:35:53that is we can replicate this exact
  38655. 24:35:55dashboard. And this is what I was kind
  38656. 24:35:57of talking about earlier, which is why
  38657. 24:35:59we're going to create a second
  38658. 24:36:00dashboard, but we're going to create the
  38659. 24:36:03exact same thing, but we're going to use
  38660. 24:36:06the other data set. So now we're in
  38661. 24:36:08sales transactions. We're going to
  38662. 24:36:09create our bar chart. For the x-axis,
  38663. 24:36:11we're going to do the sum of total
  38664. 24:36:13price. And for the yaxis, it's going to
  38665. 24:36:16be the product. Let's find it right
  38666. 24:36:18here.
  38667. 24:36:19Let's scan this all the way over. Let's
  38668. 24:36:22go down, add our labels, create our
  38669. 24:36:25custom
  38670. 24:36:27colors based off of the total price, and
  38671. 24:36:30we'll change that coloring to be the
  38672. 24:36:33green blue. And you can already see that
  38673. 24:36:35this is filtered based off of our global
  38674. 24:36:38filter right over here. So, let's get
  38675. 24:36:39rid of this. Let's just make it the
  38676. 24:36:41same. And we actually need to do one
  38677. 24:36:43more thing. We need to
  38678. 24:36:45go like this.
  38679. 24:36:47So now we have the exact same
  38680. 24:36:49visualization,
  38681. 24:36:51but this one is going to be connected to
  38682. 24:36:54our filter. So this is a really
  38683. 24:36:55important just thing to understand when
  38684. 24:36:57you're building out these dashboards is
  38685. 24:36:59people really like their filters. They
  38686. 24:37:01want to be able to do that and this is
  38687. 24:37:03actually going to be a big thing that
  38688. 24:37:04people request once you build your
  38689. 24:37:06dashboard. You're going to build it out.
  38690. 24:37:07It's going to be great and they're like,
  38691. 24:37:08"Hey, I want to be able to filter on
  38692. 24:37:10this. I want to be able to filter on
  38693. 24:37:12this." And so you're going to have to
  38694. 24:37:13build that out and you may have to go
  38695. 24:37:15back and connect your data in certain
  38696. 24:37:16ways to be able to accommodate certain
  38697. 24:37:18filters. So that's just something to
  38698. 24:37:20think about and something to know. But
  38699. 24:37:22now this one is connected just like
  38700. 24:37:24this. And so I would actually replace
  38701. 24:37:27this one with this new visualization
  38702. 24:37:30right down here because I want it to be
  38703. 24:37:32connected to all of our other data for
  38704. 24:37:34these types of global filters. Now there
  38705. 24:37:36are of course some other things that we
  38706. 24:37:38could do. We can come in here and change
  38707. 24:37:39some of these uh axes. We could add some
  38708. 24:37:41more context in here. This is our sample
  38709. 24:37:43data set. This is as far as we're going
  38710. 24:37:44to go in this lesson. But like I
  38711. 24:37:46mentioned earlier in the last video in
  38712. 24:37:48this series, we're going to be building
  38713. 24:37:49out a full project using real raw data.
  38714. 24:37:52So we're going to have to do some data
  38715. 24:37:53cleaning. We're going to have to really
  38716. 24:37:54dig in and analyze our data and
  38717. 24:37:55visualize and create our dashboard. The
  38718. 24:37:57first we're going to be looking at is
  38719. 24:37:58Genie. And Genie is built for business
  38720. 24:38:00users to be able to get insight from
  38721. 24:38:02their data just using natural language.
  38722. 24:38:04Next, we're going to be using their AI
  38723. 24:38:05assistant to help us code. So we'll be
  38724. 24:38:07using that in the SQL editor as well as
  38725. 24:38:08the notebooks. It's going to help us
  38726. 24:38:10generate code, but it's also going to
  38727. 24:38:11help us diagnose and fix issues if we
  38728. 24:38:13run into them. Next, we're going to use
  38729. 24:38:14their AI assistant in the dashboards
  38730. 24:38:16tab. So, it's going to help us create
  38731. 24:38:17visualizations. Now, what's so amazing
  38732. 24:38:19is you're going to be able to try all
  38733. 24:38:20these things completely for free because
  38734. 24:38:22in Data Bricks free edition, you can use
  38735. 24:38:24all of their AI tools completely for
  38736. 24:38:26free. Be sure to use the link in the
  38737. 24:38:27description to create your account so
  38738. 24:38:29you can follow along and practice and
  38739. 24:38:31actually use all these AI tools. With
  38740. 24:38:33that being said, let's jump on my screen
  38741. 24:38:34and get started. When you first pull up
  38742. 24:38:36data bricks, we're going to need to come
  38743. 24:38:38right down here within the SQL section
  38744. 24:38:40to Genie. Let's go ahead and click on
  38745. 24:38:42this. And this about sums it up for
  38746. 24:38:44Genie. You can ask questions about your
  38747. 24:38:46data in natural language. And that's
  38748. 24:38:48what it is. It's just a way to converse
  38749. 24:38:50with your data. Ask questions about your
  38750. 24:38:52data. Let's come over here. We're going
  38751. 24:38:54to go to new. And we want to connect to
  38752. 24:38:56a data source. We are going to use a
  38753. 24:38:58sample data set. Let's actually go to
  38754. 24:39:00all. It's within the samples right down
  38755. 24:39:03here. this New York City uh data set.
  38756. 24:39:06This is the data that we're going to be
  38757. 24:39:07using for this video. Let's go ahead and
  38758. 24:39:10create this.
  38759. 24:39:11It's going to spin up our SQL warehouse
  38760. 24:39:13because that is what we're going to be
  38761. 24:39:15using to interact with this data. Now,
  38762. 24:39:17while this is going and while it's uh
  38763. 24:39:19just starting up and we can get rid of
  38764. 24:39:21this, we now have this data that sits
  38765. 24:39:23right over here. Now, I'm just going to
  38766. 24:39:24give you kind of an introduction to kind
  38767. 24:39:26of this interface, but we're right here
  38768. 24:39:28in this configure tab. We can come over
  38769. 24:39:31here and we can create custom
  38770. 24:39:32instructions for whatever we want this
  38771. 24:39:34genie to be. So if this genie is
  38772. 24:39:36supposed to be for a specific team or a
  38773. 24:39:38specific project or whatever it is, you
  38774. 24:39:40can give it these guidelines because
  38775. 24:39:41then you can share this with other
  38776. 24:39:43people and they can interact with it. So
  38777. 24:39:44if it's people on your team who are
  38778. 24:39:46interacting with a specific data source,
  38779. 24:39:48then everyone can interact with that AI
  38780. 24:39:50in the same way. That's pretty cool. If
  38781. 24:39:52we come right over here to settings, we
  38782. 24:39:53can also name this. So, I'm just going
  38783. 24:39:55to call this one uh datab bricks genie
  38784. 24:40:00taxi. And I could add some description,
  38785. 24:40:02but I'm not going to at the moment. Now,
  38786. 24:40:04right over here, you'll notice in this
  38787. 24:40:06space, we have a little bit of kind of
  38788. 24:40:08prompting that is just, hey, here are
  38789. 24:40:10some things that you can click on and we
  38790. 24:40:11can give you that information. We can
  38791. 24:40:13also add a sample question. So, if you
  38792. 24:40:15want to add one for your team or whoever
  38793. 24:40:17you're working with or just for
  38794. 24:40:18yourself, you can add a question right
  38795. 24:40:20here. Let's just go ahead and save this.
  38796. 24:40:23and we're going to get out of here so
  38797. 24:40:25that we have just this Genie interface
  38798. 24:40:27right here. Now, as I mentioned before,
  38799. 24:40:29Genie is really great for a business
  38800. 24:40:31user, someone who's just going to be
  38801. 24:40:32using natural language in order to ask
  38802. 24:40:34questions about the data. If you are a
  38803. 24:40:37more technical user, you're most likely
  38804. 24:40:39going to be using the AI assistant that
  38805. 24:40:40we're going to be looking at in the SQL
  38806. 24:40:42editor and the notebooks. You can edit
  38807. 24:40:43and dive into the code and get into the
  38808. 24:40:45more programming side of data bricks.
  38809. 24:40:47Let's just go ahead and ask it to
  38810. 24:40:49explain this data set because we haven't
  38811. 24:40:51taken a look at this data set at all. In
  38812. 24:40:53fact, I don't even know what it looks
  38813. 24:40:54like. It's just a New York City taxi
  38814. 24:40:56data set. So, it says here's where it's
  38815. 24:40:58located. It contains taxi trips,
  38816. 24:41:00cleaning pickup, drop off, trip
  38817. 24:41:01distance, fair amount, and
  38818. 24:41:03pickoff/dropoff
  38819. 24:41:05zip codes. This is the only table in
  38820. 24:41:07here. Now, we can actually come over
  38821. 24:41:08here to configure and we can click on
  38822. 24:41:10this table and we can see a very quick
  38823. 24:41:12kind of sample of this. But I'm going to
  38824. 24:41:14ask it to show me a sample of the data,
  38825. 24:41:18please. I like to be polite uh when
  38826. 24:41:20working with AI. You just never know,
  38827. 24:41:22right? I just want to make sure I'm I'm
  38828. 24:41:24being uh respectful here. So, now it's
  38829. 24:41:26going to give me a sample of our data.
  38830. 24:41:28Now, you'll notice right over here we
  38831. 24:41:30have this show code, and this is what
  38832. 24:41:32it's going to do for basically anything.
  38833. 24:41:34It's going to show us kind of what it's
  38834. 24:41:36doing under the hood, which I really
  38835. 24:41:38like. You can also edit in here. So, if
  38836. 24:41:40we want to come in here and we want to
  38837. 24:41:41say, okay, let's limit it to 20 because
  38838. 24:41:43we only have a small sample down here.
  38839. 24:41:45Now, we can run this again and it's
  38840. 24:41:48going to keep all this information, but
  38841. 24:41:49we're now rerunning and kind of changing
  38842. 24:41:51the code as we go if you want to do
  38843. 24:41:53that. So, now let's take a look just at
  38844. 24:41:55our data really quickly. This is for
  38845. 24:41:57taxi data. So, we have a pickup time, a
  38846. 24:41:59drop off time, how long the distance
  38847. 24:42:01was, how much it cost, the pickup zip,
  38848. 24:42:04and the drop off zip. So, fairly simple
  38849. 24:42:06data. Now, there's a lot of things I
  38850. 24:42:08could ask about this data set. I'm going
  38851. 24:42:09to keep it pretty simple. As we go
  38852. 24:42:11further along in this video, we're going
  38853. 24:42:13to get a little bit more technical, a
  38854. 24:42:15little bit more challenging to the AI to
  38855. 24:42:17really see what it can do. So, I'm just
  38856. 24:42:19going to say, what zip code
  38857. 24:42:23are people
  38858. 24:42:25being picked up at
  38859. 24:42:28the most? So, I just want to know where
  38860. 24:42:31are most people being picked up? Maybe
  38861. 24:42:32there's a specific zip code that 99% of
  38862. 24:42:36these users are getting picked up at and
  38863. 24:42:38that would be really useful information.
  38864. 24:42:40So, let's see what Genie comes up with.
  38865. 24:42:41So, it says it right here. The most
  38866. 24:42:43common pickup zip is 10,01 with 1,227
  38867. 24:42:47pickups recorded. Now, you can see that
  38868. 24:42:49right down here, but again, you have to
  38869. 24:42:51remember that this is mostly for
  38870. 24:42:52business users. And so, I think it is
  38871. 24:42:54good that they include this information
  38872. 24:42:55up here just as a narrative that you can
  38873. 24:42:57read. Let's go and look at the code. So,
  38874. 24:42:59it looks like uh they're looking at the
  38875. 24:43:01pickup zip, which is exactly what we
  38876. 24:43:02would want to do. They're doing just a
  38877. 24:43:04count of everything, and then they're
  38878. 24:43:06grouping on that pickup zip as well, but
  38879. 24:43:08then ordering it, descending on the
  38880. 24:43:10pickup count, and limiting by one. This
  38881. 24:43:12is how I would have written it as well.
  38882. 24:43:13This isn't anything crazy complex. But I
  38883. 24:43:16think it did a really good job answering
  38884. 24:43:17this question. Now, as I've been testing
  38885. 24:43:20and working within Genie, it is pretty
  38886. 24:43:22good with answering a lot of the
  38887. 24:43:23questions about the data. Let's get a
  38888. 24:43:25little bit more difficult with this one.
  38889. 24:43:27So, let's come down here and let's say,
  38890. 24:43:30what time of day do most people get a
  38891. 24:43:34ride? Now, this is kind of how I would
  38892. 24:43:36imagine someone who's not very technical
  38893. 24:43:38might ask this question, right? It's not
  38894. 24:43:40very specific, and I'm curious as to how
  38895. 24:43:42it's going to handle it. So, let's see
  38896. 24:43:44what code it writes and the output that
  38897. 24:43:46we get. So, it looks like it used the
  38898. 24:43:48pickup hour. It says the highest number
  38899. 24:43:49of rides occur at 1,800, which is 6 p.m.
  38900. 24:43:53with,455
  38901. 24:43:55rides during that hour. Let's look at
  38902. 24:43:56the code really quick. So it looks like
  38903. 24:43:58it's using this hour right here within
  38904. 24:44:01our datetime. It's running a count. It's
  38905. 24:44:04kind of filtering a little bit and
  38906. 24:44:05grouping on this and doing kind of the
  38907. 24:44:07same thing it did in our previous query.
  38908. 24:44:09Now Genie does have the ability to
  38909. 24:44:11create visualizations as well. Let's see
  38910. 24:44:13if it can visualize this. I'm going to
  38911. 24:44:15say uh can you visualize this?
  38912. 24:44:20All right, it did exactly what I asked
  38913. 24:44:23it to do. I asked it to visualize it and
  38914. 24:44:25it literally is visualizing uh the
  38915. 24:44:27pickup hour and the count amount. This
  38916. 24:44:30is not exactly what I had in mind. I
  38917. 24:44:31actually wanted to see all the pickup
  38918. 24:44:33times over time. So, I'm going to ask it
  38919. 24:44:35if it can show me all the pickup hours
  38920. 24:44:37and the counts and visualize it. So, I
  38921. 24:44:39just went ahead and wrote that. I said,
  38922. 24:44:41"Write a SQL query to show me all the
  38923. 24:44:42pickup times and the counts and then
  38924. 24:44:45visualize it." Let's see if it's able to
  38925. 24:44:47do this one because the previous
  38926. 24:44:49visualization was not exactly what I was
  38927. 24:44:51hoping for. Although it gave me exactly
  38928. 24:44:53what I asked for. So it looks like it
  38929. 24:44:55did this properly. And let's just look
  38930. 24:44:57at this. They really are just doing the
  38931. 24:45:00same query, but now they're not, you
  38932. 24:45:01know, filtering on uh it descending and
  38933. 24:45:04then limiting it by one. Now we have all
  38934. 24:45:07of them. And whoops, let's go right down
  38935. 24:45:09here. And now we have a visualization of
  38936. 24:45:12this data. As you can see right here,
  38937. 24:45:15this is our highest one. This is our
  38938. 24:45:161,800 or our 6 p.m. And so now we have
  38939. 24:45:19this visualization. Now, the thing about
  38940. 24:45:21Genie is it's kind of its own standalone
  38941. 24:45:24thing. So, if we want, we can come up
  38942. 24:45:27here and we can copy this. So, we can
  38943. 24:45:29copy all of this and bring this over to
  38944. 24:45:31the SQL editor. But again, that's not
  38945. 24:45:33really the use case here. The use case
  38946. 24:45:34is that a business user can come in here
  38947. 24:45:36and ask questions about the data and get
  38948. 24:45:38their questions answered without having
  38949. 24:45:39to go into the SQL editor or a notebook
  38950. 24:45:41or build a dashboard. So, with that
  38951. 24:45:43being said, let's come right over here
  38952. 24:45:45to our SQL editor and let's go right
  38953. 24:45:48over here and let's take a look within a
  38954. 24:45:51new query window. Let's take a look at
  38955. 24:45:54the AI assistant that they have. Now,
  38956. 24:45:56they have one right here, but you can
  38957. 24:45:58also see a button right up here. They
  38958. 24:46:00are both the assistant, but they are
  38959. 24:46:02used in a different way. I'm going to
  38960. 24:46:04demonstrate that in just a little bit.
  38961. 24:46:06We're going to generate some code, but
  38962. 24:46:07then we can ask larger context questions
  38963. 24:46:10about the code and the data and
  38964. 24:46:12revisions and insight into our data with
  38965. 24:46:15our assistant up here, but we can't
  38966. 24:46:16really do that with this one cuz this is
  38967. 24:46:18purely for generating code. Let's go
  38968. 24:46:20ahead and click on generate code. Now,
  38969. 24:46:22we don't have this connected to our
  38970. 24:46:23data. So, I'm just going to say, show me
  38971. 24:46:26our New York City taxi data. And I'm
  38972. 24:46:29going to ask it to generate this. Now,
  38973. 24:46:32this is very generic. I don't even know
  38974. 24:46:34if it's connected to this data. Let's
  38975. 24:46:35just see what it does. It does not know
  38976. 24:46:38exactly what data I'm talking about. And
  38977. 24:46:40that's because we're in this
  38978. 24:46:40workspace.default.
  38979. 24:46:42I just wanted to see if it would be able
  38980. 24:46:43to pick up on it, but it's not doing
  38981. 24:46:45that. Let's click over here. Let's go to
  38982. 24:46:48our samples. And for our schema, let's
  38983. 24:46:51come down here to New York City. I'm
  38984. 24:46:53going to accept this really quick
  38985. 24:46:54because I want to demonstrate something.
  38986. 24:46:56Let's go ahead and try to run this. It's
  38987. 24:46:58not going to work. And that's okay. But
  38988. 24:47:00what we can do is we can come right down
  38989. 24:47:03here and we can say let's diagnose this
  38990. 24:47:05error. So let's click on the diagnose
  38991. 24:47:08and the assistant in the top right is
  38992. 24:47:10now going to be activated. It's going to
  38993. 24:47:11do this forward/fix. And so now it's
  38994. 24:47:14going to say okay we need to use the
  38995. 24:47:16proper schema and even if we hadn't
  38996. 24:47:18switched over honestly it would have
  38997. 24:47:20picked this up. This assistant up here
  38998. 24:47:22is slightly more contextaware I've
  38999. 24:47:25noticed than the actual code generation
  39000. 24:47:27right down here. So now we can try
  39001. 24:47:29running this. And we can run this right
  39002. 24:47:30over here. And we're going to be able to
  39003. 24:47:32see our data at the bottom. And I'm
  39004. 24:47:34going to click this button in. It's
  39005. 24:47:36going to say replace active query
  39006. 24:47:37content. And so now I'm going to paste
  39007. 24:47:39all this code right into this window.
  39008. 24:47:42Let's get rid of this for now. And what
  39009. 24:47:44we're going to do is I'm going to edit
  39010. 24:47:47this code. So as you can see, it
  39011. 24:47:48highlights all of our code. And I'm
  39012. 24:47:50going to do two things. One, I'm just
  39013. 24:47:52going to do this forward slash. And
  39014. 24:47:54we're going to get some options here.
  39015. 24:47:56We're going to say forward
  39016. 24:47:57sldoc/explain.
  39017. 24:47:58We have all these options and it tells
  39018. 24:48:00you what they do on this right hand
  39019. 24:48:02side. So we can explain the code,
  39020. 24:48:04improve the formatting, optimize the
  39021. 24:48:06code, replace parameters, fix errors in
  39022. 24:48:08our code. There's a lot of different
  39023. 24:48:10options and they're just kind of
  39024. 24:48:11defaults. And these are things that you
  39025. 24:48:12can use really easily. We just fixed our
  39026. 24:48:14code, so we're not going to do that
  39027. 24:48:16right now. But what I'm going to ask it
  39028. 24:48:17to do is do something totally different.
  39029. 24:48:19Let's actually run our code really quick
  39030. 24:48:20because I want you to be able to see the
  39031. 24:48:22data in here. But we have two really
  39032. 24:48:25useful columns, a pickup time and a drop
  39033. 24:48:27off time. And I'm going to ask it to
  39034. 24:48:29calculate the difference between this
  39035. 24:48:31and give us the average of those times.
  39036. 24:48:33What's the average length of ride? It
  39037. 24:48:35says the trip distance, but it doesn't
  39038. 24:48:37tell us how long the trip took. So, I'm
  39039. 24:48:39going to go into the code. I'm going to
  39040. 24:48:41say I want the average time it took
  39041. 24:48:46between
  39042. 24:48:49pickup and drop off. Now, this is a
  39043. 24:48:52little bit more difficult. This is more
  39044. 24:48:54difficult than anything we did in Genie.
  39045. 24:48:56Let's see if it's able to write this
  39046. 24:48:57code correctly. Now, we can see what
  39047. 24:48:59it's getting rid of with the red lines
  39048. 24:49:01and with the green lines. We can see
  39049. 24:49:02what it's actually keeping. We can
  39050. 24:49:04accept this either by clicking accept or
  39051. 24:49:06clicking tab. I'm going to go ahead and
  39052. 24:49:08click tab. And basically, what it's
  39053. 24:49:09doing is it's taking the drop off time
  39054. 24:49:11and it's taking the pickup time. It's
  39055. 24:49:13subtracting it and then it's taking the
  39056. 24:49:15average. And so, we're just going to go
  39057. 24:49:17ahead and run this.
  39058. 24:49:19And in seconds, that works perfect. But
  39059. 24:49:22I don't want it in seconds. I want it in
  39060. 24:49:23minutes. So I'm going to edit this. I'm
  39061. 24:49:25gonna say I want the average to be in
  39062. 24:49:29minutes,
  39063. 24:49:30not seconds.
  39064. 24:49:33It's going to rewrite this and it's
  39065. 24:49:34going to divide it by 60. And that's
  39066. 24:49:36really uh all it needs. Let's go ahead
  39067. 24:49:38and tap this. Let's run our code. And
  39068. 24:49:41now we have average trip duration in
  39069. 24:49:43minutes. It's around 15 minutes. Now,
  39070. 24:49:45this is really great, but somebody who
  39071. 24:49:47doesn't know what this is might be very
  39072. 24:49:49confused. So, I'm going to come up here
  39073. 24:49:52and I'm going to use one of these
  39074. 24:49:53forward slashes and I'm going to say add
  39075. 24:49:55comments to code. So, I'm just going to
  39076. 24:49:57hit enter. It's going to start
  39077. 24:49:59commenting on this code and I can click
  39078. 24:50:02accept. It's just going to say
  39079. 24:50:03calculates the average trip duration in
  39080. 24:50:04minutes by subtracting pickup from drop
  39081. 24:50:07off timestamps. Very simple, very
  39082. 24:50:09straightforward, but it is really
  39083. 24:50:10helpful for somebody who's going to be
  39084. 24:50:12coming behind you and reading this code.
  39085. 24:50:13Now, as I mentioned before, this is for
  39086. 24:50:15coding, but if you have other questions
  39087. 24:50:17about the data, you can also come over
  39088. 24:50:20here. So, I'm just going to say, tell me
  39089. 24:50:22a bit about this data. Now, this is just
  39090. 24:50:26kind of a really simple overview of the
  39091. 24:50:28columns and kind of what's in it. It's
  39092. 24:50:30pretty straightforward, but now let's
  39093. 24:50:32ask it. We're going to say, give me a
  39094. 24:50:35simple data dictionary
  39095. 24:50:37for each column. Now, I could have said
  39096. 24:50:40for the whole data set. I don't know why
  39097. 24:50:42I said column, but let's see what it
  39098. 24:50:44gives us.
  39099. 24:50:49And just like that, it is going to give
  39100. 24:50:51us a data dictionary, basically a
  39101. 24:50:52description for each column. And this is
  39102. 24:50:55really useful. It reads in the data and
  39103. 24:50:57just gives you a little bit of
  39104. 24:50:59information about what is in that data,
  39105. 24:51:01as well as the data type and the column
  39106. 24:51:02name. So, this is really useful. Now, as
  39107. 24:51:04I mentioned before, this isn't only in
  39108. 24:51:06the SQL editor. We can also do this
  39109. 24:51:08within a notebook. So let's come over
  39110. 24:51:10here and take a look at the assistant
  39111. 24:51:13within a notebook. You can see we have
  39112. 24:51:15this generate. It's going to look very
  39113. 24:51:17similar as it did before in the SQL
  39114. 24:51:18editor. Now it can do a lot of similar
  39115. 24:51:21things. It's going to generate code but
  39116. 24:51:23it can do it in different languages now.
  39117. 24:51:25So we can do markdown, Python, SQL,
  39118. 24:51:27Scola and R. By default though it is in
  39119. 24:51:29Python. So let's come over here. Let's
  39120. 24:51:32go ahead and ask it to
  39121. 24:51:35give us the sample New York City taxi
  39122. 24:51:40data and just see what it comes up with.
  39123. 24:51:43It looks like this one is going to be
  39124. 24:51:44perfect. Let's go ahead and run this.
  39125. 24:51:46And it's going to give us exactly what
  39126. 24:51:48we want. We have our data right here.
  39127. 24:51:50Now, one of the things that I want to
  39128. 24:51:52highlight is that what you can do cuz
  39129. 24:51:54when you're working within these
  39130. 24:51:55notebooks, you can use whatever language
  39131. 24:51:56you'd like. You can convert it to other
  39132. 24:51:58languages. So let's come up here to our
  39133. 24:52:01code. I'm going to say, can you convert
  39134. 24:52:06this to SQL? It's going to take this,
  39135. 24:52:09which was a dataf frame, a spark.sql
  39136. 24:52:12dataf frame, and it displayed it. It's
  39137. 24:52:13now converting it to SQL right here. And
  39138. 24:52:16then we're reading in just the SQL.
  39139. 24:52:18Let's go ahead and tab this, and we'll
  39140. 24:52:20run it. And we should get the exact same
  39141. 24:52:22output. So that's one of the things that
  39142. 24:52:25you can do in notebooks that of course
  39143. 24:52:26you're not going to do in a SQL editor
  39144. 24:52:27because you're just using SQL. So that's
  39145. 24:52:29how the assistant works within a SQL
  39146. 24:52:31editor as well as a notebook. But let's
  39147. 24:52:33head over here to our dashboards. Let's
  39148. 24:52:36go and create a new dashboard. And what
  39149. 24:52:38we're going to do is we're going to pull
  39150. 24:52:40in that data that we were using before
  39151. 24:52:42in our samples. So let's go to our
  39152. 24:52:44catalog. Let's go to our samples New
  39153. 24:52:46York City. And we'll click on this. And
  39154. 24:52:49we're going to say add to dashboard.
  39155. 24:52:52So now we have this data right up here.
  39156. 24:52:54This is our trips data. And what we're
  39157. 24:52:56going to do is come right over here and
  39158. 24:52:58we're going to add a visualization. The
  39159. 24:53:01first thing that's going to come up
  39160. 24:53:02right here is the assistant. It said ask
  39161. 24:53:04the assistant to create a chart or to
  39162. 24:53:06create anything that we want. And so
  39163. 24:53:08let's ask it to create something really
  39164. 24:53:10simple. I wanted to create a card with
  39165. 24:53:14the average fair amount. And let's go
  39166. 24:53:18ahead and run this. So, I just wanted to
  39167. 24:53:20show us the average price for one of
  39168. 24:53:22their fairs for the taxi. And there we
  39169. 24:53:24go. So, super easy, super simple. Now,
  39170. 24:53:27let's ask it a little bit more difficult
  39171. 24:53:29question. Create a line chart
  39172. 24:53:33with the count of pickup times.
  39173. 24:53:38And let's go ahead and run this. Now, it
  39174. 24:53:41did do this. And what's nice is we have
  39175. 24:53:43it right over here. It did this based
  39176. 24:53:44off of the month. I'm going to change
  39177. 24:53:46this manually to the day so that we can
  39178. 24:53:49see a little bit easier what days have a
  39179. 24:53:53lot or have a little. And we're just
  39180. 24:53:55doing a simple count on the pickup
  39181. 24:53:57dates. That's it. Now, with both of
  39182. 24:53:58these, I didn't click the accept button,
  39183. 24:54:00but once you do, once you click accept,
  39184. 24:54:02and you can of course uh change it, it
  39185. 24:54:05is going to stay there like you just
  39186. 24:54:06created it as a normal visualization.
  39187. 24:54:09Now, let's say I want to make a change
  39188. 24:54:10to this. Let's come up here and say
  39189. 24:54:11change the daily
  39190. 24:54:15and I need to spell this right. Daily to
  39191. 24:54:17hourly. Let's go ahead and run this. And
  39192. 24:54:20so there going to be a lot of people
  39193. 24:54:21they don't know how to come in here or
  39194. 24:54:23don't want to come in here. They can do
  39195. 24:54:25this by just writing change the daily to
  39196. 24:54:27hourly. I'm going to accept this. Now
  39197. 24:54:29this uh looks wild but let's uh look at
  39198. 24:54:33it. This is looking correct to me. Take
  39199. 24:54:36away that global filter. And now we're
  39200. 24:54:39looking at it hourly. And so we have a
  39201. 24:54:41very very accurate and specific view of
  39202. 24:54:44hourby hour the pickup times. And so
  39203. 24:54:46this is how we can create different
  39204. 24:54:47visualizations by just asking it. We can
  39205. 24:54:50of course come in here because it's
  39206. 24:54:52still using the exact things that we
  39207. 24:54:53would use to create these. And so if we
  39208. 24:54:56want to add labels, I'm going to say add
  39209. 24:54:58labels. I wouldn't on this data set.
  39210. 24:55:01That's going to look terrible. Um but
  39211. 24:55:02it's going to turn on the labels for
  39212. 24:55:04you. And this uh looks horrible. But it
  39213. 24:55:08did exactly what I requested. Uh it's
  39214. 24:55:10too granular to add labels. We would
  39215. 24:55:12have to change this to uh probably
  39216. 24:55:14weekly maybe um and add the labels for
  39217. 24:55:17it to even make somewhat sense. There we
  39218. 24:55:19go. So this looks a lot better. But we
  39219. 24:55:20can do a lot of the things that we can
  39220. 24:55:22manually do just using this. Now if you
  39221. 24:55:25already know how to create these
  39222. 24:55:27visualizations just by memory, you won't
  39223. 24:55:29need to use this all the time. But let's
  39224. 24:55:30say you just can't figure out how to do
  39225. 24:55:32it yourself. You can always ask. It is
  39226. 24:55:34there to assist if you need it. You
  39227. 24:55:35don't have to use it. But it can be
  39228. 24:55:38useful if you're like, I just can't
  39229. 24:55:39figure out how to create this. Let me
  39230. 24:55:41just ask the assistant and see how they
  39231. 24:55:42would create it. As you can see, there
  39232. 24:55:44are a ton of ways that you can use AI
  39233. 24:55:46and data bricks. You can use the genie.
  39234. 24:55:47You can use in the SQL editor with the
  39235. 24:55:49assistant. We can also use this
  39236. 24:55:50assistant up here, which gives a little
  39237. 24:55:52larger context and we can use it in the
  39238. 24:55:54notebooks. So, it's integrated into a
  39239. 24:55:56lot of different places that you would
  39240. 24:55:58use as an analyst or a scientist or a
  39241. 24:56:00data engineer. Now, within this entire
  39242. 24:56:02data brick series, we've learned a lot
  39243. 24:56:03of things and we're going to apply all
  39244. 24:56:05of that into our final project. If
  39245. 24:56:07you've never done one of my projects on
  39246. 24:56:09this channel before, they can be a
  39247. 24:56:10little bit long because I leave
  39248. 24:56:12everything in. I don't cut out a lot of
  39249. 24:56:13stuff. So, if I make mistakes, you're
  39250. 24:56:15going to see it so you can learn from it
  39251. 24:56:17as well. I will leave a link in the
  39252. 24:56:18description so you can go to the data
  39253. 24:56:19bricks free edition and create an
  39254. 24:56:21account so you can follow along with
  39255. 24:56:22this project. I will also have the data
  39256. 24:56:24set that we're going to be using in a
  39257. 24:56:26GitHub. So all you have to do is go and
  39258. 24:56:27download that data set and you can
  39259. 24:56:29import it and use it just like I'm
  39260. 24:56:30doing. We are going to be working with
  39261. 24:56:32real raw data. So we are going to
  39262. 24:56:33encounter some issues and some things
  39263. 24:56:35that we'll have to clean up along the
  39264. 24:56:36way. But we're going to learn a lot and
  39265. 24:56:37this is what we're going to end up with
  39266. 24:56:38at the final project. We're creating
  39267. 24:56:40this United States emissions breakdown
  39268. 24:56:42dashboard. It's going to be an awesome
  39269. 24:56:44project. So I cannot wait to do this
  39270. 24:56:45with you. Let's go ahead and jump onto
  39271. 24:56:47my screen and get started. Now, before
  39272. 24:56:48we jump into data bricks and actually
  39273. 24:56:50start building out our project, I want
  39274. 24:56:52to take a look at the data because
  39275. 24:56:54there's a lot of data here. And when I
  39276. 24:56:56say a lot, I mean, you know, there's
  39277. 24:56:58only 3,000 rows, but there's a ton of
  39278. 24:57:01different fields. So, if we start
  39279. 24:57:02scrolling over, we're going to see
  39280. 24:57:04there's so many different things that we
  39281. 24:57:06can work on. And I don't want to focus
  39282. 24:57:08on everything because it's going to be
  39283. 24:57:10impossible to get everything in there. I
  39284. 24:57:12have highlighted with yellow the ones
  39285. 24:57:14that we're going to be working with.
  39286. 24:57:15This is the emissions uh for megat tons
  39287. 24:57:17of CO2. We have our population,
  39288. 24:57:19latitude, longitude, the county name,
  39289. 24:57:22county, state name, and state
  39290. 24:57:23abbreviation. We're going to be focusing
  39291. 24:57:25on emissions, although there's so many
  39292. 24:57:27other things we could look at in this
  39293. 24:57:29data set. But we just don't have that
  39294. 24:57:31much time and we don't have, you know,
  39295. 24:57:33days and weeks to comb through this and
  39296. 24:57:36build everything out for, you know, all
  39297. 24:57:37the different scenarios and dashboards
  39298. 24:57:39that we could build out. So, this is the
  39299. 24:57:41data set that we're going to be working
  39300. 24:57:42with. Again, you can get that in the
  39301. 24:57:44GitHub. Let's get out of this. And what
  39302. 24:57:46we're going to do is I'm right here. We
  39303. 24:57:48are in our databicks free edition
  39304. 24:57:50account. I'm going to go ahead and I'm
  39305. 24:57:52going to create a new catalog. So, I'm
  39306. 24:57:54going to call this one I'm going to say
  39307. 24:57:55this is our emissions uh catalog. I'm
  39308. 24:57:58going to go ahead and create this. And
  39309. 24:58:00now we're going to have uh let's get out
  39310. 24:58:02of this. We're going to have our
  39311. 24:58:03emissions. And I'm going to go under my
  39312. 24:58:05default and I'm going to come right over
  39313. 24:58:08here and I'm going to create a table.
  39314. 24:58:10So, we're going to drop this entire
  39315. 24:58:12thing into this. Let's go ahead and
  39316. 24:58:13browse. And we're going to come up here
  39317. 24:58:15to emissions data 2023. Now, this data
  39318. 24:58:18is large. May take just a second uh to
  39319. 24:58:21bring it all in. Um but, you know, it's
  39320. 24:58:23not like 10 gigabytes or anything. So,
  39321. 24:58:25we should be able to create this quite
  39322. 24:58:27well. I'm going to rename this to just
  39323. 24:58:30emissions data because I think it looks
  39324. 24:58:32cleaner. You can keep the 2023 if you
  39325. 24:58:35would like, but I'm just going to take
  39326. 24:58:37uh emissions data.
  39327. 24:58:41All right. So, our data is in here. This
  39328. 24:58:43all looks good. We are not going to
  39329. 24:58:45transform any of this, although we may
  39330. 24:58:48need to transform some of it, right? But
  39331. 24:58:50it's going to autodetect all of our data
  39332. 24:58:53types. So, you know, if we need to
  39333. 24:58:55change something, we're going to do that
  39334. 24:58:56after the fact. We're going to take it
  39335. 24:58:57as it is with the raw data. Now, all we
  39336. 24:59:00have to do is come down here to create
  39337. 24:59:02table, and it's going to create our
  39338. 24:59:05emissions data table for us. Now, it's
  39339. 24:59:08going to give us some of this AI
  39340. 24:59:09suggested description. This looks good
  39341. 24:59:11to me. I'm going to go ahead and just
  39342. 24:59:12accept this just to have it in this data
  39343. 24:59:15set, which was uh nice to have. Now,
  39344. 24:59:17what I'm going to do is just give you
  39345. 24:59:19the scenario, right? You were hired by
  39346. 24:59:21the EPA to create a dashboard and they
  39347. 24:59:23want to focus specifically on emissions,
  39348. 24:59:25but they want a breakdown of things like
  39349. 24:59:27where it's actually coming from in the
  39350. 24:59:29United States, where the most emissions
  39351. 24:59:31are coming from. They want to see what
  39352. 24:59:32states and counties are emitting the
  39353. 24:59:34most emissions, as well as just in
  39354. 24:59:37general as a population, how much
  39355. 24:59:39emissions do we have per person per
  39356. 24:59:41area. So, these are things that we're
  39357. 24:59:42going to have to dive into. We're going
  39358. 24:59:43to write some SQL queries in order to do
  39359. 24:59:45this. Let's come over here and let's go
  39360. 24:59:48to our SQL editor.
  39361. 24:59:51Now, this is from a previous lesson. I'm
  39362. 24:59:53going to go ahead and get rid of all
  39363. 24:59:54these previous queries. And we're going
  39364. 24:59:56to get started just with a fresh new
  39365. 24:59:58query. And we will do this by selecting
  39366. 25:00:01emissions and going to default. And it
  39367. 25:00:05should be our emissions
  39368. 25:00:08data. Let's go ahead and run this. Now,
  39369. 25:00:12as our dashboards, that's going to be
  39370. 25:00:13kind of our final product that we're
  39371. 25:00:14going to hand off. I want to start with
  39372. 25:00:16our location data because I personally
  39373. 25:00:18am super interested in this. We of
  39374. 25:00:20course have the state name and the
  39375. 25:00:22county name. That's not going to be as
  39376. 25:00:24specific as something like latitude and
  39377. 25:00:26longitude. And so I want to use this
  39378. 25:00:29data along with our emissions data. And
  39379. 25:00:31let's come right over here and find
  39380. 25:00:33that. It's right here. So it's GHD
  39381. 25:00:36emissions M tons CO2E. It's a long name,
  39382. 25:00:41but that is the column that we want. So,
  39383. 25:00:44let's come right here and instead of
  39384. 25:00:46getting all of or taking all the data,
  39385. 25:00:48I'm going to do uh latitude. I'm going
  39386. 25:00:51to do tab to autocomplete, we're going
  39387. 25:00:53to do longitude and let's see if it can
  39388. 25:00:56find the CO2.
  39389. 25:00:59There it is. So, I'm going to go ahead
  39390. 25:01:00and hit tab. And I'm just going to call
  39391. 25:01:03this as emissions. I feel like that's
  39392. 25:01:06just going to be easier. Uh let's go
  39393. 25:01:08ahead and run this. And there we go.
  39394. 25:01:11Now, in terms of actually analyzing this
  39395. 25:01:14data, latitude and longitude tends to be
  39396. 25:01:16a little bit more difficult to work
  39397. 25:01:18within something like a county or a
  39398. 25:01:19state because it is so specific. So, you
  39399. 25:01:21can't really aggregate on it. It's more
  39400. 25:01:23of a visual thing. So, let's actually
  39401. 25:01:25just take this over. I'm going to copy
  39402. 25:01:28this. I'm just going to bring this over
  39403. 25:01:29to my dashboard. And we're going to
  39404. 25:01:31create our new dashboard. Uh, let's
  39405. 25:01:34rename it really quickly before we get
  39406. 25:01:35into data. I'm going to call this our
  39407. 25:01:37emissions
  39408. 25:01:39dashboard. As we build things out, we
  39409. 25:01:41will then come and add to it. We don't
  39410. 25:01:43have to do it that way. We could get all
  39411. 25:01:45the data up front and then uh go from
  39412. 25:01:48there. But I'm going to create from SQL.
  39413. 25:01:51And I'm going to run this. And we
  39414. 25:01:53actually need to specify where this is
  39415. 25:01:55coming from. So let me get rid of this.
  39416. 25:01:58I'm going to call this uh emissions
  39417. 25:02:02default emissions data. So I was just
  39418. 25:02:04tabbing there. It got our catalog, then
  39419. 25:02:06our schema, and then our table. I just
  39420. 25:02:08tabbed along the way. It makes it, you
  39421. 25:02:10know, kind of easy to work with. Let's
  39422. 25:02:12go ahead and run this. And now we have
  39423. 25:02:15our data right down here. Now, like I
  39424. 25:02:17said, this isn't the easiest data to
  39425. 25:02:20work with if you don't really know
  39426. 25:02:22latitude and longitude data, but it's
  39427. 25:02:24really easy to visualize. So, let's come
  39428. 25:02:26up here and we are going to add I'm
  39429. 25:02:29going to get rid of our filters, but I'm
  39430. 25:02:31going to add a visualization.
  39431. 25:02:33And the data that we'll connect with is
  39432. 25:02:36apparently called our untitled data set.
  39433. 25:02:38Let me change this. So I'm going to
  39434. 25:02:40rename this as our location data. We
  39435. 25:02:44will use some other location data, but
  39436. 25:02:46it's like state and county. And so we
  39437. 25:02:48should be good. Let's use our location
  39438. 25:02:50data. And what we need is actually a
  39439. 25:02:53map. And we didn't do a map when we were
  39440. 25:02:55creating and building dashboards in a
  39441. 25:02:57previous lesson. So this is a new one
  39442. 25:02:58for us. But let's come right down here.
  39443. 25:03:00We're going to go to a point map. Now
  39444. 25:03:02you can see we already have the
  39445. 25:03:03coordinates available for us. Longitude
  39446. 25:03:05and latitude. So this should be really
  39447. 25:03:07easy. We're just going to do uh for the
  39448. 25:03:09longitude we'll do longitude. And for
  39449. 25:03:12the latitude, believe it or not, this is
  39450. 25:03:13going to sound insane. We're going to do
  39451. 25:03:15latitude. Now, this is a little tricky
  39452. 25:03:18to work with sometimes. It's kind of a
  39453. 25:03:20double click. So I'm going to double
  39454. 25:03:22click in. I'm going to double click in.
  39455. 25:03:23And you can kind of scroll back. There
  39456. 25:03:26are some things that we need to
  39457. 25:03:27customize because this is just super
  39458. 25:03:29blurry. I'm going to go to the size and
  39459. 25:03:33I'm going to decrease the size a little
  39460. 25:03:35bit. I think that makes it a lot better.
  39461. 25:03:38We can always, you know, doubleclick and
  39462. 25:03:41zoom out just a little just to have
  39463. 25:03:44enough. I will say if we zoom out more,
  39464. 25:03:46you'll see some information right here.
  39465. 25:03:48I think this is Hawaii. Don't cancel me
  39466. 25:03:50if I'm wrong about that. Geography is
  39467. 25:03:52not my uh best area. Then we have Alaska
  39468. 25:03:55up here. So maybe we want to include all
  39469. 25:03:58of that. Um, that would be fine if we
  39470. 25:04:01do, but I'm going to come right in here.
  39471. 25:04:03I think this is what I want to keep,
  39472. 25:04:05which is mainland United States. So,
  39473. 25:04:07we're going to keep this. This to me is
  39474. 25:04:10really useful and it makes a lot of
  39475. 25:04:12sense. This is some of the most densely
  39476. 25:04:14populated areas over here in the uh kind
  39477. 25:04:17of the Mid East and the East. And then
  39478. 25:04:20right over here, based on emissions,
  39479. 25:04:22right, emissions is much lower. Even in
  39480. 25:04:24California, there's a lot of people in
  39481. 25:04:25California and on the west coast, but
  39482. 25:04:28not as many emissions. And so most of
  39483. 25:04:30our emissions, just looking at our, you
  39484. 25:04:32know, our visualization are over here on
  39485. 25:04:34the right hand side. Kind of
  39486. 25:04:36centralized. What is this like Ohio? Uh,
  39487. 25:04:38Chicago's in Illinois. It's like
  39488. 25:04:40Illinois, Ohio area. I'm not a geography
  39489. 25:04:42expert. Don't hate. I just I don't know
  39490. 25:04:44geography that well. So, this is really
  39491. 25:04:47interesting. I would not have guessed
  39492. 25:04:49this, but this is official EPA data. So,
  39493. 25:04:51this is, you know, pretty useful. Now,
  39494. 25:04:53real quick, I'm just going to come in
  39495. 25:04:55here and I'm going to create our title.
  39496. 25:04:57We're going to call this the United
  39497. 25:04:59States
  39498. 25:05:00uh emissions
  39499. 25:05:02breakdown. And I need to spell this
  39500. 25:05:05properly. Let's put this in the middle.
  39501. 25:05:08Let's uh make it bold. And we'll make it
  39502. 25:05:12larger. Not going to get crazy with it.
  39503. 25:05:15Maybe we'll do one more. Let me see.
  39504. 25:05:17That's too big. All right. Let's go back
  39505. 25:05:18to 24.
  39506. 25:05:20Underneath it though, I'm going to add
  39507. 25:05:21like some notes. Uh, make it a lot
  39508. 25:05:25smaller. We'll say this data was
  39509. 25:05:28collected by the EPA. I'm going to say
  39510. 25:05:32uh Environmental.
  39511. 25:05:36It's always tough to watch people watch
  39512. 25:05:37me spell. By the way, I'm not good at
  39513. 25:05:39environmental uh protection agency. And
  39514. 25:05:43then I'm going to say in 2023. I think
  39515. 25:05:46this is fine for now. If we want to add
  39516. 25:05:48something later to it, we can. Or make
  39517. 25:05:50it larger. Uh, whatever we want to do.
  39518. 25:05:52But I'm going to keep it just like this
  39519. 25:05:54for now. Actually, I think I do want to
  39520. 25:05:57make this bigger or this part at least
  39521. 25:05:58bigger. It seems like it should be. I
  39522. 25:06:01feel like it should be bigger. That just
  39523. 25:06:03feels better. I don't know why. Uh,
  39524. 25:06:05don't get onto me. Now, we can add more
  39525. 25:06:08visualizations to this, and of course,
  39526. 25:06:10we will. But the first one, this one is
  39527. 25:06:13probably the easiest one because we're
  39528. 25:06:15not really digging into the data itself.
  39529. 25:06:17We're more just trying to visualize it
  39530. 25:06:19because latitude longitude data is, you
  39531. 25:06:20know, pretty specific. Now, let's come
  39532. 25:06:22back over here to our SQL editor. I'm
  39533. 25:06:24going to try using some AI here on this
  39534. 25:06:25next one because uh the next one's going
  39535. 25:06:28to be a little bit trickier, I think. Uh
  39536. 25:06:30let's just create a new query because I
  39537. 25:06:32think that's perfectly fine. Uh, but I
  39538. 25:06:35want to make sure it's in the right
  39539. 25:06:36schema. It is not. Let's go to
  39540. 25:06:39emissions. Let's go to default. In fact,
  39541. 25:06:42I could have just copied this over. Um,
  39542. 25:06:44honestly, so I'm going to come over
  39543. 25:06:46here. Let's paste this in here. Now, I'm
  39544. 25:06:49going to edit this. I now want to focus
  39545. 25:06:52on a new thing that we're looking at. I
  39546. 25:06:54want to take a look at some data. Now,
  39547. 25:06:56I'm going to do this because this is
  39548. 25:06:57what I personally do. I'm going to
  39549. 25:06:58duplicate this and I'm going to bring it
  39550. 25:07:01back to uh the catalog
  39551. 25:07:05and go to emissions, go to default, go
  39552. 25:07:08to emissions data and look at the sample
  39553. 25:07:11data. The reason I'm doing this is
  39554. 25:07:13because I want to be able to just
  39555. 25:07:15oneclick over, take a look at my raw
  39556. 25:07:17data. You can also just create a query
  39557. 25:07:20and tab over. Um, but then I don't know,
  39558. 25:07:22that's not my that's not my workflow. I
  39559. 25:07:24like having a different thing for it.
  39560. 25:07:25You can do that if you'd like. uh just
  39561. 25:07:27do you know select everything from
  39562. 25:07:29emissions data. Now what we are going to
  39563. 25:07:31do is we're going to use the AI and what
  39564. 25:07:34we're going to be looking at is I want
  39565. 25:07:35to take a look at this county name as
  39566. 25:07:37well as the population. So for each
  39567. 25:07:40county so this is in Alabama. This is
  39568. 25:07:43the county state name in Alabama. I want
  39569. 25:07:45to look for this county and this
  39570. 25:07:47population. Let's take a look at our
  39571. 25:07:50emissions. But more specifically I want
  39572. 25:07:52to take a look at the emissions per
  39573. 25:07:54person. So, we're going to have to do a
  39574. 25:07:55calculation here. So, I'm going to ask
  39575. 25:07:58the AI. I'm going to say I want to look
  39576. 25:08:00at the emissions per person in each
  39577. 25:08:06county. Let's go ahead and generate
  39578. 25:08:08this. Let's see if it will get exactly
  39579. 25:08:11what I want. It may or may not. And
  39580. 25:08:14let's accept this. I'm just going to hit
  39581. 25:08:16tab. So, we're casting this as a double.
  39582. 25:08:19And then we're casting the population as
  39583. 25:08:21a double. And then we're saying that's
  39584. 25:08:23the emissions per person. Now, this
  39585. 25:08:25theoretically should work, right? But
  39586. 25:08:27let's go over to our GHG emissions right
  39587. 25:08:32here. Now, here's the thing, and this is
  39588. 25:08:34not, you know, a data brick specific
  39589. 25:08:37thing, but this happens all the time in
  39590. 25:08:39almost any platform is this is a number.
  39591. 25:08:42This is a 100% a number. Has a comma
  39592. 25:08:44there. Should be rented as a number. But
  39593. 25:08:46you can see right here, I can just tell
  39594. 25:08:48you right now, this query is going to
  39595. 25:08:50fail um because it needs to be changed.
  39596. 25:08:52Let's go ahead and try to run this.
  39597. 25:08:56Now, the reason why this is going to
  39598. 25:08:57fail is because this is a string, right?
  39599. 25:09:00We have letters, we have characters that
  39600. 25:09:02are not numeric in this column, and that
  39601. 25:09:05is an issue. And so, what we need to do
  39602. 25:09:07is we need to convert this or we can
  39603. 25:09:11also in here ask it to diagnose this
  39604. 25:09:13error. I'm gonna see if the assistant
  39605. 25:09:16can do it for us because if it can then
  39606. 25:09:18that would be fantastic. Let's see if
  39607. 25:09:19it's able to do this. This is kind of a
  39608. 25:09:21specific fix. It needs to look into the
  39609. 25:09:23data.
  39610. 25:09:26And it looks like it got it perfect. It
  39611. 25:09:27says you need to remove the thousands
  39612. 25:09:29separator before you cast it. This looks
  39613. 25:09:31excellent. Let's actually uh replace
  39614. 25:09:34this. Let's get rid of that. And now
  39615. 25:09:37let's try running this. And wait a
  39616. 25:09:39second. We have latitude and longitude
  39617. 25:09:41here.
  39618. 25:09:42Let's go back because I didn't want
  39619. 25:09:45latitude and longitude in the first
  39620. 25:09:46place. I was just looking at this and I
  39621. 25:09:48got mixed up. Um, okay, that's fine.
  39622. 25:09:50We'll keep this. But I am before we even
  39623. 25:09:53run this, I am going to say I don't want
  39624. 25:09:56latitude. Did I spell it right? In
  39625. 25:09:59longitude, I want the
  39626. 25:10:03county and the population for those
  39627. 25:10:06columns. I'm just using AI here. I
  39628. 25:10:09normally I could just fix this myself. I
  39629. 25:10:12just want to test it because I think
  39630. 25:10:14it's, you know, an interesting thing.
  39631. 25:10:15All right, let's accept this and let's
  39632. 25:10:17go ahead and try running it and see what
  39633. 25:10:20happens. All right, we're running into
  39634. 25:10:22some issues. And I'm just going to tell
  39635. 25:10:23you that's going to happen and that's
  39636. 25:10:25okay. Let's take a look. One, we I don't
  39637. 25:10:27think we even have a county column.
  39638. 25:10:29Let's go right over here. We have a
  39639. 25:10:31county name column, which actually
  39640. 25:10:33should be fine since we're not grouping
  39641. 25:10:35on anything. But I actually want this
  39642. 25:10:37column right here. So, I'm going to copy
  39643. 25:10:39this as the column name and we'll come
  39644. 25:10:43right back here. Population should be
  39645. 25:10:45correct. And then we're working with a
  39646. 25:10:48replace. I believe that we need back
  39647. 25:10:51ticks for this and not brackets.
  39648. 25:10:57Let's just go ahead and try that. And
  39649. 25:10:59let's run it. All right. Now, this is
  39650. 25:11:01working. Listen, AI is not perfect. Uh
  39651. 25:11:04sometimes we got to step in and do what
  39652. 25:11:06we do. So, this looks correct to me.
  39653. 25:11:09Let's take a look just really quick
  39654. 25:11:10because we are breaking it down by the
  39655. 25:11:12county state name. Um, which is what I
  39656. 25:11:15would do. I wouldn't want to use this
  39657. 25:11:18county name because what if we have
  39658. 25:11:19another county name that's Baldwin
  39659. 25:11:21County, right? And when we start trying
  39660. 25:11:23to visualize this data, then that could
  39661. 25:11:25be issues because it's going to probably
  39662. 25:11:27try to group that data and it just it'll
  39663. 25:11:29cause issues. Now, what we're going to
  39664. 25:11:31do with this is we're actually going to
  39665. 25:11:32look at the top 10 emissions uh based
  39666. 25:11:36off of probably the emissions per
  39667. 25:11:38[snorts] person. I think that's all we
  39668. 25:11:40should do. So, I'm just going to add it
  39669. 25:11:42this time. I'm not going to ask the AI.
  39670. 25:11:44So, I'm just going to say order by and
  39671. 25:11:46then I'm going to say emissions per
  39672. 25:11:47person. And we'll do descending. And
  39673. 25:11:50this should be really Actually, I should
  39674. 25:11:51have done I should limit it by like 10
  39675. 25:11:53or something. I'm going to say limit 10.
  39676. 25:11:57There we go. Now, let's run this. And
  39677. 25:12:00I'm super interested. This is real data.
  39678. 25:12:02So, you know, I'm really curious. So,
  39679. 25:12:05emissions per person, the population is
  39680. 25:12:07only 5,000. They have a lot of
  39681. 25:12:08emissions. That's in New England. This
  39682. 25:12:11is in North Dakota. New England. North
  39683. 25:12:12Dakota. Very interesting. So, based off
  39684. 25:12:16the emissions per person, these are the
  39685. 25:12:19places. And this is not what I would
  39686. 25:12:20have guessed. I would have guessed like
  39687. 25:12:22New York or, you know, I don't know,
  39688. 25:12:25North Carolina or something like that.
  39689. 25:12:27But these are we got New England and
  39690. 25:12:29North Dakota. And then I think Mo is
  39691. 25:12:32Missouri.
  39692. 25:12:34I don't quote me on that, but this looks
  39693. 25:12:36good to me. Um, this query was a little
  39694. 25:12:38bit more challenging than our last one.
  39695. 25:12:40I think you would agree. Let's bring
  39696. 25:12:42this over. We're going to go back to our
  39697. 25:12:44dashboard. I could also make this
  39698. 25:12:47another tab. Um, and it looks like that
  39699. 25:12:49reset. We'll do that at the end. Um,
  39700. 25:12:52we'll just place that how we want it at
  39701. 25:12:54the end. Now, what we actually need to
  39702. 25:12:56do is put this in our data. So, I'm
  39703. 25:12:59going to come in here. I'm going to
  39704. 25:13:01place this in there. Again, it's not um
  39705. 25:13:06it's right here. The emissions, we can
  39706. 25:13:09change this. So, we don't have to um we
  39707. 25:13:12don't have to do that. Let's go ahead
  39708. 25:13:13and run this.
  39709. 25:13:15And our data is working. Even though
  39710. 25:13:16it's underlined, it's still reading it
  39711. 25:13:18in fine. We do have it uh correctly
  39712. 25:13:20done. We can always like we did before
  39713. 25:13:23uh do emissions
  39714. 25:13:26and it shouldn't say emissions data
  39715. 25:13:27emissions.default
  39716. 25:13:30emissions data just to get rid of those
  39717. 25:13:32red lines. We can do that. Now we have
  39718. 25:13:35our data down here. This is really
  39719. 25:13:38useful. We don't necessarily have to
  39720. 25:13:41even use this column, but we do have the
  39721. 25:13:43population for emissions. And uh let's
  39722. 25:13:47get rid of our limit because I want to
  39723. 25:13:49make a specific type of visualization
  39724. 25:13:51with this. It's a scatter plot. Scatter
  39725. 25:13:53plots are really great because we're
  39726. 25:13:54going to be able to use the population
  39727. 25:13:56and the emissions per person on a
  39728. 25:13:58scatter plot and kind of take a look.
  39729. 25:13:59Hey, as the population increases, does
  39730. 25:14:02the emissions per person increase as
  39731. 25:14:04well or does it decrease? A scatter plot
  39732. 25:14:06would be great for this. Let's call this
  39733. 25:14:09uh let's do emissions
  39734. 25:14:11per person. That's what we're going to
  39735. 25:14:13call this one.
  39736. 25:14:15Let's come over here and we're going to
  39737. 25:14:17come in and we're going to choose our
  39738. 25:14:19emissions per person. Now on our xaxis
  39739. 25:14:23we can choose the emissions per person.
  39740. 25:14:25We can switch this around, see which one
  39741. 25:14:27works better. Then we'll also choose the
  39742. 25:14:29population. Let's scroll down a little
  39743. 25:14:31bit. Now we need to change this from a
  39744. 25:14:33bar chart cuz that does not look right.
  39745. 25:14:35We're going to change this into a
  39746. 25:14:37scatter plot. Now for the scatter plot,
  39747. 25:14:40we want the raw data. We don't want any
  39748. 25:14:42aggregation. So, let's say none here.
  39749. 25:14:44And for the sum of population, none as
  39750. 25:14:47well. That should be good. We can also
  39751. 25:14:51really quick change the size because
  39752. 25:14:53it's a little blurry. I want to see a
  39753. 25:14:54little bit more granular of what we're
  39754. 25:14:56looking at. We have this one up here.
  39755. 25:14:59Uh, this emissions per person is 0.5.
  39756. 25:15:01Okay, so that's low, but the population
  39757. 25:15:02is 10 million. I'm curious where this
  39758. 25:15:05actually is. Let's come down here to the
  39759. 25:15:08tool tip. Let's it add in the county
  39760. 25:15:12state name. So now when I hover over it
  39761. 25:15:15and it's so small. Um now when I hover
  39762. 25:15:18over it, this is Los Angeles County. Um
  39763. 25:15:21this is actually really good. There is a
  39764. 25:15:23very low emissions for that amount of
  39765. 25:15:25people. And you can see that because
  39766. 25:15:26it's over on this left hand side. If we
  39767. 25:15:29had something um over here, this is not
  39768. 25:15:31going to be good. Uh this is one of our
  39769. 25:15:33New England ones. They have emissions
  39770. 25:15:35per person at 5.95 and that's in uh I
  39771. 25:15:38think megat tons. So that's a lot of
  39772. 25:15:40emissions. Their population is 5.16,000.
  39773. 25:15:44That's not a lot. That's a little over
  39774. 25:15:465,000. They have a lot of emissions. So
  39775. 25:15:49as you can see, the areas that actually
  39776. 25:15:51have a higher population tend to have
  39777. 25:15:53less emissions. Um, overall, I mean,
  39778. 25:15:56these are Cook County, Harris County in
  39779. 25:16:00Texas, uh, Maricopa County in Arizona,
  39780. 25:16:03but a lot of these ones are actually
  39781. 25:16:05fairly low per person. In the areas that
  39782. 25:16:09don't have a lot of people, they
  39783. 25:16:10actually tend to looks like they have
  39784. 25:16:12higher emissions for the lower
  39785. 25:16:14population.
  39786. 25:16:16I mean, some, of course, are over here
  39787. 25:16:18with very low emissions per person. It's
  39788. 25:16:20just really interesting. I'm I'm kind
  39789. 25:16:22of, you know, I'm kind of looking into
  39790. 25:16:24this as we go. Let's add this title.
  39791. 25:16:27We'll say emissions per person. We'll
  39792. 25:16:30say emissions verse population.
  39793. 25:16:35And uh we could add some type of
  39794. 25:16:37description. We don't have to, but I'm
  39795. 25:16:39just going to say higher populations
  39796. 25:16:43tend to have lower emissions per person.
  39797. 25:16:48Um, and you know, we could go more in
  39798. 25:16:50depth and add more notes. That would be
  39799. 25:16:52useful, but we're not going to. But I
  39800. 25:16:54think that's really interesting. Uh, I'm
  39801. 25:16:56kind of fascinated by that myself. So,
  39802. 25:16:58we have this emissions verse population
  39803. 25:17:00one. Really quick, I'm going to add a
  39804. 25:17:02title to this one. I'm going to say
  39805. 25:17:05emissions
  39806. 25:17:07per location. I'm just going to keep it
  39807. 25:17:10like that. I think that's uh perfectly
  39808. 25:17:12fine.
  39809. 25:17:13Uh, let's scroll down really quick.
  39810. 25:17:15We're going to add in some more
  39811. 25:17:17visualizations. I'm going to just put
  39812. 25:17:19these here so that we can scroll down a
  39813. 25:17:21little easier. Um, but now we have these
  39814. 25:17:23ones in here with us. Let's come back to
  39815. 25:17:26our SQL editor and let's add a new tab.
  39816. 25:17:30So, I'm going to say a new query here.
  39817. 25:17:32Now, what I want to look at is the total
  39818. 25:17:34emissions by state because I want to see
  39819. 25:17:37what states are just doing the worst.
  39820. 25:17:38They have so many emissions. They're the
  39821. 25:17:40top 10 worst states in America. I
  39822. 25:17:42wouldn't say that. That's actually
  39823. 25:17:43that's a bit extreme. We will need to
  39824. 25:17:45reuse this really quick. Um, we're going
  39825. 25:17:47to have to reuse this replace. I'll just
  39826. 25:17:50copy this over. In fact, I feel like I
  39827. 25:17:52can write this quite quickly. If we were
  39828. 25:17:55in the emissions default here, um, what
  39829. 25:17:58we need to do is we need to come over
  39830. 25:18:01here and let's see. So, I don't want to
  39831. 25:18:04have to take this and break it out by
  39832. 25:18:06the state over here. We have the state
  39833. 25:18:08abbreviation. So, let's use it. Let's
  39834. 25:18:10copy this column name. Let's bring it
  39835. 25:18:13back. And all we're going to do is just
  39836. 25:18:17keep the state abbreviation. We don't
  39837. 25:18:19need to do any of these calculations. Uh
  39838. 25:18:21we should be able to get rid of all of
  39839. 25:18:23that. And let me see what I'm doing
  39840. 25:18:26wrong here. Okay, it looks like I have
  39841. 25:18:27an extra parenthesis. Then we're just
  39842. 25:18:30going to say total emissions.
  39843. 25:18:34That should be fine. Then we need to
  39844. 25:18:36group by. So we're going to say group by
  39845. 25:18:38because if we look at our data, we have
  39846. 25:18:40a lot in Alabama, right? We have a lot
  39847. 25:18:42of counties in each state. So, we have
  39848. 25:18:44to group on this state abbreviation and
  39849. 25:18:47then I'm not going to go over to it, but
  39850. 25:18:50then we're going to group and do our sum
  39851. 25:18:54right here. Right? And we're have to
  39852. 25:18:55actually do the sum in just a second.
  39853. 25:18:57So, we're going to say group by the
  39854. 25:18:58state abbreviation.
  39855. 25:19:00And there we go. And we'll take this.
  39856. 25:19:05And then right up here, we just need to
  39857. 25:19:07do the sum. So, I actually did need that
  39858. 25:19:09extra parenthesis. I got rid of it. I
  39859. 25:19:11was I was so shortsighted. I got too
  39860. 25:19:14excited. And we'll keep the top 10
  39861. 25:19:16actually. Um because I know that when we
  39862. 25:19:19start visualizing this, we're not going
  39863. 25:19:21to need uh all of them. Uh although it
  39864. 25:19:25would be Let me just comment this out
  39865. 25:19:26for a second because I am curious
  39866. 25:19:29to look at all the states and see which
  39867. 25:19:31one has the um highest. So the total
  39868. 25:19:33emissions is Texas, Florida, Ohio,
  39869. 25:19:35Illinois, Georgia. you know, that's a
  39870. 25:19:37lot of the south and southeast and and
  39871. 25:19:40not a lot from uh the west coast. Let's
  39872. 25:19:42come down here. We have Vermont,
  39873. 25:19:45Richmond, AK, is that Arkansas, uh DC,
  39874. 25:19:50me, Maine. So, actually some of the
  39875. 25:19:52Northeast is actually quite good with
  39876. 25:19:54New Hampshire. Uh but then the West
  39877. 25:19:56Coast and like kind of the Midwest tends
  39878. 25:19:58to be really low emissions probably
  39879. 25:20:01because their populations are lower, but
  39880. 25:20:04I guess maybe not because of what we
  39881. 25:20:06looked at earlier. Anyways, let's limit
  39882. 25:20:09this by 10. And then I'm going to copy
  39883. 25:20:12this over. Yeah, we'll go back to our
  39884. 25:20:14dashboards. Let me go back to the
  39885. 25:20:15emissions dashboard.
  39886. 25:20:20Let's scroll down.
  39887. 25:20:22And actually, we got to go to the data
  39888. 25:20:24first. Let's create this. And we'll run
  39889. 25:20:27this. I need to have our emissions
  39890. 25:20:31and our default.
  39891. 25:20:33That should be good. Let's run this
  39892. 25:20:35data. And then I'm going to rename this.
  39893. 25:20:38I'm going to say uh total
  39894. 25:20:41emissions per state.
  39895. 25:20:44That should be good. So now we have
  39896. 25:20:46these. These are our top 10. What I
  39897. 25:20:49actually want to look at this for is
  39898. 25:20:51percentage-wise. We're going to have to
  39899. 25:20:53do some other analysis because I do want
  39900. 25:20:55to add something that you can't
  39901. 25:20:57necessarily visualize. Um, we're just
  39902. 25:20:59going to have to dig into that in the
  39903. 25:21:01data really quickly and perform a little
  39904. 25:21:03calculation. It's not nothing crazy. Um,
  39905. 25:21:06but we may use AI for it. We'll see if
  39906. 25:21:08it can uh it can work for us. We'll do
  39907. 25:21:10totally emissions by state and we're
  39908. 25:21:14going to do a pie chart right here. Now
  39909. 25:21:18for the angle, all we have to do is the
  39910. 25:21:21total emissions, but we want to break it
  39911. 25:21:23out our color. We want to break it out
  39912. 25:21:25by the state abbreviations. Uh, we
  39913. 25:21:28definitely need to add the labels here.
  39914. 25:21:31Let's add our labels. There we go. Um,
  39915. 25:21:35and it has it over there. So, we have
  39916. 25:21:37this little legend right down here. We
  39917. 25:21:39have Texas. That's 20% in the top 10.
  39918. 25:21:42That's in our top 10. These are the
  39919. 25:21:44total emissions. If we tried to add all
  39920. 25:21:46of them, which you know what? Let's just
  39921. 25:21:48go try it. We can get rid of these 10.
  39922. 25:21:51Uh we can do that. Let's run this. We'll
  39923. 25:21:55have all of our data.
  39924. 25:21:58Let's go back to our dashboard.
  39925. 25:22:01And now we have all of them. So, it
  39926. 25:22:03looks like Texas is 10%. But that is a
  39927. 25:22:06lot, right? We have a lot of different
  39928. 25:22:08colors. And it's really hard to see uh
  39929. 25:22:11almost anything if I'm being honest.
  39930. 25:22:15If we want to, and maybe this is a good
  39931. 25:22:17uh thing to do, is we can add a filter
  39932. 25:22:20right here. And I haven't even I haven't
  39933. 25:22:23done this at all in this video yet, but
  39934. 25:22:25I'm just going to say um maybe a range
  39935. 25:22:29slider might be good. Uh for the field,
  39936. 25:22:33we can do let's see total emissions per
  39937. 25:22:37state. We'll look at the total
  39938. 25:22:38emissions. And let's see if I can just
  39939. 25:22:41kind of scroll up
  39940. 25:22:44and do something like this. That might
  39941. 25:22:46work. But then again, it's then, you
  39942. 25:22:49know, only doing the calculation or the
  39943. 25:22:51percentage based off of that. So, we're
  39944. 25:22:53just reinventing the wheel here. I'm
  39945. 25:22:55just demonstrating it can be done. Um,
  39946. 25:22:57but I don't think we need this. All that
  39947. 25:22:59being said, we're actually going to
  39948. 25:23:01delete that.
  39949. 25:23:03But that's [laughter] okay. Let's go
  39950. 25:23:04back. We're going to add the limit 10.
  39951. 25:23:06Listen, I'm here for education purposes,
  39952. 25:23:09right? I want you to know what you can
  39953. 25:23:10do. If you want to do that, you can. Um,
  39954. 25:23:14but we're not going to do it. Let's go
  39955. 25:23:15back here. Now, we have this. This looks
  39956. 25:23:18good, but I don't like uh this title,
  39957. 25:23:21actually. Let's get
  39958. 25:23:24right here. I'm just going to say
  39959. 25:23:26emissions
  39960. 25:23:28percentage or something like that is
  39961. 25:23:30fine. Feel like that's good enough for
  39962. 25:23:32like a title even. We can and I think we
  39963. 25:23:35should come in here and add some type of
  39964. 25:23:37description, some information here. So,
  39965. 25:23:40I'm just going to say the top 10 states
  39966. 25:23:42account for X amount of emissions for
  39967. 25:23:47the whole for all of the US. Now, I'm
  39968. 25:23:51saying X amount because we don't have
  39969. 25:23:54that information yet. We actually need
  39970. 25:23:56to write that query. Let's go back to
  39971. 25:23:59our SQL editor and let's dig into this.
  39972. 25:24:02I am gonna try to use this assistant
  39973. 25:24:05because I feel like it might be able to
  39974. 25:24:07understand um what I'm doing. I'm gonna
  39975. 25:24:10paste this in and I'm just going to say
  39976. 25:24:13I want to know what percentage
  39977. 25:24:17I need to write this right. But what
  39978. 25:24:19percentage
  39979. 25:24:21of emissions
  39980. 25:24:23are the top 10
  39981. 25:24:26states for the whole country?
  39982. 25:24:30and let's see if it understands that. I
  39983. 25:24:33don't know if I even wrote that well.
  39984. 25:24:35Um, but let's see if it did with it if
  39985. 25:24:38it does. Uh, this is a CTE it's writing.
  39986. 25:24:40I'm just going to see what it's writing.
  39987. 25:24:41It's writing a CTE. It's calculating the
  39988. 25:24:44top 10 and then it's selecting
  39989. 25:24:48it's selecting the sum of the total
  39990. 25:24:50emissions.
  39991. 25:24:52Okay, this could work. Let me take this
  39992. 25:24:55query real quick and I'm actually going
  39993. 25:24:57to open up a new tab or a new query.
  39994. 25:25:01And let's make sure. Oops. I need to get
  39995. 25:25:03all this.
  39996. 25:25:05Oh, it's doing it for a notebook. That's
  39997. 25:25:06all right. Um, I'm going to get rid of
  39998. 25:25:08that because I'm going to come down here
  39999. 25:25:11to emissions to default. Let's paste
  40000. 25:25:14this in here. And this may work. Let's
  40001. 25:25:18run this.
  40002. 25:25:20Okay, so this is the top 10 emissions.
  40003. 25:25:22This is the top 10 percentage.
  40004. 25:25:25I believe this is correct. Um you can
  40005. 25:25:28validate this but what it's doing is we
  40006. 25:25:30don't need this SQL here. What it's
  40007. 25:25:33doing is it's creating a CTE calling it
  40008. 25:25:35the top 10. Then we're selecting the
  40009. 25:25:37state abbreviations. We have this query.
  40010. 25:25:39It's taking the total or the sum for the
  40011. 25:25:41top 10. And then we're using that later
  40012. 25:25:44on. So now we're doing select and this
  40013. 25:25:46is the sum of the total emissions from
  40014. 25:25:49up here. And then we're taking the sum
  40015. 25:25:51of the total emissions divided by this
  40016. 25:25:54number right here which is all of them.
  40017. 25:25:56Now, wait a second. I may be wrong on
  40018. 25:25:58this because we're only pulling from the
  40019. 25:26:00top 10. So, maybe it's just looking at
  40020. 25:26:04the total emissions from up here
  40021. 25:26:08as top 10 emissions. It's taking the sum
  40022. 25:26:11of the total emissions and then
  40023. 25:26:12selecting the sum from emissions data.
  40024. 25:26:15No, you know what? No, it is taking it
  40025. 25:26:18from it's doing a subquery in here. I
  40026. 25:26:20missed that. So, this subquery is
  40027. 25:26:22actually selecting all of the emissions
  40028. 25:26:25from the emissions data. This is great.
  40029. 25:26:28I'm going to say it accounts for 51%.
  40030. 25:26:30This is uh great job, AI. I'm glad it uh
  40031. 25:26:34did a good job. I'm I I think I am going
  40032. 25:26:37to add uh make a duplicate of this. I
  40033. 25:26:41just that's how I that's my personal
  40034. 25:26:42workflow. Okay. So, let's come in here
  40035. 25:26:45and we're going to say that this
  40036. 25:26:47accounts for the top 10 account for 51%.
  40037. 25:26:54Uh, let's make sure I spell this right.
  40038. 25:26:56The top 10 states,
  40039. 25:26:59I'm actually going to say these 10
  40040. 25:27:00states. These 10 states account for 51%
  40041. 25:27:05of all emissions.
  40042. 25:27:08I'm going to say
  40043. 25:27:11of
  40044. 25:27:14What am I What am I doing
  40045. 25:27:17of all
  40046. 25:27:19emissions
  40047. 25:27:22in the US? I'm just I'm having a tough
  40048. 25:27:25time writing.
  40049. 25:27:26That is a useful statistic.
  40050. 25:27:29That is a really useful statistic. So, I
  40051. 25:27:31think this one is done. I think this is
  40052. 25:27:33a really good visualization. Look, pie
  40053. 25:27:35charts have its place. Percentages like
  40054. 25:27:37this, I think, are really useful. Um,
  40055. 25:27:40let's come back. Let's go to our SQL
  40056. 25:27:42editor. I'm going to have that over
  40057. 25:27:43here. So, I'm going to have my SQL
  40058. 25:27:44editor, emissions dashboard, and the
  40059. 25:27:46data. Now, what I want to do is I want
  40060. 25:27:49to name and shame a little bit. Okay. I
  40061. 25:27:52want to take a look the county state
  40062. 25:27:53name. What specific county? And we kind
  40063. 25:27:56of looked at this earlier when we were
  40064. 25:27:58getting our population data because we
  40065. 25:28:00had to ground it with a group by
  40066. 25:28:02something, but now we're actually using
  40067. 25:28:03the county state name. We're going to
  40068. 25:28:05take a look at the top 10 counties
  40069. 25:28:08within the US. and we want to create a
  40070. 25:28:11bar chart for this. So, let's uh use
  40071. 25:28:14this and come right back here. Uh this
  40072. 25:28:17was by far the hardest query uh that
  40073. 25:28:19we've written today. AI did well. Um we
  40074. 25:28:22you know we gave it a lot of the
  40075. 25:28:23context, but I think it did a good job.
  40076. 25:28:26Let's bring in some of our previous like
  40077. 25:28:29this was a really simple
  40078. 25:28:32um thing here. Actually, let's use this
  40079. 25:28:36because it has the uh a lot of the
  40080. 25:28:39information we're already wanting. Now,
  40081. 25:28:41all we're doing is we're just looking at
  40082. 25:28:44the total emissions, not per person. So,
  40083. 25:28:47let's get rid of
  40084. 25:28:50this. We're literally just looking at it
  40085. 25:28:52like this. So, we have the county state
  40086. 25:28:54name. Let's go to emissions default. Um,
  40087. 25:28:58we have the county state name from
  40088. 25:29:00emissions data. And we don't have to do
  40089. 25:29:03this. We need to do it.
  40090. 25:29:07Let's close this parenthesis and call
  40091. 25:29:09this as um total emissions. And then we
  40092. 25:29:14have to use this alias for this part to
  40093. 25:29:17order by it down here. We don't have to
  40094. 25:29:20technically. We could just copy this
  40095. 25:29:22whole cast uh and replace, but we're not
  40096. 25:29:24going to. So now we want to look at the
  40097. 25:29:26top 10. So this should work. Now we have
  40098. 25:29:30the county state name in Arizona, Texas,
  40099. 25:29:33Illinois, Florida. Geez, just so many so
  40100. 25:29:36many emissions. Uh, you know, think of
  40101. 25:29:40think of the world. Think of the think
  40102. 25:29:41of your country. Let's come in here. Uh,
  40103. 25:29:45no, we need to go back to the data.
  40104. 25:29:46Let's create from SQL and we're going to
  40105. 25:29:49put this in here. Let's go back to our
  40106. 25:29:51emissions. Let's run this. This should
  40107. 25:29:54be good. Awesome. So now we have the
  40108. 25:29:57highest total emissions right here.
  40109. 25:30:01I mean, listen, even though Los Angeles
  40110. 25:30:04County is in the top 10, it's because
  40111. 25:30:07their population is four times as much
  40112. 25:30:10as some of these. I mean, I just it's
  40113. 25:30:12it's really interesting. That's why we
  40114. 25:30:14did the emissions per person earlier
  40115. 25:30:15because there are outliers and, you
  40116. 25:30:17know, the total population does matter.
  40117. 25:30:20Let's come in here and we're just going
  40118. 25:30:21to rename this uh county shaming. All
  40119. 25:30:25right, that's what we're going to call
  40120. 25:30:26it because that's what we're doing.
  40121. 25:30:28Let's be honest. All right, we're just
  40122. 25:30:30going to make a bar chart. We're going
  40123. 25:30:32to go to the county shaming. We're going
  40124. 25:30:34to use a bar chart
  40125. 25:30:36for our x-axis. Uh, let's use totally
  40126. 25:30:40emissions. Then for our yaxis, we can
  40127. 25:30:43use the county state name. Um, and I do
  40128. 25:30:46want to look at that from highest to
  40129. 25:30:47lowest. So, let's do it like that. We
  40130. 25:30:51can change the coloring if you want. I
  40131. 25:30:53definitely want tool tips or not tool
  40132. 25:30:55tips, sorry, labels. I definitely want
  40133. 25:30:57labels on this. This is just our total
  40134. 25:30:59emissions in like megatons. So, I'm
  40135. 25:31:01going to say that I want to add a title.
  40136. 25:31:03I'm going to say uh total emissions.
  40137. 25:31:07I got to spell right. Emissions by M
  40138. 25:31:10ton. M ton I think of CO2.
  40139. 25:31:16Uh, and I want to make sure that's
  40140. 25:31:18correct because listen, this dashboard,
  40141. 25:31:21I'm gonna send this to the EPA right
  40142. 25:31:23away. Uh, so we have m tons of CO2.
  40143. 25:31:26Maybe CO2E. I don't know if I should be
  40144. 25:31:30putting that in here. Let's add that.
  40145. 25:31:32All right. This looks great. Um, let's
  40146. 25:31:37adjust this real quick. I'm actually
  40147. 25:31:40going to come over this way. Double
  40148. 25:31:44click.
  40149. 25:31:45Double click. Come out a little bit. Uh,
  40150. 25:31:50this this is something that I just have
  40151. 25:31:53not gotten the hang of. I don't know if
  40152. 25:31:54I'm doing something wrong, but let's
  40153. 25:31:56click in on this
  40154. 25:31:58and uh have that right there. We need to
  40155. 25:32:01bring back
  40156. 25:32:03our emissions versus population and
  40157. 25:32:06bring this up.
  40158. 25:32:09Now, I do Oh, what did I do here? Oh, I
  40159. 25:32:12think I might have clicked on. Yeah, I
  40160. 25:32:14zoomed in. Whoops. Uh, don't mind me.
  40161. 25:32:17Listen, I make mistakes all the time. I
  40162. 25:32:20want to clean this up just a little bit.
  40163. 25:32:22Things like the total emissions. I just
  40164. 25:32:25want to say total emissions, right? I'm
  40165. 25:32:28cleaning up these X and Y axes. I'm
  40166. 25:32:31going to call this uh the county name.
  40167. 25:32:35Uh, maybe I should say county state
  40168. 25:32:37name, I guess, to be more accurate. That
  40169. 25:32:41looks good. Emissions. This one looks
  40170. 25:32:43good. Here we need Oops, let me zoom
  40171. 25:32:45out.
  40172. 25:32:47We need to rename this one emissions per
  40173. 25:32:50person. We're gonna call this
  40174. 25:32:53uh emissions.
  40175. 25:32:55Oops. Did I spell that right? Emissions
  40176. 25:32:59per person. That I does not look right,
  40177. 25:33:02but maybe it is. And I'm I'm going to
  40178. 25:33:04change this population to be
  40179. 25:33:05capitalized. I just I think it looks
  40180. 25:33:07better. Population.
  40181. 25:33:11And uh let's see. Emissions per
  40182. 25:33:14location. Emissions versus population. I
  40183. 25:33:17actually should say emissions.
  40184. 25:33:20Where's the title here? Oh, I got to do
  40185. 25:33:23it up here. I'm going to say emissions
  40186. 25:33:26for continental
  40187. 25:33:29US. Did I spell that right? No.
  40188. 25:33:31Continental US. My spelling is so
  40189. 25:33:34terrible. But we're only looking at the
  40190. 25:33:36continental US here, so that might just
  40191. 25:33:37be worth noting. Um, we are done.
  40192. 25:33:42We are done here. We have our United
  40193. 25:33:45States emissions breakdown and I think
  40194. 25:33:48this looks great. Uh, we dug into some
  40195. 25:33:50of the data a little bit deeper than we
  40196. 25:33:52probably needed to, but I think this was
  40197. 25:33:54great and we're able to use AI and build
  40198. 25:33:56out our dashboard. I am super happy with
  40199. 25:33:58how this turned out. Remember, this is a
  40200. 25:34:00real data set. There's so much other
  40201. 25:34:02data in here. So if you want to, you can
  40202. 25:34:04use the assistant in here and say, "Hey,
  40203. 25:34:07what other things can I look at for
  40204. 25:34:08emissions and it'll give you
  40205. 25:34:10suggestions, but this is what I wanted
  40206. 25:34:11to build because I was super interested
  40207. 25:34:13in it." And emissions is just, you know,
  40208. 25:34:15something that everybody understands.
  40209. 25:34:18People are curious about it and so
  40210. 25:34:19visualizing it, being able to see it and
  40211. 25:34:21kind of shame some of these counties
  40212. 25:34:23that just got so many emissions, but
  40213. 25:34:26it's worth it. It's worth uh worth
  40214. 25:34:28building it out. So I hope that you
  40215. 25:34:29enjoyed this. I hope that you found this
  40216. 25:34:31helpful. Before we go, I want to give a
  40217. 25:34:33huge shout out to the sponsor of this
  40218. 25:34:34entire series and that was Data Bricks.
  40219. 25:34:36Data Bricks has been so awesome to work
  40220. 25:34:38with because I already love Data Bricks.
  40221. 25:34:40It was an easy fit. And what's even
  40222. 25:34:41better is they have this data bicks free
  40223. 25:34:43edition. If you have not already, if you
  40224. 25:34:44just watched through this without
  40225. 25:34:45following along, create a Data Bricks
  40226. 25:34:48free edition account, go ahead and do
  40227. 25:34:49that. I will leave a link in the
  40228. 25:34:50description so you can build something
  40229. 25:34:52like this completely for free. It is an
  40230. 25:34:54amazing, amazing deal. With that being
  40231. 25:34:56said, thank you guys so much for
  40232. 25:34:58following along through this entire
  40233. 25:34:59project. I had a lot of fun. and I hope
  40234. 25:35:01you did too. If you have not already, be
  40235. 25:35:03sure to like and subscribe and I will
  40236. 25:35:04see you in the next video.
  40237. 25:35:07[music]
  40238. 25:35:18What's going on everybody? Welcome back
  40239. 25:35:19to another video. Today we're going to
  40240. 25:35:21build ETL pipelines in data bricks in
  40241. 25:35:23under one hour.
  40242. 25:35:28>> [music]
  40243. 25:35:30>> Now, in this video, we're going to cover
  40244. 25:35:32several different things. First, we're
  40245. 25:35:33going to work on data ingestion, just
  40246. 25:35:35getting data in. Second, we're going to
  40247. 25:35:37actually build out our ETL pipelines.
  40248. 25:35:39And then third, we're going to work on
  40249. 25:35:40data orchestration or creating jobs in
  40250. 25:35:43data bicks. At the very end, we're going
  40251. 25:35:44to have a full end-to-end project where
  40252. 25:35:46we pull data in from a folder in an AWS
  40253. 25:35:49S3 bucket. Then, we automate it with an
  40254. 25:35:51ETL pipeline to clean that data. Now,
  40255. 25:35:53this video is made from several shorter
  40256. 25:35:56videos that we have done on data bricks
  40257. 25:35:57in previous lessons, but we're putting
  40258. 25:35:59them all into one long video, so you can
  40259. 25:36:02watch it all at one time. Let's not
  40260. 25:36:03waste any more time. Let's jump into the
  40261. 25:36:05first part, which is data ingestion.
  40262. 25:36:07Before we jump into this data
  40263. 25:36:08engineering series and start doing all
  40264. 25:36:10the things, I want to slow down for just
  40265. 25:36:12a second to take a look at what ELT is
  40266. 25:36:14in data bricks. This is the process that
  40267. 25:36:17we're going to be walking through for
  40268. 25:36:18this entire series. We're extracting
  40269. 25:36:20data or getting our data into data
  40270. 25:36:22bricks. That involves loading the data
  40271. 25:36:24into different schemas and having that
  40272. 25:36:25data available and then we transform
  40273. 25:36:28that data. Now ELT might sound odd
  40274. 25:36:30because most people are used to ETL
  40275. 25:36:32where you extract data, you transform it
  40276. 25:36:34and then you load it into the database.
  40277. 25:36:37With a lot of modern data workflows, it
  40278. 25:36:38doesn't actually make much sense to
  40279. 25:36:40transform your data before because
  40280. 25:36:42compute is quite cheap these days and so
  40281. 25:36:44you can just load your data into data
  40282. 25:36:46bricks and then transform it after. Now
  40283. 25:36:48there's something called the medallion
  40284. 25:36:49architecture. We're going to take a look
  40285. 25:36:51more at that in the next lesson when we
  40286. 25:36:52take a look at bronze, silver, and gold
  40287. 25:36:54architectures. Now, this is a really
  40288. 25:36:56great way to kind of stage your data and
  40289. 25:36:57it's been like this for a long time even
  40290. 25:37:00before data bricks, but we'll be going
  40291. 25:37:02into why and how we actually do that
  40292. 25:37:04within data bricks. Our data when we
  40293. 25:37:06actually get it into data bicks is being
  40294. 25:37:08stored in a delta table. It's kind of
  40295. 25:37:10like a delta file type, which is
  40296. 25:37:11basically just a parquet file that has
  40297. 25:37:13this log system where you can kind of
  40298. 25:37:14revert back and see previous changes to
  40299. 25:37:17the actual document. And so we store our
  40300. 25:37:18data in these delta tables and then we
  40301. 25:37:21can do all of our transformations on it
  40302. 25:37:22within a notebook or within SQL queries.
  40303. 25:37:24Now that we've got that out of the way,
  40304. 25:37:26let's actually jump into data bicks and
  40305. 25:37:28see how we can do this. All right, here
  40306. 25:37:30we are on data bicks and we're going to
  40307. 25:37:31be doing two things. One, we're just
  40308. 25:37:32going to upload a CSV file. It's
  40309. 25:37:34probably the simplest way to get data
  40310. 25:37:36into databicks, but then we're also
  40311. 25:37:38going to connect to an S3 bucket. And so
  40312. 25:37:40I'm going to show you how you can do
  40313. 25:37:42that really easily. And we're going to
  40314. 25:37:43get all of our data into data bricks.
  40315. 25:37:45Now we are just working with sample data
  40316. 25:37:47for this lesson but at the last one when
  40317. 25:37:50we start doing our full ETL process and
  40318. 25:37:52automating this entire thing then we'll
  40319. 25:37:54be using real data and so it'll be a lot
  40320. 25:37:56more a little bit more complex. There's
  40321. 25:37:58a few ways to ingest data. One you can
  40322. 25:38:00just click on this bring in data and
  40323. 25:38:03it's going to take you right down here.
  40324. 25:38:04But we can also just go to our data
  40325. 25:38:06ingestion. And so when we click on this
  40326. 25:38:08we're going to upload files to a volume
  40327. 25:38:11or we're going to create and modify a
  40328. 25:38:13table. Now, these are two separate
  40329. 25:38:15things and these are important things to
  40330. 25:38:16understand. Let's actually come over
  40331. 25:38:18here to catalog for a second. And what
  40332. 25:38:20we're going to do is we're going to come
  40333. 25:38:20over here and we're going to create a
  40334. 25:38:22new catalog. And we're just going to
  40335. 25:38:24call this one our data engineering. Uh
  40336. 25:38:27that's all we're going to call it. I was
  40337. 25:38:29going to keep going, but we'll call it
  40338. 25:38:30the data engineering one. And let's go
  40339. 25:38:33ahead and view this catalog. Now, when
  40340. 25:38:35we create a schema, we're going to say
  40341. 25:38:38this is uh video one. Let's go ahead and
  40342. 25:38:42create this.
  40343. 25:38:43We have within our data engineering we
  40344. 25:38:46have our default and then we have this
  40345. 25:38:47information schema but we also have this
  40346. 25:38:49video one. Now we don't have any data in
  40347. 25:38:53the schema but what we can do is we can
  40348. 25:38:56create different ways to store our data.
  40349. 25:38:58We can store it in a volume or we can
  40350. 25:39:00store it in a table. Now in a previous
  40351. 25:39:02series I kind of dove into these and how
  40352. 25:39:04you can store your data as well as how
  40353. 25:39:06to access the data once you put it in.
  40354. 25:39:08We're going to be putting all of our
  40355. 25:39:09data into tables. So, I'm just going to
  40356. 25:39:11set up one table. Now that we're here,
  40357. 25:39:13though, we can do the same thing that we
  40358. 25:39:15would do if we came over to our data
  40359. 25:39:17ingestion, which is basically just drop
  40360. 25:39:19a file in here like you would on any
  40361. 25:39:21platform. Let's just go over to the data
  40362. 25:39:23inestion just so we get the full
  40363. 25:39:25experience. We're going to create or
  40364. 25:39:27modify a table. We're going to select
  40365. 25:39:29our CSV file. So, it's just our users_y,
  40366. 25:39:32and we're going to go ahead and upload
  40367. 25:39:34this. So, now we have this preview of
  40368. 25:39:36our data, and we're going to specify
  40369. 25:39:38what we want to do with it. We could
  40370. 25:39:39create a table. We could overwrite an
  40371. 25:39:41existing table. And we want to put this
  40372. 25:39:43in our data engineering video one. So if
  40373. 25:39:45it doesn't automatically populate, you
  40374. 25:39:46can always just specify where you want
  40375. 25:39:48to place it. And we're going to call
  40376. 25:39:50this underscore CSV because we're going
  40377. 25:39:52to be bringing in the same file from an
  40378. 25:39:54S3 bucket. So I just want to specify
  40379. 25:39:56where we got this data. Let's come down
  40380. 25:39:59here and we're going to create our
  40381. 25:40:00table.
  40382. 25:40:02So now we have our data sitting in our
  40383. 25:40:04video one schema. So this is our
  40384. 25:40:06users_y_csv.
  40385. 25:40:08This is the simplest way to get data
  40386. 25:40:11into data bricks. But I also have this
  40387. 25:40:13exact same data sitting right over here
  40388. 25:40:16in an S3 bucket and I want to use it. I
  40389. 25:40:19want to connect to this data. I want to
  40390. 25:40:21pull it in automatically. And that's
  40391. 25:40:23going to really help us later on down
  40392. 25:40:24the line when we start automating this
  40393. 25:40:26whole process because we're going to
  40394. 25:40:27create a connection to this data source
  40395. 25:40:29so we can automatically pull this data
  40396. 25:40:31in. And that's a big part of just data
  40397. 25:40:34engineering in general, which is
  40398. 25:40:35creating systems that can automatically
  40399. 25:40:38ingest, transform, and load your data.
  40400. 25:40:40So, what we're going to do is we're
  40401. 25:40:41going to come right over here. Now, I
  40402. 25:40:43just want to show you this. I'm going to
  40403. 25:40:44have a link down below so that you can
  40404. 25:40:46see this as well. But this is basically
  40405. 25:40:48just how you're going to create the
  40406. 25:40:50connection. I'm going to show it to you
  40407. 25:40:51in a second. It is very, very simple.
  40408. 25:40:54So, let's come right over here. And what
  40409. 25:40:56we're going to do is we're going to come
  40410. 25:40:57down to data ingestion. Now, we want to
  40411. 25:41:00go to the data bricks connectors and we
  40412. 25:41:02want to go to our Amazon S3 bucket right
  40413. 25:41:05here and we need to create an external
  40414. 25:41:07location. So, we're basically connecting
  40415. 25:41:09our databicks account to our Amazon S3
  40416. 25:41:12bucket. And then we can bring that data
  40417. 25:41:15in very easily. What we're going to be
  40418. 25:41:17using is this AWS quickart. Let's go
  40419. 25:41:19ahead and select next. We need to put in
  40420. 25:41:21our bucket name. So, I'm going to come
  40421. 25:41:23over here. Let's click in here. We can
  40422. 25:41:26actually get it right here. there.
  40423. 25:41:27There's other places to get it, but I'm
  40424. 25:41:29just going to copy it from here. Uh,
  40425. 25:41:32we're going to go back to our catalog
  40426. 25:41:35explorer, and there's our bucket name.
  40427. 25:41:38So, now what we're going to do is we're
  40428. 25:41:39going to generate this new token, and
  40429. 25:41:41we're going to copy this. Now, we're
  40430. 25:41:43going to come over here to launch in
  40431. 25:41:44quick start. And all we have to do is
  40432. 25:41:47it's going to connect to our account.
  40433. 25:41:48So, that makes it pretty easy if you're
  40434. 25:41:49already logged in. Then, we're going to
  40435. 25:41:51come down here and we're going to say I
  40436. 25:41:54acknowledge and we're going to say
  40437. 25:41:56create stack. It's going to come right
  40438. 25:41:58here and it's going to say create in
  40439. 25:41:59progress. It's just going to validate it
  40440. 25:42:01for a second. I had already done this uh
  40441. 25:42:03before when I was making this video
  40442. 25:42:05earlier just to confirm everything was
  40443. 25:42:07working smoothly. And what it's going to
  40444. 25:42:08do is it's just going to say create
  40445. 25:42:10complete and then you're going to be
  40446. 25:42:12good to go. All right. So, that took
  40447. 25:42:13about 2 minutes and it says it is
  40448. 25:42:15complete. So, all we're going to do is
  40449. 25:42:17come back here and we're going to
  40450. 25:42:19refresh this page. So, I'm going to go
  40451. 25:42:21ahead and refresh.
  40452. 25:42:24And now that that connection is active,
  40453. 25:42:26we now have access to our users
  40454. 25:42:29dirty. Let's come under here. We're
  40455. 25:42:31going to click on this and we're going
  40456. 25:42:32to go to preview table. So now we get
  40457. 25:42:34this preview of the exact same data set.
  40458. 25:42:36There's nothing changed. I'm not trying
  40459. 25:42:37to trick you. All we have to do is we're
  40460. 25:42:39going to come up here to data
  40461. 25:42:40engineering and we're going to go to
  40462. 25:42:41video one. And then we need to name
  40463. 25:42:43this. So I'm going to call this one
  40464. 25:42:46dirty
  40465. 25:42:48data
  40466. 25:42:50S3. So I'm just naming it this purely so
  40467. 25:42:54that we know which one came from which.
  40468. 25:42:56Let's come down here to create table.
  40469. 25:42:58And now we can see over here we have our
  40470. 25:43:00dirty data S3 and our users_y_csv.
  40471. 25:43:04I named it completely wrong but these
  40472. 25:43:06are the exact same data sets and now we
  40473. 25:43:09have them in from two separate
  40474. 25:43:10locations. Now this is really important
  40475. 25:43:13especially as we start automating a lot
  40476. 25:43:15of this. If you have data that's sitting
  40477. 25:43:17in an S3 bucket and you have other
  40478. 25:43:18systems that then upload it into that
  40479. 25:43:20bucket, we're going to be able to ingest
  40480. 25:43:22that data automatically, whether it's
  40481. 25:43:24updated or if it's a new file. And we'll
  40482. 25:43:26set all sorts of triggers and schedules
  40483. 25:43:28and all sorts of really cool things in
  40484. 25:43:30later lessons. So that's how we ingest
  40485. 25:43:32data within data bicks. In our next
  40486. 25:43:34lesson, we're going to be transforming
  40487. 25:43:36data within an actual data pipeline. So
  40488. 25:43:38we're going to have the entire ingestion
  40489. 25:43:39process as well as the transformation
  40490. 25:43:41process all in one place. Now, in the
  40491. 25:43:44last lesson, we worked on data ingestion
  40492. 25:43:46into data bricks. So, we were able to
  40493. 25:43:47connect to just a local file, just kind
  40494. 25:43:49of reading that file in and then we were
  40495. 25:43:51also able to connect to an AWS S3
  40496. 25:43:54bucket. Now that we have that data
  40497. 25:43:55pulled in and we have it actually
  40498. 25:43:56sitting in our schema, we need to clean
  40499. 25:43:58this data up a little bit. And so, we're
  40500. 25:44:00going to need to transform this data,
  40501. 25:44:01which is part of the extract, transform,
  40502. 25:44:03and load within an ETL process. So, we
  40503. 25:44:06extracted and we ingested that data. And
  40504. 25:44:08now, we need to clean up our data
  40505. 25:44:10because it is messy. That's the
  40506. 25:44:11transformation piece of the ETL process.
  40507. 25:44:14Once we have this done, we can put it
  40508. 25:44:15into an ETL pipeline and then it sits
  40509. 25:44:17there and it does a lot of the heavy
  40510. 25:44:19lifting for us and we'll talk about that
  40511. 25:44:20in this lesson. Now, really quickly
  40512. 25:44:22before we jump into things, I want to
  40513. 25:44:24talk about this bronze, silver, and gold
  40514. 25:44:25medallion architecture that is very
  40515. 25:44:27popular within data bricks. Now, we've
  40516. 25:44:29actually already covered this bronze
  40517. 25:44:31level, which is just our raw data. We
  40518. 25:44:34ingested our data from our S3 bucket and
  40519. 25:44:37it's just sitting there in this raw
  40520. 25:44:38format. This is data that we are just
  40521. 25:44:40never going to touch. What we're going
  40522. 25:44:41to do is we're going to create
  40523. 25:44:42transformations on that data and then
  40524. 25:44:44we're going to put it into a different
  40525. 25:44:46table or even a different schema or
  40526. 25:44:48catalog. When it gets to that location
  40527. 25:44:50and the data is actually changed, that's
  40528. 25:44:52going to be in our silver. So this
  40529. 25:44:54silver layer or architecture is
  40530. 25:44:56basically just once you clean it up and
  40531. 25:44:58you have it in a lot better state where
  40532. 25:45:00there aren't a lot of duplicates, there
  40533. 25:45:01aren't a lot of issues with the data,
  40534. 25:45:03that's where it's going to sit where you
  40535. 25:45:04can then transform it into your gold
  40536. 25:45:06architecture or layer. Gold is just
  40537. 25:45:08production ready. You are ready to start
  40538. 25:45:10using this data. You're going to put it
  40539. 25:45:11into dashboards. You're going to put it
  40540. 25:45:13into reports. You're going to put it
  40541. 25:45:14into your apps. Whatever you're using
  40542. 25:45:16that data for. Back when I was just
  40543. 25:45:18using Microsoft SQL Server or any other
  40544. 25:45:20tool, we would call this raw staging and
  40545. 25:45:23production. The raw is bronze, the
  40546. 25:45:25staging is silver, and of course, the
  40547. 25:45:27production is gold where we actually use
  40548. 25:45:29that data. So, what we're going to do in
  40549. 25:45:31this lesson is we're going to actually
  40550. 25:45:32use this. We already have our bronze. we
  40551. 25:45:34need to transform my data into silver
  40552. 25:45:35and then find a business use case to
  40553. 25:45:37create the gold table. So now that we
  40554. 25:45:39have this background information, let's
  40555. 25:45:41go onto our screen and start building
  40556. 25:45:42this out. So in the last lesson, we
  40557. 25:45:44brought in this dirty data S3. And this
  40558. 25:45:48is what our data looks like. We have
  40559. 25:45:49this user ID, first name, last name,
  40560. 25:45:51their email, their sign up, the country,
  40561. 25:45:54and referral source. Now, this is just
  40562. 25:45:56our raw data. This is our bronze layer
  40563. 25:46:00right here. Now, in this video, we're
  40564. 25:46:02not going to do it exactly how I would
  40565. 25:46:04do it in the real world. I'm just going
  40566. 25:46:05to kind of keep it all in one place for
  40567. 25:46:08us. So, within this video one or within,
  40568. 25:46:11you know, whatever schema you created,
  40569. 25:46:13we're going to keep our silver and our
  40570. 25:46:15gold tables all within this one schema.
  40571. 25:46:18That is not typically how it is done.
  40572. 25:46:20Here's what you typically would do.
  40573. 25:46:21You're going to have a data engineering
  40574. 25:46:23bronze catalog. Then you have a data
  40575. 25:46:26engineering silver catalog. Then you
  40576. 25:46:28have a data engineering gold catalog.
  40577. 25:46:31And all these cataloges would hold the
  40578. 25:46:34different levels. And so you're not just
  40579. 25:46:36usually working with one small project
  40580. 25:46:38like we are in, you know, this lesson,
  40581. 25:46:40but typically you're working with lots
  40582. 25:46:42of different projects and you're working
  40583. 25:46:43with lots of different customers and you
  40584. 25:46:44want those to be separated out so you
  40585. 25:46:46don't kind of get them confused and you
  40586. 25:46:48don't know which data you're supposed to
  40587. 25:46:49be hitting off of. That typically is how
  40588. 25:46:51it's done in a real workplace
  40589. 25:46:53environment. We're just going to do it
  40590. 25:46:54all right now within this video one
  40591. 25:46:57schema. So this is our bronze layer
  40592. 25:47:00right here. This is the file that we are
  40593. 25:47:02going to be using. Now in order to
  40594. 25:47:03transform our data to get it to silver,
  40595. 25:47:06here's what we need to do. Let's come up
  40596. 25:47:07to our new. Let's go down to our
  40597. 25:47:10notebook. So we have this notebook right
  40598. 25:47:12here. Let's call this bronze to silver
  40599. 25:47:17transformation. There we go. And I'm
  40600. 25:47:19going to give you a little spoiler here.
  40601. 25:47:21Uh we're going to create another
  40602. 25:47:22notebook and we're going to call this
  40603. 25:47:24one silver to gold. And so we want to uh
  40604. 25:47:28separate these out. You don't have to
  40605. 25:47:31separate these out, but for the sake of
  40606. 25:47:32what we're going to be doing in this
  40607. 25:47:34lesson, I do want to show you how kind
  40608. 25:47:35of you set things up and you actually,
  40609. 25:47:38you know, organize things within an ETL
  40610. 25:47:39pipeline. And then in the next lesson
  40611. 25:47:41when we look at jobs and orchestration
  40612. 25:47:43and automation, this will also come into
  40613. 25:47:46play and I'll talk all about that. So
  40614. 25:47:48let's create these two different things.
  40615. 25:47:50Now, I can write all this out because,
  40616. 25:47:53you know, I know this data set. It's
  40617. 25:47:55pretty simple and I already know what's
  40618. 25:47:56wrong with it. So, I can go in and I can
  40619. 25:47:59just fix it. I can write this out
  40620. 25:48:00manually. But, uh, you know, let's get a
  40621. 25:48:03little creative. Let's take a look at
  40622. 25:48:05how we can use AI in order to see if it
  40623. 25:48:08can do most of the heavy lifting for us.
  40624. 25:48:10Now, in our sample data, I'm going to
  40625. 25:48:11give you two things that need to be
  40626. 25:48:13changed because there's only really two
  40627. 25:48:14big issues. The first thing is in this
  40628. 25:48:16date column, we actually have it as a
  40629. 25:48:19string. And that's a problem, right? We
  40630. 25:48:21need it to be a date column. And the
  40631. 25:48:23issue is is this right here. We have one
  40632. 25:48:25date field that is 2.29.24
  40633. 25:48:28instead of the uh forward slashes.
  40634. 25:48:31That's an issue. We also have a USR_109
  40635. 25:48:35as a user ID. And if we go down, we have
  40636. 25:48:38a 1009 right over here. So we have a
  40637. 25:48:41duplicate user ID. And in a primary key,
  40638. 25:48:45like a user ID typically would be,
  40639. 25:48:47that's an issue. So, we have two issues
  40640. 25:48:49we need to solve. I am going to try to
  40641. 25:48:51get the AI, which is the agentic AI,
  40642. 25:48:54which is uh this one up here that we're
  40643. 25:48:55going to be using to try to write this
  40644. 25:48:57out and get it right. So, let's come
  40645. 25:49:00back to our workspace. Let's come to our
  40646. 25:49:02bronze to silver transformation and
  40647. 25:49:05let's bring up our AI assistant. Now,
  40648. 25:49:09I'm going to describe what I want it to
  40649. 25:49:11do and then we're going to see if it's
  40650. 25:49:14able to write it out. I myself could
  40651. 25:49:15write it out very accurately in probably
  40652. 25:49:17maybe three to four minutes, but this is
  40653. 25:49:20not a coding tutorial. I want to show
  40654. 25:49:22you guys how ETL pipelines work in data
  40655. 25:49:24bricks, not how to necessarily transform
  40656. 25:49:26the data. So, let's try this out. So,
  40657. 25:49:28I'm going to say take my data set and I
  40658. 25:49:31can pull it up over here just so we can
  40659. 25:49:33see it. I'm going to go to data
  40660. 25:49:34engineering video one just so I can see
  40661. 25:49:37the data. take my data set in the data
  40662. 25:49:40engineering catalog in video one schema
  40663. 25:49:46called dirty data S3. Now I like to be
  40664. 25:49:50super explicit cuz I don't want there to
  40665. 25:49:52be confusion especially as you have like
  40666. 25:49:54hundreds of tables you don't want it to
  40667. 25:49:55read in the wrong tables. I like to be
  40668. 25:49:57super explicit. We're going to ask it.
  40669. 25:49:59I'm going to say there is something
  40670. 25:50:01wrong in the date column making it a
  40671. 25:50:05string. I want you to identify and fix
  40672. 25:50:09that issue. There's also duplicates in
  40673. 25:50:12the data set. I want you to remove
  40674. 25:50:15duplicates on the ID. Now, I'm being
  40675. 25:50:18slightly vague, right? I'm not telling
  40676. 25:50:20it exactly what it needs to do, but I'm
  40677. 25:50:22going to let this run and we're going to
  40678. 25:50:23see if it's able to identify the issues
  40679. 25:50:25and write the code. I do want it in
  40680. 25:50:28Python. I think that's just the easiest
  40681. 25:50:30way to transform this data. And so I'm
  40682. 25:50:31going to say use Python and pandas and
  40683. 25:50:36let's give it a go. So let's let this
  40684. 25:50:37think for just a little bit and we'll
  40685. 25:50:39see what it comes up with. So that took
  40686. 25:50:41about a minute or so. It did a lot of
  40687. 25:50:43different things and now it wants to
  40688. 25:50:44actually run this code. Now before we do
  40689. 25:50:47that, you can have it ask every time or
  40690. 25:50:49you can just allow it to run the code
  40691. 25:50:51after it's done. I'm going to ask it to
  40692. 25:50:53ask every time just because uh you know
  40693. 25:50:55I want to make sure. Now, it does have a
  40694. 25:50:57lot of printing just to show the work
  40695. 25:51:00that it's doing. I myself don't want
  40696. 25:51:02this in my output. So, I will ask it to
  40697. 25:51:05change that in just a second, but it
  40698. 25:51:06does identify that there's a period. It
  40699. 25:51:08replace it with a forward slash. It
  40700. 25:51:10converts it to two date time, which
  40701. 25:51:12looks correct, and it also formats it
  40702. 25:51:14for us. Uh, then it comes down here and
  40703. 25:51:16it's doing just a ton of kind of pretty
  40704. 25:51:18unnecessary things before it gets to
  40705. 25:51:21this df.drop duplicates on the user ID.
  40706. 25:51:24and we're keeping the first one, which
  40707. 25:51:25is perfectly fine. And then lastly, it's
  40708. 25:51:27doing a lot of verification. I basically
  40709. 25:51:30don't want 80% of this code. I just want
  40710. 25:51:33the simple stuff. So, all I'm going to
  40711. 25:51:34say is I like the transformations you've
  40712. 25:51:37done, but get rid of all the print
  40713. 25:51:41statements. All right, looks like it's
  40714. 25:51:43done. And as you can see, it cleaned up
  40715. 25:51:45the code immensely. Uh, this is uh
  40716. 25:51:48really looking good. I'm going to go
  40717. 25:51:49ahead and I'm going to accept all. You
  40718. 25:51:51can see the diffs down here by the way
  40719. 25:51:52for all the code that it's writing or
  40720. 25:51:54taking away. We're going to accept all
  40721. 25:51:56and we are going to run this ourselves.
  40722. 25:51:58We can I'll just click run all here. Uh
  40723. 25:52:00but we're going to run this ourselves
  40724. 25:52:01and then we'll verify and make sure that
  40725. 25:52:04this actually looks good. So let's open
  40726. 25:52:06this up. Let's come down here and let's
  40727. 25:52:08just do a display. We'll do dataf
  40728. 25:52:11frame_clean which is what it named it.
  40729. 25:52:14So now let's look at this new dataf
  40730. 25:52:16frame that it has created. That should
  40731. 25:52:18be a lot cleaner than before. So now if
  40732. 25:52:20we come down here, we have our 1009.
  40733. 25:52:23Let's go see if our 10009 was removed.
  40734. 25:52:25It was. And let's come over here to our
  40735. 25:52:28signup date. And it looks like that now
  40736. 25:52:30is converted to a timestamp, which is
  40737. 25:52:32perfectly fine. Uh we could also do it
  40738. 25:52:34as just a date column, but honestly, it
  40739. 25:52:38really doesn't matter. Uh this is a
  40740. 25:52:40great uh a great change and it cleans it
  40741. 25:52:42up immensely. So now it's all
  40742. 25:52:43standardized. It's actually in a date
  40743. 25:52:45column or a time stamp column and that
  40744. 25:52:47works great. Now, all we need to do as
  40745. 25:52:49the last part of this process is we have
  40746. 25:52:51to write this table to a new table and
  40747. 25:52:54that's going to be our silver table. So,
  40748. 25:52:56I'm going to come down here. I'm going
  40749. 25:52:58to say and I could put it as the genie
  40750. 25:53:00code or I can come over here. I tend to
  40751. 25:53:03like using the side a lot more. I don't
  40752. 25:53:04know why, but I'm going to say uh write
  40753. 25:53:07this cleaned table to a new table in the
  40754. 25:53:11same schema and call it S3_cleaned
  40755. 25:53:17silver. And so let's go ahead and let
  40756. 25:53:19that run. And it should take just a
  40757. 25:53:21second and we'll have that code for us.
  40758. 25:53:23Let's go down here really quick. We have
  40759. 25:53:25this. This looks great. I'm going to
  40760. 25:53:27allow this to run for us. So it's going
  40761. 25:53:29to run this code. Now it is giving us
  40762. 25:53:31this warning and this is a very fair
  40763. 25:53:33warning. We're using overwrite right
  40764. 25:53:34here. And basically what we're doing is
  40765. 25:53:36every time we run this, we're
  40766. 25:53:38overwriting the previous data that's in
  40767. 25:53:40that table. For now, I'm just going to
  40768. 25:53:42use that cuz it's not a huge deal. You
  40769. 25:53:44know, as you start getting more
  40770. 25:53:46sophisticated with your data pipelines,
  40771. 25:53:48you are going to want to think about
  40772. 25:53:49things like adding data to your existing
  40773. 25:53:52data instead of overwriting. But, you
  40774. 25:53:53know, that can get a little bit more
  40775. 25:53:55advanced depending on your data and your
  40776. 25:53:57data need. Now, it's going to run this
  40777. 25:53:59and I'm going to accept all. And then
  40778. 25:54:01let's come right over here to our data
  40779. 25:54:03engineering video one. And now we have
  40780. 25:54:06this S3 cleaned silver. So our bronze to
  40781. 25:54:09silver transformation is complete. This
  40782. 25:54:12is all we needed to do in order to
  40783. 25:54:14transform our data. And now we have our
  40784. 25:54:17raw data. And let's come actually back
  40785. 25:54:19to our catalog. And we'll just take a
  40786. 25:54:21look at this. We can get rid of our
  40787. 25:54:22genie code real quick. So we're going to
  40788. 25:54:24come over here. So our raw data is still
  40789. 25:54:27going to be raw. Let's go ahead and run
  40790. 25:54:28this. This is our bronze level, right?
  40791. 25:54:31We still have the raw data. We still
  40792. 25:54:33have the duplicates. But when we come
  40793. 25:54:35over to our silver, this is now going to
  40794. 25:54:37be our cleaned level. So, now that we
  40795. 25:54:40have all of our transformations
  40796. 25:54:41completed, we've taken it from bronze to
  40797. 25:54:43silver. Now, we want to create our
  40798. 25:54:45silver to gold transformations as well.
  40799. 25:54:48Let's come back to our workspace and
  40800. 25:54:50we'll come down here to the silver to
  40801. 25:54:52gold, which is going to still be right
  40802. 25:54:54up here for us. Now, let's give it a use
  40803. 25:54:55case, right? We could use this table
  40804. 25:54:58just as it raw and we could hit off of
  40805. 25:55:00it and we could build dashboards and all
  40806. 25:55:02sorts of things. Sometimes we want to
  40807. 25:55:03track certain KPIs or certain things
  40808. 25:55:05that you can't just get from the raw
  40809. 25:55:06data. So I'm just going to give it a
  40810. 25:55:08simple use case. Let it write it out and
  40811. 25:55:10we'll create our silver to gold
  40812. 25:55:11transformation. So let's come right on
  40813. 25:55:13here. I'm going to say that I want to
  40814. 25:55:14know the best day of the week that
  40815. 25:55:16people are clicking on certain ads. And
  40816. 25:55:18we're going to see what it creates for
  40817. 25:55:20us. So, uh, I want to create a new table
  40818. 25:55:25called insights
  40819. 25:55:27gold. And I want it to show me the best
  40820. 25:55:31days of the week and what ads people
  40821. 25:55:35clicked on the most. And let's run this
  40822. 25:55:37and just see what it does. All right, so
  40823. 25:55:39it went and did a lot of work for us. It
  40824. 25:55:41did not take long. This is maybe 15
  40825. 25:55:43seconds. It's doing some group buys on
  40826. 25:55:46uh some different columns and it's
  40827. 25:55:48getting some counts for us on different
  40828. 25:55:50signups and referral sources. Let's go
  40829. 25:55:53ahead and allow it to run this and let's
  40830. 25:55:55see what it does. Now, it's given us a
  40831. 25:55:57few things as far as outputs. One, this
  40832. 25:56:00first one is extracting the day of the
  40833. 25:56:01week and analyzing signup patterns. So,
  40834. 25:56:03Thursday, Tuesday, Monday, and it's
  40835. 25:56:05giving us kind of the day of the week
  40836. 25:56:07when we had the most signups. And then
  40837. 25:56:09if we come down here, we also have
  40838. 25:56:10another one where we're getting the
  40839. 25:56:12referral source, basically social media,
  40840. 25:56:14organic referral, Google ads or partner,
  40841. 25:56:16the total clicks and the countries
  40842. 25:56:18reached. And if we go down here, we have
  40843. 25:56:21this last table, but it hasn't been run
  40844. 25:56:22yet because this is actually creating
  40845. 25:56:24our table. And so this one should be
  40846. 25:56:26really interesting, but let's actually
  40847. 25:56:28stop it really quick. And then I'm going
  40848. 25:56:30to accept and then run this as well. I
  40849. 25:56:33just want to see what this one is. And
  40850. 25:56:35so then we have uh day name, the
  40851. 25:56:38referral source, signups, and unique
  40852. 25:56:40countries. I think this is the one that
  40853. 25:56:43I, you know, was kind of hoping for when
  40854. 25:56:45I asked it to run it for us, but it gave
  40855. 25:56:47us different options, which I like. Now,
  40856. 25:56:49all we have to do is we have to get rid
  40857. 25:56:51of this. And we're going to let that
  40858. 25:56:52run. And so, let's accept that. And
  40859. 25:56:55let's run this as well. Now, this
  40860. 25:56:57display is literally just displaying uh
  40861. 25:56:59right up here. So, we aren't actually
  40862. 25:57:01reading this in. But uh let's come back
  40863. 25:57:04into our catalog and let's go see if we
  40864. 25:57:06have that gold table now. So now we have
  40865. 25:57:08our video, we have our insights gold and
  40866. 25:57:12let's just look at our sample data. And
  40867. 25:57:14there we go. And so this would be like
  40868. 25:57:16our gold table that we can now use. We
  40869. 25:57:18now have some insights into our data.
  40870. 25:57:20Now all we've done so far, if we come
  40871. 25:57:23back in here, all we've done so far is
  40872. 25:57:26we've just written code. We haven't
  40873. 25:57:28necessarily created any type of
  40874. 25:57:30pipeline. And so now this is the part of
  40875. 25:57:32the video where we're going to get into
  40876. 25:57:34building an actual pipeline. And I did
  40877. 25:57:35it this way very specifically. This is
  40878. 25:57:37how I tend to write my code. I come into
  40879. 25:57:39a notebook. I write out my code. And
  40880. 25:57:41then I'm like, okay, this is looking
  40881. 25:57:43good. Let me now go create my pipeline.
  40882. 25:57:46So let's come right over here. We're
  40883. 25:57:47going to come down to our runs. And
  40884. 25:57:50there's this thing right here that says
  40885. 25:57:51ETL pipeline. Now let's get rid of this.
  40886. 25:57:54We also have this right here, which is
  40887. 25:57:57kind of what we're going to cover a lot
  40888. 25:57:58in the next lesson, but I want to talk
  40889. 25:58:00you through really quickly while we're
  40890. 25:58:01here. The difference. Now, we created
  40891. 25:58:04two separate notebooks. One from bronze
  40892. 25:58:06to silver and one from silver to gold.
  40893. 25:58:07Now, sometimes with simpler pipelines
  40894. 25:58:09like the one we just created, it could
  40895. 25:58:11be totally fine to just come in here,
  40896. 25:58:13create a job, and say, "Do this one and
  40897. 25:58:15then do this one." Right? That's all
  40898. 25:58:17we're doing. We put it on a schedule or
  40899. 25:58:18we can create uh, you know, a different
  40900. 25:58:20trigger for that. And we'll look at that
  40901. 25:58:21in the next lesson. But if you have a
  40902. 25:58:23more complex pipeline, you're typically
  40903. 25:58:26going to want to use this right here,
  40904. 25:58:27which is our ETL pipeline. Let's go
  40905. 25:58:29ahead and click in on this ETL pipeline.
  40906. 25:58:31And let's come down here to start with
  40907. 25:58:33an empty file. Now, you can start with
  40908. 25:58:36sample code in SQL, sample code in
  40909. 25:58:38Python, or if you have ones that you've
  40910. 25:58:40already done, you can do that. We don't
  40911. 25:58:42have anything, and I don't really want
  40912. 25:58:44to kind of explain all of the sample
  40913. 25:58:46code that they're going to be creating.
  40914. 25:58:47Let's just start with an empty file.
  40915. 25:58:49Now, we need to specify the language
  40916. 25:58:51that we're using. And this is very
  40917. 25:58:53important because once you create it,
  40918. 25:58:55that's kind of the one that you're going
  40919. 25:58:56to stick with. We're going to use
  40920. 25:58:58Python. And it's just asking for a
  40921. 25:59:00folder path. And so, we'll keep that.
  40922. 25:59:01And we'll say yes. And now what we have
  40923. 25:59:04looks very similar, right? We have these
  40924. 25:59:07uh kind of some notebooks on the left.
  40925. 25:59:08Then we can write our code right here.
  40926. 25:59:10It looks very similar. But there is a
  40927. 25:59:12big difference between running something
  40928. 25:59:14in a notebook like we were in our
  40929. 25:59:16workspace before and running something
  40930. 25:59:18in an ETL pipeline. When you're just
  40931. 25:59:20running your code, it's running the code
  40932. 25:59:22as is. It's pretty simple. And if you
  40933. 25:59:24did what we said earlier, which is you
  40934. 25:59:26literally just take that notebook, you
  40935. 25:59:27put it into a job, and you say run this
  40936. 25:59:29and then run this, it's literally just
  40937. 25:59:30going to take your code and run it. The
  40938. 25:59:32issue with that though is it's not going
  40939. 25:59:33to have any built-in data quality
  40940. 25:59:35checks. we're going to have to manage
  40941. 25:59:36basically all of the logic ourselves and
  40942. 25:59:39it's not going to handle any lineage
  40943. 25:59:40tracking or dependencies within your
  40944. 25:59:42code. Now, this is where ETL pipelines
  40945. 25:59:44come into play. An ETL pipeline is going
  40946. 25:59:46to have things built into it like
  40947. 25:59:47automatic incremental processing,
  40948. 25:59:49built-in data quality checks, failure
  40949. 25:59:51recovery, things like that that are
  40950. 25:59:53extremely useful when you have really
  40951. 25:59:56complex pipelines, which we aren't doing
  40952. 25:59:58in this lesson. of course is very
  40953. 25:59:59simple, but you have to think, you know,
  40954. 26:00:01if you're creating a real ETL pipeline
  40955. 26:00:03with a lot of dependencies, a lot of
  40956. 26:00:04complexities to it. You absolutely are
  40957. 26:00:06going to want to come in here. Now, when
  40958. 26:00:08we write this out, we can't just write
  40959. 26:00:10it as our regular code. And we can
  40960. 26:00:12actually do that. Let's come back and
  40961. 26:00:15let's go to all of our files. Let's go
  40962. 26:00:17to bronze to silver transformation.
  40963. 26:00:19We're going to move this just so we can
  40964. 26:00:21visually see it. We're going to put this
  40965. 26:00:23in our transformations. Then we're also
  40966. 26:00:24going to take our silver to gold and
  40967. 26:00:26we're going to move this to our
  40968. 26:00:27transformations as well. So we're going
  40969. 26:00:29to put this all in one place. And so now
  40970. 26:00:31we have this silver to gold and we have
  40971. 26:00:33the bronze. We don't actually need this
  40972. 26:00:35uh file anymore. So we could just get
  40973. 26:00:38rid of this. Now your UI might look
  40974. 26:00:40slightly different. That's just because
  40975. 26:00:41data bricks is always updating things,
  40976. 26:00:43but you should still be able to follow
  40977. 26:00:45along. But let's go ahead and this is
  40978. 26:00:47our code. It's exactly how we wrote it
  40979. 26:00:50before. Let's try to run this pipeline.
  40980. 26:00:52It's going to try to run this and it
  40981. 26:00:54should try to run that too. Let's just
  40982. 26:00:55go ahead and run it and see what
  40983. 26:00:56happens. All right, so we got this error
  40984. 26:00:58down here that says pipelines are
  40985. 26:01:00expected to have at least one table
  40986. 26:01:01defined but no tables were found in your
  40987. 26:01:04pipeline which might seem very
  40988. 26:01:06counterintuitive because you're like
  40989. 26:01:08we've created different data frames.
  40990. 26:01:09We've been working with tables. So it
  40991. 26:01:11should understand what it's doing. Now
  40992. 26:01:13it is actually rewriting the code as we
  40993. 26:01:15go. I think it's identified uh the issue
  40994. 26:01:17already. And let me explain this even
  40995. 26:01:19though uh it's starting to write it out
  40996. 26:01:22already for us which is awesome. Thank
  40997. 26:01:23you Genie Code. But here's what's
  40998. 26:01:25happening when you're running code just
  40999. 26:01:27in a notebook. It's just going line by
  41000. 26:01:29line and running the code. But within
  41001. 26:01:31this ETL process and just ignore that
  41002. 26:01:34for a second cuz I'm just going to let
  41003. 26:01:35it run within this ETL process. What
  41004. 26:01:37it's using is something called an STP
  41005. 26:01:39which is a Spark declarative pipeline.
  41006. 26:01:42This is just a different construct and a
  41007. 26:01:44different framework within the ETL
  41008. 26:01:46pipeline. And so what it actually needs
  41009. 26:01:48is something called a materialized view.
  41010. 26:01:50It needs to kind of look at what the
  41011. 26:01:51output is going to be or supposed to be.
  41012. 26:01:53It's not just blindly running your code
  41013. 26:01:55for you. It's doing a lot of heavy
  41014. 26:01:57lifting with data quality checks and all
  41015. 26:01:59these different things. Now it just went
  41016. 26:02:00through uh and it fixed it for us. It is
  41017. 26:02:03basically the same code and let's come
  41018. 26:02:06up but it's creating these materialized
  41019. 26:02:08views. So we have dp domaterialized view
  41020. 26:02:11and it's kind of naming it and giving a
  41021. 26:02:12little comment on what it is. It's doing
  41022. 26:02:14the work for us and it's creating
  41023. 26:02:16another materialized view where we use
  41024. 26:02:18this insights goal and it's actually
  41025. 26:02:20putting it all into one which is fine if
  41026. 26:02:23that's what we want to do with uh this
  41027. 26:02:25pipeline. But let's go ahead and accept
  41028. 26:02:26this and let's try running this pipeline
  41029. 26:02:29again. So now we have a little bit more
  41030. 26:02:31information. We can come right down here
  41031. 26:02:32and we can see it was trying to create
  41032. 26:02:34these different materialized views and
  41033. 26:02:36it was working. And so now this whole
  41034. 26:02:39thing has run successfully. Let's
  41035. 26:02:40actually rename this really quick. We're
  41036. 26:02:42going to do bronze. Uh, I need to spell
  41037. 26:02:44bronze, right? Bronze to silver to gold
  41038. 26:02:48ETL pipeline. And let's save it like
  41039. 26:02:50that. And we come back over here. We can
  41040. 26:02:52go to our jobs and pipelines. We now
  41041. 26:02:55have this pipeline right here. Of
  41042. 26:02:57course, uh, it failed, but now it's
  41043. 26:02:59running and it's working successfully.
  41044. 26:03:00But now we have this pipeline that we
  41045. 26:03:03have stored and we can actually start
  41046. 26:03:04using this in, you know, automations
  41047. 26:03:06where we can orchestrate these
  41048. 26:03:08pipelines. Right here it says
  41049. 26:03:09orchestrate notebooks, jobs, queries,
  41050. 26:03:11and more. And there is a lot to that,
  41051. 26:03:12and that's what we're covering in the
  41052. 26:03:14next lesson. But if we open this up, we
  41053. 26:03:16can actually see what's happening under
  41054. 26:03:18the hood. We can see these are
  41055. 26:03:19connected. We're doing this one and then
  41056. 26:03:21this one. And we can see how it's
  41057. 26:03:23running. And so there's a lot of things
  41058. 26:03:26that this ETL pipeline is going to
  41059. 26:03:27handle for us that we don't even have to
  41060. 26:03:29worry about. That really is one of the
  41061. 26:03:30biggest advantages of using an ETL
  41062. 26:03:32pipeline instead of just running your
  41063. 26:03:34notebooks. Although again, there are
  41064. 26:03:36some advantages to just running your
  41065. 26:03:38notebooks as is if it's a little bit of
  41066. 26:03:40a simpler pipeline. I really hope you're
  41067. 26:03:42able to follow along with this lesson
  41068. 26:03:44because this is really cool stuff. You
  41069. 26:03:46can also just come into here and we can
  41070. 26:03:48create an ETL pipeline and you can
  41071. 26:03:50create a pipeline with AI. So we can
  41072. 26:03:52literally just come here and we can type
  41073. 26:03:54in exactly what we want our code to look
  41074. 26:03:56like and do within our data and it can
  41075. 26:03:58build that out instead of starting with
  41076. 26:03:59a notebook and then creating our ETL
  41077. 26:04:01pipeline. you can just come right in
  41078. 26:04:03here and start doing that process here.
  41079. 26:04:05I will say though my personal workflow
  41080. 26:04:07because I'm usually not doing super
  41081. 26:04:09complex pipelines that are involving,
  41082. 26:04:10you know, ton of different dependency
  41083. 26:04:12chains and all these different things is
  41084. 26:04:14I tend to like writing my code in
  41085. 26:04:16notebooks. That's just what I'm used to.
  41086. 26:04:18Uh but there are going to be lots of use
  41087. 26:04:20cases where you're going to need to come
  41088. 26:04:21in here and you can just start here
  41089. 26:04:23instead of starting with a notebook.
  41090. 26:04:25Now, in the last two lessons, we've been
  41091. 26:04:26building out our ETL pipeline. We've
  41092. 26:04:28been writing all of our code and getting
  41093. 26:04:29everything set up. But once we actually
  41094. 26:04:31have everything set up, then we need to
  41095. 26:04:33automate this process so that we don't
  41096. 26:04:35have to manually go in and run the code
  41097. 26:04:37ourselves. Luckily, data bicks has this
  41098. 26:04:39already built out for us. It is called a
  41099. 26:04:41job. And so, we're going to jump into
  41100. 26:04:42data bicks. We're going to create our
  41101. 26:04:44own custom job and we're going to see
  41102. 26:04:45all the small things that you need to do
  41103. 26:04:47in order to create this automation. Now,
  41104. 26:04:49in our last lesson, we built out this
  41105. 26:04:51bronze to silver to gold ETL pipeline.
  41106. 26:04:54And we're basically creating two
  41107. 26:04:55separate tables. This S3_clean silver
  41108. 26:04:58and then this insights gold. And that is
  41109. 26:05:00our silver and our gold tables after
  41110. 26:05:02they're transformed. And we find our
  41111. 26:05:04business insights. Now, just for
  41112. 26:05:06demonstration purposes, I also just kept
  41113. 26:05:08our regular code in here as well. We
  41114. 26:05:10have this bronze to silver. Then we have
  41115. 26:05:12another notebook for silver to gold.
  41116. 26:05:14Now, these are just regular notebooks
  41117. 26:05:16and data bricks, but I do want to show
  41118. 26:05:18you how you can use this within a job as
  41119. 26:05:21well. But we have this bronze to silver
  41120. 26:05:23transformation. You can see it in a
  41121. 26:05:24pipeline. And then if we just go to our
  41122. 26:05:26bronze to silver, this is just a regular
  41123. 26:05:28notebook. Now, in order to create our
  41124. 26:05:30job, let's come right down here. We're
  41125. 26:05:32going to go to runs. We're going to come
  41126. 26:05:34over to job. And this is orchestrate
  41127. 26:05:35notebooks, pipelines, queries, and more.
  41128. 26:05:39So, let's come in here. Now, this is a
  41129. 26:05:41new UI for us. And what you can do here
  41130. 26:05:43is you can orchestrate the different
  41131. 26:05:45steps that you want within your job. If
  41132. 26:05:47we click right down here, we can see all
  41133. 26:05:50the things that we can do. We can create
  41134. 26:05:52ingestion pipelines or we can use
  41135. 26:05:53existing ones. We can come down here and
  41136. 26:05:56we can run notebooks, Python files, SQL
  41137. 26:05:58queries, SQL files and we have some more
  41138. 26:06:00advanced things right down here like if
  41139. 26:06:03else conditions or you can uh create
  41140. 26:06:06triggers from another job and then we
  41141. 26:06:08also have this ingestion and
  41142. 26:06:10transformation and these are really
  41143. 26:06:12useful because if you have an ingestion
  41144. 26:06:13pipeline, an ETL pipeline or a database
  41145. 26:06:16table sync then you can just use those
  41146. 26:06:18that you've already created. Now we've
  41147. 26:06:20created an ETL pipeline. Let's go ahead
  41148. 26:06:22and click on this ETL pipeline. We're
  41149. 26:06:24going to come down here and we're going
  41150. 26:06:26to click on this bronze to silver gold
  41151. 26:06:28ETL pipeline. Now, I'm just going to
  41152. 26:06:30call this uh bronze to silver to gold.
  41153. 26:06:35Keep it simple. And all we would need to
  41154. 26:06:37do is create this task. Now, of course,
  41155. 26:06:40that would be a little too simple,
  41156. 26:06:42right? But this is as simple as it can
  41157. 26:06:44get for any type of pipeline
  41158. 26:06:46orchestration that you're trying to do.
  41159. 26:06:47Oftent times when I'm creating entire
  41160. 26:06:50pipelines and there's a lot of different
  41161. 26:06:51steps to it, I package everything into
  41162. 26:06:54an ETL pipeline and then I just place it
  41163. 26:06:56in here. And then what I'll do is I'll
  41164. 26:06:58come over here to schedules and
  41165. 26:07:00triggers. Now we'll look at that in just
  41166. 26:07:02a second really quick. We can also
  41167. 26:07:04trigger a full refresh on this pipeline.
  41168. 26:07:06So we can click on this. We can also add
  41169. 26:07:08notifications if you want to send this
  41170. 26:07:10notification when it kicks off or when
  41171. 26:07:12it finishes. We can also look at
  41172. 26:07:15retries. Now, this is really important
  41173. 26:07:17because sometimes you are going to have
  41174. 26:07:18things that fail just for a various
  41175. 26:07:20number of reasons. Maybe you're trying
  41176. 26:07:21to run this, but the data hasn't all
  41177. 26:07:23imported yet, and so you're trying to
  41178. 26:07:25run this transformation, but there's
  41179. 26:07:26some connection issue, and that caused
  41180. 26:07:28it to fail. You'd want to retry maybe an
  41181. 26:07:31hour later or on a different day. You
  41182. 26:07:33would want to attempt to try this. And
  41183. 26:07:36so, you can come in here and you can
  41184. 26:07:38say, "Okay, I want to try this a ton of
  41185. 26:07:40times. Let's try it 30 total times." And
  41186. 26:07:43every single time, we're going to wait
  41187. 26:07:45maybe 30 or 40 minutes between each try
  41188. 26:07:48and then it'll keep trying until it is
  41189. 26:07:50successful. Again, with this, you can
  41190. 26:07:52notify yourself and make sure that you
  41191. 26:07:54know what's happening, especially if
  41192. 26:07:55this is a really important pipeline
  41193. 26:07:57within your company. It is important to
  41194. 26:07:59have these things set up so you don't
  41195. 26:08:01have to manually go in there and see it
  41196. 26:08:03failed, you know, last night and just
  41197. 26:08:05never got a notification. It never tried
  41198. 26:08:07again. So, this would absolutely be
  41199. 26:08:08something that you'd want to do. And
  41200. 26:08:10then you have metric thresholds. You can
  41201. 26:08:12set these, especially for something like
  41202. 26:08:14a run duration. If you know this should
  41203. 26:08:16take five minutes at most, you can set a
  41204. 26:08:18timeout threshold or a warning threshold
  41205. 26:08:20at maybe 30 minutes so that it isn't
  41206. 26:08:22just going to keep running because
  41207. 26:08:23sometimes it gets stuck in these loops
  41208. 26:08:25and it keeps trying and it's going to
  41209. 26:08:27run forever and it's going to cost a lot
  41210. 26:08:28of money and you don't want that to
  41211. 26:08:30happen. So, these are all really
  41212. 26:08:31important things to think about when you
  41213. 26:08:33are actually creating these jobs. Now,
  41214. 26:08:35let's come back here to schedules and
  41215. 26:08:37triggers for something like this. When
  41216. 26:08:40you've done almost all the work in an
  41217. 26:08:41ETL pipeline, you are going to want to
  41218. 26:08:43schedule or trigger this most of the
  41219. 26:08:45time. Now, for something like this
  41220. 26:08:47pipeline, what we've done is we've
  41221. 26:08:49extracted data out of an S3 bucket. What
  41222. 26:08:51we would want to do is probably set a
  41223. 26:08:53trigger for this. Now, what we need to
  41224. 26:08:54do is we need to create this task first.
  41225. 26:08:57So, that is saved in there. And then
  41226. 26:08:59let's say this is our entire job. It's a
  41227. 26:09:01very simple one. But now we can come in
  41228. 26:09:03here and we can add a trigger. There are
  41229. 26:09:05several different types of triggers.
  41230. 26:09:07When we have a schedule, which is as
  41231. 26:09:09simple as it sounds, we are just going
  41232. 26:09:11to schedule this. Right now, it'll be
  41233. 26:09:13active. You can pause it. We're just
  41234. 26:09:15going to schedule this. And we'll say
  41235. 26:09:17every one week. And so, every one week,
  41236. 26:09:20we're going to save this. And this is
  41237. 26:09:22going to run every week. So, that's
  41238. 26:09:24super simple. Now, let's delete this.
  41239. 26:09:26And let's add another trigger. We can
  41240. 26:09:28also schedule it. We can go a little bit
  41241. 26:09:30more advanced. And we can schedule it at
  41242. 26:09:32a very specific day and time. Now, this
  41243. 26:09:35is what I usually do because there are
  41244. 26:09:37certain cadences and timing to things
  41245. 26:09:39that I really like. For example, at a
  41246. 26:09:41previous job that I used to work at, we
  41247. 26:09:43wanted the data to be as fresh as
  41248. 26:09:45possible because we actually had it
  41249. 26:09:46refresh often, like every 10 minutes.
  41250. 26:09:48And so, what we were doing was we were
  41251. 26:09:50trying to run it as soon as we could in
  41252. 26:09:52the morning to where it would still run,
  41253. 26:09:54but it would give us the freshest set of
  41254. 26:09:56data by about 8:30 in the morning. So,
  41255. 26:09:58we would kick off this job at like 7:45
  41256. 26:10:00so that the freshest data would be
  41257. 26:10:02available by 8:30. This is more
  41258. 26:10:04advanced. You don't have to do this, but
  41259. 26:10:06this is a really useful thing to do. The
  41260. 26:10:10next thing that you can do or the next
  41261. 26:10:11type of trigger is a file arrival. So,
  41262. 26:10:14if we click on file arrival, we're going
  41263. 26:10:16to say when a file arrives at this
  41264. 26:10:18location, kick off this job and run
  41265. 26:10:21everything within it. Now, for our
  41266. 26:10:22process, this would be like our S3
  41267. 26:10:24bucket. If and we can go and look at our
  41268. 26:10:26S3 bucket. If a new file gets dropped in
  41269. 26:10:29here or this gets updated, then we may
  41270. 26:10:31trigger this job and it will run. And of
  41271. 26:10:34course, we have advanced settings as
  41272. 26:10:36well where we can wait a minimum time
  41273. 26:10:38between triggers because what if you're
  41274. 26:10:40uploading a lot of documents at the same
  41275. 26:10:41time? You don't want it to trigger 20
  41276. 26:10:43times because you just dropped 20
  41277. 26:10:45different files in there one at a time.
  41278. 26:10:46You'd want to wait for all these files
  41279. 26:10:48to get in there. So, that is absolutely
  41280. 26:10:50an option. And if we go back, we also
  41281. 26:10:53have a table update. So this would
  41282. 26:10:56trigger when new data is updated on a
  41283. 26:10:59table. Now for our use case, this may
  41284. 26:11:01work because we have S3 data. We're
  41285. 26:11:03bringing it into our bronze table. So I
  41286. 26:11:06can come in here and I can say when this
  41287. 26:11:07table and I would just specify that
  41288. 26:11:09table name that we've been using. when
  41289. 26:11:11this bronze table gets updated from that
  41290. 26:11:14S3 bucket then kick off this job which
  41291. 26:11:17of course this ETL pipeline takes that
  41292. 26:11:20bronze data we transform all the data we
  41293. 26:11:22create our gold tables and then we have
  41294. 26:11:24all that data sitting there so this
  41295. 26:11:25might be a really good use case we have
  41296. 26:11:27some advanced options down here minimum
  41297. 26:11:29time between triggers and wait after
  41298. 26:11:31last change just like we did before
  41299. 26:11:33because sometimes data gets updated
  41300. 26:11:35continuously and so it might trigger it
  41301. 26:11:37many times these are things that you
  41302. 26:11:39should test and try out within in your
  41303. 26:11:41pipelines just to make sure you get them
  41304. 26:11:42right. Now, let's cancel out of this and
  41305. 26:11:45let's actually get rid of this entirely.
  41306. 26:11:48Let's actually come here and we're going
  41307. 26:11:50to go back to our runs or sorry, back to
  41308. 26:11:54our jobs. And I want to show you one
  41309. 26:11:56more thing within here that might be
  41310. 26:11:58really useful. Now, we just kind came
  41311. 26:12:00down here and we pulled in uh this ETL
  41312. 26:12:02pipeline, but let's actually pull in and
  41313. 26:12:04run a notebook. So, we're going to
  41314. 26:12:06specify our notebook. We're just going
  41315. 26:12:08to do this is our bronze to silver and
  41316. 26:12:10this is a notebook. It's within our
  41317. 26:12:12workspace, not a git provider. And let's
  41318. 26:12:14select our notebook. So, we're going to
  41319. 26:12:16come in here. We're going to do bronze
  41320. 26:12:17to silver. Let's confirm this. And
  41321. 26:12:20you'll notice we have a lot of different
  41322. 26:12:22options in here. Some similar, right? We
  41323. 26:12:24have retries, we have notifications, and
  41324. 26:12:26we have metric thresholds, but we also
  41325. 26:12:28have parameters. These are parameters
  41326. 26:12:29that you can pass down to the task.
  41327. 26:12:31Because this is just a notebook, it
  41328. 26:12:33doesn't have all that built-in stuff
  41329. 26:12:35that we were talking about in the last
  41330. 26:12:36lesson within the ETL pipeline. So you
  41331. 26:12:38do need to configure this a little bit
  41332. 26:12:40more within a job. So we can add these
  41333. 26:12:43parameters where we create these kind of
  41334. 26:12:45key value pairs that we pass into uh a
  41335. 26:12:47notebook. But let's come in here. Let's
  41336. 26:12:50create this task. And now we're going to
  41337. 26:12:52add in another task. So let's come here.
  41338. 26:12:54We're going to add in another notebook.
  41339. 26:12:56And this is going to be
  41340. 26:12:59our silver to gold. Now, these two
  41341. 26:13:03tasks, and let's actually name this
  41342. 26:13:06these two tasks that we've created,
  41343. 26:13:07these two notebooks do the exact same
  41344. 26:13:09thing as our pipeline. But I wanted to
  41345. 26:13:12show you this because it does give us
  41346. 26:13:14some more information when we're
  41347. 26:13:15actually building out these jobs. So,
  41348. 26:13:17we've specified our path. We have our
  41349. 26:13:19computer serverless, but now we have
  41350. 26:13:20something called a dependency or a
  41351. 26:13:22dependency chain. This right here, this
  41352. 26:13:25line is a dependency with what we have
  41353. 26:13:28right now. This silver to gold is
  41354. 26:13:30completely dependent on this bronze to
  41355. 26:13:32silver. Which means if we get this data
  41356. 26:13:35in and this bronze to silver does not
  41357. 26:13:37run correctly, then this silver to gold
  41358. 26:13:40is never going to run. And in this use
  41359. 26:13:42case, that's perfectly fine because this
  41360. 26:13:45relies heavily on this bronze to silver.
  41361. 26:13:47But there are going to be use cases
  41362. 26:13:49where that is not the case where we
  41363. 26:13:51would not want that to be, you know, a
  41364. 26:13:53dependency. We wouldn't have to rely on
  41365. 26:13:55it. Or we also have an option right down
  41366. 26:13:57here to run if dependencies. And we have
  41367. 26:14:00a lot of different options. So right
  41368. 26:14:02now, all succeeded means this has to run
  41369. 26:14:05properly in order for this to run. But
  41370. 26:14:08there are going to be cases when you
  41371. 26:14:10create these chains or these dependency
  41372. 26:14:12chains where you're like, it doesn't
  41373. 26:14:14matter if this one runs. We just want it
  41374. 26:14:16to run after this one runs, whether it
  41375. 26:14:18fails or not. And so for that one, you
  41376. 26:14:20can come in here and say at least one
  41377. 26:14:22succeeded, none failed, all are done, at
  41378. 26:14:25least one failed, or all failed. It
  41379. 26:14:28doesn't matter. You can specify
  41380. 26:14:30whichever option you need. For us, we
  41381. 26:14:32would want to keep this all succeeded
  41382. 26:14:34because if this one runs, we don't
  41383. 26:14:36actually create the silver tables that
  41384. 26:14:39are needed in order to run this one. So
  41385. 26:14:41that is pretty important. We can come
  41386. 26:14:42down here and we can create this task.
  41387. 26:14:45And now we have this job that we've
  41388. 26:14:48created and we can run it now or of
  41389. 26:14:50course we could add in our trigger. Now
  41390. 26:14:53typically with something like this it
  41391. 26:14:55could go either way. You could have it
  41392. 26:14:56on file arrival table update or a
  41393. 26:14:58schedule. It really is just very
  41394. 26:15:00dependent on your workflow and how you
  41395. 26:15:02want this to trigger. For most of these
  41396. 26:15:04you're going to have some type of
  41397. 26:15:05trigger. Let's just set it on a
  41398. 26:15:07schedule. And let's go to advanced. And
  41399. 26:15:09we're going to set this for every week.
  41400. 26:15:12And let's do this on a Monday. and let's
  41401. 26:15:14do it at 7:45 because that's when I used
  41402. 26:15:16to do our some ones at uh a previous
  41403. 26:15:19job. So, I'm going to do at 7:45 every
  41404. 26:15:21morning. Let's go ahead and schedule
  41405. 26:15:23this. And now we've updated this job.
  41406. 26:15:25And now we can also rename this. I'm
  41407. 26:15:28going to call this our silver to gold
  41408. 26:15:32job. So now if we go back to our jobs
  41409. 26:15:34and pipelines, we have our silver to
  41410. 26:15:37gold job right here. This was the
  41411. 26:15:40pipeline that we built out in the last
  41412. 26:15:42lesson. And this is going to be
  41413. 26:15:44orchestrated and scheduled to run this
  41414. 26:15:46pipeline. Well, actually we used uh the
  41415. 26:15:48notebooks instead of the pipeline for
  41416. 26:15:50that last example, but we're going to be
  41417. 26:15:51running that code to actually create and
  41418. 26:15:53update those tables. So that is how we
  41419. 26:15:55create a job in data bricks. This is
  41420. 26:15:58extremely extremely useful. Again, like
  41421. 26:16:00we did just a little bit ago for our
  41422. 26:16:02silver to gold job. And let's go into
  41423. 26:16:05the tasks. If it's a really small
  41424. 26:16:07transformation and maybe it's just for
  41425. 26:16:09me, I'll just do it like this where I
  41426. 26:16:11just have the notebooks. But if it's a
  41427. 26:16:13larger transformation, especially if
  41428. 26:16:15there's a lot of dependencies, if
  41429. 26:16:16there's a lot of complexity, I will use
  41430. 26:16:18an ETL pipeline. So get in here, mess
  41431. 26:16:21around with this, try this out because
  41432. 26:16:23this is super fun to play around with
  41433. 26:16:24and kind of get all those dependency
  41434. 26:16:26chains going and getting the ETL
  41435. 26:16:28pipelines where they're triggering off
  41436. 26:16:29of each other or when a file is updated.
  41437. 26:16:31This is really cool stuff to mess around
  41438. 26:16:33with and is awesome to use within data
  41439. 26:16:35bricks. Now, if you haven't been
  41440. 26:16:36following along in the past three videos
  41441. 26:16:38in this series, we've covered several
  41442. 26:16:40things. One, we've just learned about
  41443. 26:16:42ingesting data. Then after that, we
  41444. 26:16:44looked at ETL pipelines and then we
  41445. 26:16:46looked at creating a job to orchestrate
  41446. 26:16:48all these things and to kind of automate
  41447. 26:16:50the process. In this video, we're going
  41448. 26:16:52to be putting all of that together into
  41449. 26:16:54one. We're going to add some things that
  41450. 26:16:55we didn't cover in previous lessons to
  41451. 26:16:57make it a little bit more advanced, but
  41452. 26:16:59it's going to cover a lot of the same
  41453. 26:17:01concepts. Let's not waste any time.
  41454. 26:17:03Let's jump right onto my screen and get
  41455. 26:17:04started. Now, before we actually jump
  41456. 26:17:06into data bricks, what we're going to be
  41457. 26:17:07working with is that same S3 bucket that
  41458. 26:17:10we created earlier, but I created this
  41459. 26:17:14transactions folder, and that is going
  41460. 26:17:16to be an important piece of this
  41461. 26:17:17process. It's something that we touched
  41462. 26:17:19on in a previous video, but we actually
  41463. 26:17:22going to be doing it in this lesson. So,
  41464. 26:17:24we use this users_y.csv
  41465. 26:17:26CSV in this bucket. But inside of this
  41466. 26:17:29transactions, we have three separate
  41467. 26:17:30transaction files. And we'll actually be
  41468. 26:17:33adding another one later on to show how
  41469. 26:17:35the entire process works. So, I'm going
  41470. 26:17:38to have these and the other file down in
  41471. 26:17:41the description. You can just download
  41472. 26:17:42those from GitHub, but we will need
  41473. 26:17:45those. So, we're just going to start off
  41474. 26:17:46with these three, the 16, 1_13, and
  41475. 26:17:501_20. Now, really quick, just to show
  41476. 26:17:53you what data we're working with, this
  41477. 26:17:55is our data. Let me actually zoom in
  41478. 26:17:57just a little bit. Uh, the data itself
  41479. 26:18:01is not as important for this specific
  41480. 26:18:03project just because we're more focused
  41481. 26:18:05on the process of building the pipeline
  41482. 26:18:07within data bricks, but within the
  41483. 26:18:10project, we will be cleaning this data a
  41484. 26:18:12little bit because this is just a
  41485. 26:18:14horrible column. Uh I think whoever you
  41486. 26:18:16know was collecting this data just left
  41487. 26:18:18this free text or something for people
  41488. 26:18:20to just put whatever they wanted in
  41489. 26:18:21there. Uh not a good not a good system
  41490. 26:18:25but that is the kind of data that we're
  41491. 26:18:27going to be working with. So let's come
  41492. 26:18:28up here. Let's get out of this. We don't
  41493. 26:18:31need to save it. Now let's come up to
  41494. 26:18:34our data bricks. Now in our previous
  41495. 26:18:36lesson this is what we built. We built
  41496. 26:18:38this uh pipeline right here. Bronze to
  41497. 26:18:40silver to gold ETL pipeline. And then in
  41498. 26:18:43the very last lesson, we created the
  41499. 26:18:45silver to gold job which basically
  41500. 26:18:47scheduled this and automated this and it
  41501. 26:18:50ran successfully and everything was
  41502. 26:18:51great. Now what we're going to be doing
  41503. 26:18:53is we're going to be doing it in a
  41504. 26:18:55similar fashion but covering some new
  41505. 26:18:57things. All you need to do and I
  41506. 26:18:59actually have another tab for this cuz I
  41507. 26:19:01don't want to have to keep going back
  41508. 26:19:02and forth when we're building this out.
  41509. 26:19:04But I created this end toend schema
  41510. 26:19:06within our data engineering catalog. You
  41511. 26:19:09don't have to do this. You can put this
  41512. 26:19:11wherever you want. I just did. This is
  41513. 26:19:13kind of where we'll be building things
  41514. 26:19:15out. So, I'll just come back to this as
  41515. 26:19:17we start adding in new tables, as we
  41516. 26:19:18start creating this stuff. I'm going to
  41517. 26:19:21come back to that. Now, this is where
  41518. 26:19:23we'll be doing a lot of our work on this
  41519. 26:19:25uh tab right here. So, let's come over
  41520. 26:19:28to data ingestion. Let's go over to our
  41521. 26:19:30Amazon S3. Now, if you haven't already,
  41522. 26:19:34in a previous lesson, I think the second
  41523. 26:19:36video, we connected to an S3 bucket. So,
  41524. 26:19:39if you don't know how to do that, then
  41525. 26:19:41come over here and do this. Now, we used
  41526. 26:19:43it for the one time because all we used
  41527. 26:19:45was this users dirty.csv.
  41528. 26:19:48But in order to schedule this data
  41529. 26:19:51ingestion, we're going to use a folder.
  41530. 26:19:53So, we have this transactions folder
  41531. 26:19:55right here. So, we're going to click on
  41532. 26:19:57this. We're going to click on
  41533. 26:19:58transactions and we have those three
  41534. 26:20:00separate files in there. And we can
  41535. 26:20:03schedule when we want to bring those in.
  41536. 26:20:05Now, we can be very specific or pretty
  41537. 26:20:07laid-back. Uh, so for example, if we
  41538. 26:20:10want to do, you know, once a day, we can
  41539. 26:20:12specify what time of day we want that.
  41540. 26:20:14And that's similar to a job. So it's not
  41541. 26:20:16that crazy. Now, what we're going to be
  41542. 26:20:18actually doing is we're going to
  41543. 26:20:19schedule this for basically every 30
  41544. 26:20:21minutes. And what we're going to do is
  41545. 26:20:22we're going to build this entire thing
  41546. 26:20:23out. And what our trigger is going to be
  41547. 26:20:26inside of our job is when a table gets
  41548. 26:20:29updated. So then we're going to drop a
  41549. 26:20:31file in our S3 bucket. And when this
  41550. 26:20:33brings it in at that 30 minute point,
  41551. 26:20:35it's then going to refresh, kick off the
  41552. 26:20:37job, which runs our ETL pipeline. We
  41553. 26:20:39should be able to do all this within 30
  41554. 26:20:41minutes for sure. So, I'm going to say
  41555. 26:20:43every 30 minutes, and we'll just set it
  41556. 26:20:47at 0 minutes past the hour, which means
  41557. 26:20:50at basically the top of the hour. Now,
  41558. 26:20:53this is my time zone, but you can set it
  41559. 26:20:55to whatever time zone you want. Now,
  41560. 26:20:57let's go ahead and preview this table.
  41561. 26:20:59It's going to start up our compute. Then
  41562. 26:21:01it's going to give us uh basically what
  41563. 26:21:04we need in order to create this table,
  41564. 26:21:06which is our preview, and then where we
  41565. 26:21:08want to place it along with the table
  41566. 26:21:10name. Now, an important thing to note
  41567. 26:21:12from just those three files is there's
  41568. 26:21:14only 50 rows of data in each one. So, if
  41569. 26:21:17we come down here, we got all the way up
  41570. 26:21:19to 100. So, we at least know two of
  41571. 26:21:21those files are coming in just from this
  41572. 26:21:22preview. We're going to keep this as the
  41573. 26:21:25transactions, but for the schema, we're
  41574. 26:21:28going to add the end to end, which is
  41575. 26:21:30the custom one that we created for this
  41576. 26:21:32project. So, we have transactions right
  41577. 26:21:34here. Let's go ahead and create the
  41578. 26:21:36streaming table. So, now this table has
  41579. 26:21:38been created. Let's just look at a
  41580. 26:21:40sample of this data. It should show us
  41581. 26:21:43enough to be confident all three got in.
  41582. 26:21:45But then we can just also run a query
  41583. 26:21:47and that's perfectly fine. In fact,
  41584. 26:21:49instead of waiting, uh, never mind, we
  41585. 26:21:51got them all in. I was going to say we
  41586. 26:21:53don't have to wait on this. We could
  41587. 26:21:54just run a query in like a notebook or a
  41588. 26:21:57SQL editor, but we have all 150. So
  41589. 26:21:59that's all three files. So now that we
  41590. 26:22:01know we have all three of our files in
  41591. 26:22:04cuz it's 50 each. It's going to be 150
  41592. 26:22:06rows. Now that we know those are in, we
  41593. 26:22:08can start building things out. Now that
  41594. 26:22:10we know that it's all in there, what we
  41595. 26:22:13can do is let's come over here to our
  41596. 26:22:15jobs and pipelines. Now this is where we
  41597. 26:22:17were before. We only had these two
  41598. 26:22:20things. We had a pipeline and now we had
  41599. 26:22:22a job. And now we have another pipeline.
  41600. 26:22:24And we didn't build this ourselves. This
  41601. 26:22:27was built automatically. And if we come
  41602. 26:22:29in here, we can get a little bit of
  41603. 26:22:31information on this. This is our
  41604. 26:22:34streaming pipeline that we created to
  41605. 26:22:36put into this endto-end transaction. So
  41606. 26:22:39this is that streaming table that we
  41607. 26:22:42created. And so we don't have to
  41608. 26:22:43technically manage this. It's going to
  41609. 26:22:45be managed by data bricks itself. And so
  41610. 26:22:48this is just something to note that when
  41611. 26:22:49we did that, we did create its own
  41612. 26:22:52pipeline for this. Now what we need to
  41613. 26:22:55do is we need to create an ETL pipeline.
  41614. 26:22:58So let's come in here. We're going to
  41615. 26:22:59click on the ETL pipeline. This new UI
  41616. 26:23:02pops up right away. We don't have the
  41617. 26:23:04options that we had before in previous
  41618. 26:23:05lessons. Um but now what we're going to
  41619. 26:23:08do is we're going to start building this
  41620. 26:23:09out with Genie code. Now, I could
  41621. 26:23:13absolutely just write all this out and
  41622. 26:23:14this would be like an hour and a half
  41623. 26:23:15video, or we can have Genie Code write
  41624. 26:23:18it out, which I highly recommend trying
  41625. 26:23:20it out and starting to use these tools
  41626. 26:23:22because they really speed up your work.
  41627. 26:23:24And if you already know how to program,
  41628. 26:23:25if you know how to code, this is going
  41629. 26:23:27to be a huge boost to your productivity.
  41630. 26:23:30And so, what we're now going to do is
  41631. 26:23:32use Genie Code right down here.
  41632. 26:23:33Basically, tell it what we want to
  41633. 26:23:35build. And we're going to do a few
  41634. 26:23:37things. One, we want to build that
  41635. 26:23:39bronze to silver, which is basically our
  41636. 26:23:41raw data, which is that transactions
  41637. 26:23:44table, to a silver table, which is where
  41638. 26:23:46the data is cleaned, to then a gold
  41639. 26:23:48table, which is what we would use for
  41640. 26:23:50like a production level uh product or
  41641. 26:23:53production level analysis or whatever
  41642. 26:23:54that might be. So, we can come in here
  41643. 26:23:57and we can use that at and it is
  41644. 26:23:59prompting us to do that. And if we come
  41645. 26:24:01in and we can say data engineering.end
  41646. 26:24:06end to end. And I'll just put it like
  41647. 26:24:09that. So, it's looking kind of at that
  41648. 26:24:11schema. I'm just going to say uh for the
  41649. 26:24:14transactions
  41650. 26:24:16table, I want to create a bronze to
  41651. 26:24:21silver
  41652. 26:24:22transformation on this raw data.
  41653. 26:24:26I want you to clean this data set. I'm
  41654. 26:24:30just going to leave it really open-ended
  41655. 26:24:32just to see what it does. Maybe it
  41656. 26:24:34catches something outside of that
  41657. 26:24:35column. I don't think it will, but uh
  41658. 26:24:38let's just see what it does. Then we are
  41659. 26:24:41going to create a silver to gold
  41660. 26:24:45transformation.
  41661. 26:24:47And you can do this in the same notebook
  41662. 26:24:49or separate notebooks. It may also do
  41663. 26:24:52that for you with Genie Code, but you
  41664. 26:24:54can be really specific and it's honestly
  41665. 26:24:56pretty great at what it does. And I want
  41666. 26:24:58to track daily transactions
  41667. 26:25:03in that gold table. So I'm going to give
  41668. 26:25:06it just this to work on. It's going to
  41669. 26:25:08take that. It's going to kind of create
  41670. 26:25:10its logic. It's going to start writing
  41671. 26:25:11everything out. Um I have found this is
  41672. 26:25:14not just me saying this. I genuinely
  41673. 26:25:16love working in this system because
  41674. 26:25:18Genieode is very good at understanding
  41675. 26:25:20context and what you're trying to do and
  41676. 26:25:22working with tables and just everything.
  41677. 26:25:25And so we're going to let this run for
  41678. 26:25:27just a little bit. I'm going to come
  41679. 26:25:28back. We'll take a look at what it said
  41680. 26:25:30and then we'll commit some code to start
  41681. 26:25:32going on the CTL pipeline. All right, so
  41682. 26:25:34it just finished. I haven't even really
  41683. 26:25:36reviewed this cuz it only took, you
  41684. 26:25:38know, 30 seconds, but it took a look at
  41685. 26:25:40the data. Then it came down here and
  41686. 26:25:42gave a proposed pipeline architecture.
  41687. 26:25:45So here's what we have. We have our
  41688. 26:25:47bronze layer, which is just going to be
  41689. 26:25:49our transactions. py. And this is just
  41690. 26:25:52going to read in the data as is. So,
  41691. 26:25:54it's going to recreate basically the raw
  41692. 26:25:56data, which I'm totally fine with. It's
  41693. 26:25:58not a big deal. Then for our silver
  41694. 26:26:00layer, we have the silver
  41695. 26:26:01transactions_clean. It's going to trim
  41696. 26:26:04the white space, standardize
  41697. 26:26:05capitalization, remove duplicate spaces,
  41698. 26:26:07filter out null transaction IDs or
  41699. 26:26:09negative quantities and amounts, and add
  41700. 26:26:12data quality expectations. I think these
  41701. 26:26:15are all perfectly reasonable things to
  41702. 26:26:17do. Then, we have our gold layer.
  41703. 26:26:19There's going to be transformations gold
  41704. 26:26:21daily transactions summary.py. py. So
  41705. 26:26:24there's three different files that it's
  41706. 26:26:25going to create and it's going to
  41707. 26:26:27aggregate some of this data into kind of
  41708. 26:26:29these metrics right here. I think this
  41709. 26:26:31all looks great. If there was something
  41710. 26:26:33I wanted to change, I would just tell
  41711. 26:26:34it, hey, let's do this instead. So let's
  41712. 26:26:36just say go for it. Start writing the
  41713. 26:26:39code,
  41714. 26:26:42my friend. It really is my friend at
  41715. 26:26:44this point. I've been using it a lot. So
  41716. 26:26:46let's let this run. Let's watch the code
  41717. 26:26:48and then we will commit everything. And
  41718. 26:26:50then it probably will prompt us to do
  41719. 26:26:52some type of dry run to make sure that
  41720. 26:26:54there aren't any errors that were just
  41721. 26:26:56missing. And then we will run the entire
  41722. 26:26:58thing and start automating this with a
  41723. 26:27:00job as well. It's still writing. That
  41724. 26:27:03was like 10 seconds. I stopped talking,
  41725. 26:27:04but it's still writing everything. It's
  41726. 26:27:06going to start organizing this. It's
  41727. 26:27:08going to start creating our py files or
  41728. 26:27:10just our Python files. I just am reading
  41729. 26:27:13it as is. uh but it's creating our
  41730. 26:27:15Python files and then it's going to
  41731. 26:27:17start writing the code in which we are
  41732. 26:27:19then going to review approve and then
  41733. 26:27:21run. You can see these things starting
  41734. 26:27:23to pop up. So we have our code, we have
  41735. 26:27:25our diff or you know if we had code that
  41736. 26:27:28it took out it would also say the minus.
  41737. 26:27:30Uh but we're just creating code right
  41738. 26:27:32now. And so right here it's saying all
  41739. 26:27:36right do we want to try dry running this
  41740. 26:27:38pipeline? Do we want to just see if it
  41741. 26:27:40works? Um, and of course we're going to
  41742. 26:27:43do that in a second, but I'm going to go
  41743. 26:27:44to each one just to kind of see what
  41744. 26:27:46it's doing. It looks like this is our
  41745. 26:27:48gold, and we're just using a group by
  41746. 26:27:51for this. Uh, let's just see what it did
  41747. 26:27:54for the data cleaning. So, it looks like
  41748. 26:27:56it is going to drop some stuff in here,
  41749. 26:27:59but we are looking at some regax
  41750. 26:28:01replace, which is great. Some trimming
  41751. 26:28:03and proper case uh for a few other
  41752. 26:28:05stuff. And this looks perfectly uh good
  41753. 26:28:08to me. I have no problem with what it's
  41754. 26:28:10doing. Again, this is all subject to be
  41755. 26:28:13altered. If you want to change this or
  41756. 26:28:15have it do other things or fix the code
  41757. 26:28:17yourself, you absolutely can do that.
  41758. 26:28:18Now, all we're going to do is we're just
  41759. 26:28:20going to accept this. And so, we're
  41760. 26:28:22going to allow this and it's going to
  41761. 26:28:24run a dry. So, we'll accept review next.
  41762. 26:28:27We'll accept review next. And accept. I
  41763. 26:28:29didn't have I could have done that a
  41764. 26:28:30different way, but now we're going to
  41765. 26:28:31try dry running this pipeline. Now, what
  41766. 26:28:34this does is it is not going to actually
  41767. 26:28:37run through and run your code. It's
  41768. 26:28:38doing a dry run. It's basically testing
  41769. 26:28:40are there any big errors that we need to
  41770. 26:28:42fix before you actually implement this
  41771. 26:28:44into you know whatever process you're
  41772. 26:28:46doing so that you don't have issues
  41773. 26:28:48right off the bat. It's going to run for
  41774. 26:28:50just a little bit and then it'll tell us
  41775. 26:28:52if there's any big issues. Um oftent
  41776. 26:28:54times if you've never done this before
  41777. 26:28:56you shouldn't have any big issues but
  41778. 26:28:58you could get issues like oh this table
  41779. 26:29:01uh you don't have the permissions for
  41780. 26:29:02this table. Maybe you wrote something
  41781. 26:29:04incorrectly or in this case uh you know
  41782. 26:29:06Genie code wrote something incorrectly
  41783. 26:29:08that is not going to create the
  41784. 26:29:09materialized view properly or you're
  41785. 26:29:11pulling from a table that doesn't exist
  41786. 26:29:13anymore. So there's lots of issues that
  41787. 26:29:15could arise but let's let this run. It
  41788. 26:29:17shouldn't take very long and just like
  41789. 26:29:19that we did encounter a small issue. Um
  41790. 26:29:22it's actually going to run. It'll
  41791. 26:29:24probably fix this very easily. Um, I am
  41792. 26:29:27not exactly sure what the issue is here.
  41793. 26:29:30Just glancing at it, but it looks like
  41794. 26:29:31it's fixing that code for all of it. And
  41795. 26:29:35let's go ahead and just accept that. And
  41796. 26:29:37let's try dry running this one more
  41797. 26:29:39time. Now it looks like everything is
  41798. 26:29:42running properly. And this is really
  41799. 26:29:44good. So what we can now do is we can
  41800. 26:29:48rename this. So it's going to give us
  41801. 26:29:50some feedback on that. But I'm going to
  41802. 26:29:51rename this. And I'm going to say this
  41803. 26:29:54is our end toend
  41804. 26:29:56uh ETL pipeline.
  41805. 26:30:00And that's what we're going to name it.
  41806. 26:30:02So we have our endto-end ETL pipeline.
  41807. 26:30:05And with this, if we come back here,
  41808. 26:30:08obviously nothing has changed, right?
  41809. 26:30:10This was just a dry run that we did. Now
  41810. 26:30:14what we can do is we can actually run
  41811. 26:30:16this pipeline and it will run
  41812. 26:30:18everything. It's going to do all the
  41813. 26:30:20transformations, all the things that we
  41814. 26:30:22would want it to do and we should and we
  41815. 26:30:24will do that in a little bit. Now, what
  41816. 26:30:26we want to do is we want to automate
  41817. 26:30:28this process. All we have to do is we're
  41818. 26:30:31going to come back here to not data
  41819. 26:30:33ingestion into runs and let's get rid of
  41820. 26:30:36this. Now, we're going to create a job
  41821. 26:30:39for this. So, we're going to come in
  41822. 26:30:41here and we're going to say we want our
  41823. 26:30:43pipeline. And if we come in here, we
  41824. 26:30:45have our endto-end ETL pipeline. That's
  41825. 26:30:47the one we want. We're just going to
  41826. 26:30:49call this um end to end ETL pipeline.
  41827. 26:30:53Keep it simple. Now, what we're going to
  41828. 26:30:54do, and you can always come in here and
  41829. 26:30:56add notifications and retries and metric
  41830. 26:30:58thresholds, which we covered in the last
  41831. 26:31:00lesson. Now, we're going to create this
  41832. 26:31:02task, but now we're going to add this
  41833. 26:31:04trigger right here. Now, this trigger is
  41834. 26:31:06going to be a table update. So what we
  41835. 26:31:09want it to do is when new data is
  41836. 26:31:12actually updated and brought into that
  41837. 26:31:14table, we want this job to kick off so
  41838. 26:31:16that it runs our entire ETL process to
  41839. 26:31:19clean the data and put that new data
  41840. 26:31:21into our, you know, new tables that
  41841. 26:31:23we're creating. Now what we want to do
  41842. 26:31:26is we want to say this table when this
  41843. 26:31:28table gets updated. So let's come up
  41844. 26:31:30here and we're just going to copy this
  41845. 26:31:32name to the clipboard and we're going to
  41846. 26:31:34put it right down in here. We could also
  41847. 26:31:35have typed it out. Um, either one's
  41848. 26:31:37fine, but I just wanted to copy it. So,
  41849. 26:31:39when this table gets updated by our S3
  41850. 26:31:43process, which we're running every 30
  41851. 26:31:44minutes, this is going to kick off the
  41852. 26:31:47ETL pipeline, right? It's going to kick
  41853. 26:31:49off
  41854. 26:31:51this right here. So, now that we have
  41855. 26:31:54that job updated and created, let's go
  41856. 26:31:57back to our jobs and pipelines. And now
  41857. 26:31:59we have a few new things in here. So,
  41858. 26:32:01right here we have our endtoend ETL
  41859. 26:32:03pipeline. I should have named this job.
  41860. 26:32:06Let's actually come in here really
  41861. 26:32:07quick. I'm just going to come up here.
  41862. 26:32:09I'm going to rename this. I'm going to
  41863. 26:32:10say job to run N2 to end pipeline. And
  41864. 26:32:16let's rename this. So, we have our
  41865. 26:32:19pipeline. We have our job to run the ETL
  41866. 26:32:21pipeline. And we have our transactions.
  41867. 26:32:24That's going to run 30 minutes uh on the
  41868. 26:32:26minute. It looks like um it may have
  41869. 26:32:29already run before. No, I think we're
  41870. 26:32:32good. No, it did. It's already run
  41871. 26:32:34twice. I think that's just because of
  41872. 26:32:36when I set it to the zero time perfectly
  41873. 26:32:38fine. Um, but what we're going to do now
  41874. 26:32:41is we are going to just check that this
  41875. 26:32:45end to end ETL pipeline is working
  41876. 26:32:47properly. It's going to create all of
  41877. 26:32:49our tables. We're going to then write a
  41878. 26:32:51query just to show that the data looks
  41879. 26:32:53good. And then we'll go drop our extra
  41880. 26:32:56file in there. And then we'll wait to
  41881. 26:32:58have it update and the ETL pipeline
  41882. 26:33:00bring in the data. Then our job is going
  41883. 26:33:02to trigger. And then it'll run our ETL
  41884. 26:33:05pipeline to bring in and clean that new
  41885. 26:33:06data as well. So let us run this
  41886. 26:33:09pipeline.
  41887. 26:33:11This is going to take just a little bit
  41888. 26:33:13to actually run and then we'll go check
  41889. 26:33:16the data in just a little bit. All
  41890. 26:33:18right. So this looks like it worked
  41891. 26:33:20properly. We have completed completed
  41892. 26:33:22and completed. Let us come up here and
  41893. 26:33:26let's go back and let's refresh this.
  41894. 26:33:30And it is possible that I put it in the
  41895. 26:33:34wrong place and it totally is. I
  41896. 26:33:37absolutely forgot to change that in the
  41897. 26:33:38ETL pipeline. It is pointed at the
  41898. 26:33:41workspace default. Let's actually go
  41899. 26:33:43back and you know this happens. We're
  41900. 26:33:47going to edit this pipeline. So it is
  41901. 26:33:48our default catalog that caused this
  41902. 26:33:51issue. We have our default catalog and
  41903. 26:33:53default schema as workspace and then
  41904. 26:33:56default. Um you can change this. You
  41905. 26:33:59don't have to, but you absolutely can.
  41906. 26:34:00You also, if I'm being honest, I should
  41907. 26:34:02have fixed this myself or caught uh this
  41908. 26:34:04right away. I like to be explicit when
  41909. 26:34:07I'm, you know, writing to places. I
  41910. 26:34:10don't like to have defaults like this.
  41911. 26:34:11So, I should have had it specified right
  41912. 26:34:13here where we're writing. It should have
  41913. 26:34:15been like, uh, you know, data
  41914. 26:34:16engineering.end to end dot and then the,
  41915. 26:34:20uh, table name just to be more explicit.
  41916. 26:34:22And we should have done this in
  41917. 26:34:23basically all the Python files within
  41918. 26:34:25the ETL pipeline. Totally fine though.
  41919. 26:34:28Not a massive deal, just you know,
  41920. 26:34:30something to think about. Now, if we
  41921. 26:34:33come back to this catalog and we look at
  41922. 26:34:36this, we can go to let's go to the
  41923. 26:34:39silver transactions clean. This is going
  41924. 26:34:42to be our cleaned data. Let's just go
  41925. 26:34:44ahead and run this real quick so we can
  41926. 26:34:46look at that sample data. So now this is
  41927. 26:34:48our clean data. This product name looks
  41928. 26:34:52much better. Uh looks really good. It
  41929. 26:34:55did a few other really small things in
  41930. 26:34:57here, but this is the main one that
  41931. 26:34:58we're looking at. If we go back to the
  41932. 26:35:00bronze transactions, uh, and look at our
  41933. 26:35:03sample data. So, this is our bronze
  41934. 26:35:05table.
  41935. 26:35:07This looks terrible. So, obviously, it
  41936. 26:35:09did a really good job data cleaning it.
  41937. 26:35:11Uh, and then we'll look at the gold
  41938. 26:35:13daily transactions summary.
  41939. 26:35:18And this is looking at the transactions
  41940. 26:35:20just grouping by and then looking at a
  41941. 26:35:22lot of our data. And this is great for
  41942. 26:35:24like a gold table uh that we're going to
  41943. 26:35:26be using for you know some metrics or
  41944. 26:35:29whatever we want to use it for. So all
  41945. 26:35:31of this looks really good. Now in our
  41946. 26:35:33silver transactions clean in our sample
  41947. 26:35:36data again we at least in the sample we
  41948. 26:35:40only have 100. Let's go and run this. So
  41949. 26:35:43let's actually create a notebook with
  41950. 26:35:45this and let's run this query. So now we
  41951. 26:35:48can see we have 150 rows and let's add
  41952. 26:35:52code
  41953. 26:35:54and let's copy this and instead of the
  41954. 26:35:57transactions clean we'll say
  41955. 26:36:00uh let's go see what that table's
  41956. 26:36:02called. It's not gold customers.
  41957. 26:36:05I should have kept it up over here.
  41958. 26:36:07Let's go back to our catalog. See when I
  41959. 26:36:09start when I start messing with my
  41960. 26:36:10systems I start getting messed up. It's
  41961. 26:36:13gold daily transaction summary. I could
  41962. 26:36:15have gotten copied it somewhere else.
  41963. 26:36:17Uh, but I'm going to put it right here
  41964. 26:36:19so that we can look at this. And what
  41965. 26:36:21we're going to do now is we're going to
  41966. 26:36:23go drop in that other file into the S3
  41967. 26:36:26bucket so that we can see when it gets
  41968. 26:36:29updated and to make sure that the new
  41969. 26:36:31data gets in there and gets cleaned. So,
  41970. 26:36:34let's come over here. We're going to
  41971. 26:36:36upload and let's click on add files.
  41972. 26:36:39Now, we're going to come here. We have
  41973. 26:36:41that 127. That's the new one that we
  41974. 26:36:43didn't have before. Let's upload this
  41975. 26:36:45and put this into our S3 bucket. And now
  41976. 26:36:48we have 06, 13, 20, and 27 all in this
  41977. 26:36:52S3 bucket. So now what we're going to do
  41978. 26:36:55is we're just going to I'm going to
  41979. 26:36:57literally just let this wait. Let's come
  41980. 26:36:59over here and right here, this is going
  41981. 26:37:03to kick off in probably like five
  41982. 26:37:05minutes or so. I'm just going to let it
  41983. 26:37:06run. This is going to kick off and then
  41984. 26:37:09you will see that this job to run the
  41985. 26:37:12end time pipeline will automatically
  41986. 26:37:14kick off as well once that table is
  41987. 26:37:17updated. So let's just be patient. Let's
  41988. 26:37:19just wait. I'm going to skip you ahead
  41989. 26:37:21and you will see this running in just a
  41990. 26:37:23little bit. All right. Now you can see
  41991. 26:37:25that this is kicked off. Looks like it
  41992. 26:37:28is running. When this process is
  41993. 26:37:30finished, it is going to update that
  41994. 26:37:32table with the new data which is going
  41995. 26:37:34to trigger this job right here based on
  41996. 26:37:36this table update on data
  41997. 26:37:38engineering.toend.transactions.
  41998. 26:37:42And that should start any second here.
  41999. 26:37:44And it looks like that is working. We
  42000. 26:37:46can see this one running. And since it
  42001. 26:37:48is literally running this pipeline, we
  42002. 26:37:50can also see that this one is going to
  42003. 26:37:51start running as well. It's just
  42004. 26:37:53spinning up the compute so that it can
  42005. 26:37:55run properly. Let's go ahead and let
  42006. 26:37:57this run and then we're going to see and
  42007. 26:37:59check in our queries if everything
  42008. 26:38:02actually went through properly. All
  42009. 26:38:03right, it looks like this uh job is
  42010. 26:38:06still spinning, but the pipeline was
  42011. 26:38:08kicked off successfully. It looks like
  42012. 26:38:10it ran with no issues, which is exactly
  42013. 26:38:13what we want. And now this job is done.
  42014. 26:38:15So now our entire process is complete.
  42015. 26:38:18And it is going to keep doing that every
  42016. 26:38:2130 minutes. uh every single 30 minutes
  42017. 26:38:24from now until I stop the job or I stop
  42018. 26:38:27this pipeline from running, it is going
  42019. 26:38:29to kick this off. It's going to kick off
  42020. 26:38:31the job. It's going to kick off the
  42021. 26:38:33pipeline every 30 minutes. Of course,
  42022. 26:38:35I'm going to stop that cuz that's nuts
  42023. 26:38:36to keep running. But let's come back.
  42024. 26:38:39Let's go to our workspace. And I think
  42025. 26:38:41it's this one. Let's go take a look.
  42026. 26:38:44Yeah. So, now we have 150 rows. Let's go
  42027. 26:38:46ahead and run this. We should see 200
  42028. 26:38:48rows of data.
  42029. 26:38:51And there we go. And let's just make
  42030. 26:38:53sure it's all cleaned properly in that
  42031. 26:38:56product uh name. Looks great. And let's
  42032. 26:39:00come down here and let's just make sure
  42033. 26:39:01that this gets updated. We have 21 rows,
  42034. 26:39:03but more than that, it's about the data
  42035. 26:39:05because this is aggregated. So, um let's
  42036. 26:39:08go ahead and run this as well. And we
  42037. 26:39:10have 28 rows. That's just another week's
  42038. 26:39:12worth of data. And these numbers are
  42039. 26:39:15actually look uh basically the same, but
  42040. 26:39:17we have this new uh week's worth of data
  42041. 26:39:20in here that we didn't have before. So
  42042. 26:39:22that is the entire NTN project. It
  42043. 26:39:24really brings everything together that
  42044. 26:39:26we've been working with in the past
  42045. 26:39:28several lessons into one final project.
  42046. 26:39:30And I hope you were able to follow
  42047. 26:39:32along. If you didn't follow along, you
  42048. 26:39:34just watch this video to the end. I
  42049. 26:39:36highly recommend using the free edition.
  42050. 26:39:38I will have a link in the description.
  42051. 26:39:40You can try all this out completely for
  42052. 26:39:42free. You don't even have to enter a
  42053. 26:39:43debit card or credit card, which I love.
  42054. 26:39:45So, you can just use this and it is an
  42055. 26:39:47amazing platform to try out. I highly
  42056. 26:39:50recommend it. But with that being said,
  42057. 26:39:52thank you guys so much for watching. I
  42058. 26:39:54hope you like this video. I hope you
  42059. 26:39:55learned something in this entire series.
  42060. 26:39:57If you did, be sure to like and
  42061. 26:39:59subscribe. I'll see you in the next
  42062. 26:40:01lesson.
  42063. 26:40:03[music]
  42064. 26:40:09>> [music]
  42065. 26:40:14>> What's going on everybody? Welcome back
  42066. 26:40:15to another video. Today we're going to
  42067. 26:40:17be setting up and installing R and R
  42068. 26:40:19Studio.
  42069. 26:40:23[music]
  42070. 26:40:25Now, this is our very first lesson in
  42071. 26:40:27this series, so we're just going to be
  42072. 26:40:28installing and getting R and R Studio
  42073. 26:40:30set up. In future lessons, we're going
  42074. 26:40:32to be diving into the basics of R. We'll
  42075. 26:40:33be grouping, aggregating, visualizing,
  42076. 26:40:35cleaning, and a ton of other things
  42077. 26:40:37using a lot of different packages that
  42078. 26:40:39are very popular within R. By the end of
  42079. 26:40:41this series, you should feel very
  42080. 26:40:42comfortable using R and R Studio. If you
  42081. 26:40:44haven't checked it out already, I have a
  42082. 26:40:46full course called R for data analysis
  42083. 26:40:48over on analystbuilder.com. I will leave
  42084. 26:40:50a link in the description as well as a
  42085. 26:40:51coupon code if you want to take that
  42086. 26:40:53full course. It covers more topics, has
  42087. 26:40:54practice problems throughout the course,
  42088. 26:40:56as well as goes more in depth, and has
  42089. 26:40:57more difficult projects. With all that
  42090. 26:40:59being said, I'm super excited to get
  42091. 26:41:01started on this series with you. Let's
  42092. 26:41:02jump on my screen and get started. All
  42093. 26:41:04right. So, let's get started in
  42094. 26:41:05downloading R Studio. Now, R Studio is
  42095. 26:41:09created by a company called Posit. Now,
  42096. 26:41:11R is the programming language, but R
  42097. 26:41:15Studio is the interface in which so many
  42098. 26:41:17people interact with R. And so, we're
  42099. 26:41:20going to be using R Studio throughout
  42100. 26:41:21this entire series. What we need to do
  42101. 26:41:23is first install R. And then next, we
  42102. 26:41:26need to install R Studio. R is going to
  42103. 26:41:28be installed almost the exact same way
  42104. 26:41:30on every system. And then for installing
  42105. 26:41:32R Studio, it's going to autopop populate
  42106. 26:41:34this for Windows because it recognizes
  42107. 26:41:36Windows as my machine. But if it
  42108. 26:41:38doesn't, if it gets the wrong one, you
  42109. 26:41:40go down here for uh Linux, Mac, Windows,
  42110. 26:41:43whichever one that you want. So, let's
  42111. 26:41:45get started by installing R on our
  42112. 26:41:48machine. I went ahead and deleted R and
  42113. 26:41:50R Studio from my computer. So, I'm
  42114. 26:41:52starting fresh just like you. We're
  42115. 26:41:54going to come right here. I'm going to
  42116. 26:41:55do download R for Windows, but if you
  42117. 26:41:57have a different type of machine, be
  42118. 26:41:58sure to get the correct one. I'm going
  42119. 26:42:00to download R for Windows and then I'm
  42120. 26:42:02going to come up here and say install R
  42121. 26:42:04for the first time and then we're going
  42122. 26:42:05to get this package right here. So,
  42123. 26:42:07let's go ahead and click on this and I'm
  42124. 26:42:09going to go ahead and download it. Now
  42125. 26:42:11that it's done downloading, I'm going to
  42126. 26:42:12go ahead and open that.exe file. You may
  42127. 26:42:14not be able to see it, but it just says,
  42128. 26:42:16are you sure you want to download this?
  42129. 26:42:18And I'm going to say yes. Now, we need
  42130. 26:42:20to set up our language. I'm going to
  42131. 26:42:21choose English, but go ahead and choose
  42132. 26:42:23the correct language for you. I'm going
  42133. 26:42:25to click okay. We're going to click
  42134. 26:42:27next. And now we're just saying where
  42135. 26:42:29it's actually going to be placed. So I
  42136. 26:42:31by default it gets placed in my C drive
  42137. 26:42:33under program files. That is where I
  42138. 26:42:34want it. So I'm going to go ahead and
  42139. 26:42:35click next. You can select your
  42140. 26:42:37components. We want all of them uh just
  42141. 26:42:39by default. And then it asks if you want
  42142. 26:42:41to have this, you know, boot up on
  42143. 26:42:43startup. I'm going to say no because I
  42144. 26:42:44don't need it all the time when I'm, you
  42145. 26:42:46know, restarting my computer. And then
  42146. 26:42:48you can name this as well. I'm just
  42147. 26:42:49going to keep it as R. Again, I don't
  42148. 26:42:52really need a desktop shortcut or a
  42149. 26:42:54quick launch shortcut. So, I'm just
  42150. 26:42:56going to get rid of that. And now it's
  42151. 26:42:58going to install on our computer. That
  42152. 26:43:00took about 30 seconds. And we now have R
  42153. 26:43:03on our computer, which means we can come
  42154. 26:43:06back here and we can install R Studio
  42155. 26:43:08Desktop for Windows. Again, make sure
  42156. 26:43:10you have the right one for your
  42157. 26:43:11operating system. I'm going to go ahead
  42158. 26:43:13and click on this and we are going to
  42159. 26:43:15save this. Now that it's done
  42160. 26:43:16downloading, let's go ahead and open it
  42161. 26:43:19up. Now, we're going to set up and
  42162. 26:43:21install our R Studio. Let's go ahead and
  42163. 26:43:23click next. We're just selecting our
  42164. 26:43:25location. Make sure you have enough
  42165. 26:43:27space required. It's very small, but
  42166. 26:43:29that's happened to me in the past where
  42167. 26:43:30I have no storage. Then it doesn't
  42168. 26:43:32really work. So, let's go ahead and
  42169. 26:43:34install this. It's going to install.
  42170. 26:43:36Again, this should only take about a
  42171. 26:43:38minute or so. Now that R Studio is
  42172. 26:43:40completely set up, let's go ahead and
  42173. 26:43:42click finish. And now, we're going to go
  42174. 26:43:44look for it. So, we're going to come
  42175. 26:43:45right over here. We're going to say R
  42176. 26:43:47Studio, and we're going to open up R
  42177. 26:43:49Studio. It says we need to choose our R
  42178. 26:43:51installation because R Studio requires
  42179. 26:43:53an existing installation of R. We're
  42180. 26:43:56going to go ahead and choose the default
  42181. 26:43:58one. We're going to click okay. And now
  42182. 26:44:00R Studio from Bosit is popping up for
  42183. 26:44:03us. And just like that, we are in our
  42184. 26:44:05studio and now we have our user
  42185. 26:44:08interface that we can take a look at. So
  42186. 26:44:10really quickly, let's take a look at
  42187. 26:44:12what we have here. Right here we have
  42188. 26:44:14our console, our terminal, our
  42189. 26:44:16background jobs. But this is our
  42190. 26:44:18console. If you are looking for uh where
  42191. 26:44:21you can write code, it's going to be
  42192. 26:44:22right here. We just need to click on
  42193. 26:44:24this R script and it pulls up our coding
  42194. 26:44:27workspace right up here. Now, this is
  42195. 26:44:28where we can uh start typing. We can
  42196. 26:44:31bring things in like reading in a
  42197. 26:44:34library or a package and we write all of
  42198. 26:44:36our code in here. Down here is our
  42199. 26:44:38console. So, when we execute code, this
  42200. 26:44:40will be where we get error messages or
  42201. 26:44:42we can see the output of our code. On
  42202. 26:44:44this right hand side, we have our
  42203. 26:44:46environment. Now, this is where if we uh
  42204. 26:44:48pull in some type of data frame or if we
  42205. 26:44:50create variables or lots of other things
  42206. 26:44:52that we're going to be doing throughout
  42207. 26:44:53this series, they will show up right
  42208. 26:44:55over here. And lastly, in this section
  42209. 26:44:57on the bottom, you can actually come in
  42210. 26:44:59here and we can select a file path to
  42211. 26:45:02give it. So, let's come in here. Let's
  42212. 26:45:04go to our YouTube and uh this is going
  42213. 26:45:07to be our R series. So, I'm going to
  42214. 26:45:08open up our R series. We don't have any
  42215. 26:45:11files in here just yet, but I'll have
  42216. 26:45:13access to our files where we can then
  42217. 26:45:15pull them in or read them in. And it's
  42218. 26:45:17really great that R Studio has this
  42219. 26:45:19because you use a lot of files when
  42220. 26:45:20you're working within R Studio. This is
  42221. 26:45:22absolutely something we will use quite a
  42222. 26:45:23bit. We if we come right over here,
  42223. 26:45:25actually, we can do Ctrl S and we can
  42224. 26:45:27save this. Let's go down to our YouTube
  42225. 26:45:30and I'm going to go to this R series and
  42226. 26:45:32I'm just going to save this as first
  42227. 26:45:35file. And if I save it, you'll see it
  42228. 26:45:37saves as first file.R. Now, that's
  42229. 26:45:40actually not a good naming convention. I
  42230. 26:45:41should use an underscore there. But
  42231. 26:45:43these are all things that we will get to
  42232. 26:45:45uh within this series. Now that we have
  42233. 26:45:47everything set up, we can keep going in
  42234. 26:45:50this series moving forward. We're going
  42235. 26:45:51to learn a ton of different things. But
  42236. 26:45:53with that being said, I hope that this
  42237. 26:45:55is helpful. I hope you were able to get
  42238. 26:45:56everything set up, and I will see you in
  42239. 26:45:58the [music] next lesson.
  42240. 26:46:12Hello everybody. In this lesson, we're
  42241. 26:46:13going be taking a look at the basics of
  42242. 26:46:15using R Studio and R. Now, right down
  42243. 26:46:19here in the last lesson, I showed you
  42244. 26:46:20how to access uh kind of a file path
  42245. 26:46:23here. And you can see what files are in
  42246. 26:46:25here. And all you have to do is click on
  42247. 26:46:26this. And then your file folder comes
  42248. 26:46:28up. And then you can click into wherever
  42249. 26:46:30you want. You're going to open it up.
  42250. 26:46:31And these are some of the files that
  42251. 26:46:32we're going to be using later on in this
  42252. 26:46:35series. Over here on this lefth hand
  42253. 26:46:36side, we have our console opened, but we
  42254. 26:46:39can't interact with this data or write
  42255. 26:46:42code yet because we don't have an R file
  42256. 26:46:45open. So, what we're going to do is
  42257. 26:46:46we're going to come right here. We're
  42258. 26:46:47going to open up an R script. We can
  42259. 26:46:49also open up a ton of different files.
  42260. 26:46:51In fact, at the very end, we'll be
  42261. 26:46:53opening up an R markdown file to create
  42262. 26:46:55a dashboard for some data visualization.
  42263. 26:46:57But you can open up lots of different
  42264. 26:46:59files here if you want to do that. We
  42265. 26:47:02can also open up these files over here.
  42266. 26:47:05So if we want to, we can do that. But if
  42267. 26:47:06we open it up right here, then we can
  42268. 26:47:08name it and then it gets saved into that
  42269. 26:47:10file path. So we're going to call this
  42270. 26:47:12one the basics of R. And we're going to
  42271. 26:47:15save that. So now we get this open right
  42272. 26:47:18up here where we can actually write our
  42273. 26:47:20code. Now I say write our code. We can
  42274. 26:47:22actually write code down here in our
  42275. 26:47:24console. And I'll show you that in a
  42276. 26:47:26little bit when we start creating some
  42277. 26:47:28variables and expressions and different
  42278. 26:47:29things like that. But for me personally,
  42279. 26:47:32most of my workflow is going to be up
  42280. 26:47:33here. So I'm going to add some uh lines
  42281. 26:47:36here so we have some room to work with.
  42282. 26:47:39The other thing that I typically do or
  42283. 26:47:41have set is a soft wrap long lines. Now
  42284. 26:47:44if we don't have this, if I say I uh am
  42285. 26:47:48writing something, this is going to be
  42286. 26:47:50our code. Let me spell this right. And I
  42287. 26:47:52add a bunch of dashes. You're going to
  42288. 26:47:54note it just keeps going and it keeps
  42289. 26:47:57going. Um, especially as we start
  42290. 26:47:59bringing in code or we start bringing in
  42291. 26:48:02files. Um, we're going to want something
  42292. 26:48:04like this, which is a soft wrap, which
  42293. 26:48:06will wrap it to the next line. And so,
  42294. 26:48:09we still are on line two, but it is kind
  42295. 26:48:12of all in our viewing area instead of
  42296. 26:48:15being way over to the right, which I
  42297. 26:48:17personally don't like. So, I'm going to
  42298. 26:48:18get rid of this. Now, we've opened up a
  42299. 26:48:21file. We now have access to write code
  42300. 26:48:24in R. And what we're going to do is
  42301. 26:48:26we're going to start with the very
  42302. 26:48:28basics. And I'll kind of show you how
  42303. 26:48:29you can write it up here and you can
  42304. 26:48:30write it down here. Now, one thing to
  42305. 26:48:33note is we have this little sweep button
  42306. 26:48:34right here. This is our clear console.
  42307. 26:48:36We can click this button. It's going to
  42308. 26:48:38reset everything over here. And we also
  42309. 26:48:40have a sweep button over here. We can
  42310. 26:48:43clear out our environment. We'll be
  42311. 26:48:45using both of those, but let's get
  42312. 26:48:47started with the basics. So, we're going
  42313. 26:48:49to take a look at variables.
  42314. 26:48:52Now variables are where you're going to
  42315. 26:48:54assign a value whether it is a string or
  42316. 26:48:56it is a number to a variable which is
  42317. 26:48:59then stored in R's memory. So let's call
  42318. 26:49:02this one the num variable. We have to
  42319. 26:49:05use an assignment operator. Now this
  42320. 26:49:08assignment operator right here
  42321. 26:49:10essentially says take this number. We'll
  42322. 26:49:13do 42. Take this number and put it
  42323. 26:49:15within this numbum variable. Now we want
  42324. 26:49:19to run this code and we can do that by
  42325. 26:49:21highlighting our code like this and
  42326. 26:49:23doing controll enter. Now that we've ran
  42327. 26:49:25it you can see over here it is store
  42328. 26:49:27that as a value. We have our numvar.
  42329. 26:49:30Then we have 42. Now that we have this
  42330. 26:49:33what we can do is we can say print and
  42331. 26:49:35we'll do num_var.
  42332. 26:49:38If we print out you're going to notice
  42333. 26:49:41down here in the console 42 is printed
  42334. 26:49:44out. So we printed it out up here where
  42335. 26:49:46we're actually writing our code into our
  42336. 26:49:48console. But we can interact with our
  42337. 26:49:49code as well down here. So we can do
  42338. 26:49:52num_var
  42339. 26:49:54and then we can do times 2. And if we
  42340. 26:49:56run this, we get 84. It just doubles it.
  42341. 26:49:59So we're able to write this. But notice
  42342. 26:50:01if we come up here, let's do ctrls. I
  42343. 26:50:04just saved this file. If we get rid of
  42344. 26:50:07this, so let's get rid of our basics of
  42345. 26:50:09R and we're going to clean this out. If
  42346. 26:50:11I pull back up our basics of R, that
  42347. 26:50:15multiplication times two is not there.
  42348. 26:50:17So, we don't have access to the code
  42349. 26:50:19that's written down here in our console.
  42350. 26:50:21So, that is okay if you're just messing
  42351. 26:50:24around and kind of looking at your code.
  42352. 26:50:25Maybe we've pulled in a data set and
  42353. 26:50:27we're looking at data. We don't really
  42354. 26:50:28want to save it in our code. That's okay
  42355. 26:50:31to write it down here. But anything you
  42356. 26:50:33want to save, it is best to write it up
  42357. 26:50:35here. Otherwise, when you save it and
  42358. 26:50:37you exit out and you come back later,
  42359. 26:50:39you won't have it. Now, I told you that
  42360. 26:50:41this was numeric and we can actually
  42361. 26:50:43check that by using this class right
  42362. 26:50:46here. So, we're going to say we're going
  42363. 26:50:48to pass through our variable. So, we
  42364. 26:50:50have our number var. We're passing
  42365. 26:50:51through this variable into this class
  42366. 26:50:53function. And what it's going to do, it
  42367. 26:50:56is going to output the data type of this
  42368. 26:50:58right here. Now, of course, we're
  42369. 26:51:00passing through our variable, but in the
  42370. 26:51:03memory, it has this stored right here as
  42371. 26:51:05the value in memory. So, we are looking
  42372. 26:51:08at this right here. We're not actually
  42373. 26:51:10looking at the text. So just something
  42374. 26:51:11to note. Now we don't have to just store
  42375. 26:51:14numbers like this. We can store a lot of
  42376. 26:51:16other things including string. So if we
  42377. 26:51:19want to say we'll call this a string
  42378. 26:51:22variable. You don't have to do this uh
  42379. 26:51:24but I'm going to do it. But we can put
  42380. 26:51:25it in parenthesis and say I like R. And
  42381. 26:51:29if we save this, you're going to see I
  42382. 26:51:32like R here as our string value. So, we
  42383. 26:51:35can also store strings as well as
  42384. 26:51:38numbers. Now, all we're going to do for
  42385. 26:51:40the rest of this lesson is take a look
  42386. 26:51:42at a few different ways to store data
  42387. 26:51:44inside of variables. Those are things
  42388. 26:51:46like vectors and lists and maybe even a
  42389. 26:51:49data frame. These are common ways that
  42390. 26:51:51data is stored within R. And so, really,
  42391. 26:51:53that's all we're going to take a look
  42392. 26:51:54at. If you already know data types
  42393. 26:51:56within R, this is a perfectly fine time
  42394. 26:51:58to cut out. In the lessons after this,
  42395. 26:52:00we're going to go into a lot of other
  42396. 26:52:01things like operators and expressions,
  42397. 26:52:03reading in files, sorting the data that
  42398. 26:52:05we read into dataf frames. We're going
  42399. 26:52:06to get a lot more advanced as we go, but
  42400. 26:52:08again, this is the very basics. So,
  42401. 26:52:10let's take a look at a vector. So, so
  42402. 26:52:13far we've only stored something like a
  42403. 26:52:15string or a number. That's just one
  42404. 26:52:16value and one value, but we can actually
  42405. 26:52:18store multiple values. So, let's call
  42406. 26:52:21this a vector variable. And what we can
  42407. 26:52:24do is we're going to do a c. Then we're
  42408. 26:52:27going to open up our parenthesis. And
  42409. 26:52:29this is going to say that this is a
  42410. 26:52:30vector. So we can do 10, 20, 50, 100,
  42411. 26:52:36and thousand. And then when we run this,
  42412. 26:52:39you'll notice we have this right here.
  42413. 26:52:41So it's going to say we're storing
  42414. 26:52:43numbers. And this right here is an
  42415. 26:52:46index. So we have one through five. So
  42416. 26:52:49we have one, two, three, four, and five.
  42417. 26:52:52So now we are storing multiple values
  42418. 26:52:56within one variable. So vectors are good
  42419. 26:52:59for storing sequences of the same data
  42420. 26:53:01type. But if we want to store a lot of
  42421. 26:53:02different stuff, it could be whatever we
  42422. 26:53:04want. We can store that in a list. Now
  42423. 26:53:06lists are very popular. So we're going
  42424. 26:53:09to do um a list
  42425. 26:53:12variable. And what we're going to do is
  42426. 26:53:14we're going to name each of these
  42427. 26:53:16variables that we're putting in here. So
  42428. 26:53:17I'm going to say that the name is equal
  42429. 26:53:19to Alex. And then we'll say age is equal
  42430. 26:53:23to 30. And then we'll say scores is
  42431. 26:53:27equal to we'll pass through a vector
  42432. 26:53:29here. We'll say 90, 50, and
  42433. 26:53:3424. Just like this. Let's go ahead and
  42434. 26:53:37create this list. Now, we can just call
  42435. 26:53:41this and we can just say we could even
  42436. 26:53:43just say uh list var here. And it's
  42437. 26:53:46going to pull in the name, the age, and
  42438. 26:53:49the scores. Now, you'll notice we have
  42439. 26:53:52this little shortcut right here. And
  42440. 26:53:54this is saying that's what it's called.
  42441. 26:53:56So, if I only want to call the name, I
  42442. 26:54:00only want to retrieve that from this
  42443. 26:54:02list, I can do that. And if I run it,
  42444. 26:54:05it's only going to output just Alex,
  42445. 26:54:08just the name. That's all it's going to
  42446. 26:54:09do. There are other ways to do this as
  42447. 26:54:12well. We could uh let's get rid of that.
  42448. 26:54:14We could do a bracket and we could look
  42449. 26:54:15at the index. So, if we did a one, let's
  42450. 26:54:18go ahead and run this. The first index
  42451. 26:54:21within R is Alex. So we're still pulling
  42452. 26:54:24up the same one. We could also do it by
  42453. 26:54:26the name just in a different way. We
  42454. 26:54:28would need to do a double bracket and
  42455. 26:54:30pass through name. And we can run this
  42456. 26:54:33and it's still Alex. So all these ways
  42457. 26:54:35work. I will say the one that I
  42458. 26:54:36typically do and this is not just for
  42459. 26:54:39lists. This is similar if we're working
  42460. 26:54:41with data frames where we have columns
  42461. 26:54:43and rows. You can pull specific columns
  42462. 26:54:46by using this shortcut. And I do this
  42463. 26:54:48all the time. So that is how I would do
  42464. 26:54:50it. That's my personal preference. Now
  42465. 26:54:52there are other data types within R, but
  42466. 26:54:55the last I'm going to show you, and this
  42467. 26:54:56is the one that we're going to be using
  42468. 26:54:57in future lessons, is a dataf frame.
  42469. 26:54:59Now, a dataf frame could be you just
  42470. 26:55:01pulling in a CSV file that has columns
  42471. 26:55:03and rows, which is what we are going to
  42472. 26:55:05do. But I want to show you kind of what
  42473. 26:55:07a dataf frame looks like. So if we come
  42474. 26:55:10over here, we're going to say dataf
  42475. 26:55:13frame, and we're going to pass through,
  42476. 26:55:15and you're going to actually write
  42477. 26:55:16data.frame. frame. So if we come right
  42478. 26:55:19over here, it says the function
  42479. 26:55:20data.frame creates dataf frames which is
  42480. 26:55:22coupled correlations of variables which
  42481. 26:55:24share many of the properties of
  42482. 26:55:25matrices. Now matrices is another data
  42483. 26:55:28type but we're not covering that one
  42484. 26:55:29right now. But let's click on dataf
  42485. 26:55:31frame and we can pass through different
  42486. 26:55:34things like this data right here. Now
  42487. 26:55:37when we pass through this data and let's
  42488. 26:55:39actually take a look at this. This is
  42489. 26:55:41what it actually looks like and this is
  42490. 26:55:43just some of the uh information but it's
  42491. 26:55:45storing it as data. And so what we're
  42492. 26:55:47going to do is we're going to do
  42493. 26:55:48something really similar. Let's say the
  42494. 26:55:51name. This time we're going to pass
  42495. 26:55:53through multiple values. So not just a
  42496. 26:55:55list, it's essentially multiple lists.
  42497. 26:55:57So we'll do a vector here. And I'm just
  42498. 26:55:59going to make up some names. So we'll
  42499. 26:56:01say Alex,
  42500. 26:56:03Sally, and John. And I need to have that
  42501. 26:56:07in quotes. And then we'll do a comma.
  42502. 26:56:10We'll pass through our next one. So this
  42503. 26:56:11will be age. And we'll do another
  42504. 26:56:14vector. So we'll say is equal to uh
  42505. 26:56:16we'll do 30
  42506. 26:56:1950 and 99
  42507. 26:56:21and then we'll pass through the scores.
  42508. 26:56:24And in fact uh let's just keep the
  42509. 26:56:26scores like this because it'll be
  42510. 26:56:28simpler. Now let's go ahead and create
  42511. 26:56:31our data frame. And our data frame is up
  42512. 26:56:33here in data as well. You'll see it
  42513. 26:56:35looks a little bit different. This says
  42514. 26:56:36as a list of three, but this we have
  42515. 26:56:38this little grid. Now let's actually
  42516. 26:56:40click on this. It'll pull up this data
  42517. 26:56:42frame. And now it looks like an Excel
  42518. 26:56:44spreadsheet. It looks like a CSV file or
  42519. 26:56:46a database or wherever you store
  42520. 26:56:47structured data. We have our name, age,
  42521. 26:56:50and scores. And here is kind of this
  42522. 26:56:52index that it gives us. And you can see
  42523. 26:56:54it's all pretty. It looks really nice.
  42524. 26:56:56And so data frames are extremely popular
  42525. 26:56:58within R to use, especially with
  42526. 26:57:01structured data. And this is something
  42527. 26:57:02that we are going to use when we start
  42528. 26:57:04pulling in larger data sets. And that's
  42529. 26:57:06something that as you kind of work with
  42530. 26:57:08real data in a professional environment,
  42531. 26:57:11you'll start working with CSVs and
  42532. 26:57:12larger data sets and you'll have to do
  42533. 26:57:14all these things with them. And so
  42534. 26:57:15that's what we're building up to in this
  42535. 26:57:17series. So I hope that this was helpful.
  42536. 26:57:19I hope you learned a little bit more
  42537. 26:57:20about how to use R, a little bit more
  42538. 26:57:22about data types and variables. In the
  42539. 26:57:24next lesson, we're going to be taking a
  42540. 26:57:26look at operators and expressions.
  42541. 26:57:30[music]
  42542. 26:57:40Hello everybody. In this lesson, we're
  42543. 26:57:41going to be taking a look at operators.
  42544. 26:57:43Now, operators in R are just symbols or
  42545. 26:57:46keywords that perform operations on
  42546. 26:57:49variables or values if you haven't
  42547. 26:57:51already put those values into a
  42548. 26:57:52variable. Now, we're going to take a
  42549. 26:57:54look at several different types of
  42550. 26:57:55operators, but if you've been following
  42551. 26:57:57along in this series, we've already used
  42552. 26:57:59an operator before. it was something
  42553. 26:58:02called an assignment operator. So if we
  42554. 26:58:04have our variable and we go like this,
  42555. 26:58:07this is an assignment operator. These
  42556. 26:58:10are characters that say when we put a 42
  42557. 26:58:14over here, this 42 is going to stay
  42558. 26:58:16within this variable. So this already is
  42559. 26:58:19something that we know. So that is an
  42560. 26:58:21assignment operator. Now the next one
  42561. 26:58:24that we're going to take a look at is an
  42562. 26:58:26arithmetic
  42563. 26:58:28and I spell this right? Operator. There
  42564. 26:58:31are other ones as well like comparison
  42565. 26:58:32operators and logical operators and
  42566. 26:58:35we'll get to those in just a little bit.
  42567. 26:58:37But let's start out with looking at
  42568. 26:58:38arithmetic operators. These are
  42569. 26:58:40operators that are specifically built
  42570. 26:58:42and designed for math. And so let's
  42571. 26:58:44declare two different variables just to
  42572. 26:58:46start and then we'll take a look at
  42573. 26:58:48these arithmetic operators. Let's just
  42574. 26:58:50do the classic x and y. We'll say x is
  42575. 26:58:5310 and we'll say y is three. Now let's
  42576. 26:58:59go ahead and declare those. We're going
  42577. 26:59:01to see in our environment right over
  42578. 26:59:02here. We have our x and our y. Within
  42579. 26:59:05these variables, we have the very basic
  42580. 26:59:08ones. We're going to take our variables.
  42581. 26:59:09We're going to say x + y. And this is
  42582. 26:59:12going to be, of course, 13. Now, what we
  42583. 26:59:16can do, by the way, is we can assign
  42584. 26:59:19this to another variable. So, if we
  42585. 26:59:21wanted to, we could say a is going to be
  42586. 26:59:23assigned x + y. And if we run that, x +
  42587. 26:59:27y is 13. So, a becomes 13. Now, we don't
  42588. 26:59:31have to do that every time we do any
  42589. 26:59:34type of operator or mathematical
  42590. 26:59:36equation, but if we want to store that
  42591. 26:59:38value, we can. And this may not look
  42592. 26:59:41like it makes sense, but it does make
  42593. 26:59:42sense because we've stored these values.
  42594. 26:59:44We're adding them together, and then we
  42595. 26:59:47are assigning them. So, that is just
  42596. 26:59:49simple uh x + y, but we can also do x
  42597. 26:59:53minus y. This is just subtraction. And
  42598. 26:59:56we're going to get seven. So that's 10 -
  42599. 26:59:583 is equal to 7. We also have
  42600. 27:00:00multiplication which if we do x * 10 and
  42601. 27:00:04that's the little star right here. So
  42602. 27:00:06that is on my keyboard the shift 8. If
  42603. 27:00:10we do x and sorry it's supposed to be x
  42604. 27:00:14* y we're going to get 30. And so we're
  42605. 27:00:17just multiplying them together. We have
  42606. 27:00:18one more of the basic ones and then
  42607. 27:00:20we'll start going to kind of the more
  42608. 27:00:21complicated ones. But that's division.
  42609. 27:00:24So, we're going to say x and then we're
  42610. 27:00:26going to do a forward slash y. And this
  42611. 27:00:29is going to be x / y. And that's 3.3333
  42612. 27:00:33because it's 3 into 10. Now, the next
  42613. 27:00:36one that we're going to look at is a
  42614. 27:00:38little bit more challenging. This is an
  42615. 27:00:39exponent or to the power of. So, it
  42616. 27:00:41would be x and we're going to do this
  42617. 27:00:43little carrot here. That's what it's
  42618. 27:00:45called. It's called a carrot. X to the
  42619. 27:00:47power of y. So, we're going to do 10 to
  42620. 27:00:49the^ of 3. So, it' be 10 * 10 * 10. And
  42621. 27:00:52so when we do that, we're going to get
  42622. 27:00:541,00. So that one's really good. I'm
  42623. 27:00:57sure you've seen that if you've taken
  42624. 27:00:58algebra or, you know, other types of
  42625. 27:01:00maths, you're going to recognize that
  42626. 27:01:02pretty quickly. But this next one is
  42627. 27:01:03most likely one that you haven't seen.
  42628. 27:01:05This is called a modulo. And what it
  42629. 27:01:07does is it takes the remainder of a
  42630. 27:01:10division. So if we do x and we're going
  42631. 27:01:12to do two percent signs of y. If we run
  42632. 27:01:17this, we're going to do 10 / 3, which
  42633. 27:01:21means three can go into 10, but we have
  42634. 27:01:23a remainder of one. And so that's what a
  42635. 27:01:26modulo is used for. Now, I will say
  42636. 27:01:28you're going to use these a lot. They're
  42637. 27:01:30fairly straightforward. They're not
  42638. 27:01:32crazy confusing. This is kind of
  42639. 27:01:34foundational math that most people
  42640. 27:01:36should know. If you haven't, just messed
  42641. 27:01:37around with those. Uh those are really
  42642. 27:01:39good to know. Now, I'm not going to dive
  42643. 27:01:41into it a lot, but have you ever heard
  42644. 27:01:43of Hemdos? This is the order of
  42645. 27:01:46operations within math. This is
  42646. 27:01:48something you need to be aware of
  42647. 27:01:50because if you do something like, and
  42648. 27:01:52I'm just going to use numbers. I'm going
  42649. 27:01:53to do five * 10. If we do it just like
  42650. 27:01:57this and we run it, of course, that's
  42651. 27:01:59going to be 50. But then, let's do
  42652. 27:02:03divided by 2. And let's run this. Now,
  42653. 27:02:06of course, that's going to be 25. But if
  42654. 27:02:09I add plus six here and we run this,
  42655. 27:02:13this is where it starts getting a little
  42656. 27:02:14complicated, right? What's happening
  42657. 27:02:16where and what's going to happen if I
  42658. 27:02:19add a parentheses around all of this? So
  42659. 27:02:22this is where PEMDOSS comes into play.
  42660. 27:02:24PEMDOS stands for parenthesis, exponent,
  42661. 27:02:26multiplication, division, addition,
  42662. 27:02:28subtraction. So if we are looking at
  42663. 27:02:31this, we have to start with the P, the
  42664. 27:02:33parenthesis. So, we're going to do
  42665. 27:02:35everything in this parenthesis first
  42666. 27:02:37before we do anything outside of the
  42667. 27:02:39parentheses, which is multiplying times
  42668. 27:02:415. We would also do the exponent, which
  42669. 27:02:44we don't have, multiplication, which is
  42670. 27:02:46not in the parenthesis. And then
  42671. 27:02:47division. So, we would divide 10 by 2,
  42672. 27:02:49which is 5. Then, we would add 6, which
  42673. 27:02:52is 11 * 5 is 55. Let's make sure that's
  42674. 27:02:55correct. And there we go. If we did it
  42675. 27:02:58in a different way, if we uh put the
  42676. 27:03:00parentheses over here, and let's get rid
  42677. 27:03:02of this real quick. If we put the
  42678. 27:03:05parentheses over here, now we're going
  42679. 27:03:07to multiply times 50, then divide by two
  42680. 27:03:10and add six, and that's going to be 31
  42681. 27:03:13because we're going to get 25 right
  42682. 27:03:15here, and then add six to it. And so
  42683. 27:03:17these parentheses are very important.
  42684. 27:03:20You will see these in different types of
  42685. 27:03:21equations and different types of math
  42686. 27:03:23that you'll work with within R as it is
  42687. 27:03:25very statistics heavy. So, you know,
  42688. 27:03:26this is just kind of foundational
  42689. 27:03:28arithmetic and maths that you need to
  42690. 27:03:30know in order to work with these types
  42691. 27:03:31of programming languages. The next one
  42692. 27:03:33that we're going to take a look at, and
  42693. 27:03:34let's give us some more room right here,
  42694. 27:03:36and these are going to be comparison
  42695. 27:03:39operators. Comparison operators allow
  42696. 27:03:42you to evaluate different conditions.
  42697. 27:03:44So, let's take a look at one. So, we
  42698. 27:03:47have x and y here. We created those
  42699. 27:03:49earlier. So, we're going to say x is
  42700. 27:03:52greater than y. Now, when we run this,
  42701. 27:03:55we're going to get a different output.
  42702. 27:03:56We're no longer going to get a string or
  42703. 27:03:59a number. Now, we're getting what's
  42704. 27:04:01called a boolean value.
  42705. 27:04:03Now, this boolean is either true or it
  42706. 27:04:06is false. So, now if we say x is less
  42707. 27:04:10than y and we run this, and I did an
  42708. 27:04:13uppercase, whoops. Let's go ahead and
  42709. 27:04:15run this. Now, we're going to get a
  42710. 27:04:18false. So depending on whether it is a
  42711. 27:04:21true condition, it evaluates to true or
  42712. 27:04:23it evaluates to false, that's what our
  42713. 27:04:26output is going to be. Now we can also
  42714. 27:04:28add in to these ones an equal than or an
  42715. 27:04:31equal uh as well. So it would say x is
  42716. 27:04:33less than or equal to y. And if we run
  42717. 27:04:36it, it's still going to be false, but
  42718. 27:04:37you can add that in if you want that
  42719. 27:04:40these uh to potentially be equal or you
  42720. 27:04:42want to check for that. The other ones
  42721. 27:04:44that you really need to know are x is
  42722. 27:04:47equal to y. Now this is wrong uh because
  42723. 27:04:52this is actually an assignment operator
  42724. 27:04:54just like let's go back up. This is in
  42725. 27:04:57certain conditions within R. We need to
  42726. 27:04:59say equal equal. This is actually what
  42727. 27:05:02you need to write. And so it may seem a
  42728. 27:05:04little counterintuitive but that is the
  42729. 27:05:07syntax that you need to use. Now x is
  42730. 27:05:10not equal to y. One is 10, one is three.
  42731. 27:05:12So of course that's going to be false.
  42732. 27:05:14But if we said x is equal to x then this
  42733. 27:05:18will evaluate to true. The last one that
  42734. 27:05:21you need to know and this is the
  42735. 27:05:22opposite of equal to is not equal to. So
  42736. 27:05:25if we say x is not equal to y that's an
  42737. 27:05:29exclamation point with an equal sign. If
  42738. 27:05:31we say x is not equal to y we're
  42739. 27:05:33checking are they not equal? And that is
  42740. 27:05:36true. They're not equal. And so these
  42741. 27:05:38are comparison operators that are very
  42742. 27:05:40commonly used. You'll use these so often
  42743. 27:05:43they'll just become second nature. And
  42744. 27:05:45the last one that we're going to take a
  42745. 27:05:46look at is logical operators. Now,
  42746. 27:05:49logical operators, uh, you know, aside
  42747. 27:05:52from, you know, the basics, logical
  42748. 27:05:55operators are used all the time for
  42749. 27:05:57everything. They are here to help
  42750. 27:05:59determine and evaluate expressions to
  42751. 27:06:01determine if they are true or if they
  42752. 27:06:03are false or if multiple conditions are
  42753. 27:06:06true or false. So, right up here, let's
  42754. 27:06:08get this uh x is greater than y. We know
  42755. 27:06:13that that is true, right? We know this
  42756. 27:06:15is true. But what if I add I want that
  42757. 27:06:18to be true. And this is where the
  42758. 27:06:20logical operator comes in. So we want x
  42759. 27:06:23and y that way evaluates to true. But we
  42760. 27:06:26also want x to be equal to x. So we're
  42761. 27:06:30going to put this right here.
  42762. 27:06:32So now we're evaluating two separate
  42763. 27:06:35conditions. And this one right here,
  42764. 27:06:37this amperand I believe is what it's
  42765. 27:06:39called, which is a shift uh let's see,
  42766. 27:06:42seven on my keyboard. This amperand
  42767. 27:06:44means that both this and this condition
  42768. 27:06:47need to be met in order for it to
  42769. 27:06:49evaluate to true. Let's go ahead and run
  42770. 27:06:52this. So since both of these conditions
  42771. 27:06:54is true, this is great. X is greater
  42772. 27:06:57than Y and X is equal to X, this
  42773. 27:06:59evaluates to true. But let's change
  42774. 27:07:02this. We're going to change it to Y. We
  42775. 27:07:04know this is false. So this is true but
  42776. 27:07:07this is false. So are they both true? So
  42777. 27:07:10it needs this and this need to be true.
  42778. 27:07:13Since one of them is false, we will get
  42779. 27:07:16an output of false. And so this is what
  42780. 27:07:18a logical operator is. Now we're going
  42781. 27:07:21to take the take this exact same thing
  42782. 27:07:23and we're going to bring it down here
  42783. 27:07:24and we're going to change this into a
  42784. 27:07:27bar. and I call it a bar, but it's a
  42785. 27:07:29shift and it's right above my enter key
  42786. 27:07:31on my keyboard, right next to the
  42787. 27:07:32backslash. Um, but this right here means
  42788. 27:07:35or. So, this is and and this is or.
  42789. 27:07:38These are the ones you're going to use
  42790. 27:07:4099% of the time. So, you're going to say
  42791. 27:07:43is this condition true or is this
  42792. 27:07:46condition true? If either one of these
  42793. 27:07:48conditions are true, it will be true
  42794. 27:07:51down here. They don't both have to be
  42795. 27:07:53true. So now if we run this we're going
  42796. 27:07:56to get true x is greater than y this
  42797. 27:07:59evaluates to true or this which
  42798. 27:08:03evaluates to false since just one of
  42799. 27:08:05them is true then the entire expression
  42800. 27:08:08evaluates to true there is technically
  42801. 27:08:10one more logical operator and I'm going
  42802. 27:08:12to be honest I I don't think I ever use
  42803. 27:08:14this one or if I do it's a very specific
  42804. 27:08:17use cases. This is the not operator.
  42805. 27:08:21This is going to say this. So let's run
  42806. 27:08:23this. This is false. And we're going to
  42807. 27:08:26run this with the not operator and it's
  42808. 27:08:29going to change it to true. So it
  42809. 27:08:30basically reverses the boolean value
  42810. 27:08:33that is in the output. If it's true,
  42811. 27:08:34changes it to false. If it's false, it
  42812. 27:08:36changes it to true. It just flips the
  42813. 27:08:38value. That's all this operator does. I
  42814. 27:08:40think I've used this a few times in very
  42815. 27:08:42specific use cases, but 99.9% of the
  42816. 27:08:46time I'm using the and and the or
  42817. 27:08:48logical operators. Those are the ones
  42818. 27:08:49that are the most common to use. So this
  42819. 27:08:51is the basics of using operators. Now in
  42820. 27:08:54the next lesson, we're going to start
  42821. 27:08:55working with our data set, how we can
  42822. 27:08:57pull it in, how we can put it into a
  42823. 27:08:59data frame, how we can write files and
  42824. 27:09:01create files as well. If you haven't
  42825. 27:09:03already, be sure to check out my full R
  42826. 27:09:05for data analytics course on Analyst
  42827. 27:09:07Builder. I'll leave a link in the
  42828. 27:09:08description and a coupon code if you
  42829. 27:09:10would like to take that course. Thank
  42830. 27:09:12you guys so much for watching and I will
  42831. 27:09:13see you in the next video.
  42832. 27:09:17[music]
  42833. 27:09:23>> [music]
  42834. 27:09:27>> Hello everybody. In this lesson, we're
  42835. 27:09:29going to see how we can read and write
  42836. 27:09:31files within R. Now, as you can see down
  42837. 27:09:34here, we have this parks and wreck data
  42838. 27:09:36set. I will leave, you know, the GitHub
  42839. 27:09:38below so you can go and you can get this
  42840. 27:09:40exact file. It's just a little sample
  42841. 27:09:42file that we are going to pull in. But
  42842. 27:09:44what we can do is we can literally click
  42843. 27:09:46on this and we can import this data set.
  42844. 27:09:49Now in order to do that there are some
  42845. 27:09:52packages that we need and we do want to
  42846. 27:09:54install these. So let's go ahead and get
  42847. 27:09:56those installed and then we'll continue.
  42848. 27:09:58Now you can see right down here this is
  42849. 27:10:00the code that they are writing to bring
  42850. 27:10:02in this data set. And coincidentally
  42851. 27:10:04enough in just a second we're going to
  42852. 27:10:06write this exact same thing. And there
  42853. 27:10:08are different ways to write it. We don't
  42854. 27:10:10actually have to use this library right
  42855. 27:10:13here. There are tons of other libraries
  42856. 27:10:14or even default things within R that we
  42857. 27:10:16can use but this is our data set and we
  42858. 27:10:19can import this data set just like this
  42859. 27:10:21and it's going to be saved into our
  42860. 27:10:23memory into our data and now we have
  42861. 27:10:25this data frame. So then if we come over
  42862. 27:10:28here we can call in this parks and rack
  42863. 27:10:31data set and I can just hit tab and I
  42864. 27:10:34can run this and it's going to show all
  42865. 27:10:36of this data and that is a very simple
  42866. 27:10:39way to do it. Now, the only downside to
  42867. 27:10:42doing it like this is if you are
  42868. 27:10:44creating some type of automation. Let's
  42869. 27:10:46say you're pulling in data from
  42870. 27:10:47somewhere from the web and then you are
  42871. 27:10:49creating a CSV file. You're pulling that
  42872. 27:10:51data into here with that CSV file and
  42873. 27:10:54you're manipulating it. You're changing
  42874. 27:10:55it. Then you're writing another file
  42875. 27:10:57after you've cleaned up that data for a
  42876. 27:10:59specific purpose. Now, in that scenario,
  42877. 27:11:01doing it like this is not going to work
  42878. 27:11:03at all because you need to actually
  42879. 27:11:05write out the code so it's saved to the
  42880. 27:11:07file. And so we are not going to do it
  42881. 27:11:10like that. I don't really recommend that
  42882. 27:11:12unless there's just some one-off file
  42883. 27:11:14that you just want to get in here and,
  42884. 27:11:15you know, do whatever with. Let's go
  42885. 27:11:17ahead and sweep this because uh we don't
  42886. 27:11:19need it. Um what we can do is we can
  42887. 27:11:23come in here. We can write very similar
  42888. 27:11:25code. So I'm just going to show you how
  42889. 27:11:26to do it uh without anything. So we're
  42890. 27:11:28going to do read.csv.
  42891. 27:11:31So read.csv. All we have to do is pass
  42892. 27:11:33through the file name. There's a lot of
  42893. 27:11:36other what are called parameters or
  42894. 27:11:38arguments that you can pass through as
  42895. 27:11:40well. So you know if we were uh writing
  42896. 27:11:44it out again if we write out read
  42897. 27:11:48CSV you can come in here and you can get
  42898. 27:11:50additional help on this and look at all
  42899. 27:11:52the different parameters that they have
  42900. 27:11:54in here that you can pass through. Now
  42901. 27:11:56what we need to do is pass through this
  42902. 27:11:58file. So let's come down here. I have
  42903. 27:12:01this uh parks and wreck data set. I'm
  42904. 27:12:04going to click on it and I'm going to
  42905. 27:12:05copy this as a path. You can do that
  42906. 27:12:09with a shortcutt control shift C, but
  42907. 27:12:11I'm just going to paste it in there. And
  42908. 27:12:14if we try to run this, and actually
  42909. 27:12:16let's really quick, let's declare this
  42910. 27:12:18as our data frame. But if we try to run
  42911. 27:12:21this,
  42912. 27:12:23then
  42913. 27:12:24it's not going to work. This backslash
  42914. 27:12:27is actually a special character. What it
  42915. 27:12:29does is it says that this Y, the letter
  42916. 27:12:31right next to it, is a special
  42917. 27:12:33character. Now, we can actually negate
  42918. 27:12:35this by putting another backslash. And
  42919. 27:12:39then what we're saying is is the special
  42920. 27:12:40character is this right here. And so, it
  42921. 27:12:43just keeps it. And we can Whoops. Let me
  42922. 27:12:46put it in the right spot. So, we can put
  42923. 27:12:48in a double slash. And that's perfectly
  42924. 27:12:50acceptable. Let's go ahead and run it.
  42925. 27:12:52And now we have our data frame right
  42926. 27:12:55here. And we can click on it. We can
  42927. 27:12:57open up this data frame and it's
  42928. 27:12:59beautiful. We're doing uh some parks and
  42929. 27:13:01wreck and this is what we're going to be
  42930. 27:13:02using in the next several lessons uh
  42931. 27:13:04this small parks and wreck data set but
  42932. 27:13:06that is how we can read in a CSV file.
  42933. 27:13:09Now there's lots of different types of
  42934. 27:13:10file formats. There's JSON, Excel, etc.
  42935. 27:13:13There's lots of different ones, but this
  42936. 27:13:15is in a nutshell how you do it. You may
  42937. 27:13:18just need, you know, a different way to
  42938. 27:13:19read it in. But there's so many
  42939. 27:13:21different file formats that you can read
  42940. 27:13:23in within R. Just about anything you can
  42941. 27:13:25imagine. Now when we have this data
  42942. 27:13:28frame, we've created it. It's up here.
  42943. 27:13:30It looks great. Now we can start messing
  42944. 27:13:33with this dataf frame. We can use it. We
  42945. 27:13:35can look at it. For example, we can use
  42946. 27:13:37this right here, which says the head of
  42947. 27:13:40the data frame is going to give us the
  42948. 27:13:42first five rows of that data set. I
  42949. 27:13:45guess it's giving us the first six here,
  42950. 27:13:46but this is just a sample of the data.
  42951. 27:13:49You can imagine because we're going to
  42952. 27:13:51be working with larger data sets,
  42953. 27:13:53especially as we get towards the end,
  42954. 27:13:55that if you have a thousand, 10,000,
  42955. 27:13:57100,000 rows, you don't want to look at
  42956. 27:14:00all of that every single time. You may
  42957. 27:14:02just want to print out just a few rows
  42958. 27:14:04of the data. And that is how you can do
  42959. 27:14:06this. We also have a few different
  42960. 27:14:08things that we can do to kind of check
  42961. 27:14:10our data that we just pulled in. This
  42962. 27:14:13one right here, and let's see if we have
  42963. 27:14:14it right here. This gives us the
  42964. 27:14:16structure of our data frame. So if we
  42965. 27:14:19come and open the parentheses and pass
  42966. 27:14:20through our data frame and so what it's
  42967. 27:14:22going to tell us is going to say here is
  42968. 27:14:24the character the department the role
  42969. 27:14:26these are our columns and it says this
  42970. 27:14:28is a character column character
  42971. 27:14:30character these are strings and then
  42972. 27:14:32annual salary this is an integer and
  42973. 27:14:34then dogs rescue with three legs that's
  42974. 27:14:36also an integer. Another one that you
  42975. 27:14:38might use and I do use these by the way
  42976. 27:14:41because I often uh you know kind of want
  42977. 27:14:44to see how the data is sitting. Another
  42978. 27:14:46one we can use is summary. And this is
  42979. 27:14:48going to give us some statistics of our
  42980. 27:14:50data set. Now, more specifically, this
  42981. 27:14:52is really good for our numeric columns,
  42982. 27:14:55but it's not as good or useful for our
  42983. 27:14:58character columns. But we have some min,
  42984. 27:15:00first quarter median, mean, third
  42985. 27:15:03quartile or quarter bolt, quartile max.
  42986. 27:15:06Um, and the same for the other ones. So,
  42987. 27:15:08it gives us just a little bit of
  42988. 27:15:09information about our numeric columns
  42989. 27:15:12and that can be really helpful. Now,
  42990. 27:15:14like I said, there are different things
  42991. 27:15:16when we're pulling in data. I'm going to
  42992. 27:15:17pull this down. There are different
  42993. 27:15:19things that we might want to use. For
  42994. 27:15:22example, if we say header, the header
  42995. 27:15:25says whether we're going to keep our
  42996. 27:15:26headers in our file or not. So, if I say
  42997. 27:15:29equals false, I'm going to do dataf
  42998. 27:15:32frame 2 here. So, we're pulling this in
  42999. 27:15:34and we're saying the header is equal to
  43000. 27:15:36false. Now, if we run this, it's going
  43001. 27:15:39to look a little bit different. So now
  43002. 27:15:42this row as our headers which are our
  43003. 27:15:44column names now they are actually part
  43004. 27:15:47of the data and so if you don't have a
  43005. 27:15:50header on your data it's just goes
  43006. 27:15:52straight into the data on you know row
  43007. 27:15:53one this would be something you need to
  43008. 27:15:55write in there otherwise it's going to
  43009. 27:15:57not understand that although it does
  43010. 27:15:59have header as a default saying true
  43011. 27:16:02because we didn't put it up here default
  43012. 27:16:03is true you can specify that it is false
  43013. 27:16:07another thing that you might need to use
  43014. 27:16:10and let's go back here is SP.
  43015. 27:16:13This stands for a separator. Now, by
  43016. 27:16:16default, when you're pulling in a CSV,
  43017. 27:16:18it's going to be a comma because that's
  43018. 27:16:19what CSV stands for, a comma, separated
  43019. 27:16:21value file. That's what a CSV file is.
  43020. 27:16:24Now, we don't have to keep it as a
  43021. 27:16:26comma. Let's say, for example, we have a
  43022. 27:16:29space that's separating everything or we
  43023. 27:16:31have a dash that's separating
  43024. 27:16:32everything. It's whatever you want it to
  43025. 27:16:34be. Now, by default, again, it is a
  43026. 27:16:36comma. And if we run this and we go back
  43027. 27:16:39up to our day frame two, it's going to
  43028. 27:16:41be the exact same. But if we change it
  43029. 27:16:43to something like a space, we're going
  43030. 27:16:46to completely change how this file
  43031. 27:16:48looks. Now, every space that you see
  43032. 27:16:51within here is going to be a different
  43033. 27:16:53column. It's going to separate it out
  43034. 27:16:54like this. And this looks terrible. So,
  43035. 27:16:56we definitely don't want to do that, but
  43036. 27:16:58it is something that you should be aware
  43037. 27:17:00of. That's a parameter that we can pass
  43038. 27:17:02through. So, let's run this correctly.
  43039. 27:17:05And let's actually put this back to the
  43040. 27:17:07default. Let's run this. Let's say we
  43041. 27:17:11have our data frame and we've done some
  43042. 27:17:13things to it. We are happy with it.
  43043. 27:17:15Maybe we've aggregated some of the data.
  43044. 27:17:17And now we say, okay, I want to export
  43045. 27:17:20this to a file. Instead of readcsv,
  43046. 27:17:23we're going to write.csv.
  43047. 27:17:27So write.csv right here is going to put
  43048. 27:17:30all of this data into a file. So we're
  43049. 27:17:32going to do this. And what we're going
  43050. 27:17:34to do is we're going to pass through
  43051. 27:17:35this exact same thing. I'm going to pass
  43052. 27:17:38through this file path, but we have to
  43053. 27:17:40specify what we're passing into that
  43054. 27:17:42file path. So, we're going to say here,
  43055. 27:17:44take dataf frame 2. And then here's
  43056. 27:17:47where you're going to place it. Now, we
  43057. 27:17:48don't want to call it the exact same
  43058. 27:17:50thing. It will overwrite our previous
  43059. 27:17:52file. We don't want that. So, we're
  43060. 27:17:54going to say uh output. So, now we're
  43061. 27:17:58taking this dataf frame 2, which is the
  43062. 27:18:00exact same data. We haven't done
  43063. 27:18:01anything to it, but you know, uh, we're
  43064. 27:18:03taking this dataf frame 2, and now we're
  43065. 27:18:05going to export that data set or that
  43066. 27:18:07data frame into a file. Let's go ahead
  43067. 27:18:10and run this. And there we go. So now we
  43068. 27:18:14have our parks and rack data set. If we
  43069. 27:18:16then wanted to read that in, and we can.
  43070. 27:18:21Let's come right over here. We're going
  43071. 27:18:23to do underscore output.
  43072. 27:18:26And let's do this as dataf frame 3. Now
  43073. 27:18:29let's run this. Now we have our dataf
  43074. 27:18:32frame three and there is our data set.
  43075. 27:18:35You'll notice we now have six variables
  43076. 27:18:37instead of the five. That's because when
  43077. 27:18:39we exported our data set, it brought
  43078. 27:18:42along this index right here. What we can
  43079. 27:18:45do is let's overwrite the that previous
  43080. 27:18:47one. Let's put a comma here and we're
  43081. 27:18:50going to do row.names.
  43082. 27:18:53This says whether or not we want that
  43083. 27:18:55index to be written with it or not. and
  43084. 27:18:57we're going to say false. So, let's
  43085. 27:18:59overwrite that file. And then let's read
  43086. 27:19:02this in again. And let's go take a look
  43087. 27:19:05at our dataf frame 3. It no longer has
  43088. 27:19:07that extra column with the index. We got
  43089. 27:19:10rid of that when we wrote it to the
  43090. 27:19:11file. So, this is the basics of working
  43091. 27:19:14with files. It of course goes more in
  43092. 27:19:16depth. You can connect to APIs. You can
  43093. 27:19:18connect to databases. You can connect to
  43094. 27:19:21a lot of different file paths. But this
  43095. 27:19:23is the basics of how you can read and
  43096. 27:19:25write and create dataf frames with
  43097. 27:19:27files. So, thank you guys so much for
  43098. 27:19:29watching. In the next lesson, we're
  43099. 27:19:30going to see how we can select and order
  43100. 27:19:32our data that we pulled into a dataf
  43101. 27:19:34frame.
  43102. 27:19:36[music]
  43103. 27:19:47Hello everybody. In this lesson, we're
  43104. 27:19:48going to see how we can select and order
  43105. 27:19:50our data that we're pulling in from a
  43106. 27:19:52CSV that is in a data frame. Now, what
  43107. 27:19:54we need to do is we have to first pull
  43108. 27:19:56in our data set. If you haven't been
  43109. 27:19:58following this series, then you can get
  43110. 27:20:00this data set down below. It'll be in
  43111. 27:20:02the GitHub. You can just download it,
  43112. 27:20:04put it into file path. And if you don't
  43113. 27:20:06know how to read in a file, check out my
  43114. 27:20:07last lesson because that's how you
  43115. 27:20:09actually work with files, which is right
  43116. 27:20:11here. You can see how to write files and
  43117. 27:20:13read in files. Now let's read in this
  43118. 27:20:17data frame and let's open it up. So now
  43119. 27:20:20we have columns like character,
  43120. 27:20:21department, ro, annual salary, dogs
  43121. 27:20:24rescued with three legs. Very specific
  43122. 27:20:26column here. But let's start out with
  43123. 27:20:28just seeing how we can select only
  43124. 27:20:30specific columns. Then we'll look at
  43125. 27:20:32only specific rows. And then what we're
  43126. 27:20:35going to do at the end is we'll see how
  43127. 27:20:36we can order different columns. So let's
  43128. 27:20:38come back here. And what we're going to
  43129. 27:20:40do is we're actually going to pull in a
  43130. 27:20:42library here. And let's go over here to
  43131. 27:20:45the library. And we want to pull in a
  43132. 27:20:46library. Now, if we come over to the
  43133. 27:20:48packages, we don't have a ton pulled in.
  43134. 27:20:51Right? As we're going through here,
  43135. 27:20:53there's a lot that will, you know, you
  43136. 27:20:55might want to use that are not in here.
  43137. 27:20:57And one specifically that we want is
  43138. 27:21:00dlier. And that's how I pronounce it at
  43139. 27:21:02least. Uh, but it's dpl.
  43140. 27:21:07This package is specifically made and
  43141. 27:21:10designed for people like data analyst,
  43142. 27:21:12data scientist to manipulate and select
  43143. 27:21:14and query and work with data. So we are
  43144. 27:21:17going to go ahead and we're going to run
  43145. 27:21:18this. Now it's saying there is no
  43146. 27:21:20package called dlier. That's not true.
  43147. 27:21:23There is a package called dlier. We just
  43148. 27:21:25need to install it. So we're going to
  43149. 27:21:27come up here. We'll go right above it.
  43150. 27:21:28We're going to do install.packages.
  43151. 27:21:33There we go. And then we're going to do
  43152. 27:21:36dlier. I got to spell that right. I
  43153. 27:21:38deleted everything that I had in R and
  43154. 27:21:41started from scratch at the beginning of
  43155. 27:21:42the series. So I need to install some
  43156. 27:21:44packages as well. As you can see, we
  43157. 27:21:47just installed dlier. And because of
  43158. 27:21:49that, we have a lot of different options
  43159. 27:21:50that we didn't have before. And
  43160. 27:21:53specifically, we have this one right
  43161. 27:21:54here. This is the grammar of data
  43162. 27:21:56manipulation. If you click on this, you
  43163. 27:21:59can come in here and you can see all
  43164. 27:22:01that it can do. And it can do a lot of
  43165. 27:22:03things. and we'll use a lot of these in
  43166. 27:22:05this series. And so now that we have
  43167. 27:22:07that, we're going to go ahead and we're
  43168. 27:22:09going to uh pull in that library. We
  43169. 27:22:11could also just click on this and it
  43170. 27:22:15would be ready, but I still want to
  43171. 27:22:17write it in the code. So now we've
  43172. 27:22:19pulled in that library and we can start
  43173. 27:22:21using things that are within that
  43174. 27:22:23library. I'm going to come back here
  43175. 27:22:25just to make it look nice again. Now one
  43176. 27:22:27of the functions that's within dlier is
  43177. 27:22:30select. Let's say we want to only bring
  43178. 27:22:33in the character and the role column.
  43179. 27:22:36Those are the only ones we want right
  43180. 27:22:38now. We can do that by saying select and
  43181. 27:22:42we're going to open this up. We're going
  43182. 27:22:44to pass through our data frame. And now
  43183. 27:22:46we can select what columns we want. So
  43184. 27:22:48we're going to say character and roll.
  43185. 27:22:52And let's go ahead and run this. Now,
  43186. 27:22:55we're getting our output right now as
  43187. 27:22:58just an output in the console, which is
  43188. 27:23:01perfectly fine. What a lot of people
  43189. 27:23:03will do is when they're running these
  43190. 27:23:04select statements is they're going to
  43191. 27:23:06assign this to its own data frame, which
  43192. 27:23:09is fine. Here's what I will say, and I'm
  43193. 27:23:12going to start doing it. But here's what
  43194. 27:23:13I will say. Your data right here and
  43195. 27:23:15what you're storing in your memory is
  43196. 27:23:16going to exponentially increase. It's
  43197. 27:23:18going to be kind of hard to work with
  43198. 27:23:20all these different dataf frames, but
  43199. 27:23:22I'm going to say dataf frame characters
  43200. 27:23:25and we're going to assign this
  43201. 27:23:27and then we're going to run it. So now
  43202. 27:23:30I've created a new dataf frame with only
  43203. 27:23:32uh two columns. Now we have character
  43204. 27:23:35and ro. So we're able to just take the
  43205. 27:23:39columns that we want. We don't have to
  43206. 27:23:40take all of them. Now let's say we go
  43207. 27:23:42back here and we actually want all these
  43208. 27:23:45columns except for this last one. This
  43209. 27:23:47last one we don't really need at all.
  43210. 27:23:49And so what we're going to do is we're
  43211. 27:23:51going to take that and we're going to
  43212. 27:23:53just come down here and we'll do the
  43213. 27:23:55same thing. We'll pass through our data
  43214. 27:23:57frame and we're going to say minus which
  43215. 27:23:59means we don't want this column. And
  43216. 27:24:02let's see what that's called again. Dogs
  43217. 27:24:03rescued with three legs. So I'll say
  43218. 27:24:06dogs
  43219. 27:24:07rescued
  43220. 27:24:10with three legs. We'll see if uh I
  43221. 27:24:16actually think this is capitalized. But
  43222. 27:24:18now let's run this. And now you're going
  43223. 27:24:20to see all of these columns except the
  43224. 27:24:23one that we didn't want. Now this seems
  43225. 27:24:25silly. This seems very, you know,
  43226. 27:24:26simple, at least the way I'm looking at
  43227. 27:24:28it because we're just getting rid of one
  43228. 27:24:30column. But in the real world, when I
  43229. 27:24:32have been working with data in the past,
  43230. 27:24:34I'll get data from a client and every
  43231. 27:24:36single time they send these columns that
  43232. 27:24:39I just don't care about. I don't need.
  43233. 27:24:41there's no reason they're in there and
  43234. 27:24:42they take up space, they fill up your
  43235. 27:24:44database or they take up your memory,
  43236. 27:24:45whatever it is, and you just don't want
  43237. 27:24:47to see it. This would be an example of
  43238. 27:24:49one that I'm just like, okay, get rid of
  43239. 27:24:50this column and then we can start
  43240. 27:24:52looking at it. So then I would assign
  43241. 27:24:54this to another data frame and then I
  43242. 27:24:56would only work with that new data
  43243. 27:24:57frame. I wouldn't work with the original
  43244. 27:24:59data frame because that one has that
  43245. 27:25:01dogs rescue with three lengths column
  43246. 27:25:03that we never needed in the first place.
  43247. 27:25:05We could also get this exact same output
  43248. 27:25:07by doing something a little bit
  43249. 27:25:09different. And what we would do is we
  43250. 27:25:12would say character and then we do this
  43251. 27:25:15little colon here and that means through
  43252. 27:25:18and then I believe the last one let's
  43253. 27:25:20get rid of this one is annual salary. So
  43254. 27:25:23then I would do annual
  43255. 27:25:26salary. And what this does is it says I
  43256. 27:25:28want this column through this column.
  43257. 27:25:31And then if we run this, it's again not
  43258. 27:25:33going to include that last one because
  43259. 27:25:35it is not in between character and
  43260. 27:25:37annual salary. So that's how we're able
  43261. 27:25:39to specify what columns we want. But I
  43262. 27:25:42think more importantly is actually
  43263. 27:25:44selecting what data we want. So what
  43264. 27:25:46rows of data we actually want to keep in
  43265. 27:25:49our output. So let's come down here and
  43266. 27:25:51we're going to say filtering. Now
  43267. 27:25:54filtering data is super important. You
  43268. 27:25:56don't always want all the data or you
  43269. 27:25:58want some subsection of the data. So
  43270. 27:26:01what we can do is we're going to come
  43271. 27:26:02right down here and we're going to say
  43272. 27:26:04filter. And filter is going to allow us
  43273. 27:26:06to create a specific condition. If it is
  43274. 27:26:08met, then those rows will be returned.
  43275. 27:26:11If it is not met, then it will not be
  43276. 27:26:14returned. So again, we're going to pass
  43277. 27:26:16through our data frame. But for this
  43278. 27:26:18one, let's take a look where annual
  43279. 27:26:20salary is greater than and let's say
  43280. 27:26:2450,000. So we're going to do 501 23.
  43281. 27:26:28So we're only going to filter on annual
  43282. 27:26:30salary where it's greater than 50,000.
  43283. 27:26:34Now if you look in our output, we have
  43284. 27:26:35an annual salary here and none of them
  43285. 27:26:37are going to be lower than 50,000. This
  43286. 27:26:40is using our comparison operators here.
  43287. 27:26:42So we have other comparison operators
  43288. 27:26:44that we can use. For example, we could
  43289. 27:26:48do right here. We want to say where the
  43290. 27:26:51role is equal to and now we're looking
  43291. 27:26:52at a string. We can just say they're a
  43292. 27:26:55director. And if we run this, there's
  43293. 27:26:58only going to be one person who's a
  43294. 27:26:59director, and that's Ron Swanson. Now,
  43295. 27:27:02you'll notice that we also have a
  43296. 27:27:04different director. We have Ron Swanson,
  43297. 27:27:05who's our director, but also Leslie Nope
  43298. 27:27:07is technically a director, too, but it
  43299. 27:27:10isn't a specific match here. Now, there
  43300. 27:27:13is a specific function that is kind of
  43301. 27:27:16like regular expression. It searches for
  43302. 27:27:18a specific pattern. It's called grapple.
  43303. 27:27:21And we can use that. We can say grapple.
  43304. 27:27:25and we're going to pass through
  43305. 27:27:26director. Now the only thing we have to
  43306. 27:27:28do apart from that is we're also going
  43307. 27:27:30to specify what column we're looking in
  43308. 27:27:33which is RO and we'll close our
  43309. 27:27:36parenthesis. So now we're looking for
  43310. 27:27:38the word director in this RO column. If
  43311. 27:27:42it's anywhere in there it's going to
  43312. 27:27:43return it. So now if we run this it's
  43313. 27:27:47not just director. Now we have deputy
  43314. 27:27:49director as well because it was just
  43315. 27:27:51searching for that keyword. And so if it
  43316. 27:27:53contains director anywhere in this RO
  43317. 27:27:56column, we are going to find it. Now
  43318. 27:27:58when we're filtering data, we typically
  43319. 27:28:00aren't just filtering on one thing or
  43320. 27:28:02you know sometimes you are but sometimes
  43321. 27:28:03we have multiple things. Let's go ahead
  43322. 27:28:06and let's put this filter down here. I
  43323. 27:28:09should have kept the uh previous one.
  43324. 27:28:10I'll write it again. So we're going to
  43325. 27:28:12do where the annual salary is greater
  43326. 27:28:15than 50,000 and that's 5,000. And let's
  43327. 27:28:19just run this. But we also only want to
  43328. 27:28:22see where their department is parks. So
  43329. 27:28:25what we're going to do is we're going to
  43330. 27:28:27use a logical operator which is our
  43331. 27:28:29amperand. We're going to say where the
  43332. 27:28:31annual salary is greater than 50,000 and
  43333. 27:28:35then we'll create another condition.
  43334. 27:28:37We're going to say where their
  43335. 27:28:38department is equal to
  43336. 27:28:42parks. Now let's run this and you'll see
  43337. 27:28:46now we have all the annual salaries
  43338. 27:28:48greater than 50,000 and where the
  43339. 27:28:50department is equal to parks. So we can
  43340. 27:28:52have multiple conditions in here and we
  43341. 27:28:55can either have an and or an or in order
  43342. 27:28:58to specify what we're looking for. Now
  43343. 27:29:00right now we're just filtering and
  43344. 27:29:01before we were just selecting. Let's see
  43345. 27:29:03how we can combine these. And there's
  43346. 27:29:06going to be a little bit more advanced
  43347. 27:29:07and we'll get to a lot of this in the
  43348. 27:29:09next several lessons.
  43349. 27:29:10What we're going to do is we're going to
  43350. 27:29:12use something called a pipe operator. So
  43351. 27:29:14we're going to take our dataf frame and
  43352. 27:29:16we're going to build our pipe operator.
  43353. 27:29:18This says take the data frame and then
  43354. 27:29:22so what are we going to do next? We're
  43355. 27:29:25going to select just this data set.
  43356. 27:29:29So let's bring this back. So we're
  43357. 27:29:32taking our data frame and then we're
  43358. 27:29:34only selecting character through annual
  43359. 27:29:37salary. So we don't have that last
  43360. 27:29:39column. And then we're going to add this
  43361. 27:29:41pipe operator as well. And then we'll
  43362. 27:29:45say do this.
  43363. 27:29:48And let's format a little better. This
  43364. 27:29:50is kind of how you add multiple things
  43365. 27:29:52on top of another. So we're going to
  43366. 27:29:54take our data frame. We're going to say
  43367. 27:29:56and then select only these columns. And
  43368. 27:29:59then we're going to filter it down like
  43369. 27:30:01this. So let's run this right here. And
  43370. 27:30:04actually we're getting an error because
  43371. 27:30:06uh we don't need to pass through these
  43372. 27:30:10data frames anymore because we are
  43373. 27:30:12already specifying at the very beginning
  43374. 27:30:14take this data frame and then select
  43375. 27:30:17just this data. If we do it if we keep
  43376. 27:30:20passing through the data frame it kind
  43377. 27:30:22of gets wonky because it's like yes I
  43378. 27:30:24already know I'm supposed to be using
  43379. 27:30:25the data frame. So it gets confused. But
  43380. 27:30:27this right here is how we kind of chain
  43381. 27:30:29these together. Now we only have these
  43382. 27:30:31four columns and only with those
  43383. 27:30:33conditions being met. Now the last thing
  43384. 27:30:35that we're going to look at and I'm
  43385. 27:30:37going to actually put this down here.
  43386. 27:30:39I'm going to say uh this is our called
  43387. 27:30:41our pipe operator. I'm going to put this
  43388. 27:30:44down here. And up here I'm going to say
  43389. 27:30:46ordering.
  43390. 27:30:47And once we add ordering and see how we
  43391. 27:30:49can order it, we're going to add it down
  43392. 27:30:51here into kind of our chain is what
  43393. 27:30:54we're going to call it. Now for ordering
  43394. 27:30:55data, let's take this right here. We're
  43395. 27:30:57going to look at our annual salary.
  43396. 27:30:59Let's say we wanted to order it like
  43397. 27:31:01this, lowest to highest. That's very
  43398. 27:31:04easy to do when you're looking at the
  43399. 27:31:06data in here, but there's a hund
  43400. 27:31:08different reasons why you'd need to
  43401. 27:31:09actually order it in your code. And so
  43402. 27:31:11let's come over here and we're going to
  43403. 27:31:13use arrange. Again, this is in within
  43404. 27:31:15dlier even says it right here. This is
  43405. 27:31:18how you order the rows of your data. So
  43406. 27:31:21we're going to say arrange and what we
  43407. 27:31:23need to do, of course, is pass through
  43408. 27:31:24our data frame, but then we're going to
  43409. 27:31:26specify what column do we want to order
  43410. 27:31:28it on. We're going to say annual
  43411. 27:31:31I need to spell right. I'm not spelling
  43412. 27:31:34right at all. Annual salary. And then if
  43413. 27:31:38we run this, you'll notice right up here
  43414. 27:31:42that the annual salary is from lowest to
  43415. 27:31:44highest. So by default it is ascending
  43416. 27:31:48which means lowest to highest. But we
  43417. 27:31:51can reverse that to do highest to
  43418. 27:31:53lowest. Let's say uh let's do lower c
  43419. 27:31:55lowerase actually. Uh let's pass through
  43420. 27:31:58this annual salary. Give me one sec. So
  43421. 27:32:02now we're saying take the annual salary
  43422. 27:32:04but do it from highest to lowest. That's
  43423. 27:32:06what descending means. It's going to be
  43424. 27:32:08the exact same thing except the
  43425. 27:32:10opposite. So we have lowest to highest
  43426. 27:32:12here. So now let's go back to our pipe
  43427. 27:32:15operator area where we've chained these
  43428. 27:32:17all together. Now we have all this
  43429. 27:32:18information, but I want to order it by
  43430. 27:32:21annual salary right here. So, I'm going
  43431. 27:32:23to take uh this and I'm going to say
  43432. 27:32:28oops my pipe and I'm going to paste this
  43433. 27:32:31in. But I have to get rid of this data
  43434. 27:32:34frame again. So now I'm saying take our
  43435. 27:32:36data frame, select these columns, filter
  43436. 27:32:40on these conditions, and then arrange
  43437. 27:32:43them with annual salary descending.
  43438. 27:32:46Let's go ahead and run this. And there
  43439. 27:32:48we go. So we have our output that we're
  43440. 27:32:51looking for. and we filtered down by a
  43441. 27:32:54ton of different stuff while selecting
  43442. 27:32:55columns, rows, and ordering our data all
  43443. 27:32:58in just one kind of easily readable
  43444. 27:33:01code. And so that's how we select,
  43445. 27:33:03filter, and order our data specifically
  43446. 27:33:05using that dlier package. That is
  43447. 27:33:07something that's very popular and very
  43448. 27:33:09common to use within R. If you haven't
  43449. 27:33:11already, be sure to check out my full R
  43450. 27:33:12course on analybuilder.com. I will leave
  43451. 27:33:14a link in the description with a coupon
  43452. 27:33:16code if you are interested. Thank you
  43453. 27:33:18guys so much for watching and I will see
  43454. 27:33:20you in the next lesson.
  43455. 27:33:24>> [music]
  43456. 27:33:34>> Hello everybody. In this lesson, we're
  43457. 27:33:35going to see how we can group and
  43458. 27:33:37aggregate our data in R. Now, we're
  43459. 27:33:40working with the exact same data set
  43460. 27:33:41that we were in the previous lessons,
  43461. 27:33:43but if you don't have it yet, then you
  43462. 27:33:45can get this data set down below in the
  43463. 27:33:47GitHub. You just have to download it and
  43464. 27:33:48you'll be able to work with it along
  43465. 27:33:50with me. Now, we also need this library
  43466. 27:33:53dlier. Let's go ahead and run both of
  43467. 27:33:55these. So, we've loaded our library and
  43468. 27:33:58we've read in our file. Let's open up
  43469. 27:34:01our file so we can take a look. Here we
  43470. 27:34:03have our character. We have the
  43471. 27:34:05department that they work in, their
  43472. 27:34:06role, their annual salary, and dogs
  43473. 27:34:09rescued with three legs. What we're
  43474. 27:34:13going to be doing is we're going to be
  43475. 27:34:14grouping on our data and then looking at
  43476. 27:34:16aggregations. For example, we have a lot
  43477. 27:34:19of people who work in the parks
  43478. 27:34:21department. And let's say we want to
  43479. 27:34:23know what's the average salary of
  43480. 27:34:25someone who works at the parks
  43481. 27:34:26department. Right now, just looking at
  43482. 27:34:28this data, we don't know. We could kind
  43483. 27:34:30of guess maybe it's, I don't know, like
  43484. 27:34:3350ome thousand, but we don't know for
  43485. 27:34:35certain. And so that's what group by and
  43486. 27:34:38aggregations in general within R are
  43487. 27:34:40used for. Let's go in here and let's see
  43488. 27:34:43how we can write this. In the last
  43489. 27:34:46lesson, we learned about the pipe
  43490. 27:34:47operator, and we're going to be using
  43491. 27:34:49that again. So, we're going to write it
  43492. 27:34:50just like this. We're going to take our
  43493. 27:34:52data frame, and then we're going to
  43494. 27:34:54write our group by first. So, the group
  43495. 27:34:56by says we want to take a specific
  43496. 27:34:58column, put it all into one row, and
  43497. 27:35:01then perform an aggregation on it. So,
  43498. 27:35:02our group by is grouping the values
  43499. 27:35:06right here in this department. So, let's
  43500. 27:35:08say group, and we're going to do
  43501. 27:35:09underscore by, and we're going to do
  43502. 27:35:11this based off of the department. And
  43503. 27:35:13then we'll use another pipe right here
  43504. 27:35:16and we'll go down. Now we need to
  43505. 27:35:18actually aggregate our data. Now we do
  43506. 27:35:20this with summarize. Summarize allows us
  43507. 27:35:24to use some median whatever it is and do
  43508. 27:35:28it on whatever column we choose. Now it
  43509. 27:35:30has to be except if we just use a count.
  43510. 27:35:33Typical aggregations need to be on some
  43511. 27:35:34type of numeric column. Now I'm going to
  43512. 27:35:37show you the one where we don't have to
  43513. 27:35:38do that. That would just be n. That's
  43514. 27:35:41going to be account. And let's run this.
  43515. 27:35:44So you're going to see right down here
  43516. 27:35:45in our output we have city management,
  43517. 27:35:47health, and parks. So we have two, one,
  43518. 27:35:50and then seven. This is just getting a
  43519. 27:35:53count. So we don't have to specify a
  43520. 27:35:57column that's numeric because we're just
  43521. 27:35:59counting the rows. We're not counting a
  43522. 27:36:01specific column. You'll also notice that
  43523. 27:36:04we have this n and then in parentheses
  43524. 27:36:07for our column name. If we were to save
  43525. 27:36:09this to a dataf frame, then it would
  43526. 27:36:11have n with the uh parenthesis like
  43527. 27:36:14that. We can change that by saying count
  43528. 27:36:16is equal to. So we're going to assign
  43529. 27:36:18these counts and sign it the name of
  43530. 27:36:21count. So if you run this now, we have
  43531. 27:36:24count right here. Now that is the most
  43532. 27:36:27simple one. It's just a classic count.
  43533. 27:36:30But let's take a look at let's say an
  43534. 27:36:32average. So we're going to copy this.
  43535. 27:36:35And now we're going to get the average
  43536. 27:36:37of the salary. So we're going to say
  43537. 27:36:40mean and mean means average uh within R.
  43538. 27:36:44And then we're going to do annual
  43539. 27:36:47salary. Now if we run this, we're going
  43540. 27:36:51to take a look at the average salaries
  43541. 27:36:53within each department. So within our
  43542. 27:36:56parks departments, 54,571.
  43543. 27:36:59Health only has one person as we know.
  43544. 27:37:01So that's going to be 60,000. And then
  43545. 27:37:04city management is 90,000. This is
  43546. 27:37:07something that is really important when
  43547. 27:37:08you're doing aggregations because right
  43548. 27:37:10here, if you only had this information,
  43549. 27:37:13you don't really know how many people
  43550. 27:37:16are in each of these departments. Maybe
  43551. 27:37:18it's only two people, maybe it's three,
  43552. 27:37:19maybe it's 100, maybe it's 10,000. It is
  43553. 27:37:22important to know when you're doing
  43554. 27:37:23aggregations, especially with something
  43555. 27:37:25like an average, how many numbers or how
  43556. 27:37:28many data points are behind these
  43557. 27:37:29numbers. we are actually able to add
  43558. 27:37:33multiple. So if I put a comma there,
  43559. 27:37:36then I go right down here and I say
  43560. 27:37:38count of is equal to the n. I can run
  43561. 27:37:42this. And in this aggregation, it
  43562. 27:37:45doesn't change the department or the
  43563. 27:37:46annual salary. But now we have an
  43564. 27:37:48additional aggregation that we've added.
  43565. 27:37:51And we can do that for as many as we'd
  43566. 27:37:52like. We can do three, four, five, six,
  43567. 27:37:55seven different types of aggregations.
  43568. 27:37:56That would be perfectly acceptable. So,
  43569. 27:37:59let's take a look at some other
  43570. 27:38:00aggregations, and we're just going to
  43571. 27:38:01add them in here. And we can always name
  43572. 27:38:03them. This one, of course, says mean
  43573. 27:38:04annual salary, but I could call this uh
  43574. 27:38:07average
  43575. 27:38:11salary is equal to,
  43576. 27:38:14and I need to find that equal to. And
  43577. 27:38:17then when we run this in just a second,
  43578. 27:38:18it will work. But we have other types of
  43579. 27:38:20aggregations. We can do the minimum of
  43580. 27:38:24our annual salary. And if we run this,
  43581. 27:38:26it'll give us the smallest salary within
  43582. 27:38:30each department. So we have department
  43583. 27:38:33average salary right here, the count,
  43584. 27:38:35and then we have our minimum salary.
  43585. 27:38:37Here's the minimum amount that someone
  43586. 27:38:38makes in each of these. Conversely, we
  43587. 27:38:41can also do the maximum salary. Let's go
  43588. 27:38:43ahead and
  43589. 27:38:46do the max. And we're just going to keep
  43590. 27:38:48stacking these aggregations all on the
  43591. 27:38:50department. But this is the most that
  43592. 27:38:52somebody makes within that department.
  43593. 27:38:54Now, we also have another interesting
  43594. 27:38:56one, and this is one that I think gets
  43595. 27:38:58overlooked a lot, but that's going to be
  43596. 27:39:00median. Median gets the exact middle
  43597. 27:39:02point of your aggregation. So, let's put
  43598. 27:39:05in annual salary here. And I'll explain
  43599. 27:39:08this in just a sec. I'm actually getting
  43600. 27:39:10a few too many of these aggregations.
  43601. 27:39:12Let's put this into a data frame. So,
  43602. 27:39:13I'm going to say aggregation data frame.
  43603. 27:39:16We're going to assign this. And let's
  43604. 27:39:18run this right here. And let's open it
  43605. 27:39:21up. So, here we have our median annual
  43606. 27:39:25salary and this says 90,000. Let's go
  43607. 27:39:28back and let's take a look. Let's just
  43608. 27:39:31take a look at city management. This
  43609. 27:39:34only has two values. If it had three
  43610. 27:39:37values, it would take the one in the
  43611. 27:39:39middle, but we only have two. So, what
  43612. 27:39:42it does is it takes those two middle
  43613. 27:39:44points. It takes the average of those
  43614. 27:39:46two middle points, which is going to be
  43615. 27:39:4790,000. Now, 60,000, we already know
  43616. 27:39:50what happens there. But 52,000 is the
  43617. 27:39:53one that's interesting to us. So let's
  43618. 27:39:55order by the salary, then the
  43619. 27:39:57department. So now we have 25,000 all
  43620. 27:40:00the way up to 90. So we have 1 2 3 4 5 6
  43621. 27:40:047. 7 is an odd number, which means it
  43622. 27:40:06has a middle point, which is going to be
  43623. 27:40:08four. So if we go 1 2 3 and four, this
  43624. 27:40:12is the middle point of our data. If we
  43625. 27:40:15go back to this data frame, 52,000 is
  43626. 27:40:18our median right here. Now, as I've
  43627. 27:40:20gotten more into data analysis and
  43628. 27:40:22working with numbers, I find myself
  43629. 27:40:24using median a lot because average has
  43630. 27:40:27the possibility, it doesn't always, but
  43631. 27:40:29it has a possibility of skewing some
  43632. 27:40:30numbers. Let's say, for example, in our
  43633. 27:40:33data frame, we had Ron Swanson and he's
  43634. 27:40:36making $10 million or $100 million.
  43635. 27:40:40If we went and aggregated and just
  43636. 27:40:42looked at the average, the average would
  43637. 27:40:44be like $20 million or something like
  43638. 27:40:46that. I don't know. I'm just throwing
  43639. 27:40:47out a number, but the average would be
  43640. 27:40:49insanely high, but only one person
  43641. 27:40:52actually makes that much in the
  43642. 27:40:53department. If we took a look at the
  43643. 27:40:55median, the median is still going to be
  43644. 27:40:5852,000 because that's the middle point
  43645. 27:41:00of the data. And so depending on what
  43646. 27:41:02type of analysis you're doing, depending
  43647. 27:41:04on what you're looking for, average and
  43648. 27:41:06median can show you and give you
  43649. 27:41:07different insights into the data. So,
  43650. 27:41:09it's just one to be aware of and to use
  43651. 27:41:11wisely. Let's go back and take a look at
  43652. 27:41:14our data. And so that is how we group
  43653. 27:41:17and aggregate our data. And again, you
  43654. 27:41:19can do multiple aggregations. If you
  43655. 27:41:21want to go even more in depth on
  43656. 27:41:22grouping and aggregating data within R,
  43657. 27:41:24I have a full R for data analytics
  43658. 27:41:26course on analystbuilder.com. I will
  43659. 27:41:28have a link in the description if you
  43660. 27:41:29want to check it out, as well as a
  43661. 27:41:31coupon code just in case you want to
  43662. 27:41:32take it. With that being said, I hope
  43663. 27:41:34that this was helpful. I hope that you
  43664. 27:41:35learned something and I will see you in
  43665. 27:41:36the next [music] lesson.
  43666. 27:41:50Hello everybody. In this lesson, we're
  43667. 27:41:51going to see how we can handle missing
  43668. 27:41:53data within our data set. Now, in order
  43669. 27:41:55to do this, we're going to be working
  43670. 27:41:56with a new data set. It's called the
  43671. 27:41:58messy data set. You can get that down in
  43672. 27:42:00the GitHub. I'll have a link in the
  43673. 27:42:02description. We're going to need a new
  43674. 27:42:04library for this called TidyR. This is
  43675. 27:42:06part of the tidyiverse and they have
  43676. 27:42:07functions that are specifically created
  43677. 27:42:09for cleaning up data. And so we're going
  43678. 27:42:11to be using that in the next several
  43679. 27:42:12lessons as we look at different things
  43680. 27:42:14that we need to do in order to clean up
  43681. 27:42:16data. If you haven't already installed
  43682. 27:42:18it, you can just install it like this.
  43683. 27:42:20It's install.packages and then tidyverse
  43684. 27:42:23in quotes. And then you'll have access
  43685. 27:42:25to tidyr.
  43686. 27:42:27It'll look just like this. But I'm going
  43687. 27:42:29to go ahead and get rid of this because
  43688. 27:42:31I have it right down here for you. Now,
  43689. 27:42:33let's go ahead and bring in our data
  43690. 27:42:35set. We'll take a look at it. So, I'm
  43691. 27:42:36just going to run everything really
  43692. 27:42:37quickly, and we're going to take a look
  43693. 27:42:40at our data set. So, going through our
  43694. 27:42:41data really quickly, we have customer
  43695. 27:42:43ID, customer name, email, transaction
  43696. 27:42:46amount, transaction date, and category.
  43697. 27:42:49Now, when I'm looking through this, I
  43698. 27:42:51can just at a glimpse see very easily
  43699. 27:42:54that there's several issues. One, we
  43700. 27:42:56have some null data. So, there isn't any
  43701. 27:42:59data in here. Now, these look a little
  43702. 27:43:01bit different than this in the
  43703. 27:43:03transaction amount, numeric versus
  43704. 27:43:04string. We'll take a look at that in a
  43705. 27:43:06little bit. We also have a transaction
  43706. 27:43:08date, and these are all different types
  43707. 27:43:10of formats, and that doesn't look good.
  43708. 27:43:11So, we need to fix that up. We also have
  43709. 27:43:13a category, and in this category, we
  43710. 27:43:15have capital electronics, lowercase
  43711. 27:43:17electronics, and maybe some different
  43712. 27:43:19spellings as well in here. So, we need
  43713. 27:43:21to clean these things up. These are all
  43714. 27:43:23things that if I was working with this
  43715. 27:43:25in a real data set, I would be taking a
  43716. 27:43:27look at these, trying to standardize
  43717. 27:43:29dates, as well as take a look at this
  43718. 27:43:31data and see, do we want to do something
  43719. 27:43:33with NLES or the blanks? Cuz sometimes
  43720. 27:43:35we do, sometimes we don't. So, let's
  43721. 27:43:37come right back over here. We're not
  43722. 27:43:38going to get to everything in this
  43723. 27:43:40lesson because, you know, they do have
  43724. 27:43:42different use cases. We're just going to
  43725. 27:43:43be looking at missing data. So, to get
  43726. 27:43:47started, let's come right down here. And
  43727. 27:43:49what we're going to do is we're going to
  43728. 27:43:50check our null values within our data
  43729. 27:43:53set. So what we're going to do is we're
  43730. 27:43:54going to do call and then sums and we're
  43731. 27:43:56going to take a look and it's basically
  43732. 27:43:57just going to summarize uh we're going
  43733. 27:43:59to do is na and then pass to our data
  43734. 27:44:02frame. We're just going to summarize for
  43735. 27:44:04each column which ones have no values or
  43736. 27:44:07blank values. Let's go ahead and run
  43737. 27:44:09this. Now you'll notice on here we have
  43738. 27:44:11customer ID, customer name, email,
  43739. 27:44:13transaction amount, but we have no
  43740. 27:44:15blanks in these columns. But if we look
  43741. 27:44:19back here, we know that in customer name
  43742. 27:44:21and in email, we have blanks. Uh we see
  43743. 27:44:24them, but it's only showing up for
  43744. 27:44:27transaction amount. Now, that has to do
  43745. 27:44:29with just how it was pulled in as a data
  43746. 27:44:32set. Now, we can actually fix this very
  43747. 27:44:35easily by coming in here and passing
  43748. 27:44:37through a parameter called NA.
  43749. 27:44:43This is going to take the blank fields
  43750. 27:44:45and make them NA. So, we're just going
  43751. 27:44:47to hit tab and we're going to pass
  43752. 27:44:49through a vector here and we're just
  43753. 27:44:50going to say if it's blank then, comma,
  43754. 27:44:55make it NA. That's all we're doing. So,
  43755. 27:44:57for these blank strings, if they're
  43756. 27:44:59blank, we want to make them NA. Let's
  43757. 27:45:02read this in again. We'll overwrite our
  43758. 27:45:04previous data set. Now, let's look at
  43759. 27:45:06our data frame. And now, you'll see that
  43760. 27:45:08these are NA as well. This is just
  43761. 27:45:10something that sometimes you have to do
  43762. 27:45:12kind of somewhat manually. you have to
  43763. 27:45:14specify you want that to be done. But
  43764. 27:45:16now if we run this, you'll see we have
  43765. 27:45:19one, one, and two. So this is a lot more
  43766. 27:45:21accurate. Now, within this data,
  43767. 27:45:24sometimes what you're going to want to
  43768. 27:45:25do is just get rid of it. So for
  43769. 27:45:27example, let's say we're creating an
  43770. 27:45:29email list and we say we have to have
  43771. 27:45:31this email available, otherwise this
  43772. 27:45:33data is just not useful to us at all. So
  43773. 27:45:36what we want to do is we want to
  43774. 27:45:37actually get rid of this data. So, what
  43775. 27:45:40we're going to do is let's come right
  43776. 27:45:42down here and let's create we'll do
  43777. 27:45:45dataf frame cleaned. We're just going to
  43778. 27:45:46create a new dataf frame. But all we're
  43779. 27:45:49going to do is we're going to drop that
  43780. 27:45:52row if it is blank. So, we're going to
  43781. 27:45:54say uh we can take the data frame and
  43782. 27:45:57we'll use a pipe here. Then we're going
  43783. 27:45:59to say drop na. And that's right here.
  43784. 27:46:02And you can see it uses this tidy r. And
  43785. 27:46:05it's just going to drop the rows where
  43786. 27:46:06any column specified contains a missing
  43787. 27:46:08value. So, we're going to come here and
  43788. 27:46:10we're going to specify the email column.
  43789. 27:46:12And if you remember, we have this email
  43790. 27:46:14right here. So, let's go ahead. Let's
  43791. 27:46:17run this. Let's take a look. You'll
  43792. 27:46:19notice we have one less row. Let's take
  43793. 27:46:21a look at the data frame cleaned. And
  43794. 27:46:23we'll compare. So, now we only have 11
  43795. 27:46:27rows of data compared to the 12 before.
  43796. 27:46:30And now we don't have this customer ID
  43797. 27:46:32109, which is uh Helen Carter. We have
  43798. 27:46:36109 completely gone. And so we just got
  43799. 27:46:39rid of that data. That is a perfectly
  43800. 27:46:41acceptable thing to do depending on the
  43801. 27:46:43use case for your data. Our use case was
  43802. 27:46:45we're creating an email list. It's
  43803. 27:46:47pretty hard to give an email list to
  43804. 27:46:50somebody to email out if that person
  43805. 27:46:51doesn't have an email. So we just got
  43806. 27:46:54rid of it. And that is a perfectly
  43807. 27:46:56acceptable thing to do. And I'm actually
  43808. 27:46:58going to put up here. I'm going to say
  43809. 27:46:59uh remove rows when no email is present.
  43810. 27:47:06Now another thing that we could do is we
  43811. 27:47:09could actually fill in this data. So for
  43812. 27:47:12example we have transaction amount and
  43813. 27:47:15let's say we need to use this
  43814. 27:47:17transaction amount. For example in
  43815. 27:47:19transaction amount let's assume that
  43816. 27:47:21when it has na it's actually a zero. It
  43817. 27:47:24means there was zero transaction amount
  43818. 27:47:27paid here. Maybe they got a full
  43819. 27:47:29discount but this would be contextual.
  43820. 27:47:31It would be we know that when it says NA
  43821. 27:47:33it's supposed to be a zero. So we just
  43822. 27:47:35want to populate this with a zero. Now
  43823. 27:47:37this makes a big difference when you
  43824. 27:47:39start doing aggregations on it. Now we
  43825. 27:47:41looked at aggregations and grouping.
  43826. 27:47:43When you have a zero in here, that zero
  43827. 27:47:44is going to be counted in that
  43828. 27:47:46aggregation. And so if you just did 0
  43829. 27:47:49and 99, then the average is going to be
  43830. 27:47:52about a 50. If we have NA here, this
  43831. 27:47:55does not count towards the aggregation.
  43832. 27:47:57So it would just be 99.99.
  43833. 27:48:00So let's go ahead and do that first
  43834. 27:48:01option. Let's go through here and let's
  43835. 27:48:04populate these with zeros. Let's say
  43836. 27:48:06that's our use case for what we're
  43837. 27:48:08doing. So, we need to take this column,
  43838. 27:48:11this transaction amount. So, we're going
  43839. 27:48:14to come right down here. We're going to
  43840. 27:48:15say data frame. Then, we're going to do
  43841. 27:48:17a dollar sign, and this is just a
  43842. 27:48:18shortcut of specifying the column name.
  43843. 27:48:20We're going to do transaction amount.
  43844. 27:48:22And we just want to say when the
  43845. 27:48:24transaction amount is null, then
  43846. 27:48:27populate it with zero. So, we're going
  43847. 27:48:29to create a bracket here. We're going to
  43848. 27:48:31do is na and we're going to pass through
  43849. 27:48:34this exact column. So we can just copy
  43850. 27:48:36this. So we're saying when this column
  43851. 27:48:38is blank then what are we going to do?
  43852. 27:48:41We're going to populate it with a zero.
  43853. 27:48:43And that's it. So let's go ahead and
  43854. 27:48:45actually real quick let's do this on
  43855. 27:48:47dataf frame cleaned. Glad I caught that.
  43856. 27:48:49Otherwise we'd be doing that to our
  43857. 27:48:51original dataf frame. So let's go ahead
  43858. 27:48:53and run this and let's go back to our
  43859. 27:48:56dataf frame cleaned. And you'll see 0.00
  43860. 27:48:590 0 and 0.00.
  43861. 27:49:02And that is fantastic. When we go to
  43862. 27:49:04aggregate this, these zeros are going to
  43863. 27:49:06be counted because now they're numbers.
  43864. 27:49:08They're not null. Now, sometimes that's
  43865. 27:49:10not what we want to do. Maybe we know
  43866. 27:49:12that NA means it just didn't take the
  43867. 27:49:15data incorrectly, but we want to count
  43868. 27:49:17it as an actual sale. We know that it
  43869. 27:49:20wasn't zero. It's a nonzero number.
  43870. 27:49:22Maybe it was 50, maybe it was 100. We
  43871. 27:49:24don't know. But we don't want to
  43872. 27:49:26populate it with a zero because that's
  43873. 27:49:27going to bring down our averages and we
  43874. 27:49:29know that can't be correct. So what if
  43875. 27:49:31we just wanted to populate it with the
  43876. 27:49:33average value? We can definitely do that
  43877. 27:49:36as well. Let's come back here and let's
  43878. 27:49:39redo this really quick. Let's overwrite
  43879. 27:49:42and we're going to go like this. It
  43880. 27:49:45should bring us back to how it was
  43881. 27:49:47before. So this is just the first option
  43882. 27:49:50to populate
  43883. 27:49:53null
  43884. 27:49:55numeric values.
  43885. 27:49:58Now we'll have our second option. So
  43886. 27:50:00we're going to take this column again,
  43887. 27:50:02this data frame cleaned. And in fact, we
  43888. 27:50:05need this whole thing. So let's just
  43889. 27:50:06copy this down.
  43890. 27:50:08And we're going to populate it by going
  43891. 27:50:11like this. And now we're going to say
  43892. 27:50:13take the mean of the transaction amount.
  43893. 27:50:16So we're going to say mean and then
  43894. 27:50:18we're going to pass through
  43895. 27:50:21just the transaction amount. So let's
  43896. 27:50:22get rid of this and let's make sure we
  43897. 27:50:26have our wrap on so we can see it all.
  43898. 27:50:29So now we're taking the average of this
  43899. 27:50:31column. Let's go ahead and run this and
  43900. 27:50:35take a look. Now, it isn't populating
  43901. 27:50:37it. And I have a feeling we need to pass
  43902. 27:50:39through another parameter here,
  43903. 27:50:43which is na.rm.
  43904. 27:50:46It's basically going to say when you're
  43905. 27:50:48taking this, make sure and check that
  43906. 27:50:50it's the correct one. Otherwise, it may
  43907. 27:50:52not evaluate it to NA when that is what
  43908. 27:50:55we're looking for. So, we want to say
  43909. 27:50:56that's equal to true. And we're going to
  43910. 27:50:59run it just like this.
  43911. 27:51:02And now we have these values populated.
  43912. 27:51:04Now, if we go back at Charlie Brown, he
  43913. 27:51:07had NA and so did Ian Brooks. So, let's
  43914. 27:51:10come right here. We have 180.2656.
  43915. 27:51:13180.2656.
  43916. 27:51:15Now, when we run this, these people, Ian
  43917. 27:51:18Brooks and Charlie Brown are going to be
  43918. 27:51:20included in the aggregation, but they
  43919. 27:51:22won't change the number if we're just
  43920. 27:51:23looking at averages. Now, if we start
  43921. 27:51:25doing other things and other types of
  43922. 27:51:27aggregations, of course, it's going to
  43923. 27:51:29change the output, but we're looking at
  43924. 27:51:30specifically for averages. these people
  43925. 27:51:32will be included and we can also run
  43926. 27:51:34counts on them to know this is how many
  43927. 27:51:36sales or counts we made. So that is very
  43928. 27:51:38much an option, but you need to be
  43929. 27:51:40really really confident that what you're
  43930. 27:51:42filling in is accurate and useful for
  43931. 27:51:44your analysis down the line. You don't
  43932. 27:51:46want to put this in here and maybe just
  43933. 27:51:48leave it in there because someone coming
  43934. 27:51:50behind you is not going to understand
  43935. 27:51:51that that's what that is. So you always
  43936. 27:51:54want to keep an original data frame. You
  43937. 27:51:56always want to kind of document what
  43938. 27:51:58you're doing and why you're doing it
  43939. 27:51:59because otherwise your analysis might
  43940. 27:52:01not make sense down the line. Now, some
  43941. 27:52:03other data that is missing is right
  43942. 27:52:05here. This is a customer name. Now, we
  43943. 27:52:08don't have this full customer name and
  43944. 27:52:10maybe we don't have another data set or
  43945. 27:52:12another part of our database where we
  43946. 27:52:14can pull that in. And maybe we just want
  43947. 27:52:16to pull in Emma. Maybe that's all we
  43948. 27:52:18know and that's all we want to do. But,
  43949. 27:52:21you know, people's emails aren't always
  43950. 27:52:23accurate. So maybe we just want to fill
  43951. 27:52:25this in with unknown. We know that the
  43952. 27:52:28customer has a name. Everybody has a
  43953. 27:52:30name. We just don't know it. And that
  43954. 27:52:32isn't necessarily the most important
  43955. 27:52:34part of the data. They can still reach
  43956. 27:52:36out to this person via email and say,
  43957. 27:52:38"Hey, customer or whatever it is." So
  43958. 27:52:40we're going to put unknown here. And
  43959. 27:52:42this would be something that we would
  43960. 27:52:43have. And this is a small data set. But
  43961. 27:52:46let's imagine we have a 100,000 rows of
  43962. 27:52:47data. Maybe there's, you know, 200, 500,
  43963. 27:52:50a thousand people with no customer name.
  43964. 27:52:52we now can just specify that and so we
  43965. 27:52:55keep it in the data set but it isn't
  43966. 27:52:57just blank. And so let's see how we can
  43967. 27:52:59do that. We're going to come here to
  43968. 27:53:02dataf frame and let's actually pull it
  43969. 27:53:04in just like this.
  43970. 27:53:07Whoops. I'm just messing up here. Let's
  43971. 27:53:09pull in this dataf frame cleaned. And
  43972. 27:53:11now we're going to do customer name.
  43973. 27:53:14Isn't that what it's called? Yeah,
  43974. 27:53:15customer_enamed.
  43975. 27:53:17And let's pull it in right here. Now
  43976. 27:53:18we're going to do the same thing. We're
  43977. 27:53:20going to say if it's blank. So, we're
  43978. 27:53:21going to do is na and then we're going
  43979. 27:53:24to push in here or or pass through in
  43980. 27:53:27here our customer name just like we
  43981. 27:53:29wrote it. If it's blank, then instead of
  43982. 27:53:32a number, we're going to do unknown.
  43983. 27:53:36And so that's it. We're checking if it's
  43984. 27:53:38blank and we're passing through unknown
  43985. 27:53:41if it's not. This again safeguards
  43986. 27:53:43against other things you might do later
  43987. 27:53:46on when working with this data set.
  43988. 27:53:48Sometimes when you're working with nulls
  43989. 27:53:49and you're putting it into a CSV or you
  43990. 27:53:51put it into a data set, those get
  43991. 27:53:52dropped. I know for I know for instance
  43992. 27:53:56that if you put certain data that has
  43993. 27:53:58blanks into something like my SQL, those
  43994. 27:54:00rows just get dropped in some instances.
  43995. 27:54:02And so you want to be careful about
  43996. 27:54:04leaving things blank. Even though it's,
  43997. 27:54:06you know, inconspicuous, it's just a
  43998. 27:54:07customer name. We don't need it.
  43999. 27:54:09Sometimes you just want to populate it
  44000. 27:54:10just to make sure that if it's been put
  44001. 27:54:12in other systems, it doesn't get dropped
  44002. 27:54:14or deleted in some way. And so these are
  44003. 27:54:16some of the ways that you can handle
  44004. 27:54:18missing data within AR and within your
  44005. 27:54:20data frame. We're going to call this one
  44006. 27:54:22populating text or character
  44007. 27:54:27columns. And so I hope that this was
  44008. 27:54:29helpful. If you haven't checked it out
  44009. 27:54:30already, I have a full course on R for
  44010. 27:54:32data analytics. We go even more in depth
  44011. 27:54:34into handling missing data as well as a
  44012. 27:54:35bunch of other data cleaning techniques.
  44013. 27:54:37I will leave a link in the description
  44014. 27:54:38as well as a coupon code if you would
  44015. 27:54:40like to check that out. But with that
  44016. 27:54:41being said, thank you guys so much for
  44017. 27:54:43watching. If you like this video, be
  44018. 27:54:44sure to like and subscribe below and I
  44019. 27:54:46will see you [music] in the next video.
  44020. 27:54:48[snorts]
  44021. 27:55:00Hello everybody. In this lesson, we're
  44022. 27:55:01going to be taking a look at parsing and
  44023. 27:55:03converting dates in an R dataf frame.
  44024. 27:55:05We're going to be using this lubricate
  44025. 27:55:07package right here. You can use library
  44026. 27:55:09and lubricate to load in that package
  44027. 27:55:12that we can use it. We're going to be
  44028. 27:55:14using the exact same data set from our
  44029. 27:55:16last lesson. If you haven't already
  44030. 27:55:18gotten that from the GitHub, I'll have
  44031. 27:55:20the GitHub below so you can go ahead and
  44032. 27:55:21download it. And then we're going to
  44033. 27:55:23import it exactly as we have it right
  44034. 27:55:25here. This is what our data frame looks
  44035. 27:55:27like. And we're going to be specifically
  44036. 27:55:29looking at this transaction date. In
  44037. 27:55:31here, you can see we have a ton of
  44038. 27:55:33different formats. And that's not a good
  44039. 27:55:35thing. uh that is a bad thing because if
  44040. 27:55:37we want to use this, let's just say we
  44041. 27:55:39wanted to use dates in order to create a
  44042. 27:55:41line chart, so a time series plot or
  44043. 27:55:44something like that. Well, if the data
  44044. 27:55:46sits like this, it's not going to work.
  44045. 27:55:48Or if you want to aggregate it on or if
  44046. 27:55:50you want to parse it out or if you want
  44047. 27:55:52to do anything, you can't really do that
  44048. 27:55:54with how it sits right here. Now, this
  44049. 27:55:56is a very exaggerated view of this. It
  44050. 27:55:59normally doesn't look like this, but
  44051. 27:56:01let's say, for example, you're pulling
  44052. 27:56:03data from a database in two separate
  44053. 27:56:05parts and you're putting into one output
  44054. 27:56:06and you're outputting it to a CSV. I've
  44055. 27:56:09seen it a 100 times where you have two
  44056. 27:56:11different types of transaction dates.
  44057. 27:56:12Ones like this and ones like this. And
  44058. 27:56:15they both are technically dates and
  44059. 27:56:17they're being stored, but they're being
  44060. 27:56:18stored differently. And so, this is
  44061. 27:56:19something that we want to clean up and
  44062. 27:56:21we want to standardize so they're all
  44063. 27:56:23looking the same in the same format. And
  44064. 27:56:25Lubdate is very helpful with this. And
  44065. 27:56:27what we're going to do is come right
  44066. 27:56:28back here. We're going to run our code
  44067. 27:56:32so that we pull in that data frame. And
  44068. 27:56:34now we can start working with it. So
  44069. 27:56:35we're going to specify. We're going to
  44070. 27:56:37do data frame. The dollar sign is just a
  44071. 27:56:39shortcut to specify our column. We're
  44072. 27:56:41going to choose our transaction date.
  44073. 27:56:43Now what we want to do is we want to
  44074. 27:56:47first standardize all of them and then
  44075. 27:56:50later we're going to parse them out into
  44076. 27:56:53day, month, year, whatever we want
  44077. 27:56:55because that can be very helpful as
  44078. 27:56:56well. So the first thing that we're
  44079. 27:56:58going to do is we're going to use parse
  44080. 27:57:01date and let's see if it comes up right
  44081. 27:57:03here. Parse date time. This is from the
  44082. 27:57:05lubber date package as you can see right
  44083. 27:57:07here and it basically is just a really
  44084. 27:57:09helpful function to help standardize
  44085. 27:57:11your dates. So let's go ahead and click
  44086. 27:57:12on this and we need to pass through as
  44087. 27:57:15one of the uh as one of our arguments
  44088. 27:57:18you need to pass through what column
  44089. 27:57:20we're actually working on. But now we
  44090. 27:57:22need to pass through orders. So for
  44091. 27:57:25parse date time this orders allows us to
  44092. 27:57:27specify different formats that our dates
  44093. 27:57:30are going to be in and then it
  44094. 27:57:32standardizes them for us. So we're going
  44095. 27:57:34to say orders here. We're going to say
  44096. 27:57:36that's equal to. Now, let's make sure we
  44097. 27:57:38have the soft wrap lines on uh just in
  44098. 27:57:41case it gets long. Or we could just pull
  44099. 27:57:43it down here. But what we need to do is
  44100. 27:57:47we're going to pass through a vector and
  44101. 27:57:50we just need to specify what different
  44102. 27:57:52formats are we actually working with
  44103. 27:57:54here because we have year, that's month
  44104. 27:57:57and day. This one, and those are dashes,
  44105. 27:57:59and then we have month, day, year with
  44106. 27:58:02these forward slashes. And so we need to
  44107. 27:58:05just kind of go through here and see
  44108. 27:58:07what different formats we have and it'll
  44109. 27:58:08standardize them. So let's do this first
  44110. 27:58:11one. It's year, month, and day with
  44111. 27:58:13dashes in between them. So we're going
  44112. 27:58:15to do capital Y for the year, month, and
  44113. 27:58:19day. And of course, this needs to be
  44114. 27:58:21within quotes. Let's make sure we get
  44115. 27:58:23that. Let me go back. There we go. But
  44116. 27:58:26let's put a quote right here. And there
  44117. 27:58:29we go. And now we can just do that and
  44118. 27:58:31separate them by commas. Let's run this
  44119. 27:58:33one actually
  44120. 27:58:36and let's come in here and you'll see
  44121. 27:58:39that now we have one and those are all
  44122. 27:58:42standardized and all working correctly.
  44123. 27:58:44We're getting a message down here saying
  44124. 27:58:46seven failed to parse. This is just a
  44125. 27:58:48message saying hey we did some of them
  44126. 27:58:51correctly but there's a bunch that
  44127. 27:58:53didn't work correctly and this is a very
  44128. 27:58:54helpful hint for us. This is kind of a
  44129. 27:58:56message that's saying hey you didn't get
  44130. 27:58:58them all so be sure to go back. Now that
  44131. 27:59:00isn't all of them. So, let's reread our
  44132. 27:59:03data frame since we overwrote that. Uh,
  44133. 27:59:06but let's look at our data frame and
  44134. 27:59:07let's do some of these other formats as
  44135. 27:59:09well. So, for that one, we're going to
  44136. 27:59:12do a comma and then we're going to say
  44137. 27:59:15month slash dayward slashyear and then
  44138. 27:59:19we'll look at another one. So, let's
  44139. 27:59:21come in here. We have another one with
  44140. 27:59:23slashes or forward slashes, but this one
  44141. 27:59:25is a different direction. We have year,
  44142. 27:59:28month, and day. So, let's make sure we
  44143. 27:59:30get this one as well. So we'll do year
  44144. 27:59:32that's a forward slashmon and day. Now
  44145. 27:59:36one thing and this is just I just know
  44146. 27:59:38this is this right here isn't actually
  44147. 27:59:41text. It is still a date although it has
  44148. 27:59:44text in it. It's still being stored as a
  44149. 27:59:46date properly but it has a different way
  44150. 27:59:48it's displaying it. So on the back end
  44151. 27:59:50it could actually look like this but
  44152. 27:59:53it's displaying like this. So what we're
  44153. 27:59:56going to do is let's run this one and
  44154. 27:59:57see what happens. And we got one that
  44155. 28:00:00failed to parse. So let's come back
  44156. 28:00:02here. So this Grace Adams is the only
  44157. 28:00:05one that failed to parse. Let's come up
  44158. 28:00:08here. Let's run this again. And let's
  44159. 28:00:11create a duplicate of this. We're just
  44160. 28:00:12going to do dataf frame raw. And we're
  44161. 28:00:15just going to pass through the data
  44162. 28:00:16frame just so we have it. Um so we can
  44163. 28:00:19compare. So we have our dataf frame raw.
  44164. 28:00:22And if we go back the one that didn't
  44165. 28:00:24work and let's run this one more time.
  44166. 28:00:27Sorry about that. The one that didn't
  44167. 28:00:29work was
  44168. 28:00:33right here. So that's gonna be Grace
  44169. 28:00:34Adams. Let's go through to Grace Adams.
  44170. 28:00:37And that's because this is a different
  44171. 28:00:39format than up here. Again, this is
  44172. 28:00:41year, month, day. This is day, month,
  44173. 28:00:45and year with dashes. So, let's come in
  44174. 28:00:47here. We're going to say day- month
  44175. 28:00:51dashy year. And we just need to rerun
  44176. 28:00:54our data frame so that we can rerun this
  44177. 28:00:56one one more time. Let's go ahead and
  44178. 28:00:57run this. And now we're not getting any
  44179. 28:01:00error message. So now if we go and we
  44180. 28:01:02look at our data frame, this looks just
  44181. 28:01:05beautiful. I mean, that is a thing of
  44182. 28:01:07beauty. Let's compare it to how it was
  44183. 28:01:08before. And I'm just going to go back
  44184. 28:01:11and forth. You can see that this one is
  44185. 28:01:14much more preferred, right? We now have
  44186. 28:01:16everything in one format that we want.
  44187. 28:01:18Now, after we get this, we can also
  44188. 28:01:21parse these dates out. So let's get rid
  44189. 28:01:24of this data frame raw. We don't need
  44190. 28:01:26that anymore. Now we can take this
  44191. 28:01:28transaction date and we can pull out the
  44192. 28:01:31year, the month, and the day. And we can
  44193. 28:01:33actually create new columns with this.
  44194. 28:01:35So what we can do is we'll take data
  44195. 28:01:37frame. But now we're not going to do
  44196. 28:01:39transaction date. We're going to do
  44197. 28:01:40transaction date
  44198. 28:01:42let's do year. And then we're going to
  44199. 28:01:46pass through. So for this new column,
  44200. 28:01:48we're going to take this transaction
  44201. 28:01:50date. But we only want the month. So
  44202. 28:01:53let's just make this month. And I
  44203. 28:01:55actually said year here. So let's
  44204. 28:01:57actually do year. This year is going to
  44205. 28:02:00extract just the year from here, which
  44206. 28:02:04is 2024 for all of them, I believe. And
  44207. 28:02:06it's going to make its own column. And
  44208. 28:02:09we can do this exact same thing with the
  44209. 28:02:12month.
  44210. 28:02:14Whoops. And the day. So we can say month
  44211. 28:02:18here. And then we have a function that's
  44212. 28:02:20month that's going to extract just the
  44213. 28:02:24month. And then of course we'll have one
  44214. 28:02:26as well for day
  44215. 28:02:29and we'll do day as well. So I'm going
  44216. 28:02:31to run both of these.
  44217. 28:02:34And if we come up here and go all the
  44218. 28:02:36way to the right now we have this all
  44219. 28:02:37broken out by the year, the month, and
  44220. 28:02:40the day. Zuber Date makes it really easy
  44221. 28:02:44to standardize and work with these dates
  44222. 28:02:46because there's a lot of different
  44223. 28:02:47reasons why you would want to actually
  44224. 28:02:49parse these out. It just depends on what
  44225. 28:02:51you're using it for in the future. And
  44226. 28:02:53so, I hope that this was helpful. If you
  44227. 28:02:56haven't already, I have a full course
  44228. 28:02:57where we'll dive a lot more into the
  44229. 28:02:59data cleaning process. So, if you want
  44230. 28:03:01to check that out, I'll have a link down
  44231. 28:03:02in the description as well as a coupon
  44232. 28:03:04code if you would like to use that. With
  44233. 28:03:06that being said, I hope you enjoyed this
  44234. 28:03:07video. Thank you guys so much for
  44235. 28:03:09watching. If you have not already, be
  44236. 28:03:10sure to like and subscribe, and I will
  44237. 28:03:12see you in the [music] next lesson.
  44238. 28:03:26Hello everybody. In this lesson, we're
  44239. 28:03:27going to see how we can remove
  44240. 28:03:28duplicates from a data set. Now, if you
  44241. 28:03:31have not been following along, you can
  44242. 28:03:33get this messy data set down in the
  44243. 28:03:34GitHub below. I'll have a link. You can
  44244. 28:03:36just download the CSV and you are good
  44245. 28:03:38to go. All we're going to need for this
  44246. 28:03:40lesson is our dlier. Let's go ahead and
  44247. 28:03:43run this whole thing. So, we get the
  44248. 28:03:44library and the data frame. And let's
  44249. 28:03:47open up our data frame. Now, at first
  44250. 28:03:49glance, even if you've been using this
  44251. 28:03:51data set in previous lessons when we
  44252. 28:03:53were looking at parsing and converting
  44253. 28:03:54dates as well as handling missing data,
  44254. 28:03:57you may not have noticed that we have
  44255. 28:03:58duplicates in here. We do. We have
  44256. 28:04:00duplicates right down here. We have
  44257. 28:04:02Alice Johnson and Alice Johnson. It just
  44258. 28:04:05wasn't something that maybe I pointed
  44259. 28:04:07out so maybe you just didn't notice. But
  44260. 28:04:09we have another duplicate which is we
  44261. 28:04:11have a customer ID here that's 104 and
  44262. 28:04:13we have another customer ID that's 104.
  44263. 28:04:15And typically within a data set like
  44264. 28:04:17this, this is going to be our unique ID.
  44265. 28:04:19This is our primary key. So we shouldn't
  44266. 28:04:21have duplicates for a customer ID. And
  44267. 28:04:24so there are a few things that we're
  44268. 28:04:26going to be doing within this in order
  44269. 28:04:28to make sure that we remove the correct
  44270. 28:04:30duplicates from our data set. So let's
  44271. 28:04:33come over here and the first thing that
  44272. 28:04:35we are going to do is we want to check
  44273. 28:04:37to see are there duplicate rows. So
  44274. 28:04:41we're going to take our data frame and
  44275. 28:04:43we'll just do it like this because it's
  44276. 28:04:45a little easier to read. And we're going
  44277. 28:04:46to do a distinct on it. So distinct,
  44278. 28:04:50it's going to keep only unique or
  44279. 28:04:52distinct rows from a data frame. And
  44280. 28:04:55that's it. It's pretty simple. And I
  44281. 28:04:57actually need to I don't think I wrote
  44282. 28:04:59that right. Uh we're going to run it
  44283. 28:05:01just like this. Keep it simple.
  44284. 28:05:03And as we go up, you'll notice we still
  44285. 28:05:06have the 104 and the 104 because it's
  44286. 28:05:10looking for a distinct across all
  44287. 28:05:12columns. So the only one that is the
  44288. 28:05:14same across all columns is Alice
  44289. 28:05:16Johnson. You'll see 101, Alice Johnson,
  44290. 28:05:18Alice J. Same transaction amount, same
  44291. 28:05:20transaction day, same category, same
  44292. 28:05:23everything. But 104 David Lee is not the
  44293. 28:05:27same as 104 Emma who made a different
  44294. 28:05:29purchase. We got those confused. So the
  44295. 28:05:32only true duplicate across all columns
  44296. 28:05:34is going to be Alice Johnson. Now we can
  44297. 28:05:37very easily remove the second Alice
  44298. 28:05:40Johnson because we can come right here.
  44299. 28:05:42We're just going to say dataf frame no
  44300. 28:05:46spell duplicates right. If you guys have
  44301. 28:05:49ever watched me, you know how terrible I
  44302. 28:05:51am at uh
  44303. 28:05:53at spelling. We're going to take our
  44304. 28:05:55data frame. We're going to look at the
  44305. 28:05:56distinct and that's going to get passed
  44306. 28:05:58through into this new data frame. So
  44307. 28:06:01let's run this. You'll see we have one
  44308. 28:06:03less. And so now we have this saved.
  44309. 28:06:06There's no more Alice Johnson. And so we
  44310. 28:06:09are doing really good. But what about
  44311. 28:06:13this 104 right here? Well, we can do it
  44312. 28:06:15kind of the easy way, which is just
  44313. 28:06:17saying, okay, we only want to keep one
  44314. 28:06:19of these people. And so we can actually
  44315. 28:06:22use this exact same syntax. And let's
  44316. 28:06:26get it over here just so it looks nice.
  44317. 28:06:28We'll do duplicates two here. And I'm
  44318. 28:06:30going to say take the distinct but only
  44319. 28:06:33of this one specific column customer ID.
  44320. 28:06:36So we're going to pass through I need to
  44321. 28:06:39spell this right. Customer ID. And when
  44322. 28:06:41we run this, let's go ahead and run it.
  44323. 28:06:46We're going to go like that. And now we
  44324. 28:06:48don't have any duplicates in our
  44325. 28:06:49customer ID. You're going to quickly
  44326. 28:06:51notice though we don't have the rest of
  44327. 28:06:54our data and that's not ideal. Let's
  44328. 28:06:56come right here and we're going to use
  44329. 28:06:59another argument which is keep all and
  44330. 28:07:02we'll do keep all. And you can go back
  44331. 28:07:04and check. It's just going to keep all
  44332. 28:07:06the other columns. And so we just want
  44333. 28:07:07to say true. By default it was false. So
  44334. 28:07:10we'll run this again in duplicates 2. We
  44335. 28:07:12now have all the columns and we got rid
  44336. 28:07:16of that second one. Now, was that
  44337. 28:07:18correct? I don't know. And there may be
  44338. 28:07:22a better methodology to actually keep to
  44339. 28:07:24actually determine which customer ID we
  44340. 28:07:27want to keep because this one doesn't
  44341. 28:07:28have a customer name. And if we go back
  44342. 28:07:31to right here, this person made a
  44343. 28:07:33purchase on 10 or the transaction date
  44344. 28:07:35at least on 104 of 2024. And this person
  44345. 28:07:39up here only made one on March, which is
  44346. 28:07:4135, which is before it. So, you might
  44347. 28:07:44want to incorporate some logic here to
  44348. 28:07:47say we actually want to take the person
  44349. 28:07:48with the most recent transaction date.
  44350. 28:07:51And we can do that. And that's actually
  44351. 28:07:53not super hard to do. So, let's come
  44352. 28:07:56here. Let's put this right down here.
  44353. 28:07:59We'll do we'll make this uh node
  44354. 28:08:02duplicates three.
  44355. 28:08:04We're going to take our data frame and
  44356. 28:08:07let's tab over here. We still want to
  44357. 28:08:10look at the customer ID and take the
  44358. 28:08:12distinct customer ID. We just want to
  44359. 28:08:14arrange it because it's taking it going
  44360. 28:08:16top down. It's saying, "Okay, keep that
  44361. 28:08:18one. If there's ever a duplicate down
  44362. 28:08:20here, get rid of it." Which is what it
  44363. 28:08:21did right here. It said, "Okay, keep
  44364. 28:08:23this one. Oh, we have a duplicate. Get
  44365. 28:08:25rid of it." So, what we want to do is we
  44366. 28:08:27want to order this. And so, we're going
  44367. 28:08:29to do an enter here. And let me just
  44368. 28:08:32bring it over here so it looks nice.
  44369. 28:08:34We'll do arrange. And we want to arrange
  44370. 28:08:37this by that transaction date. We want
  44371. 28:08:40to do it by the customer ID first and
  44372. 28:08:42then the transaction date. But we want
  44373. 28:08:45to do this descending from highest to
  44374. 28:08:48lowest. That's the most recent. So we
  44375. 28:08:50want to say take the most recent person.
  44376. 28:08:53Then we'll add our pipe here. And now
  44377. 28:08:56when we run this, we get an error
  44378. 28:08:58because this is all caps. All right,
  44379. 28:08:59let's try this again. I got excited and
  44380. 28:09:02let's go look at this uh no duplicates
  44381. 28:09:04three and unfortunately we're getting
  44382. 28:09:06the same thing and that's because of a
  44383. 28:09:09transaction date issue. Uh we're going
  44384. 28:09:11to go back and if you haven't done this
  44385. 28:09:14already or you haven't taken that lesson
  44386. 28:09:16on parsing and converting dates you we
  44387. 28:09:18need to do that. That is really
  44388. 28:09:20important actually. So we're going to um
  44389. 28:09:22clean this data up a little bit. I'm
  44390. 28:09:23going to place it right here. So you'll
  44391. 28:09:25have that in the code in the GitHub. But
  44392. 28:09:27I'm going to take this. I'm going to run
  44393. 28:09:29this. And if we go and look at our
  44394. 28:09:33original data frame. Now we have
  44395. 28:09:34standardized these dates. So now when we
  44396. 28:09:38run this and we take a look at the
  44397. 28:09:40duplicates three, now it's taking David
  44398. 28:09:43Lee. It was not working properly because
  44399. 28:09:46our dates were not properly cleaned. And
  44400. 28:09:49so before they looked horrible. And I
  44401. 28:09:52think we should be able to see this
  44402. 28:09:54right here. These dates are all over the
  44403. 28:09:56place and so it didn't know how to order
  44404. 28:09:58them properly until we cleaned them.
  44405. 28:10:01Now, I'm not going to go into the data
  44406. 28:10:02cleaning process for the dates because
  44407. 28:10:04that was our last lesson in this series.
  44408. 28:10:05So, you can go and check that out if you
  44409. 28:10:07want to. Again, I'll have this code in
  44410. 28:10:09the GitHub so you can just copy and
  44411. 28:10:11paste this if you'd like. But, it is
  44412. 28:10:13worth noting that you can go learn how
  44413. 28:10:14to do it in that last lesson. But then
  44414. 28:10:16once we clean that up and we standardize
  44415. 28:10:18them all properly, we order them from
  44416. 28:10:21highest to lowest, which is going to
  44417. 28:10:22look like this. So these are the most
  44418. 28:10:25recent all the way down to the old ones.
  44419. 28:10:28And then we kept the distinct customer
  44420. 28:10:32ID. And so now our output looks a lot
  44421. 28:10:35better. We now only have one Alice
  44422. 28:10:36Johnson. And now we kept David Lee
  44423. 28:10:38because he had the more recent
  44424. 28:10:40transaction date. Now for this use case,
  44425. 28:10:42that logic works. But you need to figure
  44426. 28:10:44out the logic for your actual data set
  44427. 28:10:46because maybe that doesn't make sense.
  44428. 28:10:48Maybe you want the original person and
  44429. 28:10:50this new person needs to get a new
  44430. 28:10:52customer ID. And you can do that by
  44431. 28:10:53maybe taking the max customer ID and
  44432. 28:10:55adding one to it. I don't know. Depends
  44433. 28:10:57on what you're doing. But that is how we
  44434. 28:10:59can remove the duplicates and we can
  44435. 28:11:01make sure at least follows some type of
  44436. 28:11:02logic that we can actually document and
  44437. 28:11:04hand off and people can understand. So I
  44438. 28:11:07hope that you learned something. And if
  44439. 28:11:09you want to dive into data cleaning and
  44440. 28:11:10using R even more, I have a full course
  44441. 28:11:12on my platform analyst builder. I will
  44442. 28:11:14have a link in the description. But I
  44443. 28:11:15hope that this was helpful. If it was,
  44444. 28:11:18be sure to like and subscribe below and
  44445. 28:11:20I will see you in the next video.
  44446. 28:11:23>> [music]
  44447. 28:11:33>> Hello everybody. In this lesson, we're
  44448. 28:11:35going to be taking a look at data
  44449. 28:11:36visualization and then creating a
  44450. 28:11:38presentation. This is kind of like a
  44451. 28:11:40little mini project and kind of shows
  44452. 28:11:41you how to put all your visualizations
  44453. 28:11:43into one output, which can be really
  44454. 28:11:46helpful. Now, what we're going to do is
  44455. 28:11:47work with a new data set here. We're
  44456. 28:11:49going to be using this parks and wreckb
  44457. 28:11:51budget.csv. This is a new data set for
  44458. 28:11:53this series. So go ahead and get that
  44459. 28:11:55down below in the GitHub and we're going
  44460. 28:11:57to get going. The only thing that you
  44461. 28:11:59need to do besides things that we've
  44462. 28:12:01done in previous lessons is we're going
  44463. 28:12:02to using a different library. It's
  44464. 28:12:04called ggplot 2. This is a data
  44465. 28:12:06visualization library specifically
  44466. 28:12:08designed to make it easier to visualize
  44467. 28:12:10your data. Let's go ahead and run this
  44468. 28:12:14and let's take a look at this data
  44469. 28:12:16frame. So in this data frame we have
  44470. 28:12:18year, we have the department, then we
  44471. 28:12:21have budget in thousands. And if you go
  44472. 28:12:24down, you can see we have a lot of
  44473. 28:12:25different departments. Sanitation,
  44474. 28:12:27public works, city management,
  44475. 28:12:29education, transportation. There's a lot
  44476. 28:12:31of different departments. Now, what
  44477. 28:12:33we're going to be working on is we're
  44478. 28:12:34going to be taking a look at bar charts,
  44479. 28:12:37and we're also going to take a look at
  44480. 28:12:39line charts, some categorization with a
  44481. 28:12:41bar chart, as well as some time series
  44482. 28:12:44visualizations with a line chart. Once
  44483. 28:12:47we get those, we are going to be putting
  44484. 28:12:48this into an R markdown file, and we're
  44485. 28:12:52going to kind of make it look pretty.
  44486. 28:12:53We're going to make it look nice, and
  44487. 28:12:54then this will be something you can hand
  44488. 28:12:56off to somebody. So, let's get started
  44489. 28:12:59and let's take a look at how we can get
  44490. 28:13:02our very first bar chart. So, we have
  44491. 28:13:04our data frame here and I'm just going
  44492. 28:13:07to start by saying we do need to do a
  44493. 28:13:09little bit of work to get it properly
  44494. 28:13:11formatted for something like a bar
  44495. 28:13:13chart. Bar charts are great when working
  44496. 28:13:16aggregated data and we can easily
  44497. 28:13:19aggregate this data because we have
  44498. 28:13:21something like a department to then
  44499. 28:13:22aggregate on something with the budget
  44500. 28:13:24in thousands. We could also aggregate on
  44501. 28:13:26the year and look at the total budget
  44502. 28:13:28for the year, but I'm more interested to
  44503. 28:13:31see how much money have we budgeted for
  44504. 28:13:34in total for every single department.
  44505. 28:13:37So, we can just use a sum here. If you
  44506. 28:13:39want to change it up and you want to
  44507. 28:13:40look at maybe the median or you want to
  44508. 28:13:42look at the max or whatever it is, you
  44509. 28:13:44can do that. But, we're going to do the
  44510. 28:13:47sum of this parks and recck department
  44511. 28:13:48to see how much money they budgeted for
  44512. 28:13:50over all these years. So let's take our
  44513. 28:13:54data frame. We're going to use our pipe
  44514. 28:13:56operator and we're going to use some of
  44515. 28:13:58the things that we've used throughout
  44516. 28:14:00this entire series. If you haven't gone
  44517. 28:14:01through the series, this is what we've
  44518. 28:14:03covered so far. And then grouping and
  44519. 28:14:05aggregating is one of them. So we're
  44520. 28:14:07going to group on the department and
  44521. 28:14:10then we'll add another pipe here.
  44522. 28:14:14We're going to summarize this. And we
  44523. 28:14:17want to do this on the budget. So we're
  44524. 28:14:20going to do the sum
  44525. 28:14:22of the budget in thousands. Now, we can
  44526. 28:14:25name this as well. It isn't super
  44527. 28:14:28important, but we'll call this total
  44528. 28:14:30budget and we'll say that's equal to the
  44529. 28:14:32sum of budget in thousands. Now, the
  44530. 28:14:36next thing that we're going to do is
  44531. 28:14:37where we actually start creating our
  44532. 28:14:39visualization. And so, this is where it
  44533. 28:14:40starts to get different than what we've
  44534. 28:14:43just looked at with grouping and
  44535. 28:14:44aggregating. Now, we're going to
  44536. 28:14:45actually build out the visualization.
  44537. 28:14:47Now, for the very basics, especially
  44538. 28:14:49with using ggplot 2, is we need to just
  44539. 28:14:51be able to kind of get something over
  44540. 28:14:53here under our plots. So, we kind of
  44541. 28:14:56want to create our very first layer. And
  44542. 28:14:58that's how plots typically work is
  44543. 28:15:00you're layering one thing on top of
  44544. 28:15:02another. And then you're also adding in
  44545. 28:15:05different adding in different colors or
  44546. 28:15:07different variations of things that you
  44547. 28:15:09want to change. Typically, when you're
  44548. 28:15:11doing a plot, you're going to start off
  44549. 28:15:13with ggplot. This ggplot is going to
  44550. 28:15:16give us that first layer of what data
  44551. 28:15:18are we actually working with. And the
  44552. 28:15:19ones that we're working with are the
  44553. 28:15:21department and our total budget. So
  44554. 28:15:23we're going to come down here. We're
  44555. 28:15:24going to say aes. Now AES is something
  44556. 28:15:28that you use to specify the variables
  44557. 28:15:30that are going to be mapped into the
  44558. 28:15:31data. And you can look through it right
  44559. 28:15:33here and read into that. But we're going
  44560. 28:15:35to specify AES for our aesthetics. And
  44561. 28:15:37we're going to pass through our X and
  44562. 28:15:39our Y. So we're going to say X is equal
  44563. 28:15:42to department. And I need to spell this
  44564. 28:15:45right. And then we'll do a comma. And
  44565. 28:15:47we'll say the Y is equal to, and let me
  44566. 28:15:50make it look a little bit better.
  44567. 28:15:52Total_budget.
  44568. 28:15:54And we can keep it like that for now.
  44569. 28:15:57But just knowing what's to come, we will
  44570. 28:15:59come back and we'll edit this a little
  44571. 28:16:01bit. But when we start getting to
  44572. 28:16:04visualizations, we're no longer going to
  44573. 28:16:05use these pipe operators. We're now just
  44574. 28:16:07going to say plus. And that says, okay,
  44575. 28:16:10we're adding to the next layer of our
  44576. 28:16:13visualization. We can actually look at
  44577. 28:16:15just this. Let's go ahead and run this.
  44578. 28:16:18And we have down here our X and our Y,
  44579. 28:16:22but we don't have the layer on top of
  44580. 28:16:24it. What are we actually putting in this
  44581. 28:16:25visualization? You'll also notice this
  44582. 28:16:28looks horrible at the bottom. It's text
  44583. 28:16:30over text, and it just does not look
  44584. 28:16:32good. We'll fix that later on, trust me.
  44585. 28:16:35But let's keep going. We want to add a
  44586. 28:16:38bar chart here. So what we want to do is
  44587. 28:16:40we're going to do geo m_bar
  44588. 28:16:44and you can see it right down here. So
  44589. 28:16:45within ggplot so within ggplot they have
  44590. 28:16:48all these geometry visualizations is
  44591. 28:16:51that's what that g stands for the g_bar
  44592. 28:16:54and so we want to specify this is a bar
  44593. 28:16:56chart and we can leave it just like
  44594. 28:16:58this. Let's go ahead and run this. Now
  44595. 28:16:59we're going to get an error here because
  44596. 28:17:01we need to set up a specific parameter
  44597. 28:17:04called stat or stat count. Now just
  44598. 28:17:06knowing these if we come in here we have
  44599. 28:17:08just the classic stat and then you can
  44600. 28:17:11also do different options like stat
  44601. 28:17:14count. I'm just going to use stat and
  44602. 28:17:16we're going to say it's equal to
  44603. 28:17:18identity. We're going to do it like this
  44604. 28:17:20identity. And so this is just something
  44605. 28:17:23that we have to pass through in order
  44606. 28:17:24for it to actually kind of understand
  44607. 28:17:26what we're working with here. So now
  44608. 28:17:28we're actually getting a visualization.
  44609. 28:17:30This looks really good, but we're going
  44610. 28:17:32to have to clean this up quite a bit.
  44611. 28:17:34make several changes to it. One thing we
  44612. 28:17:36can just add really quickly is we're
  44613. 28:17:38going to add a title. So we're going to
  44614. 28:17:40do gg title and we just have to pass
  44615. 28:17:42through a string. So we'll call this
  44616. 28:17:44total budget
  44617. 28:17:46by department. Just keep it super duper
  44618. 28:17:50simple here. And so now we have a nice
  44619. 28:17:52little title here. But the first thing
  44620. 28:17:55that I want to fix is we want some
  44621. 28:17:57colors in here. So, we're going to come
  44622. 28:17:59back to our aesthetics and we're going
  44623. 28:18:01to do a comma and we're going to say
  44624. 28:18:02fill is equal to and we're going to do
  44625. 28:18:05department. So, now it's going to give
  44626. 28:18:07us a legend and each one of these colors
  44627. 28:18:09will be a different department. Let's
  44628. 28:18:11run this.
  44629. 28:18:13And so, you don't have to do this. In
  44630. 28:18:15fact, we could just make it a specific
  44631. 28:18:17color. We could just say we could just
  44632. 28:18:20say red. And we could do it like that.
  44633. 28:18:24We'll make them all red. or it's kind of
  44634. 28:18:26like a salmon almost, but a different
  44635. 28:18:28color. We can just make it a specific
  44636. 28:18:30color and that'd be perfectly fine. But
  44637. 28:18:32let's just go back. I like this kind of
  44638. 28:18:34like rainbow color here. It's nice. But
  44639. 28:18:37at the very bottom, we're still having
  44640. 28:18:38an issue with how this looks. Now,
  44641. 28:18:42typically, if I'm working with kind of a
  44642. 28:18:43simpler visualization, I would do a
  44643. 28:18:46theme. And again, we're just adding a
  44644. 28:18:48layer here. I would do this like minimal
  44645. 28:18:50theme. And it would kind of get rid of
  44646. 28:18:52some of these colors in the back. do a
  44647. 28:18:55little bit of spacing and it looks nice.
  44648. 28:18:56It's a minimal theme, but for this
  44649. 28:19:00theme, we actually need to specify this
  44650. 28:19:02right here, which is an element. So, we
  44651. 28:19:05need to come back here. I'm going to get
  44652. 28:19:07rid of this. I'm just going to have a
  44653. 28:19:08base theme and we need to do axis.ext
  44654. 28:19:12and we need this for the xaxis. So,
  44655. 28:19:15along this x-axis, we need to work with
  44656. 28:19:18this text. So, we're going to say is
  44657. 28:19:20equal to. And now we need to pass
  44658. 28:19:22through element
  44659. 28:19:25text. And all we're going to do is
  44660. 28:19:27adjust the angle. And we're just going
  44661. 28:19:29to come in here. We're going to say the
  44662. 28:19:30angle, not angel. The angle is equal to
  44663. 28:19:3445. So now it's going to be at a 45
  44664. 28:19:36degree angle. Let's go ahead and run
  44665. 28:19:38this and just see how it looks.
  44666. 28:19:40And this looks aund times better, but I
  44667. 28:19:43think we need to adjust a little bit uh
  44668. 28:19:45as well. So, we'll do the height
  44669. 28:19:48adjustment and we'll say it's equal to
  44670. 28:19:51one. Let's try this.
  44671. 28:19:54And there we go. So, this looks a
  44672. 28:19:57hundred times better. The only thing
  44673. 28:19:59that I would change is I would want to
  44674. 28:20:02order this from highest down to lowest.
  44675. 28:20:05So, I could visually just see in order
  44676. 28:20:07from highest to lowest which department
  44677. 28:20:10is which. Now, we can do that. It's
  44678. 28:20:12going to be right up here in our
  44679. 28:20:13summarize. Now, we can do that. It's
  44680. 28:20:16going to be right here in this X because
  44681. 28:20:18we have our department right here. We
  44682. 28:20:20can actually use something called a
  44683. 28:20:22reorder
  44684. 28:20:24and we pass through the department first
  44685. 28:20:27but then we do a comma here and we say
  44686. 28:20:31minus the total budget. That minus just
  44687. 28:20:34means go from high to low. That's all
  44688. 28:20:37that minus means. If we did it the other
  44689. 28:20:38way, it'd be from low to high. Let's go
  44690. 28:20:40ahead and run this. So now we see that
  44691. 28:20:42public works takes about a hundred. I
  44692. 28:20:44think that's a million dollars. Then we
  44693. 28:20:46have recreation, park, sanitation. So
  44694. 28:20:48that is visually you can see it going
  44695. 28:20:50down. Again, we don't have to use this,
  44696. 28:20:52but I just like the colors and I wanted
  44697. 28:20:55to uh so let's keep going because I
  44698. 28:20:58think we got a good gist of how we can
  44699. 28:20:59create this visualization and we will
  44700. 28:21:01add this to our output in a little bit.
  44701. 28:21:04I might want to just show you what this
  44702. 28:21:07R markdown looks like. We're going to
  44703. 28:21:09call this uh presentation_final.
  44704. 28:21:14Let's open this up real quick. It
  44705. 28:21:16creates this output for an HTML
  44706. 28:21:18document, which is perfectly fine. Um,
  44707. 28:21:20I'm going to use a different one called
  44708. 28:21:22flex dashboard. You don't have to use
  44709. 28:21:24that, but that's the one I'm going to
  44710. 28:21:25use in this lesson, but we'll be passing
  44711. 28:21:27through this right here. And so, hold on
  44712. 28:21:31to this. Don't change that because we
  44713. 28:21:33will need it. Now, let's go down to our
  44714. 28:21:35line chart. Now, line charts are a
  44715. 28:21:37little bit different because in this
  44716. 28:21:40we're just looking at as an in total.
  44717. 28:21:42We're not looking at it over time, but
  44718. 28:21:44now we're about to use this column right
  44719. 28:21:47here. And now we have a specific year
  44720. 28:21:50that we're going to look at over time
  44721. 28:21:52for all of our data. I think we should
  44722. 28:21:54do two separate visualizations. One
  44723. 28:21:56where it's all the departments together
  44724. 28:21:58and then one broken out by departments
  44725. 28:22:00because those are two very different
  44726. 28:22:01visualizations. And so what we're going
  44727. 28:22:04to do is we can actually copy um I don't
  44728. 28:22:08know quite a bit of this. Let's just
  44729. 28:22:09copy this whole thing down because now
  44730. 28:22:12we're just grouping on the year, but we
  44731. 28:22:14still want that sum of total budget. And
  44732. 28:22:17then down here in the X, we're not
  44733. 28:22:20looking at the department anymore. Now
  44734. 28:22:23we're looking at the year. So then our Y
  44735. 28:22:25is our total budget, which because we're
  44736. 28:22:28grouping on the year, we might want to
  44737. 28:22:29call this our annual
  44738. 28:22:32because this is our total budget. So now
  44739. 28:22:34we should change this to annual budget.
  44740. 28:22:37And we can still use the same fill at
  44741. 28:22:40least for this visualization. It
  44742. 28:22:41shouldn't matter at all. Um, but we will
  44743. 28:22:44use it in the next one. We break it out
  44744. 28:22:45by the department. The only thing that's
  44745. 28:22:48really going to change is we have to go
  44746. 28:22:50to GM and I'm going to say line here.
  44747. 28:22:54So, this is going to create a line
  44748. 28:22:56visualization. And let's just run it
  44749. 28:22:58just like this. And apparently this
  44750. 28:23:01actually does matter. Let's get rid of
  44751. 28:23:02this really quick. And let's try running
  44752. 28:23:05this one more time. And in essence, this
  44753. 28:23:08is our visualization. It's very simple.
  44754. 28:23:11Uh let's actually add in that minimal
  44755. 28:23:14theme. So I'm going to do uh theme
  44756. 28:23:17minimal. This is just the one that I
  44757. 28:23:20think makes it look nicer. We can also
  44758. 28:23:22add in little dots on the year so we can
  44759. 28:23:24kind of see what this is supposed to
  44760. 28:23:26look like. So I'm going to do gam point
  44761. 28:23:29and this is just going to add dots on
  44762. 28:23:32where the data goes. And you can see, so
  44763. 28:23:34this is 2005 6 7 8 9 10. And it's just
  44764. 28:23:38easier to see. And I think just for a
  44765. 28:23:40quick line chart for the budget or the
  44766. 28:23:44annual budget over the years, this is
  44767. 28:23:46pretty good. But we could also add in a
  44768. 28:23:48title here. So I'm going to say uh GG
  44769. 28:23:52title and I'm going to say annual budget
  44770. 28:23:57for all departments.
  44771. 28:24:00And we'll do it just like this. And that
  44772. 28:24:03looks great. Now, what if we want to
  44773. 28:24:05break this out by the different
  44774. 28:24:07departments? This is where it gets a
  44775. 28:24:09little trickier. Not much. Let's copy
  44776. 28:24:12this down. And we want to break this.
  44777. 28:24:15I'm going to say break out by
  44778. 28:24:18departments. That's just for the people
  44779. 28:24:20who are looking at the code. Um, so now
  44780. 28:24:22we're not really needing to group by
  44781. 28:24:25this because it kind of already has this
  44782. 28:24:27for us. Whoops. It kind of already has
  44783. 28:24:29this for us. I just messed up all the
  44784. 28:24:33data, but it has the year, the
  44785. 28:24:35department, and the budget. So, we
  44786. 28:24:37really shouldn't need to group this
  44787. 28:24:39data. Let's pull this back. But in our
  44788. 28:24:43ggplot, we do need the year. We do need
  44789. 28:24:47the budget in thousands. So, we're going
  44790. 28:24:49to do budget in thousands. And then
  44791. 28:24:53we're going to need our color or our
  44792. 28:24:55fill. So, I'll do color is equal to I'm
  44793. 28:24:58going say department. So, let's go ahead
  44794. 28:25:01and just try this.
  44795. 28:25:05And there we go. Now, this is kind of
  44796. 28:25:06all over the place. Maybe we want to get
  44797. 28:25:07rid of these points real quick. Just see
  44798. 28:25:09what this looks like.
  44799. 28:25:11Maybe this looks a little bit better.
  44800. 28:25:13But we have this department as our
  44801. 28:25:15legend. And so now you can see you can
  44802. 28:25:18just kind of follow one of these colors,
  44803. 28:25:20whatever one you want to follow. And
  44804. 28:25:21you'll be able to see that budget
  44805. 28:25:23changing over the years. This is not the
  44806. 28:25:25annual budget for all departments. Uh
  44807. 28:25:28this is the angel budget per department.
  44808. 28:25:33There we go. And we'll run it just like
  44809. 28:25:35this. So this looks good. And we have
  44810. 28:25:38you can even go back and look at you
  44811. 28:25:40know previous ones you've done. And so
  44812. 28:25:43you know we're holding a lot in memory
  44813. 28:25:44just storing these. But
  44814. 28:25:47these look really good to me. I think we
  44815. 28:25:49are good to go. So what we need to do
  44816. 28:25:52now is we want to group all of this.
  44817. 28:25:55Now, what we want to do is we're going
  44818. 28:25:56to change this a little bit and we're
  44819. 28:25:57going to put all of our visualizations
  44820. 28:25:59and essentially all of our data in here.
  44821. 28:26:01Now, I'm going to change this to a flex
  44822. 28:26:05dashboard.
  44823. 28:26:06And I just find these easier to work
  44824. 28:26:08with. Uh, so we're do flex
  44825. 28:26:11dashboard here. Now, I'm going to save
  44826. 28:26:14this. And when I save this on knit,
  44827. 28:26:17which means we're going to actually
  44828. 28:26:18process the data and we're going to
  44829. 28:26:20create it. We're now knitting to a
  44830. 28:26:21dashboard instead of before we were
  44831. 28:26:23doing to an HTML document.
  44832. 28:26:26Now, if you don't have this installed,
  44833. 28:26:27which I completely deleted my R Studio
  44834. 28:26:30and R in order to do this, I need to
  44835. 28:26:32install this again. So, let's go ahead
  44836. 28:26:34and do that. But while it's working on
  44837. 28:26:36that, let's start moving over all of our
  44838. 28:26:39stuff. So, I'm going to come up here and
  44839. 28:26:42I'm going to get this right here. And
  44840. 28:26:45what we need to do is put it in a little
  44841. 28:26:46code block. and we're going to use
  44842. 28:26:48little tick marks to specify where
  44843. 28:26:52we're going to have our code. Now, I
  44844. 28:26:54need to use what I like to call squiggly
  44845. 28:26:56brackets. And I need to specify that
  44846. 28:26:58this is our code because you don't have
  44847. 28:27:00to use this uh just with R. You can use
  44848. 28:27:03this with other programming languages.
  44849. 28:27:05So, we want to specify this is our code.
  44850. 28:27:07So, all we're doing is just getting in
  44851. 28:27:09our data set. If we had other things
  44852. 28:27:11where we were cleaning it up or
  44853. 28:27:12transforming it or whatever it was, it'd
  44854. 28:27:14be in this code block. Now, we want to
  44855. 28:27:17put in our first one. This is our bar
  44856. 28:27:19chart and we're going to come down here
  44857. 28:27:22and we're going to do three with the R,
  44858. 28:27:26of course. Oops.
  44859. 28:27:28Let me fix that. We're going to post our
  44860. 28:27:31code and then do three as well. And so
  44861. 28:27:34now you'll notice it kind of has it
  44862. 28:27:36highlighted. This is where our R code
  44863. 28:27:38is. Now, if we try to just run this,
  44864. 28:27:40let's save this and let's knit it. So I
  44865. 28:27:43just clicked dit.
  44866. 28:27:46It's going to start processing this as
  44867. 28:27:47well as our visualization and it's going
  44868. 28:27:49to give us an output. Now it just gives
  44869. 28:27:51us our presentation final and our one
  44870. 28:27:54visualization. But we haven't really
  44871. 28:27:56added a lot to this. Let's add our other
  44872. 28:27:59stuff as well. So now we're going to
  44873. 28:28:01come down here and we can just copy
  44874. 28:28:03this. Let's not get crazy. And we're
  44875. 28:28:06going to do one, two, three. And then
  44876. 28:28:07I'm going to do another one down here.
  44877. 28:28:09One, two, three. So, let's go back and
  44878. 28:28:11get our two other visualizations. We
  44879. 28:28:13have this one, and I'll paste it right
  44880. 28:28:15in here. And then we have this one. And
  44881. 28:28:18I'll paste that one in the bottom one.
  44882. 28:28:21And let's go ahead and save this as well
  44883. 28:28:24as knit to flex dashboard, which is what
  44884. 28:28:26we just did before.
  44885. 28:28:33And taking a look at this, it looks like
  44886. 28:28:35something went wrong because none of
  44887. 28:28:37this is working properly. If we scroll
  44888. 28:28:39up and down, this just doesn't look
  44889. 28:28:41right.
  44890. 28:28:44Let's go ahead and exit out of this.
  44891. 28:28:46Let's go back up and let's give these
  44892. 28:28:50titles really quick. We're going to do
  44893. 28:28:51one, two, three. And I'm just going to
  44894. 28:28:53give it the same title as we have up
  44895. 28:28:55here.
  44896. 28:28:58We don't need these uh quotes right
  44897. 28:29:01here.
  44898. 28:29:04We go down here. Let's give it three
  44899. 28:29:08annual budget for all departments. And
  44900. 28:29:11then lastly down here as well. And this
  44901. 28:29:15is annual budget per department. Let's
  44902. 28:29:19go ahead and run this
  44903. 28:29:25and let's see what our output looks like
  44904. 28:29:26this time.
  44905. 28:29:29It looks quite a bit different. We have
  44906. 28:29:31this right here. This uh side data that
  44907. 28:29:34does not look correct. Uh we need to go
  44908. 28:29:36back and we need to get rid of this.
  44909. 28:29:39Let's go back to our visualization.
  44910. 28:29:42Let's just run this and we'll run it
  44911. 28:29:45just like that. You'll see in our output
  44912. 28:29:48we're getting all these things and this
  44913. 28:29:50is being put into our visualization or
  44914. 28:29:52our output as well. We don't want this.
  44915. 28:29:55Now, if I'm looking at this really
  44916. 28:29:57quickly, I think we just didn't add in a
  44917. 28:30:00space here. And so, it's like printing
  44918. 28:30:02out these themes uh as we go. So, let me
  44919. 28:30:06add in
  44920. 28:30:08this space right here.
  44921. 28:30:11And we'll add it in here as well. Now,
  44922. 28:30:13let's try saving this. And let's knit
  44923. 28:30:16it.
  44924. 28:30:22And this looks good. Although it's
  44925. 28:30:24really small in order to make it larger.
  44926. 28:30:27Let's try something right here. Let's do
  44927. 28:30:30a colon. We're going to say vertical
  44928. 28:30:33layout. We'll do a colon and say screen.
  44929. 28:30:38Just like this. Let's save this.
  44930. 28:30:41And this should allow us to have them
  44931. 28:30:43stacked on top of each other.
  44932. 28:30:47And let's see. Knit to flex. So, let's
  44933. 28:30:49just make sure it's working. I think
  44934. 28:30:51this may need to be lowercase, which is
  44935. 28:30:53why it's not working. Let's try this
  44936. 28:30:55again.
  44937. 28:30:56There we go. But this vertical scroll
  44938. 28:30:59stacks them on top of each other and
  44939. 28:31:00allows you to scroll down. And there we
  44940. 28:31:03go. And this looks 100 times better than
  44941. 28:31:06how we had it before because now it has
  44942. 28:31:07a scroll wheel, allows these things to
  44943. 28:31:09expand. Now, we can also publish this.
  44944. 28:31:12We can say publish document. In order to
  44945. 28:31:15do that, you have to have these
  44946. 28:31:16connected. And RS Connect is is
  44947. 28:31:18something that Posit created in order to
  44948. 28:31:20publish these. We're just going to say
  44949. 28:31:22yes. Uh I had this before, but you know,
  44950. 28:31:24I deleted everything. So now I'm
  44951. 28:31:26starting over with you guys. But let's
  44952. 28:31:27go ahead and publish this. It looks like
  44953. 28:31:30it's still working on that. Let's give
  44954. 28:31:32it just a sec. It took about 1 minute.
  44955. 28:31:35Says it is installed. Let's bring this
  44956. 28:31:37back. Now we can p publish it to our
  44957. 28:31:40pubs, which is a free service. You can
  44958. 28:31:42also do Posit Connect and Posit Cloud
  44959. 28:31:44which are paid services or at least in
  44960. 28:31:46some way or shape or form. You'll have
  44961. 28:31:47to pay for it. We're just going to use
  44962. 28:31:49our pubs and we're going to go ahead and
  44963. 28:31:51click publish. Now, all you have to do
  44964. 28:31:52is create an account, share it, and
  44965. 28:31:54you'll get a sharable link that you can
  44966. 28:31:55then put on your resume, put on
  44967. 28:31:57LinkedIn, put anywhere you want in order
  44968. 28:31:58to actually share your project. So, I
  44969. 28:32:01hope that this was helpful. If you
  44970. 28:32:02haven't already, I have a full R course
  44971. 28:32:04that goes a lot more in depth into the
  44972. 28:32:05data visualization and presentation side
  44973. 28:32:07of things. So, if you want to go ahead
  44974. 28:32:09and check that out, I will leave a link
  44975. 28:32:10in the description below. I'll also have
  44976. 28:32:12a coupon code if you want that as well.
  44977. 28:32:15But I really appreciate you watching and
  44978. 28:32:17I hope that this whole series was really
  44979. 28:32:19helpful. If you did find if you did like
  44980. 28:32:21it, be sure to like and subscribe and I
  44981. 28:32:23will see you in the next [music] lesson.
  44982. 28:32:37What's going on everybody? My name is
  44983. 28:32:38Alex Freeberg and today we're going to
  44984. 28:32:40be walking through my top three tips on
  44985. 28:32:42how to use LinkedIn to land a job.
  44986. 28:32:44LinkedIn is a fantastic place to look
  44987. 28:32:46for a job. It's its own little ecosystem
  44988. 28:32:48where careerdriven people can connect
  44989. 28:32:49and talk with one another and help each
  44990. 28:32:51other find jobs. I personally have
  44991. 28:32:53landed jobs through LinkedIn and so I
  44992. 28:32:54know how effective it can be. Let's jump
  44993. 28:32:56over to my screen and I'm going to show
  44994. 28:32:58you my top three strategies that I have
  44995. 28:33:00found to be the most successful to
  44996. 28:33:01actually finding a job. So, I'm logged
  44997. 28:33:03into my completely anonymous account
  44998. 28:33:05here and I'm going to show you the very
  44999. 28:33:06first tip, which is you shouldn't be
  45000. 28:33:08just applying to a position. You should
  45001. 28:33:09be actually reaching out to the
  45002. 28:33:10recruiter. And I'm going to show you
  45003. 28:33:12exactly how to do that. So, the first
  45004. 28:33:13thing that we have to do is to actually
  45005. 28:33:15find a job that we want to apply to. So,
  45006. 28:33:17let's go to the job section right over
  45007. 28:33:19here and let's search for data analyst.
  45008. 28:33:25And let's do that in
  45009. 28:33:28uh let's do Chicago
  45010. 28:33:30cuz why not? Uh so it's going to search
  45011. 28:33:33for data analyst positions in Chicago.
  45012. 28:33:36Uh we have one right here. Let's see
  45013. 28:33:38what it looks like cuz you know I don't
  45014. 28:33:40want to apply to jobs that I'm not
  45015. 28:33:42extremely qualified for. So this is a
  45016. 28:33:45job that I want to apply for. And before
  45017. 28:33:46I actually go and apply to the job, I
  45018. 28:33:48want to see if I can reach out to a
  45019. 28:33:49recruiter and talk to them beforehand.
  45020. 28:33:51So let me show you how to do that. So,
  45021. 28:33:53what we're going to do is actually click
  45022. 28:33:54on the company right here. It's going to
  45023. 28:33:56take us to basically their LinkedIn
  45024. 28:33:57profile page for their entire company.
  45025. 28:34:00And we're going to scroll down. We're
  45026. 28:34:01going to go over to people.
  45027. 28:34:03And then we're going to search for
  45028. 28:34:05recruiter.
  45029. 28:34:08So, if we scroll down all the way to the
  45030. 28:34:10bottom, we can see that there are
  45031. 28:34:11recruiters that actually work inhouse
  45032. 28:34:13for this company. And so, now would be a
  45033. 28:34:15time where I actually reach out to some
  45034. 28:34:16of these recruiters and I say, "Hey, I
  45035. 28:34:18see a job that I really like. I think
  45036. 28:34:20I'm really qualified for and I would
  45037. 28:34:21love to talk more about it with you. You
  45038. 28:34:23can ask them things about the job to
  45039. 28:34:25make sure that it is a good fit for you.
  45040. 28:34:26And then I highly recommend you asking
  45041. 28:34:28them what they think is the best way to
  45042. 28:34:30apply for this job to make sure that
  45043. 28:34:31your resume gets noticed and you get an
  45044. 28:34:33interview. Since they are a recruiter
  45045. 28:34:35who works at this company, they may be
  45046. 28:34:36the one who's actually going to be
  45047. 28:34:37looking at these résumés. And so they
  45048. 28:34:39may give you a tip on the best way to
  45049. 28:34:41actually apply. They may also just ask
  45050. 28:34:43you to send them your resume directly so
  45051. 28:34:45that they can look at it. or maybe later
  45052. 28:34:46on down the line, this actually is a
  45053. 28:34:48person who is reviewing résumés and so
  45054. 28:34:50if they come across your resume, they
  45055. 28:34:51may be able to put a face to the name
  45056. 28:34:53and that may give you bonus points. I'm
  45057. 28:34:55going to leave a template script in the
  45058. 28:34:56description in case you don't know
  45059. 28:34:57exactly what you want to say to this
  45060. 28:34:59recruiter and it'll give you just a
  45061. 28:35:00baseline of some of the things that you
  45062. 28:35:02might want to say. Number two is to
  45063. 28:35:03actually ask for a referral. Now, if you
  45064. 28:35:05don't know what a referral is, it is
  45065. 28:35:07where somebody who already works at the
  45066. 28:35:08company can refer you to a specific job
  45067. 28:35:11and it might get you a little bit higher
  45068. 28:35:12on the list for interviews. So, I highly
  45069. 28:35:14recommend reaching out to somebody who
  45070. 28:35:15already works at that company and ask if
  45071. 28:35:18they're willing to be a referral for
  45072. 28:35:19you. I get people reaching out to me all
  45073. 28:35:21the time asking to be a referral for
  45074. 28:35:23them for my company. And nine times out
  45075. 28:35:25of 10, I say yes. I always ask to see
  45076. 28:35:27their resume first just to make sure
  45077. 28:35:28that their resume aligns with the
  45078. 28:35:30position at least a little bit. But
  45079. 28:35:32there's basically no harm in me being a
  45080. 28:35:34referral for somebody. In fact, I may
  45081. 28:35:36actually get a bonus if that person ends
  45082. 28:35:37up getting hired. And so, for the most
  45083. 28:35:39part, there's almost no risk for the
  45084. 28:35:41employee to actually being a referral.
  45085. 28:35:43And so a lot of times they will say yes.
  45086. 28:35:45Now let me show you how to do that. And
  45087. 28:35:46it is very similar to finding a
  45088. 28:35:48recruiter. So we're going to stay on
  45089. 28:35:49this people section, but instead of
  45090. 28:35:51searching for a recruiter, we're going
  45091. 28:35:53to search for a job title that is
  45092. 28:35:54similar to yours. So let's actually see
  45093. 28:35:56if they do already have any data
  45094. 28:35:58analysts. And if they do, that is the
  45095. 28:36:00person that we're going to reach out to
  45096. 28:36:01cuz that is the person we'll probably
  45097. 28:36:02have the best connection with. So it
  45098. 28:36:04looks like we have six employees. And
  45099. 28:36:06let's scroll down. And so it looks like
  45100. 28:36:08all these people have data related jobs.
  45101. 28:36:10And so I would reach out to these people
  45102. 28:36:12and say, "I saw an open data analyst
  45103. 28:36:13position at your company. I would love
  45104. 28:36:15to know more about your company as a
  45105. 28:36:17whole." And then you can talk to them a
  45106. 28:36:18little bit and then in the end your goal
  45107. 28:36:20is to ask them for a referral. And if
  45108. 28:36:22that happens, that is fantastic. And
  45109. 28:36:24then you can go ahead and apply for the
  45110. 28:36:25job and mark them as a referral for you.
  45111. 28:36:27Now my third tip on how to get a job
  45112. 28:36:29through LinkedIn is to actually have
  45113. 28:36:30recruiters reach out to you. So let me
  45114. 28:36:32show you how to do that. The first thing
  45115. 28:36:34we're going to do is actually go over to
  45116. 28:36:36my profile here and we'll click view
  45117. 28:36:38profile.
  45118. 28:36:40Now, there's a few things that we want
  45119. 28:36:42to make sure that we have on here so
  45120. 28:36:44that recruiters can reach out to us. The
  45121. 28:36:46first thing that I want to do is to
  45122. 28:36:47actually come to this section right
  45123. 28:36:48here, which is show recruiters you're
  45124. 28:36:50open to work. And when I click on this,
  45125. 28:36:52I can actually choose some job titles
  45126. 28:36:54and some locations where I actually want
  45127. 28:36:55to apply and have recruiters reach out
  45128. 28:36:57to me. And so, right now, I have data
  45129. 28:36:59analyst. I have in the DFW area, which
  45130. 28:37:02is where I live. I can also add titles
  45131. 28:37:04like business analyst
  45132. 28:37:06um and then maybe junior data analyst,
  45133. 28:37:08entry- level data analyst or things like
  45134. 28:37:10that that could potentially have
  45135. 28:37:11recruiters reach out to me for positions
  45136. 28:37:13that I'm interested in. And then you can
  45137. 28:37:14say that you're immediately and actively
  45138. 28:37:16applying. And you can also say that
  45139. 28:37:18you're only looking for full-time
  45140. 28:37:20positions or contract positions. And
  45141. 28:37:22then you can actually add this to your
  45142. 28:37:23profile. And I only want recruiters to
  45143. 28:37:25see that because I do currently have a
  45144. 28:37:27job at McDonald's. And so I don't want
  45145. 28:37:29McDonald's firing me because I'm looking
  45146. 28:37:31for employment elsewhere. So let's save
  45147. 28:37:33that. And it looks like it was updated.
  45148. 28:37:36And so now when recruiters are searching
  45149. 28:37:37for candidates for a specific position,
  45150. 28:37:39you will be on that list so that they
  45151. 28:37:41can find you and reach out to you.
  45152. 28:37:43Something else I should mention is on
  45153. 28:37:44your profile page, I would try to have
  45154. 28:37:46some type of professional photo so that
  45155. 28:37:48you look really good. I would also try
  45156. 28:37:50to include data analyst somewhere in
  45157. 28:37:51your title. If you already have a data
  45158. 28:37:53analyst job and you're looking for
  45159. 28:37:54another one, you can just have your
  45160. 28:37:55previous company. But if you're looking
  45161. 28:37:57for a data analyst job, you can always
  45162. 28:37:58put seeking data analyst position or
  45163. 28:38:00something like that. Another thing I
  45164. 28:38:02think is really important is having
  45165. 28:38:04really good descriptions for your
  45166. 28:38:05previous work. I don't currently have
  45167. 28:38:07this, but I would go a little bit into
  45168. 28:38:09the work that I actually do. Make sure
  45169. 28:38:11that the experience matches kind of what
  45170. 28:38:13you're looking for if you do have
  45171. 28:38:14previous experience. If not, that's
  45172. 28:38:16totally fine. The next section on your
  45173. 28:38:18profile page that I would recommend
  45174. 28:38:19looking at and updating is your skill
  45175. 28:38:21section. And so you want to go in there
  45176. 28:38:23and make sure that you have all of your
  45177. 28:38:24relevant really data analyst heavy
  45178. 28:38:26skills on there, specifically hard
  45179. 28:38:28skills because soft skills aren't going
  45180. 28:38:30to translate too much into this section.
  45181. 28:38:32I would definitely stick to things like
  45182. 28:38:34SQL, Python, Tableau, Excel, things that
  45183. 28:38:37data analysts are going to use because
  45184. 28:38:39this is where they're going to actually
  45185. 28:38:40look and see if you have the skills that
  45186. 28:38:41they are looking for for that position.
  45187. 28:38:43When I was applying to jobs and only
  45188. 28:38:45applying to job postings and not using
  45189. 28:38:47any of these strategies, my success rate
  45190. 28:38:49was 0.04, 04, which means out of 1,000
  45191. 28:38:52applications that I filled out and sent
  45192. 28:38:54my resume to, I only heard back from
  45193. 28:38:56four of them to actually get an
  45194. 28:38:57interview. But with these strategies, I
  45195. 28:38:59was able to get that up to 10% and at my
  45196. 28:39:01best, I was able to get that up to 15%.
  45197. 28:39:03But that's because I was applying to a
  45198. 28:39:05lot less positions, and I was targeting
  45199. 28:39:06jobs that I really wanted to work for.
  45200. 28:39:08And so, I put in more effort in order to
  45201. 28:39:10contact people and work with recruiters
  45202. 28:39:11in order to get that job. I genuinely
  45203. 28:39:14hope that these strategies can be
  45204. 28:39:15helpful for you, especially if you're
  45205. 28:39:16trying to apply for jobs right now.
  45206. 28:39:18Thank you guys so much for watching. I
  45207. 28:39:20really appreciate it. If you like this
  45208. 28:39:21video and got anything out of it at all,
  45209. 28:39:23be sure to like and subscribe below and
  45210. 28:39:25I'll see you in the next video. Hello
  45211. 28:39:26everybody. Congratulations. If you are
  45212. 28:39:28watching this, that means that you
  45213. 28:39:30completed the data analyst boot camp. If
  45214. 28:39:32you haven't, don't keep watching. This
  45215. 28:39:33is only for people who have completed
  45216. 28:39:35the data analyst boot camp playlist on
  45217. 28:39:37my YouTube channel. Woo! All right. Now
  45218. 28:39:39that we filtered those people out, I'm
  45219. 28:39:41going to show you how you can download
  45220. 28:39:42your certificate and your certification
  45221. 28:39:44now that you've completed the data
  45222. 28:39:46analyst boot camp. I will leave a link
  45223. 28:39:47in the description, but let's go on to
  45224. 28:39:49my screen. I'm going to show you how to
  45225. 28:39:50actually access this and download your
  45226. 28:39:52certification. All right, guys. Don't go
  45227. 28:39:54around telling people this or sharing
  45228. 28:39:56this. Uh, but this is our data analytics
  45229. 28:39:58boot camp on the Alex the Analyst GitHub
  45230. 28:40:01right up here. I will have this link in
  45231. 28:40:03the description. What you can go ahead
  45232. 28:40:04and do is you can come right here and
  45233. 28:40:06you can download this. You'll just
  45234. 28:40:08rightclick or click download and you
  45235. 28:40:09just do something like save image as.
  45236. 28:40:12Um, or you can come to this one. This is
  45237. 28:40:14the one that I think is the the real
  45238. 28:40:15money maker here. Uh this is the
  45239. 28:40:17certificate of completion for the data
  45240. 28:40:20analytics boot camp. I have my not
  45241. 28:40:22signature but my name as well as u my
  45242. 28:40:25position with a blank space right here
  45243. 28:40:28to fill in your name. Feel free to put
  45244. 28:40:30this on LinkedIn or Twitter or Instagram
  45245. 28:40:32and tag me in that because I would love
  45246. 28:40:33to just say congratulations because
  45247. 28:40:35honestly it's a lot of work to go
  45248. 28:40:37through all those videos and learn all
  45249. 28:40:38of those skills. So congratulations. I
  45250. 28:40:40hope that you learned something along
  45251. 28:40:41this journey. A new skill, a new
  45252. 28:40:43thought, a new idea and I'm proud of
  45253. 28:40:45you. I'm proud of you for putting in the
  45254. 28:40:46work. It's not easy, but you did it. And
  45255. 28:40:48I hope that you came out on the other
  45256. 28:40:51side better for it. So, congrats. I'll
  45257. 28:40:53see you in the next video.
  45258. 28:40:58[music]

About this transcript

This page contains the full transcript of 2026 FREE Data Analyst Bootcamp [24 Hours+] for FREE | SQL, Excel, Python, Power BI, GitHub, AWS by Alex The Analyst, generated from the public captions YouTube serves with the video. The transcript has 334,400 words across 45,258 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.