├── LICENSE ├── README.md ├── Tutorial 2- PySpark DataFrames- Part 1.ipynb ├── Tutorial 3- Pyspark Dataframe- Handling Missing Values.ipynb ├── Tutorial 4- Pyspark Dataframes- Filter operation.ipynb ├── Tutorial 5- Pyspark With Python-GroupBy And Aggregate Functions.ipynb ├── Tutorial 6-Example Of Pyspark ML.ipynb ├── Tutorial 8-Linear Regression With Pyspark.ipynb ├── pyspark basic introduction.ipynb ├── test1.csv ├── test2.csv ├── test3.csv └── tips.csv /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pyspark-With-Python -------------------------------------------------------------------------------- /Tutorial 2- PySpark DataFrames- Part 1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "00166693", 6 | "metadata": {}, 7 | "source": [ 8 | "#### In this Video We will Cover\n", 9 | "- PySpark Dataframe \n", 10 | "- Reading The Dataset\n", 11 | "- Checking the Datatypes of the Column(Schema)\n", 12 | "- Selecting Columns And Indexing\n", 13 | "- Check Describe option similar to Pandas\n", 14 | "- Adding Columns\n", 15 | "- Dropping columns\n", 16 | "- Renaming Columns" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 1, 22 | "id": "fb37d003", 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "from pyspark.sql import SparkSession" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 2, 32 | "id": "a1d46445", 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "spark=SparkSession.builder.appName('Dataframe').getOrCreate()" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 3, 42 | "id": "078fccba", 43 | "metadata": {}, 44 | "outputs": [ 45 | { 46 | "data": { 47 | "text/html": [ 48 | "\n", 49 | "
\n", 50 | "

SparkSession - in-memory

\n", 51 | " \n", 52 | "
\n", 53 | "

SparkContext

\n", 54 | "\n", 55 | "

Spark UI

\n", 56 | "\n", 57 | "
\n", 58 | "
Version
\n", 59 | "
v3.1.1
\n", 60 | "
Master
\n", 61 | "
local[*]
\n", 62 | "
AppName
\n", 63 | "
Dataframe
\n", 64 | "
\n", 65 | "
\n", 66 | " \n", 67 | "
\n", 68 | " " 69 | ], 70 | "text/plain": [ 71 | "" 72 | ] 73 | }, 74 | "execution_count": 3, 75 | "metadata": {}, 76 | "output_type": "execute_result" 77 | } 78 | ], 79 | "source": [ 80 | "spark" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 34, 86 | "id": "b7b4a628", 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "## read the dataset\n", 91 | "df_pyspark=spark.read.option('header','true').csv('test1.csv',inferSchema=True)" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 35, 97 | "id": "79a95903", 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "name": "stdout", 102 | "output_type": "stream", 103 | "text": [ 104 | "root\n", 105 | " |-- Name: string (nullable = true)\n", 106 | " |-- age: integer (nullable = true)\n", 107 | " |-- Experience: integer (nullable = true)\n", 108 | "\n" 109 | ] 110 | } 111 | ], 112 | "source": [ 113 | "### Check the schema\n", 114 | "df_pyspark.printSchema()" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 12, 120 | "id": "8a0d131b", 121 | "metadata": {}, 122 | "outputs": [ 123 | { 124 | "name": "stdout", 125 | "output_type": "stream", 126 | "text": [ 127 | "+---------+---+----------+\n", 128 | "| Name|age|Experience|\n", 129 | "+---------+---+----------+\n", 130 | "| Krish| 31| 10|\n", 131 | "|Sudhanshu| 30| 8|\n", 132 | "| Sunny| 29| 4|\n", 133 | "+---------+---+----------+\n", 134 | "\n" 135 | ] 136 | } 137 | ], 138 | "source": [ 139 | "df_pyspark=spark.read.csv('test1.csv',header=True,inferSchema=True)\n", 140 | "df_pyspark.show()" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 13, 146 | "id": "47a5a108", 147 | "metadata": {}, 148 | "outputs": [ 149 | { 150 | "name": "stdout", 151 | "output_type": "stream", 152 | "text": [ 153 | "root\n", 154 | " |-- Name: string (nullable = true)\n", 155 | " |-- age: integer (nullable = true)\n", 156 | " |-- Experience: integer (nullable = true)\n", 157 | "\n" 158 | ] 159 | } 160 | ], 161 | "source": [ 162 | "### Check the schema\n", 163 | "df_pyspark.printSchema()" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 14, 169 | "id": "19da5885", 170 | "metadata": {}, 171 | "outputs": [ 172 | { 173 | "data": { 174 | "text/plain": [ 175 | "pyspark.sql.dataframe.DataFrame" 176 | ] 177 | }, 178 | "execution_count": 14, 179 | "metadata": {}, 180 | "output_type": "execute_result" 181 | } 182 | ], 183 | "source": [ 184 | "type(df_pyspark)" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 16, 190 | "id": "e4a3c8eb", 191 | "metadata": {}, 192 | "outputs": [ 193 | { 194 | "data": { 195 | "text/plain": [ 196 | "[Row(Name='Krish', age=31, Experience=10),\n", 197 | " Row(Name='Sudhanshu', age=30, Experience=8),\n", 198 | " Row(Name='Sunny', age=29, Experience=4)]" 199 | ] 200 | }, 201 | "execution_count": 16, 202 | "metadata": {}, 203 | "output_type": "execute_result" 204 | } 205 | ], 206 | "source": [ 207 | "df_pyspark.head(3)" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": 17, 213 | "id": "5523ae24", 214 | "metadata": {}, 215 | "outputs": [ 216 | { 217 | "name": "stdout", 218 | "output_type": "stream", 219 | "text": [ 220 | "+---------+---+----------+\n", 221 | "| Name|age|Experience|\n", 222 | "+---------+---+----------+\n", 223 | "| Krish| 31| 10|\n", 224 | "|Sudhanshu| 30| 8|\n", 225 | "| Sunny| 29| 4|\n", 226 | "+---------+---+----------+\n", 227 | "\n" 228 | ] 229 | } 230 | ], 231 | "source": [ 232 | "df_pyspark.show()" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": 23, 238 | "id": "c513816d", 239 | "metadata": {}, 240 | "outputs": [ 241 | { 242 | "name": "stdout", 243 | "output_type": "stream", 244 | "text": [ 245 | "+---------+----------+\n", 246 | "| Name|Experience|\n", 247 | "+---------+----------+\n", 248 | "| Krish| 10|\n", 249 | "|Sudhanshu| 8|\n", 250 | "| Sunny| 4|\n", 251 | "+---------+----------+\n", 252 | "\n" 253 | ] 254 | } 255 | ], 256 | "source": [ 257 | "df_pyspark.select(['Name','Experience']).show()" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 26, 263 | "id": "a8bd20e3", 264 | "metadata": {}, 265 | "outputs": [ 266 | { 267 | "data": { 268 | "text/plain": [ 269 | "Column<'Name'>" 270 | ] 271 | }, 272 | "execution_count": 26, 273 | "metadata": {}, 274 | "output_type": "execute_result" 275 | } 276 | ], 277 | "source": [ 278 | "df_pyspark['Name']" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": 27, 284 | "id": "c3d42722", 285 | "metadata": {}, 286 | "outputs": [ 287 | { 288 | "data": { 289 | "text/plain": [ 290 | "[('Name', 'string'), ('age', 'int'), ('Experience', 'int')]" 291 | ] 292 | }, 293 | "execution_count": 27, 294 | "metadata": {}, 295 | "output_type": "execute_result" 296 | } 297 | ], 298 | "source": [ 299 | "df_pyspark.dtypes" 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": 29, 305 | "id": "fa74b18e", 306 | "metadata": {}, 307 | "outputs": [ 308 | { 309 | "name": "stdout", 310 | "output_type": "stream", 311 | "text": [ 312 | "+-------+-----+----+-----------------+\n", 313 | "|summary| Name| age| Experience|\n", 314 | "+-------+-----+----+-----------------+\n", 315 | "| count| 3| 3| 3|\n", 316 | "| mean| null|30.0|7.333333333333333|\n", 317 | "| stddev| null| 1.0|3.055050463303893|\n", 318 | "| min|Krish| 29| 4|\n", 319 | "| max|Sunny| 31| 10|\n", 320 | "+-------+-----+----+-----------------+\n", 321 | "\n" 322 | ] 323 | } 324 | ], 325 | "source": [ 326 | "df_pyspark.describe().show()" 327 | ] 328 | }, 329 | { 330 | "cell_type": "code", 331 | "execution_count": 36, 332 | "id": "6a8d7b54", 333 | "metadata": {}, 334 | "outputs": [], 335 | "source": [ 336 | "### Adding Columns in data frame\n", 337 | "df_pyspark=df_pyspark.withColumn('Experience After 2 year',df_pyspark['Experience']+2)" 338 | ] 339 | }, 340 | { 341 | "cell_type": "code", 342 | "execution_count": 38, 343 | "id": "e9ff01ed", 344 | "metadata": {}, 345 | "outputs": [ 346 | { 347 | "name": "stdout", 348 | "output_type": "stream", 349 | "text": [ 350 | "+---------+---+----------+-----------------------+\n", 351 | "| Name|age|Experience|Experience After 2 year|\n", 352 | "+---------+---+----------+-----------------------+\n", 353 | "| Krish| 31| 10| 12|\n", 354 | "|Sudhanshu| 30| 8| 10|\n", 355 | "| Sunny| 29| 4| 6|\n", 356 | "+---------+---+----------+-----------------------+\n", 357 | "\n" 358 | ] 359 | } 360 | ], 361 | "source": [ 362 | "df_pyspark.show()" 363 | ] 364 | }, 365 | { 366 | "cell_type": "code", 367 | "execution_count": 41, 368 | "id": "d98641db", 369 | "metadata": {}, 370 | "outputs": [], 371 | "source": [ 372 | "### Drop the columns\n", 373 | "df_pyspark=df_pyspark.drop('Experience After 2 year')" 374 | ] 375 | }, 376 | { 377 | "cell_type": "code", 378 | "execution_count": 42, 379 | "id": "e0a2723f", 380 | "metadata": {}, 381 | "outputs": [ 382 | { 383 | "name": "stdout", 384 | "output_type": "stream", 385 | "text": [ 386 | "+---------+---+----------+\n", 387 | "| Name|age|Experience|\n", 388 | "+---------+---+----------+\n", 389 | "| Krish| 31| 10|\n", 390 | "|Sudhanshu| 30| 8|\n", 391 | "| Sunny| 29| 4|\n", 392 | "+---------+---+----------+\n", 393 | "\n" 394 | ] 395 | } 396 | ], 397 | "source": [ 398 | "df_pyspark.show()" 399 | ] 400 | }, 401 | { 402 | "cell_type": "code", 403 | "execution_count": 44, 404 | "id": "5432faa1", 405 | "metadata": {}, 406 | "outputs": [ 407 | { 408 | "name": "stdout", 409 | "output_type": "stream", 410 | "text": [ 411 | "+---------+---+----------+\n", 412 | "| New Name|age|Experience|\n", 413 | "+---------+---+----------+\n", 414 | "| Krish| 31| 10|\n", 415 | "|Sudhanshu| 30| 8|\n", 416 | "| Sunny| 29| 4|\n", 417 | "+---------+---+----------+\n", 418 | "\n" 419 | ] 420 | } 421 | ], 422 | "source": [ 423 | "### Rename the columns\n", 424 | "df_pyspark.withColumnRenamed('Name','New Name').show()" 425 | ] 426 | }, 427 | { 428 | "cell_type": "code", 429 | "execution_count": null, 430 | "id": "2e5b7d72", 431 | "metadata": {}, 432 | "outputs": [], 433 | "source": [] 434 | }, 435 | { 436 | "cell_type": "code", 437 | "execution_count": null, 438 | "id": "f211a741", 439 | "metadata": {}, 440 | "outputs": [], 441 | "source": [] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": null, 446 | "id": "9a80b806", 447 | "metadata": {}, 448 | "outputs": [], 449 | "source": [] 450 | }, 451 | { 452 | "cell_type": "code", 453 | "execution_count": null, 454 | "id": "e00f90e8", 455 | "metadata": {}, 456 | "outputs": [], 457 | "source": [] 458 | }, 459 | { 460 | "cell_type": "code", 461 | "execution_count": null, 462 | "id": "7c6cb899", 463 | "metadata": {}, 464 | "outputs": [], 465 | "source": [] 466 | }, 467 | { 468 | "cell_type": "code", 469 | "execution_count": null, 470 | "id": "2e0a8c75", 471 | "metadata": {}, 472 | "outputs": [], 473 | "source": [] 474 | } 475 | ], 476 | "metadata": { 477 | "kernelspec": { 478 | "display_name": "Python 3", 479 | "language": "python", 480 | "name": "python3" 481 | }, 482 | "language_info": { 483 | "codemirror_mode": { 484 | "name": "ipython", 485 | "version": 3 486 | }, 487 | "file_extension": ".py", 488 | "mimetype": "text/x-python", 489 | "name": "python", 490 | "nbconvert_exporter": "python", 491 | "pygments_lexer": "ipython3", 492 | "version": "3.7.10" 493 | } 494 | }, 495 | "nbformat": 4, 496 | "nbformat_minor": 5 497 | } 498 | -------------------------------------------------------------------------------- /Tutorial 3- Pyspark Dataframe- Handling Missing Values.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "ded0783b", 6 | "metadata": {}, 7 | "source": [ 8 | "### Pyspark Handling Missing Values\n", 9 | "- Dropping Columns\n", 10 | "- Dropping Rows\n", 11 | "- Various Parameter In Dropping functionalities\n", 12 | "- Handling Missing values by Mean, MEdian And Mode" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 3, 18 | "id": "805e7382", 19 | "metadata": {}, 20 | "outputs": [], 21 | "source": [ 22 | "from pyspark.sql import SparkSession\n", 23 | "spark=SparkSession.builder.appName('Practise').getOrCreate()" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 4, 29 | "id": "e48ebc07", 30 | "metadata": {}, 31 | "outputs": [], 32 | "source": [ 33 | "df_pyspark=spark.read.csv('test2.csv',header=True,inferSchema=True)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 5, 39 | "id": "53ab7bbc", 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "root\n", 47 | " |-- Name: string (nullable = true)\n", 48 | " |-- age: integer (nullable = true)\n", 49 | " |-- Experience: integer (nullable = true)\n", 50 | " |-- Salary: integer (nullable = true)\n", 51 | "\n" 52 | ] 53 | } 54 | ], 55 | "source": [ 56 | "df_pyspark.printSchema()" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 6, 62 | "id": "ed677b30", 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "+---------+----+----------+------+\n", 70 | "| Name| age|Experience|Salary|\n", 71 | "+---------+----+----------+------+\n", 72 | "| Krish| 31| 10| 30000|\n", 73 | "|Sudhanshu| 30| 8| 25000|\n", 74 | "| Sunny| 29| 4| 20000|\n", 75 | "| Paul| 24| 3| 20000|\n", 76 | "| Harsha| 21| 1| 15000|\n", 77 | "| Shubham| 23| 2| 18000|\n", 78 | "| Mahesh|null| null| 40000|\n", 79 | "| null| 34| 10| 38000|\n", 80 | "| null| 36| null| null|\n", 81 | "+---------+----+----------+------+\n", 82 | "\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "df_pyspark.show()" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 7, 93 | "id": "523d3c4e", 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "name": "stdout", 98 | "output_type": "stream", 99 | "text": [ 100 | "+----+----------+------+\n", 101 | "| age|Experience|Salary|\n", 102 | "+----+----------+------+\n", 103 | "| 31| 10| 30000|\n", 104 | "| 30| 8| 25000|\n", 105 | "| 29| 4| 20000|\n", 106 | "| 24| 3| 20000|\n", 107 | "| 21| 1| 15000|\n", 108 | "| 23| 2| 18000|\n", 109 | "|null| null| 40000|\n", 110 | "| 34| 10| 38000|\n", 111 | "| 36| null| null|\n", 112 | "+----+----------+------+\n", 113 | "\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "##drop the columns\n", 119 | "df_pyspark.drop('Name').show()" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 8, 125 | "id": "9c041e07", 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "+---------+----+----------+------+\n", 133 | "| Name| age|Experience|Salary|\n", 134 | "+---------+----+----------+------+\n", 135 | "| Krish| 31| 10| 30000|\n", 136 | "|Sudhanshu| 30| 8| 25000|\n", 137 | "| Sunny| 29| 4| 20000|\n", 138 | "| Paul| 24| 3| 20000|\n", 139 | "| Harsha| 21| 1| 15000|\n", 140 | "| Shubham| 23| 2| 18000|\n", 141 | "| Mahesh|null| null| 40000|\n", 142 | "| null| 34| 10| 38000|\n", 143 | "| null| 36| null| null|\n", 144 | "+---------+----+----------+------+\n", 145 | "\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "df_pyspark.show()" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 9, 156 | "id": "36845e38", 157 | "metadata": {}, 158 | "outputs": [ 159 | { 160 | "name": "stdout", 161 | "output_type": "stream", 162 | "text": [ 163 | "+---------+---+----------+------+\n", 164 | "| Name|age|Experience|Salary|\n", 165 | "+---------+---+----------+------+\n", 166 | "| Krish| 31| 10| 30000|\n", 167 | "|Sudhanshu| 30| 8| 25000|\n", 168 | "| Sunny| 29| 4| 20000|\n", 169 | "| Paul| 24| 3| 20000|\n", 170 | "| Harsha| 21| 1| 15000|\n", 171 | "| Shubham| 23| 2| 18000|\n", 172 | "+---------+---+----------+------+\n", 173 | "\n" 174 | ] 175 | } 176 | ], 177 | "source": [ 178 | "df_pyspark.na.drop().show()" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 14, 184 | "id": "156e41cf", 185 | "metadata": {}, 186 | "outputs": [ 187 | { 188 | "name": "stdout", 189 | "output_type": "stream", 190 | "text": [ 191 | "+---------+---+----------+------+\n", 192 | "| Name|age|Experience|Salary|\n", 193 | "+---------+---+----------+------+\n", 194 | "| Krish| 31| 10| 30000|\n", 195 | "|Sudhanshu| 30| 8| 25000|\n", 196 | "| Sunny| 29| 4| 20000|\n", 197 | "| Paul| 24| 3| 20000|\n", 198 | "| Harsha| 21| 1| 15000|\n", 199 | "| Shubham| 23| 2| 18000|\n", 200 | "| | | | |\n", 201 | "+---------+---+----------+------+\n", 202 | "\n" 203 | ] 204 | } 205 | ], 206 | "source": [ 207 | "### any==how\n", 208 | "df_pyspark.na.drop(how=\"any\").show()" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 17, 214 | "id": "e9af0da0", 215 | "metadata": {}, 216 | "outputs": [ 217 | { 218 | "name": "stdout", 219 | "output_type": "stream", 220 | "text": [ 221 | "+---------+---+----------+------+\n", 222 | "| Name|age|Experience|Salary|\n", 223 | "+---------+---+----------+------+\n", 224 | "| Krish| 31| 10| 30000|\n", 225 | "|Sudhanshu| 30| 8| 25000|\n", 226 | "| Sunny| 29| 4| 20000|\n", 227 | "| Paul| 24| 3| 20000|\n", 228 | "| Harsha| 21| 1| 15000|\n", 229 | "| Shubham| 23| 2| 18000|\n", 230 | "| null| 34| 10| 38000|\n", 231 | "| | | | |\n", 232 | "+---------+---+----------+------+\n", 233 | "\n" 234 | ] 235 | } 236 | ], 237 | "source": [ 238 | "##threshold\n", 239 | "df_pyspark.na.drop(how=\"any\",thresh=3).show()" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 19, 245 | "id": "787fc949", 246 | "metadata": {}, 247 | "outputs": [ 248 | { 249 | "name": "stdout", 250 | "output_type": "stream", 251 | "text": [ 252 | "+---------+---+----------+------+\n", 253 | "| Name|age|Experience|Salary|\n", 254 | "+---------+---+----------+------+\n", 255 | "| Krish| 31| 10| 30000|\n", 256 | "|Sudhanshu| 30| 8| 25000|\n", 257 | "| Sunny| 29| 4| 20000|\n", 258 | "| Paul| 24| 3| 20000|\n", 259 | "| Harsha| 21| 1| 15000|\n", 260 | "| Shubham| 23| 2| 18000|\n", 261 | "| null| 34| 10| 38000|\n", 262 | "| null| 36| null| null|\n", 263 | "| | | | |\n", 264 | "+---------+---+----------+------+\n", 265 | "\n" 266 | ] 267 | } 268 | ], 269 | "source": [ 270 | "##Subset\n", 271 | "df_pyspark.na.drop(how=\"any\",subset=['Age']).show()" 272 | ] 273 | }, 274 | { 275 | "cell_type": "code", 276 | "execution_count": 22, 277 | "id": "72bad9ba", 278 | "metadata": {}, 279 | "outputs": [ 280 | { 281 | "name": "stdout", 282 | "output_type": "stream", 283 | "text": [ 284 | "+---------+--------------+--------------+------+\n", 285 | "| Name| age| Experience|Salary|\n", 286 | "+---------+--------------+--------------+------+\n", 287 | "| Krish| 31| 10| 30000|\n", 288 | "|Sudhanshu| 30| 8| 25000|\n", 289 | "| Sunny| 29| 4| 20000|\n", 290 | "| Paul| 24| 3| 20000|\n", 291 | "| Harsha| 21| 1| 15000|\n", 292 | "| Shubham| 23| 2| 18000|\n", 293 | "| Mahesh|Missing Values|Missing Values| 40000|\n", 294 | "| null| 34| 10| 38000|\n", 295 | "| null| 36|Missing Values| null|\n", 296 | "| | | | |\n", 297 | "+---------+--------------+--------------+------+\n", 298 | "\n" 299 | ] 300 | } 301 | ], 302 | "source": [ 303 | "### Filling the Missing Value\n", 304 | "df_pyspark.na.fill('Missing Values',['Experience','age']).show()" 305 | ] 306 | }, 307 | { 308 | "cell_type": "code", 309 | "execution_count": 38, 310 | "id": "64e01bb9", 311 | "metadata": {}, 312 | "outputs": [ 313 | { 314 | "name": "stdout", 315 | "output_type": "stream", 316 | "text": [ 317 | "+---------+----+----------+------+\n", 318 | "| Name| age|Experience|Salary|\n", 319 | "+---------+----+----------+------+\n", 320 | "| Krish| 31| 10| 30000|\n", 321 | "|Sudhanshu| 30| 8| 25000|\n", 322 | "| Sunny| 29| 4| 20000|\n", 323 | "| Paul| 24| 3| 20000|\n", 324 | "| Harsha| 21| 1| 15000|\n", 325 | "| Shubham| 23| 2| 18000|\n", 326 | "| Mahesh|null| null| 40000|\n", 327 | "| null| 34| 10| 38000|\n", 328 | "| null| 36| null| null|\n", 329 | "| | | | |\n", 330 | "+---------+----+----------+------+\n", 331 | "\n" 332 | ] 333 | } 334 | ], 335 | "source": [ 336 | "df_pyspark.show()" 337 | ] 338 | }, 339 | { 340 | "cell_type": "code", 341 | "execution_count": 44, 342 | "id": "b66832fd", 343 | "metadata": {}, 344 | "outputs": [ 345 | { 346 | "name": "stdout", 347 | "output_type": "stream", 348 | "text": [ 349 | "root\n", 350 | " |-- Name: string (nullable = true)\n", 351 | " |-- age: string (nullable = true)\n", 352 | " |-- Experience: string (nullable = true)\n", 353 | " |-- Salary: string (nullable = true)\n", 354 | "\n" 355 | ] 356 | } 357 | ], 358 | "source": [ 359 | "df_pyspark.printSchema()" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": 13, 365 | "id": "e31190f2", 366 | "metadata": {}, 367 | "outputs": [], 368 | "source": [ 369 | "from pyspark.ml.feature import Imputer\n", 370 | "\n", 371 | "imputer = Imputer(\n", 372 | " inputCols=['age', 'Experience', 'Salary'], \n", 373 | " outputCols=[\"{}_imputed\".format(c) for c in ['age', 'Experience', 'Salary']]\n", 374 | " ).setStrategy(\"median\")" 375 | ] 376 | }, 377 | { 378 | "cell_type": "code", 379 | "execution_count": 14, 380 | "id": "d84c4a3d", 381 | "metadata": {}, 382 | "outputs": [ 383 | { 384 | "name": "stdout", 385 | "output_type": "stream", 386 | "text": [ 387 | "+---------+----+----------+------+-----------+------------------+--------------+\n", 388 | "| Name| age|Experience|Salary|age_imputed|Experience_imputed|Salary_imputed|\n", 389 | "+---------+----+----------+------+-----------+------------------+--------------+\n", 390 | "| Krish| 31| 10| 30000| 31| 10| 30000|\n", 391 | "|Sudhanshu| 30| 8| 25000| 30| 8| 25000|\n", 392 | "| Sunny| 29| 4| 20000| 29| 4| 20000|\n", 393 | "| Paul| 24| 3| 20000| 24| 3| 20000|\n", 394 | "| Harsha| 21| 1| 15000| 21| 1| 15000|\n", 395 | "| Shubham| 23| 2| 18000| 23| 2| 18000|\n", 396 | "| Mahesh|null| null| 40000| 29| 4| 40000|\n", 397 | "| null| 34| 10| 38000| 34| 10| 38000|\n", 398 | "| null| 36| null| null| 36| 4| 20000|\n", 399 | "+---------+----+----------+------+-----------+------------------+--------------+\n", 400 | "\n" 401 | ] 402 | } 403 | ], 404 | "source": [ 405 | "# Add imputation cols to df\n", 406 | "imputer.fit(df_pyspark).transform(df_pyspark).show()" 407 | ] 408 | }, 409 | { 410 | "cell_type": "code", 411 | "execution_count": null, 412 | "id": "8cd38651", 413 | "metadata": {}, 414 | "outputs": [], 415 | "source": [] 416 | }, 417 | { 418 | "cell_type": "code", 419 | "execution_count": null, 420 | "id": "b63a65ae", 421 | "metadata": {}, 422 | "outputs": [], 423 | "source": [] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": null, 428 | "id": "2992b6a2", 429 | "metadata": {}, 430 | "outputs": [], 431 | "source": [] 432 | }, 433 | { 434 | "cell_type": "code", 435 | "execution_count": null, 436 | "id": "d995bc12", 437 | "metadata": {}, 438 | "outputs": [], 439 | "source": [] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": null, 444 | "id": "c17fd913", 445 | "metadata": {}, 446 | "outputs": [], 447 | "source": [] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "execution_count": null, 452 | "id": "cdf76805", 453 | "metadata": {}, 454 | "outputs": [], 455 | "source": [] 456 | }, 457 | { 458 | "cell_type": "code", 459 | "execution_count": null, 460 | "id": "835812ae", 461 | "metadata": {}, 462 | "outputs": [], 463 | "source": [] 464 | } 465 | ], 466 | "metadata": { 467 | "kernelspec": { 468 | "display_name": "Python 3", 469 | "language": "python", 470 | "name": "python3" 471 | }, 472 | "language_info": { 473 | "codemirror_mode": { 474 | "name": "ipython", 475 | "version": 3 476 | }, 477 | "file_extension": ".py", 478 | "mimetype": "text/x-python", 479 | "name": "python", 480 | "nbconvert_exporter": "python", 481 | "pygments_lexer": "ipython3", 482 | "version": "3.7.10" 483 | } 484 | }, 485 | "nbformat": 4, 486 | "nbformat_minor": 5 487 | } 488 | -------------------------------------------------------------------------------- /Tutorial 4- Pyspark Dataframes- Filter operation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "5d6364f6", 6 | "metadata": {}, 7 | "source": [ 8 | "### Pyspark Dataframes\n", 9 | "- Filter Operation\n", 10 | "- &,|,==\n", 11 | "- ~" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "id": "d8d843e1", 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [ 21 | "from pyspark.sql import SparkSession" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 2, 27 | "id": "9fd2900c", 28 | "metadata": {}, 29 | "outputs": [], 30 | "source": [ 31 | "spark=SparkSession.builder.appName('dataframe').getOrCreate()" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 3, 37 | "id": "7964d064", 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "name": "stdout", 42 | "output_type": "stream", 43 | "text": [ 44 | "+---------+---+----------+------+\n", 45 | "| Name|age|Experience|Salary|\n", 46 | "+---------+---+----------+------+\n", 47 | "| Krish| 31| 10| 30000|\n", 48 | "|Sudhanshu| 30| 8| 25000|\n", 49 | "| Sunny| 29| 4| 20000|\n", 50 | "| Paul| 24| 3| 20000|\n", 51 | "| Harsha| 21| 1| 15000|\n", 52 | "| Shubham| 23| 2| 18000|\n", 53 | "+---------+---+----------+------+\n", 54 | "\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "df_pyspark=spark.read.csv('test1.csv',header=True,inferSchema=True)\n", 60 | "df_pyspark.show()" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "id": "e0fdbb15", 66 | "metadata": {}, 67 | "source": [ 68 | "### Filter Operations" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 4, 74 | "id": "c21edffc", 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "name": "stdout", 79 | "output_type": "stream", 80 | "text": [ 81 | "+-------+---+----------+------+\n", 82 | "| Name|age|Experience|Salary|\n", 83 | "+-------+---+----------+------+\n", 84 | "| Sunny| 29| 4| 20000|\n", 85 | "| Paul| 24| 3| 20000|\n", 86 | "| Harsha| 21| 1| 15000|\n", 87 | "|Shubham| 23| 2| 18000|\n", 88 | "+-------+---+----------+------+\n", 89 | "\n" 90 | ] 91 | } 92 | ], 93 | "source": [ 94 | "### Salary of the people less than or equal to 20000\n", 95 | "df_pyspark.filter(\"Salary<=20000\").show()" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 5, 101 | "id": "d5a5f3af", 102 | "metadata": {}, 103 | "outputs": [ 104 | { 105 | "name": "stdout", 106 | "output_type": "stream", 107 | "text": [ 108 | "+-------+---+\n", 109 | "| Name|age|\n", 110 | "+-------+---+\n", 111 | "| Sunny| 29|\n", 112 | "| Paul| 24|\n", 113 | "| Harsha| 21|\n", 114 | "|Shubham| 23|\n", 115 | "+-------+---+\n", 116 | "\n" 117 | ] 118 | } 119 | ], 120 | "source": [ 121 | "df_pyspark.filter(\"Salary<=20000\").select(['Name','age']).show()" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 6, 127 | "id": "4bebe963", 128 | "metadata": {}, 129 | "outputs": [ 130 | { 131 | "name": "stdout", 132 | "output_type": "stream", 133 | "text": [ 134 | "+-------+---+----------+------+\n", 135 | "| Name|age|Experience|Salary|\n", 136 | "+-------+---+----------+------+\n", 137 | "| Sunny| 29| 4| 20000|\n", 138 | "| Paul| 24| 3| 20000|\n", 139 | "| Harsha| 21| 1| 15000|\n", 140 | "|Shubham| 23| 2| 18000|\n", 141 | "+-------+---+----------+------+\n", 142 | "\n" 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "df_pyspark.filter(df_pyspark['Salary']<=20000).show()" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 8, 153 | "id": "26f76ee1", 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "name": "stdout", 158 | "output_type": "stream", 159 | "text": [ 160 | "+---------+---+----------+------+\n", 161 | "| Name|age|Experience|Salary|\n", 162 | "+---------+---+----------+------+\n", 163 | "| Krish| 31| 10| 30000|\n", 164 | "|Sudhanshu| 30| 8| 25000|\n", 165 | "| Sunny| 29| 4| 20000|\n", 166 | "| Paul| 24| 3| 20000|\n", 167 | "| Harsha| 21| 1| 15000|\n", 168 | "| Shubham| 23| 2| 18000|\n", 169 | "+---------+---+----------+------+\n", 170 | "\n" 171 | ] 172 | } 173 | ], 174 | "source": [ 175 | "df_pyspark.filter((df_pyspark['Salary']<=20000) | \n", 176 | " (df_pyspark['Salary']>=15000)).show()" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 9, 182 | "id": "5df3d5ab", 183 | "metadata": {}, 184 | "outputs": [ 185 | { 186 | "name": "stdout", 187 | "output_type": "stream", 188 | "text": [ 189 | "+---------+---+----------+------+\n", 190 | "| Name|age|Experience|Salary|\n", 191 | "+---------+---+----------+------+\n", 192 | "| Krish| 31| 10| 30000|\n", 193 | "|Sudhanshu| 30| 8| 25000|\n", 194 | "+---------+---+----------+------+\n", 195 | "\n" 196 | ] 197 | } 198 | ], 199 | "source": [ 200 | "df_pyspark.filter(~(df_pyspark['Salary']<=20000)).show()" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": null, 206 | "id": "afc87f75", 207 | "metadata": {}, 208 | "outputs": [], 209 | "source": [] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": null, 214 | "id": "060e065a", 215 | "metadata": {}, 216 | "outputs": [], 217 | "source": [] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": null, 222 | "id": "5a4c8d24", 223 | "metadata": {}, 224 | "outputs": [], 225 | "source": [] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": null, 230 | "id": "699d560f", 231 | "metadata": {}, 232 | "outputs": [], 233 | "source": [] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": null, 238 | "id": "bd74ab0c", 239 | "metadata": {}, 240 | "outputs": [], 241 | "source": [] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": null, 246 | "id": "cbc4375a", 247 | "metadata": {}, 248 | "outputs": [], 249 | "source": [] 250 | } 251 | ], 252 | "metadata": { 253 | "kernelspec": { 254 | "display_name": "Python 3", 255 | "language": "python", 256 | "name": "python3" 257 | }, 258 | "language_info": { 259 | "codemirror_mode": { 260 | "name": "ipython", 261 | "version": 3 262 | }, 263 | "file_extension": ".py", 264 | "mimetype": "text/x-python", 265 | "name": "python", 266 | "nbconvert_exporter": "python", 267 | "pygments_lexer": "ipython3", 268 | "version": "3.7.10" 269 | } 270 | }, 271 | "nbformat": 4, 272 | "nbformat_minor": 5 273 | } 274 | -------------------------------------------------------------------------------- /Tutorial 5- Pyspark With Python-GroupBy And Aggregate Functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "2efa0fce", 6 | "metadata": {}, 7 | "source": [ 8 | "### Pyspark GroupBy And Aggregate Functions" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "8f336300", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "from pyspark.sql import SparkSession" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 2, 24 | "id": "23513a5d", 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "spark=SparkSession.builder.appName('Agg').getOrCreate()" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 3, 34 | "id": "248b3a5c", 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "data": { 39 | "text/html": [ 40 | "\n", 41 | "
\n", 42 | "

SparkSession - in-memory

\n", 43 | " \n", 44 | "
\n", 45 | "

SparkContext

\n", 46 | "\n", 47 | "

Spark UI

\n", 48 | "\n", 49 | "
\n", 50 | "
Version
\n", 51 | "
v3.1.1
\n", 52 | "
Master
\n", 53 | "
local[*]
\n", 54 | "
AppName
\n", 55 | "
Agg
\n", 56 | "
\n", 57 | "
\n", 58 | " \n", 59 | "
\n", 60 | " " 61 | ], 62 | "text/plain": [ 63 | "" 64 | ] 65 | }, 66 | "execution_count": 3, 67 | "metadata": {}, 68 | "output_type": "execute_result" 69 | } 70 | ], 71 | "source": [ 72 | "spark" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 4, 78 | "id": "4d3bd081", 79 | "metadata": {}, 80 | "outputs": [], 81 | "source": [ 82 | "df_pyspark=spark.read.csv('test3.csv',header=True,inferSchema=True)" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 5, 88 | "id": "7ed791ed", 89 | "metadata": {}, 90 | "outputs": [ 91 | { 92 | "name": "stdout", 93 | "output_type": "stream", 94 | "text": [ 95 | "+---------+------------+------+\n", 96 | "| Name| Departments|salary|\n", 97 | "+---------+------------+------+\n", 98 | "| Krish|Data Science| 10000|\n", 99 | "| Krish| IOT| 5000|\n", 100 | "| Mahesh| Big Data| 4000|\n", 101 | "| Krish| Big Data| 4000|\n", 102 | "| Mahesh|Data Science| 3000|\n", 103 | "|Sudhanshu|Data Science| 20000|\n", 104 | "|Sudhanshu| IOT| 10000|\n", 105 | "|Sudhanshu| Big Data| 5000|\n", 106 | "| Sunny|Data Science| 10000|\n", 107 | "| Sunny| Big Data| 2000|\n", 108 | "+---------+------------+------+\n", 109 | "\n" 110 | ] 111 | } 112 | ], 113 | "source": [ 114 | "df_pyspark.show()" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 6, 120 | "id": "d57d24ca", 121 | "metadata": {}, 122 | "outputs": [ 123 | { 124 | "name": "stdout", 125 | "output_type": "stream", 126 | "text": [ 127 | "root\n", 128 | " |-- Name: string (nullable = true)\n", 129 | " |-- Departments: string (nullable = true)\n", 130 | " |-- salary: integer (nullable = true)\n", 131 | "\n" 132 | ] 133 | } 134 | ], 135 | "source": [ 136 | "df_pyspark.printSchema()" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 9, 142 | "id": "f15f8197", 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "output_type": "stream", 148 | "text": [ 149 | "+---------+-----------+\n", 150 | "| Name|sum(salary)|\n", 151 | "+---------+-----------+\n", 152 | "|Sudhanshu| 35000|\n", 153 | "| Sunny| 12000|\n", 154 | "| Krish| 19000|\n", 155 | "| Mahesh| 7000|\n", 156 | "+---------+-----------+\n", 157 | "\n" 158 | ] 159 | } 160 | ], 161 | "source": [ 162 | "## Groupby\n", 163 | "### Grouped to find the maximum salary\n", 164 | "df_pyspark.groupBy('Name').sum().show()" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": 19, 170 | "id": "fc122ace", 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "name": "stdout", 175 | "output_type": "stream", 176 | "text": [ 177 | "+---------+------------------+\n", 178 | "| Name| avg(salary)|\n", 179 | "+---------+------------------+\n", 180 | "|Sudhanshu|11666.666666666666|\n", 181 | "| Sunny| 6000.0|\n", 182 | "| Krish| 6333.333333333333|\n", 183 | "| Mahesh| 3500.0|\n", 184 | "+---------+------------------+\n", 185 | "\n" 186 | ] 187 | } 188 | ], 189 | "source": [ 190 | "df_pyspark.groupBy('Name').avg().show()" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 11, 196 | "id": "151d2264", 197 | "metadata": {}, 198 | "outputs": [ 199 | { 200 | "name": "stdout", 201 | "output_type": "stream", 202 | "text": [ 203 | "+------------+-----------+\n", 204 | "| Departments|sum(salary)|\n", 205 | "+------------+-----------+\n", 206 | "| IOT| 15000|\n", 207 | "| Big Data| 15000|\n", 208 | "|Data Science| 43000|\n", 209 | "+------------+-----------+\n", 210 | "\n" 211 | ] 212 | } 213 | ], 214 | "source": [ 215 | "### Groupby Departmernts which gives maximum salary\n", 216 | "df_pyspark.groupBy('Departments').sum().show()" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": 12, 222 | "id": "66fe5552", 223 | "metadata": {}, 224 | "outputs": [ 225 | { 226 | "name": "stdout", 227 | "output_type": "stream", 228 | "text": [ 229 | "+------------+-----------+\n", 230 | "| Departments|avg(salary)|\n", 231 | "+------------+-----------+\n", 232 | "| IOT| 7500.0|\n", 233 | "| Big Data| 3750.0|\n", 234 | "|Data Science| 10750.0|\n", 235 | "+------------+-----------+\n", 236 | "\n" 237 | ] 238 | } 239 | ], 240 | "source": [ 241 | "df_pyspark.groupBy('Departments').mean().show()" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "execution_count": 14, 247 | "id": "bc7bf192", 248 | "metadata": {}, 249 | "outputs": [ 250 | { 251 | "name": "stdout", 252 | "output_type": "stream", 253 | "text": [ 254 | "+------------+-----+\n", 255 | "| Departments|count|\n", 256 | "+------------+-----+\n", 257 | "| IOT| 2|\n", 258 | "| Big Data| 4|\n", 259 | "|Data Science| 4|\n", 260 | "+------------+-----+\n", 261 | "\n" 262 | ] 263 | } 264 | ], 265 | "source": [ 266 | "df_pyspark.groupBy('Departments').count().show()" 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": 15, 272 | "id": "37b26cbe", 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "name": "stdout", 277 | "output_type": "stream", 278 | "text": [ 279 | "+-----------+\n", 280 | "|sum(Salary)|\n", 281 | "+-----------+\n", 282 | "| 73000|\n", 283 | "+-----------+\n", 284 | "\n" 285 | ] 286 | } 287 | ], 288 | "source": [ 289 | "df_pyspark.agg({'Salary':'sum'}).show()" 290 | ] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "execution_count": null, 295 | "id": "bb21f03f", 296 | "metadata": {}, 297 | "outputs": [], 298 | "source": [] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": null, 303 | "id": "1c7d8f83", 304 | "metadata": {}, 305 | "outputs": [], 306 | "source": [] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": null, 311 | "id": "9dc7aa65", 312 | "metadata": {}, 313 | "outputs": [], 314 | "source": [] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "execution_count": null, 319 | "id": "fdd3fbac", 320 | "metadata": {}, 321 | "outputs": [], 322 | "source": [] 323 | }, 324 | { 325 | "cell_type": "code", 326 | "execution_count": null, 327 | "id": "375a6fda", 328 | "metadata": {}, 329 | "outputs": [], 330 | "source": [] 331 | }, 332 | { 333 | "cell_type": "code", 334 | "execution_count": null, 335 | "id": "0aa434e6", 336 | "metadata": {}, 337 | "outputs": [], 338 | "source": [] 339 | }, 340 | { 341 | "cell_type": "code", 342 | "execution_count": null, 343 | "id": "c82781ad", 344 | "metadata": {}, 345 | "outputs": [], 346 | "source": [] 347 | } 348 | ], 349 | "metadata": { 350 | "kernelspec": { 351 | "display_name": "Python 3", 352 | "language": "python", 353 | "name": "python3" 354 | }, 355 | "language_info": { 356 | "codemirror_mode": { 357 | "name": "ipython", 358 | "version": 3 359 | }, 360 | "file_extension": ".py", 361 | "mimetype": "text/x-python", 362 | "name": "python", 363 | "nbconvert_exporter": "python", 364 | "pygments_lexer": "ipython3", 365 | "version": "3.7.10" 366 | } 367 | }, 368 | "nbformat": 4, 369 | "nbformat_minor": 5 370 | } 371 | -------------------------------------------------------------------------------- /Tutorial 6-Example Of Pyspark ML.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "16da6c54", 6 | "metadata": {}, 7 | "source": [ 8 | "### Examples Of Pyspark ML" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 71, 14 | "id": "0b9da3ad", 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "from pyspark.sql import SparkSession\n", 19 | "spark=SparkSession.builder.appName('Missing').getOrCreate()" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 72, 25 | "id": "735525da", 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "## Read The dataset\n", 30 | "training = spark.read.csv('test1.csv',header=True,inferSchema=True)" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 73, 36 | "id": "d6e038c9", 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "name": "stdout", 41 | "output_type": "stream", 42 | "text": [ 43 | "+---------+---+----------+------+\n", 44 | "| Name|age|Experience|Salary|\n", 45 | "+---------+---+----------+------+\n", 46 | "| Krish| 31| 10| 30000|\n", 47 | "|Sudhanshu| 30| 8| 25000|\n", 48 | "| Sunny| 29| 4| 20000|\n", 49 | "| Paul| 24| 3| 20000|\n", 50 | "| Harsha| 21| 1| 15000|\n", 51 | "| Shubham| 23| 2| 18000|\n", 52 | "+---------+---+----------+------+\n", 53 | "\n" 54 | ] 55 | } 56 | ], 57 | "source": [ 58 | "training.show()\n", 59 | "\n" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 74, 65 | "id": "6b3dd5ff", 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "name": "stdout", 70 | "output_type": "stream", 71 | "text": [ 72 | "root\n", 73 | " |-- Name: string (nullable = true)\n", 74 | " |-- age: integer (nullable = true)\n", 75 | " |-- Experience: integer (nullable = true)\n", 76 | " |-- Salary: integer (nullable = true)\n", 77 | "\n" 78 | ] 79 | } 80 | ], 81 | "source": [ 82 | "training.printSchema()" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 75, 88 | "id": "5d3227e6", 89 | "metadata": {}, 90 | "outputs": [ 91 | { 92 | "data": { 93 | "text/plain": [ 94 | "['Name', 'age', 'Experience', 'Salary']" 95 | ] 96 | }, 97 | "execution_count": 75, 98 | "metadata": {}, 99 | "output_type": "execute_result" 100 | } 101 | ], 102 | "source": [ 103 | "training.columns" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "id": "cffef5b9", 110 | "metadata": {}, 111 | "outputs": [], 112 | "source": [ 113 | "[Age,Experience]----> new feature--->independent feature" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 76, 119 | "id": "e6273555", 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "from pyspark.ml.feature import VectorAssembler\n", 124 | "featureassembler=VectorAssembler(inputCols=[\"age\",\"Experience\"],outputCol=\"Independent Features\")" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 77, 130 | "id": "0b69744c", 131 | "metadata": {}, 132 | "outputs": [], 133 | "source": [ 134 | "output=featureassembler.transform(training)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 78, 140 | "id": "60961194", 141 | "metadata": {}, 142 | "outputs": [ 143 | { 144 | "name": "stdout", 145 | "output_type": "stream", 146 | "text": [ 147 | "+---------+---+----------+------+--------------------+\n", 148 | "| Name|age|Experience|Salary|Independent Features|\n", 149 | "+---------+---+----------+------+--------------------+\n", 150 | "| Krish| 31| 10| 30000| [31.0,10.0]|\n", 151 | "|Sudhanshu| 30| 8| 25000| [30.0,8.0]|\n", 152 | "| Sunny| 29| 4| 20000| [29.0,4.0]|\n", 153 | "| Paul| 24| 3| 20000| [24.0,3.0]|\n", 154 | "| Harsha| 21| 1| 15000| [21.0,1.0]|\n", 155 | "| Shubham| 23| 2| 18000| [23.0,2.0]|\n", 156 | "+---------+---+----------+------+--------------------+\n", 157 | "\n" 158 | ] 159 | } 160 | ], 161 | "source": [ 162 | "output.show()" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 79, 168 | "id": "2c27434a", 169 | "metadata": {}, 170 | "outputs": [ 171 | { 172 | "data": { 173 | "text/plain": [ 174 | "['Name', 'age', 'Experience', 'Salary', 'Independent Features']" 175 | ] 176 | }, 177 | "execution_count": 79, 178 | "metadata": {}, 179 | "output_type": "execute_result" 180 | } 181 | ], 182 | "source": [ 183 | "output.columns" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 80, 189 | "id": "54a0ccab", 190 | "metadata": {}, 191 | "outputs": [], 192 | "source": [ 193 | "finalized_data=output.select(\"Independent Features\",\"Salary\")" 194 | ] 195 | }, 196 | { 197 | "cell_type": "code", 198 | "execution_count": 81, 199 | "id": "f7a73845", 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "name": "stdout", 204 | "output_type": "stream", 205 | "text": [ 206 | "+--------------------+------+\n", 207 | "|Independent Features|Salary|\n", 208 | "+--------------------+------+\n", 209 | "| [31.0,10.0]| 30000|\n", 210 | "| [30.0,8.0]| 25000|\n", 211 | "| [29.0,4.0]| 20000|\n", 212 | "| [24.0,3.0]| 20000|\n", 213 | "| [21.0,1.0]| 15000|\n", 214 | "| [23.0,2.0]| 18000|\n", 215 | "+--------------------+------+\n", 216 | "\n" 217 | ] 218 | } 219 | ], 220 | "source": [ 221 | "finalized_data.show()" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": 82, 227 | "id": "0b11192b", 228 | "metadata": {}, 229 | "outputs": [], 230 | "source": [ 231 | "from pyspark.ml.regression import LinearRegression\n", 232 | "##train test split\n", 233 | "train_data,test_data=finalized_data.randomSplit([0.75,0.25])\n", 234 | "regressor=LinearRegression(featuresCol='Independent Features', labelCol='Salary')\n", 235 | "regressor=regressor.fit(train_data)" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": 83, 241 | "id": "fa4ec997", 242 | "metadata": {}, 243 | "outputs": [ 244 | { 245 | "data": { 246 | "text/plain": [ 247 | "DenseVector([-5000.0, 7000.0])" 248 | ] 249 | }, 250 | "execution_count": 83, 251 | "metadata": {}, 252 | "output_type": "execute_result" 253 | } 254 | ], 255 | "source": [ 256 | "### Coefficients\n", 257 | "regressor.coefficients" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 84, 263 | "id": "eba911b6", 264 | "metadata": {}, 265 | "outputs": [ 266 | { 267 | "data": { 268 | "text/plain": [ 269 | "118999.99999893687" 270 | ] 271 | }, 272 | "execution_count": 84, 273 | "metadata": {}, 274 | "output_type": "execute_result" 275 | } 276 | ], 277 | "source": [ 278 | "### Intercepts\n", 279 | "regressor.intercept" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 85, 285 | "id": "2ba2bc70", 286 | "metadata": {}, 287 | "outputs": [], 288 | "source": [ 289 | "### Prediction\n", 290 | "pred_results=regressor.evaluate(test_data)" 291 | ] 292 | }, 293 | { 294 | "cell_type": "code", 295 | "execution_count": 86, 296 | "id": "489d6392", 297 | "metadata": {}, 298 | "outputs": [ 299 | { 300 | "name": "stdout", 301 | "output_type": "stream", 302 | "text": [ 303 | "+--------------------+------+-----------------+\n", 304 | "|Independent Features|Salary| prediction|\n", 305 | "+--------------------+------+-----------------+\n", 306 | "| [21.0,1.0]| 15000|20999.99999996154|\n", 307 | "| [29.0,4.0]| 20000|2000.000000192551|\n", 308 | "| [31.0,10.0]| 30000|33999.99999993094|\n", 309 | "+--------------------+------+-----------------+\n", 310 | "\n" 311 | ] 312 | } 313 | ], 314 | "source": [ 315 | "pred_results.predictions.show()" 316 | ] 317 | }, 318 | { 319 | "cell_type": "code", 320 | "execution_count": 87, 321 | "id": "0534e854", 322 | "metadata": {}, 323 | "outputs": [ 324 | { 325 | "data": { 326 | "text/plain": [ 327 | "(9333.333333233308, 125333333.3306847)" 328 | ] 329 | }, 330 | "execution_count": 87, 331 | "metadata": {}, 332 | "output_type": "execute_result" 333 | } 334 | ], 335 | "source": [ 336 | "pred_results.meanAbsoluteError,pred_results.meanSquaredError" 337 | ] 338 | }, 339 | { 340 | "cell_type": "code", 341 | "execution_count": null, 342 | "id": "70de559b", 343 | "metadata": {}, 344 | "outputs": [], 345 | "source": [] 346 | } 347 | ], 348 | "metadata": { 349 | "kernelspec": { 350 | "display_name": "Python 3", 351 | "language": "python", 352 | "name": "python3" 353 | }, 354 | "language_info": { 355 | "codemirror_mode": { 356 | "name": "ipython", 357 | "version": 3 358 | }, 359 | "file_extension": ".py", 360 | "mimetype": "text/x-python", 361 | "name": "python", 362 | "nbconvert_exporter": "python", 363 | "pygments_lexer": "ipython3", 364 | "version": "3.7.10" 365 | } 366 | }, 367 | "nbformat": 4, 368 | "nbformat_minor": 5 369 | } 370 | -------------------------------------------------------------------------------- /Tutorial 8-Linear Regression With Pyspark.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","source":["## Overview\n\nThis notebook will show you how to create and query a table or DataFrame that you uploaded to DBFS. [DBFS](https://docs.databricks.com/user-guide/dbfs-databricks-file-system.html) is a Databricks File System that allows you to store data for querying inside of Databricks. This notebook assumes that you have a file already inside of DBFS that you would like to read from.\n\nThis notebook is written in **Python** so the default cell type is Python. However, you can use different languages by using the `%LANGUAGE` syntax. Python, Scala, SQL, and R are all supported."],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"96816ed7-b08a-4ca3-abb9-f99880c3535d"}}},{"cell_type":"code","source":["# File location and type\nfile_location = \"/FileStore/tables/tips.csv\"\nfile_type = \"csv\"\n\n# The applied options are for CSV files. For other file types, these will be ignored.\ndf =spark.read.csv(file_location,header=True,inferSchema=True)\ndf.show()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"6482be4c-f067-47c9-b0ac-35c938b94601"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
+----------+----+------+------+---+------+----+\n|total_bill| tip| sex|smoker|day| time|size|\n+----------+----+------+------+---+------+----+\n| 16.99|1.01|Female| No|Sun|Dinner| 2|\n| 10.34|1.66| Male| No|Sun|Dinner| 3|\n| 21.01| 3.5| Male| No|Sun|Dinner| 3|\n| 23.68|3.31| Male| No|Sun|Dinner| 2|\n| 24.59|3.61|Female| No|Sun|Dinner| 4|\n| 25.29|4.71| Male| No|Sun|Dinner| 4|\n| 8.77| 2.0| Male| No|Sun|Dinner| 2|\n| 26.88|3.12| Male| No|Sun|Dinner| 4|\n| 15.04|1.96| Male| No|Sun|Dinner| 2|\n| 14.78|3.23| Male| No|Sun|Dinner| 2|\n| 10.27|1.71| Male| No|Sun|Dinner| 2|\n| 35.26| 5.0|Female| No|Sun|Dinner| 4|\n| 15.42|1.57| Male| No|Sun|Dinner| 2|\n| 18.43| 3.0| Male| No|Sun|Dinner| 4|\n| 14.83|3.02|Female| No|Sun|Dinner| 2|\n| 21.58|3.92| Male| No|Sun|Dinner| 2|\n| 10.33|1.67|Female| No|Sun|Dinner| 3|\n| 16.29|3.71| Male| No|Sun|Dinner| 3|\n| 16.97| 3.5|Female| No|Sun|Dinner| 3|\n| 20.65|3.35| Male| No|Sat|Dinner| 3|\n+----------+----+------+------+---+------+----+\nonly showing top 20 rows\n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
+----------+----+------+------+---+------+----+\ntotal_bill| tip| sex|smoker|day| time|size|\n+----------+----+------+------+---+------+----+\n 16.99|1.01|Female| No|Sun|Dinner| 2|\n 10.34|1.66| Male| No|Sun|Dinner| 3|\n 21.01| 3.5| Male| No|Sun|Dinner| 3|\n 23.68|3.31| Male| No|Sun|Dinner| 2|\n 24.59|3.61|Female| No|Sun|Dinner| 4|\n 25.29|4.71| Male| No|Sun|Dinner| 4|\n 8.77| 2.0| Male| No|Sun|Dinner| 2|\n 26.88|3.12| Male| No|Sun|Dinner| 4|\n 15.04|1.96| Male| No|Sun|Dinner| 2|\n 14.78|3.23| Male| No|Sun|Dinner| 2|\n 10.27|1.71| Male| No|Sun|Dinner| 2|\n 35.26| 5.0|Female| No|Sun|Dinner| 4|\n 15.42|1.57| Male| No|Sun|Dinner| 2|\n 18.43| 3.0| Male| No|Sun|Dinner| 4|\n 14.83|3.02|Female| No|Sun|Dinner| 2|\n 21.58|3.92| Male| No|Sun|Dinner| 2|\n 10.33|1.67|Female| No|Sun|Dinner| 3|\n 16.29|3.71| Male| No|Sun|Dinner| 3|\n 16.97| 3.5|Female| No|Sun|Dinner| 3|\n 20.65|3.35| Male| No|Sat|Dinner| 3|\n+----------+----+------+------+---+------+----+\nonly showing top 20 rows\n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["df.printSchema()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"5e5b80f2-3426-44e1-b86e-171314f4827e"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
root\n |-- total_bill: double (nullable = true)\n |-- tip: double (nullable = true)\n |-- sex: string (nullable = true)\n |-- smoker: string (nullable = true)\n |-- day: string (nullable = true)\n |-- time: string (nullable = true)\n |-- size: integer (nullable = true)\n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
root\n-- total_bill: double (nullable = true)\n-- tip: double (nullable = true)\n-- sex: string (nullable = true)\n-- smoker: string (nullable = true)\n-- day: string (nullable = true)\n-- time: string (nullable = true)\n-- size: integer (nullable = true)\n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["df.columns"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"0432b71c-b266-417d-b0d5-1c17afa0f090"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[3]: ['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size']
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[3]: ['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size']
"]}}],"execution_count":0},{"cell_type":"code","source":["### Handling Categorical Features\nfrom pyspark.ml.feature import StringIndexer"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"0ae62ac1-81a6-4b1d-92b9-f85ec9cc93ff"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
"]}}],"execution_count":0},{"cell_type":"code","source":["df.show()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"faa6f9b0-6f8b-4dbd-a5a2-dc074181f2e3"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
+----------+----+------+------+---+------+----+\n|total_bill| tip| sex|smoker|day| time|size|\n+----------+----+------+------+---+------+----+\n| 16.99|1.01|Female| No|Sun|Dinner| 2|\n| 10.34|1.66| Male| No|Sun|Dinner| 3|\n| 21.01| 3.5| Male| No|Sun|Dinner| 3|\n| 23.68|3.31| Male| No|Sun|Dinner| 2|\n| 24.59|3.61|Female| No|Sun|Dinner| 4|\n| 25.29|4.71| Male| No|Sun|Dinner| 4|\n| 8.77| 2.0| Male| No|Sun|Dinner| 2|\n| 26.88|3.12| Male| No|Sun|Dinner| 4|\n| 15.04|1.96| Male| No|Sun|Dinner| 2|\n| 14.78|3.23| Male| No|Sun|Dinner| 2|\n| 10.27|1.71| Male| No|Sun|Dinner| 2|\n| 35.26| 5.0|Female| No|Sun|Dinner| 4|\n| 15.42|1.57| Male| No|Sun|Dinner| 2|\n| 18.43| 3.0| Male| No|Sun|Dinner| 4|\n| 14.83|3.02|Female| No|Sun|Dinner| 2|\n| 21.58|3.92| Male| No|Sun|Dinner| 2|\n| 10.33|1.67|Female| No|Sun|Dinner| 3|\n| 16.29|3.71| Male| No|Sun|Dinner| 3|\n| 16.97| 3.5|Female| No|Sun|Dinner| 3|\n| 20.65|3.35| Male| No|Sat|Dinner| 3|\n+----------+----+------+------+---+------+----+\nonly showing top 20 rows\n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
+----------+----+------+------+---+------+----+\ntotal_bill| tip| sex|smoker|day| time|size|\n+----------+----+------+------+---+------+----+\n 16.99|1.01|Female| No|Sun|Dinner| 2|\n 10.34|1.66| Male| No|Sun|Dinner| 3|\n 21.01| 3.5| Male| No|Sun|Dinner| 3|\n 23.68|3.31| Male| No|Sun|Dinner| 2|\n 24.59|3.61|Female| No|Sun|Dinner| 4|\n 25.29|4.71| Male| No|Sun|Dinner| 4|\n 8.77| 2.0| Male| No|Sun|Dinner| 2|\n 26.88|3.12| Male| No|Sun|Dinner| 4|\n 15.04|1.96| Male| No|Sun|Dinner| 2|\n 14.78|3.23| Male| No|Sun|Dinner| 2|\n 10.27|1.71| Male| No|Sun|Dinner| 2|\n 35.26| 5.0|Female| No|Sun|Dinner| 4|\n 15.42|1.57| Male| No|Sun|Dinner| 2|\n 18.43| 3.0| Male| No|Sun|Dinner| 4|\n 14.83|3.02|Female| No|Sun|Dinner| 2|\n 21.58|3.92| Male| No|Sun|Dinner| 2|\n 10.33|1.67|Female| No|Sun|Dinner| 3|\n 16.29|3.71| Male| No|Sun|Dinner| 3|\n 16.97| 3.5|Female| No|Sun|Dinner| 3|\n 20.65|3.35| Male| No|Sat|Dinner| 3|\n+----------+----+------+------+---+------+----+\nonly showing top 20 rows\n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["indexer=StringIndexer(inputCol=\"sex\",outputCol=\"sex_indexed\")\ndf_r=indexer.fit(df).transform(df)\ndf_r.show()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"2ee7ab64-9804-4afb-852c-ee02eb5d3a20"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
+----------+----+------+------+---+------+----+-----------+\n|total_bill| tip| sex|smoker|day| time|size|sex_indexed|\n+----------+----+------+------+---+------+----+-----------+\n| 16.99|1.01|Female| No|Sun|Dinner| 2| 1.0|\n| 10.34|1.66| Male| No|Sun|Dinner| 3| 0.0|\n| 21.01| 3.5| Male| No|Sun|Dinner| 3| 0.0|\n| 23.68|3.31| Male| No|Sun|Dinner| 2| 0.0|\n| 24.59|3.61|Female| No|Sun|Dinner| 4| 1.0|\n| 25.29|4.71| Male| No|Sun|Dinner| 4| 0.0|\n| 8.77| 2.0| Male| No|Sun|Dinner| 2| 0.0|\n| 26.88|3.12| Male| No|Sun|Dinner| 4| 0.0|\n| 15.04|1.96| Male| No|Sun|Dinner| 2| 0.0|\n| 14.78|3.23| Male| No|Sun|Dinner| 2| 0.0|\n| 10.27|1.71| Male| No|Sun|Dinner| 2| 0.0|\n| 35.26| 5.0|Female| No|Sun|Dinner| 4| 1.0|\n| 15.42|1.57| Male| No|Sun|Dinner| 2| 0.0|\n| 18.43| 3.0| Male| No|Sun|Dinner| 4| 0.0|\n| 14.83|3.02|Female| No|Sun|Dinner| 2| 1.0|\n| 21.58|3.92| Male| No|Sun|Dinner| 2| 0.0|\n| 10.33|1.67|Female| No|Sun|Dinner| 3| 1.0|\n| 16.29|3.71| Male| No|Sun|Dinner| 3| 0.0|\n| 16.97| 3.5|Female| No|Sun|Dinner| 3| 1.0|\n| 20.65|3.35| Male| No|Sat|Dinner| 3| 0.0|\n+----------+----+------+------+---+------+----+-----------+\nonly showing top 20 rows\n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
+----------+----+------+------+---+------+----+-----------+\ntotal_bill| tip| sex|smoker|day| time|size|sex_indexed|\n+----------+----+------+------+---+------+----+-----------+\n 16.99|1.01|Female| No|Sun|Dinner| 2| 1.0|\n 10.34|1.66| Male| No|Sun|Dinner| 3| 0.0|\n 21.01| 3.5| Male| No|Sun|Dinner| 3| 0.0|\n 23.68|3.31| Male| No|Sun|Dinner| 2| 0.0|\n 24.59|3.61|Female| No|Sun|Dinner| 4| 1.0|\n 25.29|4.71| Male| No|Sun|Dinner| 4| 0.0|\n 8.77| 2.0| Male| No|Sun|Dinner| 2| 0.0|\n 26.88|3.12| Male| No|Sun|Dinner| 4| 0.0|\n 15.04|1.96| Male| No|Sun|Dinner| 2| 0.0|\n 14.78|3.23| Male| No|Sun|Dinner| 2| 0.0|\n 10.27|1.71| Male| No|Sun|Dinner| 2| 0.0|\n 35.26| 5.0|Female| No|Sun|Dinner| 4| 1.0|\n 15.42|1.57| Male| No|Sun|Dinner| 2| 0.0|\n 18.43| 3.0| Male| No|Sun|Dinner| 4| 0.0|\n 14.83|3.02|Female| No|Sun|Dinner| 2| 1.0|\n 21.58|3.92| Male| No|Sun|Dinner| 2| 0.0|\n 10.33|1.67|Female| No|Sun|Dinner| 3| 1.0|\n 16.29|3.71| Male| No|Sun|Dinner| 3| 0.0|\n 16.97| 3.5|Female| No|Sun|Dinner| 3| 1.0|\n 20.65|3.35| Male| No|Sat|Dinner| 3| 0.0|\n+----------+----+------+------+---+------+----+-----------+\nonly showing top 20 rows\n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["indexer=StringIndexer(inputCols=[\"smoker\",\"day\",\"time\"],outputCols=[\"smoker_indexed\",\"day_indexed\",\n \"time_index\"])\ndf_r=indexer.fit(df_r).transform(df_r)\ndf_r.show()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"6b95d734-4c80-4762-bd9b-92b6a107dced"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+\n|total_bill| tip| sex|smoker|day| time|size|sex_indexed|smoker_indexed|day_indexed|time_index|\n+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+\n| 16.99|1.01|Female| No|Sun|Dinner| 2| 1.0| 0.0| 1.0| 0.0|\n| 10.34|1.66| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|\n| 21.01| 3.5| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|\n| 23.68|3.31| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n| 24.59|3.61|Female| No|Sun|Dinner| 4| 1.0| 0.0| 1.0| 0.0|\n| 25.29|4.71| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|\n| 8.77| 2.0| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n| 26.88|3.12| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|\n| 15.04|1.96| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n| 14.78|3.23| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n| 10.27|1.71| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n| 35.26| 5.0|Female| No|Sun|Dinner| 4| 1.0| 0.0| 1.0| 0.0|\n| 15.42|1.57| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n| 18.43| 3.0| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|\n| 14.83|3.02|Female| No|Sun|Dinner| 2| 1.0| 0.0| 1.0| 0.0|\n| 21.58|3.92| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n| 10.33|1.67|Female| No|Sun|Dinner| 3| 1.0| 0.0| 1.0| 0.0|\n| 16.29|3.71| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|\n| 16.97| 3.5|Female| No|Sun|Dinner| 3| 1.0| 0.0| 1.0| 0.0|\n| 20.65|3.35| Male| No|Sat|Dinner| 3| 0.0| 0.0| 0.0| 0.0|\n+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+\nonly showing top 20 rows\n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+\ntotal_bill| tip| sex|smoker|day| time|size|sex_indexed|smoker_indexed|day_indexed|time_index|\n+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+\n 16.99|1.01|Female| No|Sun|Dinner| 2| 1.0| 0.0| 1.0| 0.0|\n 10.34|1.66| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|\n 21.01| 3.5| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|\n 23.68|3.31| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n 24.59|3.61|Female| No|Sun|Dinner| 4| 1.0| 0.0| 1.0| 0.0|\n 25.29|4.71| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|\n 8.77| 2.0| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n 26.88|3.12| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|\n 15.04|1.96| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n 14.78|3.23| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n 10.27|1.71| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n 35.26| 5.0|Female| No|Sun|Dinner| 4| 1.0| 0.0| 1.0| 0.0|\n 15.42|1.57| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n 18.43| 3.0| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|\n 14.83|3.02|Female| No|Sun|Dinner| 2| 1.0| 0.0| 1.0| 0.0|\n 21.58|3.92| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|\n 10.33|1.67|Female| No|Sun|Dinner| 3| 1.0| 0.0| 1.0| 0.0|\n 16.29|3.71| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|\n 16.97| 3.5|Female| No|Sun|Dinner| 3| 1.0| 0.0| 1.0| 0.0|\n 20.65|3.35| Male| No|Sat|Dinner| 3| 0.0| 0.0| 0.0| 0.0|\n+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+\nonly showing top 20 rows\n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["df_r.columns"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"a9909b0b-caee-4838-b477-47c3701dbfd4"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[9]: ['total_bill',\n 'tip',\n 'sex',\n 'smoker',\n 'day',\n 'time',\n 'size',\n 'sex_indexed',\n 'smoker_indexed',\n 'day_indexed',\n 'time_index']
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[9]: ['total_bill',\n 'tip',\n 'sex',\n 'smoker',\n 'day',\n 'time',\n 'size',\n 'sex_indexed',\n 'smoker_indexed',\n 'day_indexed',\n 'time_index']
"]}}],"execution_count":0},{"cell_type":"code","source":["from pyspark.ml.feature import VectorAssembler\nfeatureassembler=VectorAssembler(inputCols=['tip','size','sex_indexed','smoker_indexed','day_indexed',\n 'time_index'],outputCol=\"Independent Features\")\noutput=featureassembler.transform(df_r)"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"61d875e5-71fa-4dc4-ae90-54924b00a632"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
"]}}],"execution_count":0},{"cell_type":"code","source":["output.select('Independent Features').show()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"d33d1178-95a2-468f-a94a-e0eebc67be86"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
+--------------------+\n|Independent Features|\n+--------------------+\n|[1.01,2.0,1.0,0.0...|\n|[1.66,3.0,0.0,0.0...|\n|[3.5,3.0,0.0,0.0,...|\n|[3.31,2.0,0.0,0.0...|\n|[3.61,4.0,1.0,0.0...|\n|[4.71,4.0,0.0,0.0...|\n|[2.0,2.0,0.0,0.0,...|\n|[3.12,4.0,0.0,0.0...|\n|[1.96,2.0,0.0,0.0...|\n|[3.23,2.0,0.0,0.0...|\n|[1.71,2.0,0.0,0.0...|\n|[5.0,4.0,1.0,0.0,...|\n|[1.57,2.0,0.0,0.0...|\n|[3.0,4.0,0.0,0.0,...|\n|[3.02,2.0,1.0,0.0...|\n|[3.92,2.0,0.0,0.0...|\n|[1.67,3.0,1.0,0.0...|\n|[3.71,3.0,0.0,0.0...|\n|[3.5,3.0,1.0,0.0,...|\n|(6,[0,1],[3.35,3.0])|\n+--------------------+\nonly showing top 20 rows\n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
+--------------------+\nIndependent Features|\n+--------------------+\n[1.01,2.0,1.0,0.0...|\n[1.66,3.0,0.0,0.0...|\n[3.5,3.0,0.0,0.0,...|\n[3.31,2.0,0.0,0.0...|\n[3.61,4.0,1.0,0.0...|\n[4.71,4.0,0.0,0.0...|\n[2.0,2.0,0.0,0.0,...|\n[3.12,4.0,0.0,0.0...|\n[1.96,2.0,0.0,0.0...|\n[3.23,2.0,0.0,0.0...|\n[1.71,2.0,0.0,0.0...|\n[5.0,4.0,1.0,0.0,...|\n[1.57,2.0,0.0,0.0...|\n[3.0,4.0,0.0,0.0,...|\n[3.02,2.0,1.0,0.0...|\n[3.92,2.0,0.0,0.0...|\n[1.67,3.0,1.0,0.0...|\n[3.71,3.0,0.0,0.0...|\n[3.5,3.0,1.0,0.0,...|\n(6,[0,1],[3.35,3.0])|\n+--------------------+\nonly showing top 20 rows\n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["output.show()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"f2646b66-7710-4297-a6e1-156a37e6582d"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+--------------------+\n|total_bill| tip| sex|smoker|day| time|size|sex_indexed|smoker_indexed|day_indexed|time_index|Independent Features|\n+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+--------------------+\n| 16.99|1.01|Female| No|Sun|Dinner| 2| 1.0| 0.0| 1.0| 0.0|[1.01,2.0,1.0,0.0...|\n| 10.34|1.66| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|[1.66,3.0,0.0,0.0...|\n| 21.01| 3.5| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|[3.5,3.0,0.0,0.0,...|\n| 23.68|3.31| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[3.31,2.0,0.0,0.0...|\n| 24.59|3.61|Female| No|Sun|Dinner| 4| 1.0| 0.0| 1.0| 0.0|[3.61,4.0,1.0,0.0...|\n| 25.29|4.71| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|[4.71,4.0,0.0,0.0...|\n| 8.77| 2.0| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[2.0,2.0,0.0,0.0,...|\n| 26.88|3.12| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|[3.12,4.0,0.0,0.0...|\n| 15.04|1.96| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[1.96,2.0,0.0,0.0...|\n| 14.78|3.23| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[3.23,2.0,0.0,0.0...|\n| 10.27|1.71| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[1.71,2.0,0.0,0.0...|\n| 35.26| 5.0|Female| No|Sun|Dinner| 4| 1.0| 0.0| 1.0| 0.0|[5.0,4.0,1.0,0.0,...|\n| 15.42|1.57| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[1.57,2.0,0.0,0.0...|\n| 18.43| 3.0| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|[3.0,4.0,0.0,0.0,...|\n| 14.83|3.02|Female| No|Sun|Dinner| 2| 1.0| 0.0| 1.0| 0.0|[3.02,2.0,1.0,0.0...|\n| 21.58|3.92| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[3.92,2.0,0.0,0.0...|\n| 10.33|1.67|Female| No|Sun|Dinner| 3| 1.0| 0.0| 1.0| 0.0|[1.67,3.0,1.0,0.0...|\n| 16.29|3.71| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|[3.71,3.0,0.0,0.0...|\n| 16.97| 3.5|Female| No|Sun|Dinner| 3| 1.0| 0.0| 1.0| 0.0|[3.5,3.0,1.0,0.0,...|\n| 20.65|3.35| Male| No|Sat|Dinner| 3| 0.0| 0.0| 0.0| 0.0|(6,[0,1],[3.35,3.0])|\n+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+--------------------+\nonly showing top 20 rows\n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+--------------------+\ntotal_bill| tip| sex|smoker|day| time|size|sex_indexed|smoker_indexed|day_indexed|time_index|Independent Features|\n+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+--------------------+\n 16.99|1.01|Female| No|Sun|Dinner| 2| 1.0| 0.0| 1.0| 0.0|[1.01,2.0,1.0,0.0...|\n 10.34|1.66| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|[1.66,3.0,0.0,0.0...|\n 21.01| 3.5| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|[3.5,3.0,0.0,0.0,...|\n 23.68|3.31| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[3.31,2.0,0.0,0.0...|\n 24.59|3.61|Female| No|Sun|Dinner| 4| 1.0| 0.0| 1.0| 0.0|[3.61,4.0,1.0,0.0...|\n 25.29|4.71| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|[4.71,4.0,0.0,0.0...|\n 8.77| 2.0| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[2.0,2.0,0.0,0.0,...|\n 26.88|3.12| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|[3.12,4.0,0.0,0.0...|\n 15.04|1.96| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[1.96,2.0,0.0,0.0...|\n 14.78|3.23| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[3.23,2.0,0.0,0.0...|\n 10.27|1.71| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[1.71,2.0,0.0,0.0...|\n 35.26| 5.0|Female| No|Sun|Dinner| 4| 1.0| 0.0| 1.0| 0.0|[5.0,4.0,1.0,0.0,...|\n 15.42|1.57| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[1.57,2.0,0.0,0.0...|\n 18.43| 3.0| Male| No|Sun|Dinner| 4| 0.0| 0.0| 1.0| 0.0|[3.0,4.0,0.0,0.0,...|\n 14.83|3.02|Female| No|Sun|Dinner| 2| 1.0| 0.0| 1.0| 0.0|[3.02,2.0,1.0,0.0...|\n 21.58|3.92| Male| No|Sun|Dinner| 2| 0.0| 0.0| 1.0| 0.0|[3.92,2.0,0.0,0.0...|\n 10.33|1.67|Female| No|Sun|Dinner| 3| 1.0| 0.0| 1.0| 0.0|[1.67,3.0,1.0,0.0...|\n 16.29|3.71| Male| No|Sun|Dinner| 3| 0.0| 0.0| 1.0| 0.0|[3.71,3.0,0.0,0.0...|\n 16.97| 3.5|Female| No|Sun|Dinner| 3| 1.0| 0.0| 1.0| 0.0|[3.5,3.0,1.0,0.0,...|\n 20.65|3.35| Male| No|Sat|Dinner| 3| 0.0| 0.0| 0.0| 0.0|(6,[0,1],[3.35,3.0])|\n+----------+----+------+------+---+------+----+-----------+--------------+-----------+----------+--------------------+\nonly showing top 20 rows\n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["finalized_data=output.select(\"Independent Features\",\"total_bill\")"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"d1c1fa4c-c78a-441a-bed9-3bcfcc5af966"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
"]}}],"execution_count":0},{"cell_type":"code","source":["finalized_data.show()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"3d14fe7b-bc59-4376-8139-142283af09b0"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
+--------------------+----------+\n|Independent Features|total_bill|\n+--------------------+----------+\n|[1.01,2.0,1.0,0.0...| 16.99|\n|[1.66,3.0,0.0,0.0...| 10.34|\n|[3.5,3.0,0.0,0.0,...| 21.01|\n|[3.31,2.0,0.0,0.0...| 23.68|\n|[3.61,4.0,1.0,0.0...| 24.59|\n|[4.71,4.0,0.0,0.0...| 25.29|\n|[2.0,2.0,0.0,0.0,...| 8.77|\n|[3.12,4.0,0.0,0.0...| 26.88|\n|[1.96,2.0,0.0,0.0...| 15.04|\n|[3.23,2.0,0.0,0.0...| 14.78|\n|[1.71,2.0,0.0,0.0...| 10.27|\n|[5.0,4.0,1.0,0.0,...| 35.26|\n|[1.57,2.0,0.0,0.0...| 15.42|\n|[3.0,4.0,0.0,0.0,...| 18.43|\n|[3.02,2.0,1.0,0.0...| 14.83|\n|[3.92,2.0,0.0,0.0...| 21.58|\n|[1.67,3.0,1.0,0.0...| 10.33|\n|[3.71,3.0,0.0,0.0...| 16.29|\n|[3.5,3.0,1.0,0.0,...| 16.97|\n|(6,[0,1],[3.35,3.0])| 20.65|\n+--------------------+----------+\nonly showing top 20 rows\n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
+--------------------+----------+\nIndependent Features|total_bill|\n+--------------------+----------+\n[1.01,2.0,1.0,0.0...| 16.99|\n[1.66,3.0,0.0,0.0...| 10.34|\n[3.5,3.0,0.0,0.0,...| 21.01|\n[3.31,2.0,0.0,0.0...| 23.68|\n[3.61,4.0,1.0,0.0...| 24.59|\n[4.71,4.0,0.0,0.0...| 25.29|\n[2.0,2.0,0.0,0.0,...| 8.77|\n[3.12,4.0,0.0,0.0...| 26.88|\n[1.96,2.0,0.0,0.0...| 15.04|\n[3.23,2.0,0.0,0.0...| 14.78|\n[1.71,2.0,0.0,0.0...| 10.27|\n[5.0,4.0,1.0,0.0,...| 35.26|\n[1.57,2.0,0.0,0.0...| 15.42|\n[3.0,4.0,0.0,0.0,...| 18.43|\n[3.02,2.0,1.0,0.0...| 14.83|\n[3.92,2.0,0.0,0.0...| 21.58|\n[1.67,3.0,1.0,0.0...| 10.33|\n[3.71,3.0,0.0,0.0...| 16.29|\n[3.5,3.0,1.0,0.0,...| 16.97|\n(6,[0,1],[3.35,3.0])| 20.65|\n+--------------------+----------+\nonly showing top 20 rows\n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["from pyspark.ml.regression import LinearRegression\n##train test split\ntrain_data,test_data=finalized_data.randomSplit([0.75,0.25])\nregressor=LinearRegression(featuresCol='Independent Features', labelCol='total_bill')\nregressor=regressor.fit(train_data)"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"dbe03a38-e728-40f9-8a53-0b7968b8dc87"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
"]}}],"execution_count":0},{"cell_type":"code","source":["regressor.coefficients"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"0fdc835a-96fb-4ab3-89be-6cfbc57c7ac6"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[17]: DenseVector([3.3598, 3.3861, -0.6641, 2.5847, -0.1423, -1.3377])
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[17]: DenseVector([3.3598, 3.3861, -0.6641, 2.5847, -0.1423, -1.3377])
"]}}],"execution_count":0},{"cell_type":"code","source":["regressor.intercept"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"fd1642d4-bb73-4fc0-a410-ada61d0f3410"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[18]: 0.9231025978363154
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[18]: 0.9231025978363154
"]}}],"execution_count":0},{"cell_type":"code","source":["### Predictions\npred_results=regressor.evaluate(test_data)"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"2e45a3d8-af1c-408b-b64f-fe466c3401bd"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
"]}}],"execution_count":0},{"cell_type":"code","source":["## Final comparison\npred_results.predictions.show()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"01d128d2-1a71-44d0-a14c-b0377693547b"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
+--------------------+----------+------------------+\n|Independent Features|total_bill| prediction|\n+--------------------+----------+------------------+\n| (6,[0,1],[2.0,2.0])| 12.69|14.414877568922382|\n|(6,[0,1],[3.35,3.0])| 20.65|22.336705086951124|\n|[1.0,1.0,1.0,0.0,...| 7.25| 7.004851678101628|\n|[1.17,2.0,0.0,1.0...| 32.83|14.210940490994291|\n|[1.36,3.0,1.0,0.0...| 18.64|13.364280305420156|\n|[1.5,2.0,0.0,1.0,...| 11.59|15.319683950195104|\n|[1.58,2.0,0.0,1.0...| 13.42| 13.82395853728497|\n|[1.66,3.0,0.0,0.0...| 10.34|16.516310272733463|\n|[1.73,2.0,0.0,0.0...| 9.78| 11.88549649517034|\n|[2.0,2.0,0.0,0.0,...| 13.81| 14.27259319727858|\n|[2.0,2.0,0.0,0.0,...| 13.03| 12.79265023451646|\n|[2.0,2.0,1.0,0.0,...| 14.15|12.128511829238738|\n|[2.0,2.0,1.0,0.0,...| 14.52|12.128511829238738|\n|[2.0,2.0,1.0,1.0,...| 10.63|16.335459877039824|\n|[2.0,2.0,1.0,1.0,...| 27.18|16.335459877039824|\n|[2.0,3.0,1.0,0.0,...| 16.21|16.994513613299002|\n|[2.23,2.0,1.0,1.0...| 12.76| 17.10822046981615|\n|[2.24,2.0,0.0,0.0...| 20.76|15.078952076697353|\n|[2.31,2.0,0.0,0.0...| 11.69|13.834197120432375|\n|[2.5,2.0,0.0,0.0,...| 14.07|15.952507529401023|\n+--------------------+----------+------------------+\nonly showing top 20 rows\n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
+--------------------+----------+------------------+\nIndependent Features|total_bill| prediction|\n+--------------------+----------+------------------+\n (6,[0,1],[2.0,2.0])| 12.69|14.414877568922382|\n(6,[0,1],[3.35,3.0])| 20.65|22.336705086951124|\n[1.0,1.0,1.0,0.0,...| 7.25| 7.004851678101628|\n[1.17,2.0,0.0,1.0...| 32.83|14.210940490994291|\n[1.36,3.0,1.0,0.0...| 18.64|13.364280305420156|\n[1.5,2.0,0.0,1.0,...| 11.59|15.319683950195104|\n[1.58,2.0,0.0,1.0...| 13.42| 13.82395853728497|\n[1.66,3.0,0.0,0.0...| 10.34|16.516310272733463|\n[1.73,2.0,0.0,0.0...| 9.78| 11.88549649517034|\n[2.0,2.0,0.0,0.0,...| 13.81| 14.27259319727858|\n[2.0,2.0,0.0,0.0,...| 13.03| 12.79265023451646|\n[2.0,2.0,1.0,0.0,...| 14.15|12.128511829238738|\n[2.0,2.0,1.0,0.0,...| 14.52|12.128511829238738|\n[2.0,2.0,1.0,1.0,...| 10.63|16.335459877039824|\n[2.0,2.0,1.0,1.0,...| 27.18|16.335459877039824|\n[2.0,3.0,1.0,0.0,...| 16.21|16.994513613299002|\n[2.23,2.0,1.0,1.0...| 12.76| 17.10822046981615|\n[2.24,2.0,0.0,0.0...| 20.76|15.078952076697353|\n[2.31,2.0,0.0,0.0...| 11.69|13.834197120432375|\n[2.5,2.0,0.0,0.0,...| 14.07|15.952507529401023|\n+--------------------+----------+------------------+\nonly showing top 20 rows\n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["### PErformance Metrics\npred_results.r2,pred_results.meanAbsoluteError,pred_results.meanSquaredError"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"75e3e5b1-0bb4-4dbe-a1ca-08e5a31ee173"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[25]: (0.40050077944613716, 4.809771114444798, 40.934088106916576)
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[25]: (0.40050077944613716, 4.809771114444798, 40.934088106916576)
"]}}],"execution_count":0},{"cell_type":"code","source":[""],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"ce0398a7-7ebd-4f2c-b12e-2ef701925124"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"data":"","errorSummary":"","metadata":{},"type":"ipynbError","arguments":{}}},"output_type":"display_data","data":{"text/html":[""]}}],"execution_count":0}],"metadata":{"application/vnd.databricks.v1+notebook":{"notebookName":"Tutorial 8-Linear Regression With Pyspark","dashboards":[],"notebookMetadata":{"pythonIndentUnit":2},"language":"python","widgets":{},"notebookOrigID":523045182520803}},"nbformat":4,"nbformat_minor":0} 2 | -------------------------------------------------------------------------------- /pyspark basic introduction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "8ff41f5d", 6 | "metadata": {}, 7 | "source": [ 8 | "#### Pyspark Basic Introduction" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "4abcaad4", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "Requirement already satisfied: pyspark in c:\\users\\win10\\anaconda3\\envs\\myenv\\lib\\site-packages (3.1.1)\n", 22 | "Requirement already satisfied: py4j==0.10.9 in c:\\users\\win10\\anaconda3\\envs\\myenv\\lib\\site-packages (from pyspark) (0.10.9)\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "!pip install pyspark" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 2, 33 | "id": "08b29f6a", 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "import pyspark" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 15, 43 | "id": "e1de79e4", 44 | "metadata": {}, 45 | "outputs": [ 46 | { 47 | "data": { 48 | "text/plain": [ 49 | "pandas.core.frame.DataFrame" 50 | ] 51 | }, 52 | "execution_count": 15, 53 | "metadata": {}, 54 | "output_type": "execute_result" 55 | } 56 | ], 57 | "source": [ 58 | "import pandas as pd\n", 59 | "type(pd.read_csv('test1.csv'))" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 4, 65 | "id": "37a82e23", 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "from pyspark.sql import SparkSession" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 5, 75 | "id": "c334b45e", 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "spark=SparkSession.builder.appName('Practise').getOrCreate()" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 6, 85 | "id": "558caca5", 86 | "metadata": {}, 87 | "outputs": [ 88 | { 89 | "data": { 90 | "text/html": [ 91 | "\n", 92 | "
\n", 93 | "

SparkSession - in-memory

\n", 94 | " \n", 95 | "
\n", 96 | "

SparkContext

\n", 97 | "\n", 98 | "

Spark UI

\n", 99 | "\n", 100 | "
\n", 101 | "
Version
\n", 102 | "
v3.1.1
\n", 103 | "
Master
\n", 104 | "
local[*]
\n", 105 | "
AppName
\n", 106 | "
Practise
\n", 107 | "
\n", 108 | "
\n", 109 | " \n", 110 | "
\n", 111 | " " 112 | ], 113 | "text/plain": [ 114 | "" 115 | ] 116 | }, 117 | "execution_count": 6, 118 | "metadata": {}, 119 | "output_type": "execute_result" 120 | } 121 | ], 122 | "source": [ 123 | "spark" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 8, 129 | "id": "f7ac726b", 130 | "metadata": {}, 131 | "outputs": [], 132 | "source": [ 133 | "df_pyspark=spark.read.csv('test1.csv')" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 13, 139 | "id": "6f077d49", 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "df_pyspark=spark.read.option('header','true').csv('test1.csv')" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 14, 149 | "id": "2e0eee51", 150 | "metadata": {}, 151 | "outputs": [ 152 | { 153 | "data": { 154 | "text/plain": [ 155 | "pyspark.sql.dataframe.DataFrame" 156 | ] 157 | }, 158 | "execution_count": 14, 159 | "metadata": {}, 160 | "output_type": "execute_result" 161 | } 162 | ], 163 | "source": [ 164 | "type(df_pyspark)" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": 18, 170 | "id": "bb26bf24", 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "name": "stdout", 175 | "output_type": "stream", 176 | "text": [ 177 | "root\n", 178 | " |-- Name: string (nullable = true)\n", 179 | " |-- age: string (nullable = true)\n", 180 | "\n" 181 | ] 182 | } 183 | ], 184 | "source": [ 185 | "df_pyspark.printSchema()" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": null, 191 | "id": "17a81cc1", 192 | "metadata": {}, 193 | "outputs": [], 194 | "source": [] 195 | }, 196 | { 197 | "cell_type": "code", 198 | "execution_count": null, 199 | "id": "45996ebc", 200 | "metadata": {}, 201 | "outputs": [], 202 | "source": [] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": null, 207 | "id": "2cb5eda4", 208 | "metadata": {}, 209 | "outputs": [], 210 | "source": [] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": null, 215 | "id": "60d8d7b6", 216 | "metadata": {}, 217 | "outputs": [], 218 | "source": [] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": null, 223 | "id": "e9c3ce8e", 224 | "metadata": {}, 225 | "outputs": [], 226 | "source": [] 227 | } 228 | ], 229 | "metadata": { 230 | "kernelspec": { 231 | "display_name": "Python 3", 232 | "language": "python", 233 | "name": "python3" 234 | }, 235 | "language_info": { 236 | "codemirror_mode": { 237 | "name": "ipython", 238 | "version": 3 239 | }, 240 | "file_extension": ".py", 241 | "mimetype": "text/x-python", 242 | "name": "python", 243 | "nbconvert_exporter": "python", 244 | "pygments_lexer": "ipython3", 245 | "version": "3.7.10" 246 | } 247 | }, 248 | "nbformat": 4, 249 | "nbformat_minor": 5 250 | } 251 | -------------------------------------------------------------------------------- /test1.csv: -------------------------------------------------------------------------------- 1 | Name,age,Experience,Salary 2 | Krish,31,10,30000 3 | Sudhanshu,30,8,25000 4 | Sunny,29,4,20000 5 | Paul,24,3,20000 6 | Harsha,21,1,15000 7 | Shubham,23,2,18000 8 | -------------------------------------------------------------------------------- /test2.csv: -------------------------------------------------------------------------------- 1 | Name,age,Experience,Salary 2 | Krish,31,10,30000 3 | Sudhanshu,30,8,25000 4 | Sunny,29,4,20000 5 | Paul,24,3,20000 6 | Harsha,21,1,15000 7 | Shubham,23,2,18000 8 | Mahesh,,,40000 9 | ,34,10,38000 10 | ,36,, 11 | -------------------------------------------------------------------------------- /test3.csv: -------------------------------------------------------------------------------- 1 | Name,Departments,salary 2 | Krish,Data Science,10000 3 | Krish,IOT,5000 4 | Mahesh,Big Data,4000 5 | Krish,Big Data,4000 6 | Mahesh,Data Science,3000 7 | Sudhanshu,Data Science,20000 8 | Sudhanshu,IOT,10000 9 | Sudhanshu,Big Data,5000 10 | Sunny,Data Science,10000 11 | Sunny,Big Data,2000 12 | -------------------------------------------------------------------------------- /tips.csv: -------------------------------------------------------------------------------- 1 | total_bill,tip,sex,smoker,day,time,size 2 | 16.99,1.01,Female,No,Sun,Dinner,2 3 | 10.34,1.66,Male,No,Sun,Dinner,3 4 | 21.01,3.5,Male,No,Sun,Dinner,3 5 | 23.68,3.31,Male,No,Sun,Dinner,2 6 | 24.59,3.61,Female,No,Sun,Dinner,4 7 | 25.29,4.71,Male,No,Sun,Dinner,4 8 | 8.77,2.0,Male,No,Sun,Dinner,2 9 | 26.88,3.12,Male,No,Sun,Dinner,4 10 | 15.04,1.96,Male,No,Sun,Dinner,2 11 | 14.78,3.23,Male,No,Sun,Dinner,2 12 | 10.27,1.71,Male,No,Sun,Dinner,2 13 | 35.26,5.0,Female,No,Sun,Dinner,4 14 | 15.42,1.57,Male,No,Sun,Dinner,2 15 | 18.43,3.0,Male,No,Sun,Dinner,4 16 | 14.83,3.02,Female,No,Sun,Dinner,2 17 | 21.58,3.92,Male,No,Sun,Dinner,2 18 | 10.33,1.67,Female,No,Sun,Dinner,3 19 | 16.29,3.71,Male,No,Sun,Dinner,3 20 | 16.97,3.5,Female,No,Sun,Dinner,3 21 | 20.65,3.35,Male,No,Sat,Dinner,3 22 | 17.92,4.08,Male,No,Sat,Dinner,2 23 | 20.29,2.75,Female,No,Sat,Dinner,2 24 | 15.77,2.23,Female,No,Sat,Dinner,2 25 | 39.42,7.58,Male,No,Sat,Dinner,4 26 | 19.82,3.18,Male,No,Sat,Dinner,2 27 | 17.81,2.34,Male,No,Sat,Dinner,4 28 | 13.37,2.0,Male,No,Sat,Dinner,2 29 | 12.69,2.0,Male,No,Sat,Dinner,2 30 | 21.7,4.3,Male,No,Sat,Dinner,2 31 | 19.65,3.0,Female,No,Sat,Dinner,2 32 | 9.55,1.45,Male,No,Sat,Dinner,2 33 | 18.35,2.5,Male,No,Sat,Dinner,4 34 | 15.06,3.0,Female,No,Sat,Dinner,2 35 | 20.69,2.45,Female,No,Sat,Dinner,4 36 | 17.78,3.27,Male,No,Sat,Dinner,2 37 | 24.06,3.6,Male,No,Sat,Dinner,3 38 | 16.31,2.0,Male,No,Sat,Dinner,3 39 | 16.93,3.07,Female,No,Sat,Dinner,3 40 | 18.69,2.31,Male,No,Sat,Dinner,3 41 | 31.27,5.0,Male,No,Sat,Dinner,3 42 | 16.04,2.24,Male,No,Sat,Dinner,3 43 | 17.46,2.54,Male,No,Sun,Dinner,2 44 | 13.94,3.06,Male,No,Sun,Dinner,2 45 | 9.68,1.32,Male,No,Sun,Dinner,2 46 | 30.4,5.6,Male,No,Sun,Dinner,4 47 | 18.29,3.0,Male,No,Sun,Dinner,2 48 | 22.23,5.0,Male,No,Sun,Dinner,2 49 | 32.4,6.0,Male,No,Sun,Dinner,4 50 | 28.55,2.05,Male,No,Sun,Dinner,3 51 | 18.04,3.0,Male,No,Sun,Dinner,2 52 | 12.54,2.5,Male,No,Sun,Dinner,2 53 | 10.29,2.6,Female,No,Sun,Dinner,2 54 | 34.81,5.2,Female,No,Sun,Dinner,4 55 | 9.94,1.56,Male,No,Sun,Dinner,2 56 | 25.56,4.34,Male,No,Sun,Dinner,4 57 | 19.49,3.51,Male,No,Sun,Dinner,2 58 | 38.01,3.0,Male,Yes,Sat,Dinner,4 59 | 26.41,1.5,Female,No,Sat,Dinner,2 60 | 11.24,1.76,Male,Yes,Sat,Dinner,2 61 | 48.27,6.73,Male,No,Sat,Dinner,4 62 | 20.29,3.21,Male,Yes,Sat,Dinner,2 63 | 13.81,2.0,Male,Yes,Sat,Dinner,2 64 | 11.02,1.98,Male,Yes,Sat,Dinner,2 65 | 18.29,3.76,Male,Yes,Sat,Dinner,4 66 | 17.59,2.64,Male,No,Sat,Dinner,3 67 | 20.08,3.15,Male,No,Sat,Dinner,3 68 | 16.45,2.47,Female,No,Sat,Dinner,2 69 | 3.07,1.0,Female,Yes,Sat,Dinner,1 70 | 20.23,2.01,Male,No,Sat,Dinner,2 71 | 15.01,2.09,Male,Yes,Sat,Dinner,2 72 | 12.02,1.97,Male,No,Sat,Dinner,2 73 | 17.07,3.0,Female,No,Sat,Dinner,3 74 | 26.86,3.14,Female,Yes,Sat,Dinner,2 75 | 25.28,5.0,Female,Yes,Sat,Dinner,2 76 | 14.73,2.2,Female,No,Sat,Dinner,2 77 | 10.51,1.25,Male,No,Sat,Dinner,2 78 | 17.92,3.08,Male,Yes,Sat,Dinner,2 79 | 27.2,4.0,Male,No,Thur,Lunch,4 80 | 22.76,3.0,Male,No,Thur,Lunch,2 81 | 17.29,2.71,Male,No,Thur,Lunch,2 82 | 19.44,3.0,Male,Yes,Thur,Lunch,2 83 | 16.66,3.4,Male,No,Thur,Lunch,2 84 | 10.07,1.83,Female,No,Thur,Lunch,1 85 | 32.68,5.0,Male,Yes,Thur,Lunch,2 86 | 15.98,2.03,Male,No,Thur,Lunch,2 87 | 34.83,5.17,Female,No,Thur,Lunch,4 88 | 13.03,2.0,Male,No,Thur,Lunch,2 89 | 18.28,4.0,Male,No,Thur,Lunch,2 90 | 24.71,5.85,Male,No,Thur,Lunch,2 91 | 21.16,3.0,Male,No,Thur,Lunch,2 92 | 28.97,3.0,Male,Yes,Fri,Dinner,2 93 | 22.49,3.5,Male,No,Fri,Dinner,2 94 | 5.75,1.0,Female,Yes,Fri,Dinner,2 95 | 16.32,4.3,Female,Yes,Fri,Dinner,2 96 | 22.75,3.25,Female,No,Fri,Dinner,2 97 | 40.17,4.73,Male,Yes,Fri,Dinner,4 98 | 27.28,4.0,Male,Yes,Fri,Dinner,2 99 | 12.03,1.5,Male,Yes,Fri,Dinner,2 100 | 21.01,3.0,Male,Yes,Fri,Dinner,2 101 | 12.46,1.5,Male,No,Fri,Dinner,2 102 | 11.35,2.5,Female,Yes,Fri,Dinner,2 103 | 15.38,3.0,Female,Yes,Fri,Dinner,2 104 | 44.3,2.5,Female,Yes,Sat,Dinner,3 105 | 22.42,3.48,Female,Yes,Sat,Dinner,2 106 | 20.92,4.08,Female,No,Sat,Dinner,2 107 | 15.36,1.64,Male,Yes,Sat,Dinner,2 108 | 20.49,4.06,Male,Yes,Sat,Dinner,2 109 | 25.21,4.29,Male,Yes,Sat,Dinner,2 110 | 18.24,3.76,Male,No,Sat,Dinner,2 111 | 14.31,4.0,Female,Yes,Sat,Dinner,2 112 | 14.0,3.0,Male,No,Sat,Dinner,2 113 | 7.25,1.0,Female,No,Sat,Dinner,1 114 | 38.07,4.0,Male,No,Sun,Dinner,3 115 | 23.95,2.55,Male,No,Sun,Dinner,2 116 | 25.71,4.0,Female,No,Sun,Dinner,3 117 | 17.31,3.5,Female,No,Sun,Dinner,2 118 | 29.93,5.07,Male,No,Sun,Dinner,4 119 | 10.65,1.5,Female,No,Thur,Lunch,2 120 | 12.43,1.8,Female,No,Thur,Lunch,2 121 | 24.08,2.92,Female,No,Thur,Lunch,4 122 | 11.69,2.31,Male,No,Thur,Lunch,2 123 | 13.42,1.68,Female,No,Thur,Lunch,2 124 | 14.26,2.5,Male,No,Thur,Lunch,2 125 | 15.95,2.0,Male,No,Thur,Lunch,2 126 | 12.48,2.52,Female,No,Thur,Lunch,2 127 | 29.8,4.2,Female,No,Thur,Lunch,6 128 | 8.52,1.48,Male,No,Thur,Lunch,2 129 | 14.52,2.0,Female,No,Thur,Lunch,2 130 | 11.38,2.0,Female,No,Thur,Lunch,2 131 | 22.82,2.18,Male,No,Thur,Lunch,3 132 | 19.08,1.5,Male,No,Thur,Lunch,2 133 | 20.27,2.83,Female,No,Thur,Lunch,2 134 | 11.17,1.5,Female,No,Thur,Lunch,2 135 | 12.26,2.0,Female,No,Thur,Lunch,2 136 | 18.26,3.25,Female,No,Thur,Lunch,2 137 | 8.51,1.25,Female,No,Thur,Lunch,2 138 | 10.33,2.0,Female,No,Thur,Lunch,2 139 | 14.15,2.0,Female,No,Thur,Lunch,2 140 | 16.0,2.0,Male,Yes,Thur,Lunch,2 141 | 13.16,2.75,Female,No,Thur,Lunch,2 142 | 17.47,3.5,Female,No,Thur,Lunch,2 143 | 34.3,6.7,Male,No,Thur,Lunch,6 144 | 41.19,5.0,Male,No,Thur,Lunch,5 145 | 27.05,5.0,Female,No,Thur,Lunch,6 146 | 16.43,2.3,Female,No,Thur,Lunch,2 147 | 8.35,1.5,Female,No,Thur,Lunch,2 148 | 18.64,1.36,Female,No,Thur,Lunch,3 149 | 11.87,1.63,Female,No,Thur,Lunch,2 150 | 9.78,1.73,Male,No,Thur,Lunch,2 151 | 7.51,2.0,Male,No,Thur,Lunch,2 152 | 14.07,2.5,Male,No,Sun,Dinner,2 153 | 13.13,2.0,Male,No,Sun,Dinner,2 154 | 17.26,2.74,Male,No,Sun,Dinner,3 155 | 24.55,2.0,Male,No,Sun,Dinner,4 156 | 19.77,2.0,Male,No,Sun,Dinner,4 157 | 29.85,5.14,Female,No,Sun,Dinner,5 158 | 48.17,5.0,Male,No,Sun,Dinner,6 159 | 25.0,3.75,Female,No,Sun,Dinner,4 160 | 13.39,2.61,Female,No,Sun,Dinner,2 161 | 16.49,2.0,Male,No,Sun,Dinner,4 162 | 21.5,3.5,Male,No,Sun,Dinner,4 163 | 12.66,2.5,Male,No,Sun,Dinner,2 164 | 16.21,2.0,Female,No,Sun,Dinner,3 165 | 13.81,2.0,Male,No,Sun,Dinner,2 166 | 17.51,3.0,Female,Yes,Sun,Dinner,2 167 | 24.52,3.48,Male,No,Sun,Dinner,3 168 | 20.76,2.24,Male,No,Sun,Dinner,2 169 | 31.71,4.5,Male,No,Sun,Dinner,4 170 | 10.59,1.61,Female,Yes,Sat,Dinner,2 171 | 10.63,2.0,Female,Yes,Sat,Dinner,2 172 | 50.81,10.0,Male,Yes,Sat,Dinner,3 173 | 15.81,3.16,Male,Yes,Sat,Dinner,2 174 | 7.25,5.15,Male,Yes,Sun,Dinner,2 175 | 31.85,3.18,Male,Yes,Sun,Dinner,2 176 | 16.82,4.0,Male,Yes,Sun,Dinner,2 177 | 32.9,3.11,Male,Yes,Sun,Dinner,2 178 | 17.89,2.0,Male,Yes,Sun,Dinner,2 179 | 14.48,2.0,Male,Yes,Sun,Dinner,2 180 | 9.6,4.0,Female,Yes,Sun,Dinner,2 181 | 34.63,3.55,Male,Yes,Sun,Dinner,2 182 | 34.65,3.68,Male,Yes,Sun,Dinner,4 183 | 23.33,5.65,Male,Yes,Sun,Dinner,2 184 | 45.35,3.5,Male,Yes,Sun,Dinner,3 185 | 23.17,6.5,Male,Yes,Sun,Dinner,4 186 | 40.55,3.0,Male,Yes,Sun,Dinner,2 187 | 20.69,5.0,Male,No,Sun,Dinner,5 188 | 20.9,3.5,Female,Yes,Sun,Dinner,3 189 | 30.46,2.0,Male,Yes,Sun,Dinner,5 190 | 18.15,3.5,Female,Yes,Sun,Dinner,3 191 | 23.1,4.0,Male,Yes,Sun,Dinner,3 192 | 15.69,1.5,Male,Yes,Sun,Dinner,2 193 | 19.81,4.19,Female,Yes,Thur,Lunch,2 194 | 28.44,2.56,Male,Yes,Thur,Lunch,2 195 | 15.48,2.02,Male,Yes,Thur,Lunch,2 196 | 16.58,4.0,Male,Yes,Thur,Lunch,2 197 | 7.56,1.44,Male,No,Thur,Lunch,2 198 | 10.34,2.0,Male,Yes,Thur,Lunch,2 199 | 43.11,5.0,Female,Yes,Thur,Lunch,4 200 | 13.0,2.0,Female,Yes,Thur,Lunch,2 201 | 13.51,2.0,Male,Yes,Thur,Lunch,2 202 | 18.71,4.0,Male,Yes,Thur,Lunch,3 203 | 12.74,2.01,Female,Yes,Thur,Lunch,2 204 | 13.0,2.0,Female,Yes,Thur,Lunch,2 205 | 16.4,2.5,Female,Yes,Thur,Lunch,2 206 | 20.53,4.0,Male,Yes,Thur,Lunch,4 207 | 16.47,3.23,Female,Yes,Thur,Lunch,3 208 | 26.59,3.41,Male,Yes,Sat,Dinner,3 209 | 38.73,3.0,Male,Yes,Sat,Dinner,4 210 | 24.27,2.03,Male,Yes,Sat,Dinner,2 211 | 12.76,2.23,Female,Yes,Sat,Dinner,2 212 | 30.06,2.0,Male,Yes,Sat,Dinner,3 213 | 25.89,5.16,Male,Yes,Sat,Dinner,4 214 | 48.33,9.0,Male,No,Sat,Dinner,4 215 | 13.27,2.5,Female,Yes,Sat,Dinner,2 216 | 28.17,6.5,Female,Yes,Sat,Dinner,3 217 | 12.9,1.1,Female,Yes,Sat,Dinner,2 218 | 28.15,3.0,Male,Yes,Sat,Dinner,5 219 | 11.59,1.5,Male,Yes,Sat,Dinner,2 220 | 7.74,1.44,Male,Yes,Sat,Dinner,2 221 | 30.14,3.09,Female,Yes,Sat,Dinner,4 222 | 12.16,2.2,Male,Yes,Fri,Lunch,2 223 | 13.42,3.48,Female,Yes,Fri,Lunch,2 224 | 8.58,1.92,Male,Yes,Fri,Lunch,1 225 | 15.98,3.0,Female,No,Fri,Lunch,3 226 | 13.42,1.58,Male,Yes,Fri,Lunch,2 227 | 16.27,2.5,Female,Yes,Fri,Lunch,2 228 | 10.09,2.0,Female,Yes,Fri,Lunch,2 229 | 20.45,3.0,Male,No,Sat,Dinner,4 230 | 13.28,2.72,Male,No,Sat,Dinner,2 231 | 22.12,2.88,Female,Yes,Sat,Dinner,2 232 | 24.01,2.0,Male,Yes,Sat,Dinner,4 233 | 15.69,3.0,Male,Yes,Sat,Dinner,3 234 | 11.61,3.39,Male,No,Sat,Dinner,2 235 | 10.77,1.47,Male,No,Sat,Dinner,2 236 | 15.53,3.0,Male,Yes,Sat,Dinner,2 237 | 10.07,1.25,Male,No,Sat,Dinner,2 238 | 12.6,1.0,Male,Yes,Sat,Dinner,2 239 | 32.83,1.17,Male,Yes,Sat,Dinner,2 240 | 35.83,4.67,Female,No,Sat,Dinner,3 241 | 29.03,5.92,Male,No,Sat,Dinner,3 242 | 27.18,2.0,Female,Yes,Sat,Dinner,2 243 | 22.67,2.0,Male,Yes,Sat,Dinner,2 244 | 17.82,1.75,Male,No,Sat,Dinner,2 245 | 18.78,3.0,Female,No,Thur,Dinner,2 246 | --------------------------------------------------------------------------------