Spaces:
Sleeping
Sleeping
File size: 50,680 Bytes
f4d3b0d cda6b32 f4d3b0d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
{
"cells": [
{
"cell_type": "markdown",
"id": "089fb047",
"metadata": {},
"source": [
"# Workflow of QuizTube 🧠"
]
},
{
"cell_type": "markdown",
"id": "f7cf0634",
"metadata": {},
"source": [
"## 1. Extract the YouTube ID from a given link"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "8415cbde",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SA2iWivDJiE\n",
"_oPAwA_Udwc\n",
"SA2iWivDJiE\n",
"SA2iWivDJiE\n",
"rTHlyTphWP0\n",
"n0g-Y0oo5Qs\n"
]
}
],
"source": [
"from pytube import extract\n",
"\n",
"urls = [\n",
" 'http://youtu.be/SA2iWivDJiE',\n",
" 'http://www.youtube.com/watch?v=_oPAwA_Udwc&feature=feedu',\n",
" 'http://www.youtube.com/embed/SA2iWivDJiE',\n",
" 'http://www.youtube.com/v/SA2iWivDJiE?version=3&hl=en_US',\n",
" 'https://www.youtube.com/watch?v=rTHlyTphWP0&index=6&list=PLjeDyYvG6-40qawYNR4juzvSOg-ezZ2a6',\n",
" 'https://www.youtube.com/watch?time_continue=9&v=n0g-Y0oo5Qs&feature=emb_logo'\n",
"]\n",
"\n",
"for url in urls:\n",
" video_id = extract.video_id(url)\n",
" print(video_id)"
]
},
{
"cell_type": "markdown",
"id": "cc0e3642",
"metadata": {},
"source": [
"## 2. Extract & transform video captions"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0809fc83",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'text': 'Okay, some of you might have heard already,\\nbut you can now use Python inside Excel.',\n",
" 'start': 0.13,\n",
" 'duration': 4.74},\n",
" {'text': \"In this video, I will show some basic examples\\nof how to use it, and I'll guide you through\",\n",
" 'start': 4.87,\n",
" 'duration': 5.2},\n",
" {'text': 'a real-world example to give you an idea of\\nthe possibilities.',\n",
" 'start': 10.07,\n",
" 'duration': 4.199},\n",
" {'text': \"In that example, I'll show you some very useful\\npandas features and some more advanced charts.\",\n",
" 'start': 14.269,\n",
" 'duration': 5.301},\n",
" {'text': \"Towards the end, I'll also share my personal\\nopinion about this new feature and point out\",\n",
" 'start': 19.57,\n",
" 'duration': 4.58},\n",
" {'text': 'some limitations.', 'start': 24.15, 'duration': 1.26},\n",
" {'text': 'But, before we start, a quick shout-out to\\nLuke.',\n",
" 'start': 25.41,\n",
" 'duration': 3.1},\n",
" {'text': 'Luke was kind enough to connect me with people\\nfrom Anaconda so that I could test this feature.',\n",
" 'start': 28.51,\n",
" 'duration': 4.93},\n",
" {'text': 'So, thank you very much, Luke and the team\\nfrom Anaconda.',\n",
" 'start': 33.44,\n",
" 'duration': 3.45},\n",
" {'text': \"And with that said, let's dive in.\",\n",
" 'start': 36.89,\n",
" 'duration': 2.17},\n",
" {'text': \"Ok, let's start with a basic example.\",\n",
" 'start': 39.06,\n",
" 'duration': 2.72},\n",
" {'text': \"Under the formulas ribbon, there's a new Python\\nsection.\",\n",
" 'start': 41.78,\n",
" 'duration': 3.549},\n",
" {'text': \"When I click on the Python logo, you'll notice\\nthat the appearance of the formula bar changes.\",\n",
" 'start': 45.329,\n",
" 'duration': 5.5},\n",
" {'text': 'This is where you can now write your Python\\ncode.',\n",
" 'start': 50.829,\n",
" 'duration': 2.691},\n",
" {'text': 'For the first step, I\\'ll create a dataframe\\nwith the command \"df is equal to\", and then',\n",
" 'start': 53.52,\n",
" 'duration': 5.03},\n",
" {'text': 'simply select my Excel table here on the left.',\n",
" 'start': 58.55,\n",
" 'duration': 2.82},\n",
" {'text': \"It doesn't have to be a table, by the way;\\na normal cell range will also work.\",\n",
" 'start': 61.37,\n",
" 'duration': 4.24},\n",
" {'text': 'To execute the code, I will press Ctrl + Enter.',\n",
" 'start': 65.61,\n",
" 'duration': 3.2},\n",
" {'text': 'If you just press Enter, it will insert a\\nnew line.',\n",
" 'start': 68.81,\n",
" 'duration': 2.91},\n",
" {'text': 'So now, the data source is now your table.',\n",
" 'start': 71.72,\n",
" 'duration': 2.74},\n",
" {'text': 'In my case, the table is named IrisDataSet,\\nand as it is correctly recognized, it has',\n",
" 'start': 74.46,\n",
" 'duration': 4.89},\n",
" {'text': 'a header row.', 'start': 79.35, 'duration': 1.0},\n",
" {'text': 'In the cell where I wrote the Python code,\\nthe dataframe object now appears.',\n",
" 'start': 80.35,\n",
" 'duration': 3.53},\n",
" {'text': 'So, as you might already know, everything\\nin Python is an object, and we can store that',\n",
" 'start': 83.88,\n",
" 'duration': 5.3},\n",
" {'text': 'object in a cell.', 'start': 89.18, 'duration': 1.52},\n",
" {'text': 'I can also get a preview of what the dataframe\\nlooks like when I click on the icon.',\n",
" 'start': 90.7,\n",
" 'duration': 4.33},\n",
" {'text': 'It gives me a preview of the dataframe.',\n",
" 'start': 95.03,\n",
" 'duration': 4.06},\n",
" {'text': 'Now that we have our dataframe, you can use\\nall the different Pandas functions.',\n",
" 'start': 99.09,\n",
" 'duration': 3.96},\n",
" {'text': \"I named my dataframe 'df', so in the next\\ncell, I just need to type 'df'.\",\n",
" 'start': 103.05,\n",
" 'duration': 5.54},\n",
" {'text': \"And for this example, I will use the 'describe'\\nmethod to get some statistical insights into\",\n",
" 'start': 108.59,\n",
" 'duration': 4.48},\n",
" {'text': 'the data.', 'start': 113.07, 'duration': 1.079},\n",
" {'text': 'When I execute the cell using Ctrl + Enter,\\nExcel returns the object.',\n",
" 'start': 114.149,\n",
" 'duration': 4.111},\n",
" {'text': \"In this case, the 'describe' method returns\\na dataframe.\",\n",
" 'start': 118.26,\n",
" 'duration': 4.179},\n",
" {'text': 'If you actually want to print the dataframe\\nto Excel, you can select \"Excel value\" from',\n",
" 'start': 122.439,\n",
" 'duration': 4.47},\n",
" {'text': 'the drop-down list.', 'start': 126.909, 'duration': 1.081},\n",
" {'text': \"You'll then see a statistical summary of the\\ndata directly in Excel.\",\n",
" 'start': 127.99,\n",
" 'duration': 3.139},\n",
" {'text': 'Likewise, I will calculate the correlation.',\n",
" 'start': 131.129,\n",
" 'duration': 2.551},\n",
" {'text': \"But this time, instead of using my 'df' variable,\\nI will refer to the cell that holds the dataframe\",\n",
" 'start': 133.68,\n",
" 'duration': 5.3},\n",
" {'text': 'object, which is H2 in my case.',\n",
" 'start': 138.98,\n",
" 'duration': 2.36},\n",
" {'text': 'Then, on my dataframe object, I can call the\\ncorrelation method.',\n",
" 'start': 141.34,\n",
" 'duration': 4.47},\n",
" {'text': 'As before, we get a dataframe in return.',\n",
" 'start': 145.81,\n",
" 'duration': 2.44},\n",
" {'text': 'However, I will adjust the output to insert\\nthe data into the spreadsheet.',\n",
" 'start': 148.25,\n",
" 'duration': 4.709},\n",
" {'text': \"Okay, now let's proceed to some basic plots.\",\n",
" 'start': 152.959,\n",
" 'duration': 2.991},\n",
" {'text': 'With the integration of Python, we can tap\\ninto various plotting libraries.',\n",
" 'start': 155.95,\n",
" 'duration': 4.1},\n",
" {'text': 'For my demonstration, I will use matplotlib\\nto craft a scatter plot.',\n",
" 'start': 160.05,\n",
" 'duration': 4.24},\n",
" {'text': 'When I run the code, it returns an image object.',\n",
" 'start': 164.29,\n",
" 'duration': 2.75},\n",
" {'text': 'However, as with the earlier examples, I want\\nto display the actual chart.',\n",
" 'start': 167.04,\n",
" 'duration': 4.42},\n",
" {'text': 'So, I just need to switch the output.',\n",
" 'start': 171.46,\n",
" 'duration': 2.39},\n",
" {'text': 'As a result, we have an image stored in a\\ncell.',\n",
" 'start': 173.85,\n",
" 'duration': 3.71},\n",
" {'text': 'You can right-click on this image to create\\na reference to the cell.',\n",
" 'start': 177.56,\n",
" 'duration': 4.08},\n",
" {'text': 'And now, we have an Excel image with our scatter\\nplot.',\n",
" 'start': 181.64,\n",
" 'duration': 2.929},\n",
" {'text': 'Next, I plan to generate a Seaborn pair plot,\\nwhich only requires one line of code.',\n",
" 'start': 184.569,\n",
" 'duration': 6.14},\n",
" {'text': 'The execution of this cell might take a moment,\\nbut once complete, it also returns an image',\n",
" 'start': 190.709,\n",
" 'duration': 6.041},\n",
" {'text': 'object.', 'start': 196.75, 'duration': 1.0},\n",
" {'text': \"Similar to before, I'll create a reference\\nfor this image.\",\n",
" 'start': 197.75,\n",
" 'duration': 3.4},\n",
" {'text': 'And there we have it: our pair plot.',\n",
" 'start': 201.15,\n",
" 'duration': 2.41},\n",
" {'text': 'This is particularly useful for visualizing\\nthe linear correlation among all dataset variables',\n",
" 'start': 203.56,\n",
" 'duration': 4.87},\n",
" {'text': 'and displaying the distribution.',\n",
" 'start': 208.43,\n",
" 'duration': 2.51},\n",
" {'text': 'Lastly, I will generate a linear regression\\nplot for two distinct variables.',\n",
" 'start': 210.94,\n",
" 'duration': 4.94},\n",
" {'text': 'Once again, in Seaborn, we only need one line\\nof code for this.',\n",
" 'start': 215.88,\n",
" 'duration': 4.55},\n",
" {'text': 'Okay, so those were some basic examples that\\ngive some general idea of this new feature.',\n",
" 'start': 220.43,\n",
" 'duration': 5.699},\n",
" {'text': 'Now, let us move on to a real-world example.',\n",
" 'start': 226.129,\n",
" 'duration': 3.211},\n",
" {'text': 'Here in the datasheet, I have a transaction\\ntable of sales for five different stores in',\n",
" 'start': 229.34,\n",
" 'duration': 4.47},\n",
" {'text': 'Japan.', 'start': 233.81, 'duration': 1.0},\n",
" {'text': 'We have there the City where the store is\\nlocated, the information of the customer,',\n",
" 'start': 234.81,\n",
" 'duration': 3.709},\n",
" {'text': 'so, if the customer was a member or not and\\nthe gender of the customer.',\n",
" 'start': 238.519,\n",
" 'duration': 3.881},\n",
" {'text': 'Next, we have the information about the product\\nline, unit price, quantity, date and time',\n",
" 'start': 242.4,\n",
" 'duration': 5.39},\n",
" {'text': 'of the purchase, the payment method, the rating\\nfrom the customer and the sales amount, which',\n",
" 'start': 247.79,\n",
" 'duration': 5.49},\n",
" {'text': 'is the unit price multiplied by the quantity.',\n",
" 'start': 253.28,\n",
" 'duration': 2.769},\n",
" {'text': 'As before, this data is an Excel table; I\\nnamed it \"table Sales\".',\n",
" 'start': 256.049,\n",
" 'duration': 6.071},\n",
" {'text': \"Okay, now I've taken this data and conducted\\nsome analysis using Python.\",\n",
" 'start': 262.12,\n",
" 'duration': 5.269},\n",
" {'text': 'First, I loaded the dataframe and named it\\n\"data\".',\n",
" 'start': 267.389,\n",
" 'duration': 4.991},\n",
" {'text': \"After loading the data, there wasn't much\\ncleanup needed.\",\n",
" 'start': 272.38,\n",
" 'duration': 2.48},\n",
" {'text': 'The main task was converting the date and\\ntime column into a DateTime object, which',\n",
" 'start': 274.86,\n",
" 'duration': 5.16},\n",
" {'text': 'is required for my time and date-based analysis.',\n",
" 'start': 280.02,\n",
" 'duration': 3.05},\n",
" {'text': \"And there's also an important hint: the cleanup\\nprocess is in a cell below the actual dataframe.\",\n",
" 'start': 283.07,\n",
" 'duration': 6.31},\n",
" {'text': \"This is important because I refer to the 'data'\\nvariable, which should be defined in a cell\",\n",
" 'start': 289.38,\n",
" 'duration': 4.93},\n",
" {'text': 'above my current one, as the Python code is\\nvalidated from top to bottom and left to right.',\n",
" 'start': 294.31,\n",
" 'duration': 6.9},\n",
" {'text': 'With that said, let me show you my code that\\nreturns the top 5 selling products.',\n",
" 'start': 301.21,\n",
" 'duration': 4.22},\n",
" {'text': 'I grouped our dataframe by Product and, following\\nthat, specified the aggregation mode.',\n",
" 'start': 305.43,\n",
" 'duration': 5.04},\n",
" {'text': 'This next part is pretty cool; instead of\\nhardcoding the aggregation method, I linked',\n",
" 'start': 310.47,\n",
" 'duration': 5.789},\n",
" {'text': 'it to cell C7.', 'start': 316.259, 'duration': 1.341},\n",
" {'text': 'I named this cell \"Calc_Method\".',\n",
" 'start': 317.6,\n",
" 'duration': 2.37},\n",
" {'text': 'This is pretty neat because now you can combine\\nthe flexibility of Excel with Python.',\n",
" 'start': 319.97,\n",
" 'duration': 4.73},\n",
" {'text': 'So, before I linked it, I hardcoded the aggregation\\nmethod sum in my Pandas code.',\n",
" 'start': 324.7,\n",
" 'duration': 5.279},\n",
" {'text': 'I then inserted a drop-down menu and named\\nthe cell \"Calc_Method\".',\n",
" 'start': 329.979,\n",
" 'duration': 2.761},\n",
" {'text': 'And now, in the Python code, you could just\\ntype out the cell reference, or if you delete',\n",
" 'start': 332.74,\n",
" 'duration': 6.79},\n",
" {'text': 'it again, you could also just select the cell.',\n",
" 'start': 339.53,\n",
" 'duration': 3.28},\n",
" {'text': 'And when I execute the code, it is calculated\\ncorrectly.',\n",
" 'start': 342.81,\n",
" 'duration': 2.97},\n",
" {'text': 'Now, the cool part is that I just need to\\nchange this cell here, and then all my calculations',\n",
" 'start': 345.78,\n",
" 'duration': 5.67},\n",
" {'text': 'will show the average sales amount.',\n",
" 'start': 351.45,\n",
" 'duration': 2.38},\n",
" {'text': 'When I do this, you will also notice that\\nall my charts are also being updated.',\n",
" 'start': 353.83,\n",
" 'duration': 4.01},\n",
" {'text': 'In fact, if we look at my chart for the top\\n5 selling products, you will see that I have',\n",
" 'start': 357.84,\n",
" 'duration': 4.919},\n",
" {'text': 'done the same for the colours of the bars.',\n",
" 'start': 362.759,\n",
" 'duration': 2.561},\n",
" {'text': 'This is linked to the following cell.',\n",
" 'start': 365.32,\n",
" 'duration': 2.07},\n",
" {'text': \"Okay, I'll reduce the size of the formula\\nbar, and then from the drop-down menu, I'll\",\n",
" 'start': 367.39,\n",
" 'duration': 6.33},\n",
" {'text': 'select another colour.', 'start': 373.72, 'duration': 1.52},\n",
" {'text': 'Doing so will change the colours of the bars.',\n",
" 'start': 375.24,\n",
" 'duration': 3.57},\n",
" {'text': 'For the next analysis, I will group the sales\\nby weekday.',\n",
" 'start': 378.81,\n",
" 'duration': 3.37},\n",
" {'text': 'Doing this in Pandas is actually not too complicated.',\n",
" 'start': 382.18,\n",
" 'duration': 3.26},\n",
" {'text': \"On the dataframe, I'll create a new column\\nusing the assign method.\",\n",
" 'start': 385.44,\n",
" 'duration': 2.991},\n",
" {'text': \"The new column will be named 'weekday', and\\nI'll extract the weekday from the date column.\",\n",
" 'start': 388.431,\n",
" 'duration': 5.208},\n",
" {'text': \"I'll then group the data by this new column,\\naggregate the sales, and rename and reset\",\n",
" 'start': 393.639,\n",
" 'duration': 5.351},\n",
" {'text': 'the index.', 'start': 398.99, 'duration': 1.36},\n",
" {'text': \"And another quick note here: I'm using a lot\\nof pandas steps one after the other.\",\n",
" 'start': 400.35,\n",
" 'duration': 4.1},\n",
" {'text': 'I think it makes the code easy to read.',\n",
" 'start': 404.45,\n",
" 'duration': 2.29},\n",
" {'text': 'But if you like, you can do each step one\\nat a time.',\n",
" 'start': 406.74,\n",
" 'duration': 4.221},\n",
" {'text': 'However, if you want to learn more about chaining\\ndifferent pandas methods, I suggest my following',\n",
" 'start': 410.961,\n",
" 'duration': 3.999},\n",
" {'text': 'video.', 'start': 414.96, 'duration': 1.0},\n",
" {'text': 'In that video, I will walk you through how\\nchain pandas methods and also explain why',\n",
" 'start': 415.96,\n",
" 'duration': 4.09},\n",
" {'text': 'you might want to use that approach.',\n",
" 'start': 420.05,\n",
" 'duration': 1.89},\n",
" {'text': \"I've put the link to that video in the info\\ncard above and in the description below.\",\n",
" 'start': 421.94,\n",
" 'duration': 4.17},\n",
" {'text': 'Okay, so now that we have the sales grouped\\nby weekday, we can also plot it.',\n",
" 'start': 426.11,\n",
" 'duration': 4.929},\n",
" {'text': 'For this, I wrote the code next to the table.',\n",
" 'start': 431.039,\n",
" 'duration': 2.75},\n",
" {'text': \"And here is also a fun fact: I didn't write\\nall the code myself; I got help from ChatGPT.\",\n",
" 'start': 433.789,\n",
" 'duration': 5.331},\n",
" {'text': 'OK, next up, I calculated sales by the hour.',\n",
" 'start': 439.12,\n",
" 'duration': 3.72},\n",
" {'text': 'Again, not much pandas code is needed for\\nthis type of calculation.',\n",
" 'start': 442.84,\n",
" 'duration': 4.25},\n",
" {'text': 'And if we look at the chart, most customers\\nseem to do their shopping after work, especially',\n",
" 'start': 447.09,\n",
" 'duration': 4.561},\n",
" {'text': 'from 7 pm onwards.', 'start': 451.651, 'duration': 1.529},\n",
" {'text': 'So, during these peak hours, we might need\\nadditional staff and cashiers.',\n",
" 'start': 453.18,\n",
" 'duration': 4.6},\n",
" {'text': \"With that insight, let's move on to the next\\nanalysis.\",\n",
" 'start': 457.78,\n",
" 'duration': 2.44},\n",
" {'text': 'Here, I utilized the pandas method \"percentage\\nchange\" to calculate the month-over-month',\n",
" 'start': 460.22,\n",
" 'duration': 5.06},\n",
" {'text': 'growth rate.', 'start': 465.28, 'duration': 1.46},\n",
" {'text': 'I then again asked ChatGPT to provide me with\\nthe code to plot the sales amount by month',\n",
" 'start': 466.74,\n",
" 'duration': 5.03},\n",
" {'text': 'and, on the secondary axis, the growth rate.',\n",
" 'start': 471.77,\n",
" 'duration': 2.81},\n",
" {'text': 'And as a result, I have got back the following\\nchart.',\n",
" 'start': 474.58,\n",
" 'duration': 3.679},\n",
" {'text': 'Frankly speaking, I think using native Excel\\ncharts would have been quicker for this purpose.',\n",
" 'start': 478.259,\n",
" 'duration': 4.861},\n",
" {'text': 'Also, all the charts I chose here are fairly\\nbasic.',\n",
" 'start': 483.12,\n",
" 'duration': 3.139},\n",
" {'text': \"There's really no need to overcomplicate things\\nby using Python for this.\",\n",
" 'start': 486.259,\n",
" 'duration': 4.071},\n",
" {'text': 'However, I will also demonstrate a scenario\\nwhere you might want to use a Python chart.',\n",
" 'start': 490.33,\n",
" 'duration': 5.96},\n",
" {'text': 'For the following heatmap, I created a pivot\\ntable using pandas to display the sales amount',\n",
" 'start': 496.29,\n",
" 'duration': 5.379},\n",
" {'text': 'by product line and month.', 'start': 501.669, 'duration': 1.74},\n",
" {'text': 'I then plotted this new dataframe with a Seaborn\\nheatmap.',\n",
" 'start': 503.409,\n",
" 'duration': 3.711},\n",
" {'text': 'The resulting chart has a colour scale: the\\ndarker the colour, the higher the sales.',\n",
" 'start': 507.12,\n",
" 'duration': 4.68},\n",
" {'text': 'The y-axis represents the months, while the\\nx-axis displays the different product lines.',\n",
" 'start': 511.8,\n",
" 'duration': 5.919},\n",
" {'text': 'And from this heatmap, we can see, that sales\\nfor groceries remain relatively consistent',\n",
" 'start': 517.719,\n",
" 'duration': 4.661},\n",
" {'text': 'throughout the year, which is kind of expected.',\n",
" 'start': 522.38,\n",
" 'duration': 3.31},\n",
" {'text': 'However, for the Electronics, we will notice\\nhigher sales in a specific month.',\n",
" 'start': 525.69,\n",
" 'duration': 3.769},\n",
" {'text': 'So, we might want to dig deeper into these\\ninsights.',\n",
" 'start': 529.459,\n",
" 'duration': 3.07},\n",
" {'text': 'So, this is just one example of a more advanced\\nchart that would be difficult to replicate',\n",
" 'start': 532.529,\n",
" 'duration': 5.071},\n",
" {'text': 'in Excel.', 'start': 537.6, 'duration': 1.1},\n",
" {'text': \"Obviously, you shouldn't just pick a chart\\nbecause it looks fancy.\",\n",
" 'start': 538.7,\n",
" 'duration': 3.92},\n",
" {'text': 'It should simply convey the message of your\\ninsights.',\n",
" 'start': 542.62,\n",
" 'duration': 3.43},\n",
" {'text': \"Now that you've seen some potential use cases\\nlet me share my thoughts about running Python\",\n",
" 'start': 546.05,\n",
" 'duration': 4.4},\n",
" {'text': 'code in Excel.', 'start': 550.45, 'duration': 1.04},\n",
" {'text': \"In general, I think, it's fantastic that you\\ncan now integrate Python with Excel.\",\n",
" 'start': 551.49,\n",
" 'duration': 3.86},\n",
" {'text': 'This just adds another tool to your toolbox.',\n",
" 'start': 555.35,\n",
" 'duration': 3.21},\n",
" {'text': 'Especially when dealing with dates and times,\\ncertain calculations are much more straightforward',\n",
" 'start': 558.56,\n",
" 'duration': 4.019},\n",
" {'text': 'in pandas, at least in my opinion.',\n",
" 'start': 562.579,\n",
" 'duration': 2.611},\n",
" {'text': 'However, Excel also offers another powerful\\ntool for data cleaning and aggregation: PowerQuery.',\n",
" 'start': 565.19,\n",
" 'duration': 5.9},\n",
" {'text': \"If you've worked with PowerQuery before, you'll\\nknow its capabilities.\",\n",
" 'start': 571.09,\n",
" 'duration': 4.27},\n",
" {'text': \"Also, even though I'm not a beginner with\\npandas, I often need to test my code and tinker\",\n",
" 'start': 575.36,\n",
" 'duration': 5.37},\n",
" {'text': 'around with it.', 'start': 580.73, 'duration': 1.29},\n",
" {'text': \"And I've noticed that the more Python calculations\\nyou have in your spreadsheet, the slower the\",\n",
" 'start': 582.02,\n",
" 'duration': 5.059},\n",
" {'text': 'calculation becomes.', 'start': 587.079, 'duration': 1.311},\n",
" {'text': 'So, I find it rather clunky to do my exploratory\\ndata analysis directly in Excel.',\n",
" 'start': 588.39,\n",
" 'duration': 5.79},\n",
" {'text': \"Instead, I've been turning to a Jupyter Notebook.\",\n",
" 'start': 594.18,\n",
" 'duration': 3.0},\n",
" {'text': 'Once I tested my code in a Jupyter Notebook,\\nI plugged it into Excel.',\n",
" 'start': 597.18,\n",
" 'duration': 4.27},\n",
" {'text': 'Now, to quickly get the Excel data into a\\nJupyter Notebook, I created my own add-in,',\n",
" 'start': 601.45,\n",
" 'duration': 5.11},\n",
" {'text': 'which is called \"MyToolBelt\".', 'start': 606.56, 'duration': 1.0},\n",
" {'text': 'With it, I just click a button, select the\\ncell range I want to analyze, provide a title',\n",
" 'start': 607.56,\n",
" 'duration': 6.26},\n",
" {'text': \"if I wish, and then hit 'OK'.\", 'start': 613.82, 'duration': 2.66},\n",
" {'text': \"This action generates a new Jupyter Notebook\\nin my workbook's directory.\",\n",
" 'start': 616.48,\n",
" 'duration': 3.19},\n",
" {'text': 'When I open it, I have my title, library imports,\\nand the respective code to load the Excel',\n",
" 'start': 619.67,\n",
" 'duration': 6.94},\n",
" {'text': 'data as a pandas dataframe – with the correct\\npath to the spreadsheet, sheet name, columns,',\n",
" 'start': 626.61,\n",
" 'duration': 5.56},\n",
" {'text': 'and row count.', 'start': 632.17, 'duration': 1.05},\n",
" {'text': 'So, with this add-in, I can speed up my analysis,\\nand now I also have a clear separation between',\n",
" 'start': 633.22,\n",
" 'duration': 5.14},\n",
" {'text': 'my data and the code I write.', 'start': 638.36, 'duration': 2.86},\n",
" {'text': \"If you also want to install the add-in, I'll\\ndrop a link in the description below.\",\n",
" 'start': 641.22,\n",
" 'duration': 3.66},\n",
" {'text': \"However, it's worth noting that the Jupyter\\nNotebook feature is only available in the\",\n",
" 'start': 644.88,\n",
" 'duration': 4.26},\n",
" {'text': 'paid version.', 'start': 649.14, 'duration': 1.0},\n",
" {'text': \"Now, let's get back to native Python functionality\\nin Excel.\",\n",
" 'start': 650.14,\n",
" 'duration': 4.28},\n",
" {'text': 'In this video, I showcased examples using\\npandas, matplotlib, and seaborn.',\n",
" 'start': 654.42,\n",
" 'duration': 4.52},\n",
" {'text': 'However, you can also access additional packages\\navailable in the Anaconda distribution, like',\n",
" 'start': 658.94,\n",
" 'duration': 5.8},\n",
" {'text': 'statsmodels, scipy, and scikit-learn.',\n",
" 'start': 664.74,\n",
" 'duration': 2.31},\n",
" {'text': 'By default, many of these packages are directly\\nloaded when initializing the environment.',\n",
" 'start': 667.05,\n",
" 'duration': 5.339},\n",
" {'text': \"That's why, in my example, I didn't need to\\nimport the libraries separately.\",\n",
" 'start': 672.389,\n",
" 'duration': 4.88},\n",
" {'text': 'So, in my upcoming videos, I also want to\\nexplore the possibilities of using basic machine',\n",
" 'start': 677.269,\n",
" 'duration': 5.161},\n",
" {'text': 'learning with scikit-learn directly in Excel.',\n",
" 'start': 682.43,\n",
" 'duration': 3.19},\n",
" {'text': \"Because those types of calculations can't\\nbe done with PowerQuery.\",\n",
" 'start': 685.62,\n",
" 'duration': 3.82},\n",
" {'text': 'And speaking of PowerQuery, you can actually\\nalso connect Python to your PowerQuery tables,',\n",
" 'start': 689.44,\n",
" 'duration': 5.57},\n",
" {'text': \"something I haven't shown in this video.\",\n",
" 'start': 695.01,\n",
" 'duration': 1.699},\n",
" {'text': 'Lastly, before you go, let me highlight some\\nlimitations.',\n",
" 'start': 696.709,\n",
" 'duration': 3.781},\n",
" {'text': \"As of now, animated Python charts like those\\nfrom Plotly aren't supported.\",\n",
" 'start': 700.49,\n",
" 'duration': 4.99},\n",
" {'text': 'Also, the Python functionality is currently\\nexclusive to Excel Desktop 365 Beta Channel',\n",
" 'start': 705.48,\n",
" 'duration': 6.67},\n",
" {'text': 'users, and it only works on Windows at the\\nmoment.',\n",
" 'start': 712.15,\n",
" 'duration': 3.52},\n",
" {'text': 'Another constraint is that you cannot connect\\nto external files using Python; so, if you',\n",
" 'start': 715.67,\n",
" 'duration': 5.469},\n",
" {'text': \"want to connect to other files and folders,\\nyou'd need to use PowerQuery.\",\n",
" 'start': 721.139,\n",
" 'duration': 4.82},\n",
" {'text': 'Moreover, only the libraries supported by\\nAnaconda are available for use.',\n",
" 'start': 725.959,\n",
" 'duration': 4.861},\n",
" {'text': \"So, if there's a 3rd party package that isn't\\npart of the Anaconda distribution, you won't\",\n",
" 'start': 730.82,\n",
" 'duration': 5.11},\n",
" {'text': 'be able to use it.', 'start': 735.93, 'duration': 1.77},\n",
" {'text': \"With that said, I'd love to hear your thoughts\\non this new functionality.\",\n",
" 'start': 737.7,\n",
" 'duration': 2.87},\n",
" {'text': 'Please share them in the comments below.',\n",
" 'start': 740.57,\n",
" 'duration': 1.87},\n",
" {'text': \"And as always, thanks for watching, and I'll\\nsee you in the next video.\",\n",
" 'start': 742.44,\n",
" 'duration': 20.29}]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from youtube_transcript_api import YouTubeTranscriptApi\n",
"video_id = \"bcYwiwsDfGE\"\n",
"transcript = YouTubeTranscriptApi.get_transcript(video_id)\n",
"transcript"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "baeae965",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Okay, some of you might have heard already,\\nbut you can now use Python inside Excel. In this video, I will show some basic examples\\nof how to use it, and I\\'ll guide you through a real-world example to give you an idea of\\nthe possibilities. In that example, I\\'ll show you some very useful\\npandas features and some more advanced charts. Towards the end, I\\'ll also share my personal\\nopinion about this new feature and point out some limitations. But, before we start, a quick shout-out to\\nLuke. Luke was kind enough to connect me with people\\nfrom Anaconda so that I could test this feature. So, thank you very much, Luke and the team\\nfrom Anaconda. And with that said, let\\'s dive in. Ok, let\\'s start with a basic example. Under the formulas ribbon, there\\'s a new Python\\nsection. When I click on the Python logo, you\\'ll notice\\nthat the appearance of the formula bar changes. This is where you can now write your Python\\ncode. For the first step, I\\'ll create a dataframe\\nwith the command \"df is equal to\", and then simply select my Excel table here on the left. It doesn\\'t have to be a table, by the way;\\na normal cell range will also work. To execute the code, I will press Ctrl + Enter. If you just press Enter, it will insert a\\nnew line. So now, the data source is now your table. In my case, the table is named IrisDataSet,\\nand as it is correctly recognized, it has a header row. In the cell where I wrote the Python code,\\nthe dataframe object now appears. So, as you might already know, everything\\nin Python is an object, and we can store that object in a cell. I can also get a preview of what the dataframe\\nlooks like when I click on the icon. It gives me a preview of the dataframe. Now that we have our dataframe, you can use\\nall the different Pandas functions. I named my dataframe \\'df\\', so in the next\\ncell, I just need to type \\'df\\'. And for this example, I will use the \\'describe\\'\\nmethod to get some statistical insights into the data. When I execute the cell using Ctrl + Enter,\\nExcel returns the object. In this case, the \\'describe\\' method returns\\na dataframe. If you actually want to print the dataframe\\nto Excel, you can select \"Excel value\" from the drop-down list. You\\'ll then see a statistical summary of the\\ndata directly in Excel. Likewise, I will calculate the correlation. But this time, instead of using my \\'df\\' variable,\\nI will refer to the cell that holds the dataframe object, which is H2 in my case. Then, on my dataframe object, I can call the\\ncorrelation method. As before, we get a dataframe in return. However, I will adjust the output to insert\\nthe data into the spreadsheet. Okay, now let\\'s proceed to some basic plots. With the integration of Python, we can tap\\ninto various plotting libraries. For my demonstration, I will use matplotlib\\nto craft a scatter plot. When I run the code, it returns an image object. However, as with the earlier examples, I want\\nto display the actual chart. So, I just need to switch the output. As a result, we have an image stored in a\\ncell. You can right-click on this image to create\\na reference to the cell. And now, we have an Excel image with our scatter\\nplot. Next, I plan to generate a Seaborn pair plot,\\nwhich only requires one line of code. The execution of this cell might take a moment,\\nbut once complete, it also returns an image object. Similar to before, I\\'ll create a reference\\nfor this image. And there we have it: our pair plot. This is particularly useful for visualizing\\nthe linear correlation among all dataset variables and displaying the distribution. Lastly, I will generate a linear regression\\nplot for two distinct variables. Once again, in Seaborn, we only need one line\\nof code for this. Okay, so those were some basic examples that\\ngive some general idea of this new feature. Now, let us move on to a real-world example. Here in the datasheet, I have a transaction\\ntable of sales for five different stores in Japan. We have there the City where the store is\\nlocated, the information of the customer, so, if the customer was a member or not and\\nthe gender of the customer. Next, we have the information about the product\\nline, unit price, quantity, date and time of the purchase, the payment method, the rating\\nfrom the customer and the sales amount, which is the unit price multiplied by the quantity. As before, this data is an Excel table; I\\nnamed it \"table Sales\". Okay, now I\\'ve taken this data and conducted\\nsome analysis using Python. First, I loaded the dataframe and named it\\n\"data\". After loading the data, there wasn\\'t much\\ncleanup needed. The main task was converting the date and\\ntime column into a DateTime object, which is required for my time and date-based analysis. And there\\'s also an important hint: the cleanup\\nprocess is in a cell below the actual dataframe. This is important because I refer to the \\'data\\'\\nvariable, which should be defined in a cell above my current one, as the Python code is\\nvalidated from top to bottom and left to right. With that said, let me show you my code that\\nreturns the top 5 selling products. I grouped our dataframe by Product and, following\\nthat, specified the aggregation mode. This next part is pretty cool; instead of\\nhardcoding the aggregation method, I linked it to cell C7. I named this cell \"Calc_Method\". This is pretty neat because now you can combine\\nthe flexibility of Excel with Python. So, before I linked it, I hardcoded the aggregation\\nmethod sum in my Pandas code. I then inserted a drop-down menu and named\\nthe cell \"Calc_Method\". And now, in the Python code, you could just\\ntype out the cell reference, or if you delete it again, you could also just select the cell. And when I execute the code, it is calculated\\ncorrectly. Now, the cool part is that I just need to\\nchange this cell here, and then all my calculations will show the average sales amount. When I do this, you will also notice that\\nall my charts are also being updated. In fact, if we look at my chart for the top\\n5 selling products, you will see that I have done the same for the colours of the bars. This is linked to the following cell. Okay, I\\'ll reduce the size of the formula\\nbar, and then from the drop-down menu, I\\'ll select another colour. Doing so will change the colours of the bars. For the next analysis, I will group the sales\\nby weekday. Doing this in Pandas is actually not too complicated. On the dataframe, I\\'ll create a new column\\nusing the assign method. The new column will be named \\'weekday\\', and\\nI\\'ll extract the weekday from the date column. I\\'ll then group the data by this new column,\\naggregate the sales, and rename and reset the index. And another quick note here: I\\'m using a lot\\nof pandas steps one after the other. I think it makes the code easy to read. But if you like, you can do each step one\\nat a time. However, if you want to learn more about chaining\\ndifferent pandas methods, I suggest my following video. In that video, I will walk you through how\\nchain pandas methods and also explain why you might want to use that approach. I\\'ve put the link to that video in the info\\ncard above and in the description below. Okay, so now that we have the sales grouped\\nby weekday, we can also plot it. For this, I wrote the code next to the table. And here is also a fun fact: I didn\\'t write\\nall the code myself; I got help from ChatGPT. OK, next up, I calculated sales by the hour. Again, not much pandas code is needed for\\nthis type of calculation. And if we look at the chart, most customers\\nseem to do their shopping after work, especially from 7 pm onwards. So, during these peak hours, we might need\\nadditional staff and cashiers. With that insight, let\\'s move on to the next\\nanalysis. Here, I utilized the pandas method \"percentage\\nchange\" to calculate the month-over-month growth rate. I then again asked ChatGPT to provide me with\\nthe code to plot the sales amount by month and, on the secondary axis, the growth rate. And as a result, I have got back the following\\nchart. Frankly speaking, I think using native Excel\\ncharts would have been quicker for this purpose. Also, all the charts I chose here are fairly\\nbasic. There\\'s really no need to overcomplicate things\\nby using Python for this. However, I will also demonstrate a scenario\\nwhere you might want to use a Python chart. For the following heatmap, I created a pivot\\ntable using pandas to display the sales amount by product line and month. I then plotted this new dataframe with a Seaborn\\nheatmap. The resulting chart has a colour scale: the\\ndarker the colour, the higher the sales. The y-axis represents the months, while the\\nx-axis displays the different product lines. And from this heatmap, we can see, that sales\\nfor groceries remain relatively consistent throughout the year, which is kind of expected. However, for the Electronics, we will notice\\nhigher sales in a specific month. So, we might want to dig deeper into these\\ninsights. So, this is just one example of a more advanced\\nchart that would be difficult to replicate in Excel. Obviously, you shouldn\\'t just pick a chart\\nbecause it looks fancy. It should simply convey the message of your\\ninsights. Now that you\\'ve seen some potential use cases\\nlet me share my thoughts about running Python code in Excel. In general, I think, it\\'s fantastic that you\\ncan now integrate Python with Excel. This just adds another tool to your toolbox. Especially when dealing with dates and times,\\ncertain calculations are much more straightforward in pandas, at least in my opinion. However, Excel also offers another powerful\\ntool for data cleaning and aggregation: PowerQuery. If you\\'ve worked with PowerQuery before, you\\'ll\\nknow its capabilities. Also, even though I\\'m not a beginner with\\npandas, I often need to test my code and tinker around with it. And I\\'ve noticed that the more Python calculations\\nyou have in your spreadsheet, the slower the calculation becomes. So, I find it rather clunky to do my exploratory\\ndata analysis directly in Excel. Instead, I\\'ve been turning to a Jupyter Notebook. Once I tested my code in a Jupyter Notebook,\\nI plugged it into Excel. Now, to quickly get the Excel data into a\\nJupyter Notebook, I created my own add-in, which is called \"MyToolBelt\". With it, I just click a button, select the\\ncell range I want to analyze, provide a title if I wish, and then hit \\'OK\\'. This action generates a new Jupyter Notebook\\nin my workbook\\'s directory. When I open it, I have my title, library imports,\\nand the respective code to load the Excel data as a pandas dataframe – with the correct\\npath to the spreadsheet, sheet name, columns, and row count. So, with this add-in, I can speed up my analysis,\\nand now I also have a clear separation between my data and the code I write. If you also want to install the add-in, I\\'ll\\ndrop a link in the description below. However, it\\'s worth noting that the Jupyter\\nNotebook feature is only available in the paid version. Now, let\\'s get back to native Python functionality\\nin Excel. In this video, I showcased examples using\\npandas, matplotlib, and seaborn. However, you can also access additional packages\\navailable in the Anaconda distribution, like statsmodels, scipy, and scikit-learn. By default, many of these packages are directly\\nloaded when initializing the environment. That\\'s why, in my example, I didn\\'t need to\\nimport the libraries separately. So, in my upcoming videos, I also want to\\nexplore the possibilities of using basic machine learning with scikit-learn directly in Excel. Because those types of calculations can\\'t\\nbe done with PowerQuery. And speaking of PowerQuery, you can actually\\nalso connect Python to your PowerQuery tables, something I haven\\'t shown in this video. Lastly, before you go, let me highlight some\\nlimitations. As of now, animated Python charts like those\\nfrom Plotly aren\\'t supported. Also, the Python functionality is currently\\nexclusive to Excel Desktop 365 Beta Channel users, and it only works on Windows at the\\nmoment. Another constraint is that you cannot connect\\nto external files using Python; so, if you want to connect to other files and folders,\\nyou\\'d need to use PowerQuery. Moreover, only the libraries supported by\\nAnaconda are available for use. So, if there\\'s a 3rd party package that isn\\'t\\npart of the Anaconda distribution, you won\\'t be able to use it. With that said, I\\'d love to hear your thoughts\\non this new functionality. Please share them in the comments below. And as always, thanks for watching, and I\\'ll\\nsee you in the next video.'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"transcript = \" \".join([item[\"text\"] for item in transcript])\n",
"transcript"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b44040c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "29bb8efa",
"metadata": {},
"source": [
"## 3. Feed video captions into LLM (OpenAI)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ad82f2d3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'str'>\n",
"[\n",
" [\"What is the purpose of the video?\", \"To demonstrate how to use Python inside Excel\", \"To explain the limitations of using Python in Excel\", \"To showcase different data visualization libraries\"],\n",
" [\"What is the advantage of using pandas in Python?\", \"It makes certain calculations with dates and times easier\", \"It allows for the creation of fancy charts\", \"It speeds up the calculation process in Excel\"],\n",
" [\"How can you display a statistical summary of a dataframe in Excel?\", \"By selecting 'Excel value' from the drop-down list\", \"By clicking on the preview icon\", \"By right-clicking on the dataframe object\"],\n",
" [\"What is the purpose of the 'Calc_Method' cell?\", \"To specify the aggregation method for the top 5 selling products\", \"To determine the color scheme for the charts\", \"To calculate the month-over-month growth rate\"],\n",
" [\"What are some limitations of using Python in Excel?\", \"Animated charts and external file connections are not supported\", \"It only works on Windows and with Excel Desktop 365 Beta Channel\", \"Only libraries supported by Anaconda can be used\"]\n",
"]\n"
]
}
],
"source": [
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.prompts.chat import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate\n",
"from langchain.chains import LLMChain\n",
"\n",
"#########################################\n",
"OPENAI_API_KEY = \"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\"\n",
"#########################################\n",
"\n",
"\n",
"template = f\"\"\"\n",
"You are a helpful assistant programmed to generate questions based on any text provided. For every chunk of text you receive, you're tasked with designing 5 distinct questions. Each of these questions will be accompanied by 3 possible answers: one correct answer and two incorrect ones. \n",
"\n",
"For clarity and ease of processing, structure your response in a way that emulates a Python list of lists. \n",
"\n",
"Your output should be shaped as follows:\n",
"\n",
"1. An outer list that contains 5 inner lists.\n",
"2. Each inner list represents a set of question and answers, and contains exactly 4 strings in this order:\n",
"- The generated question.\n",
"- The correct answer.\n",
"- The first incorrect answer.\n",
"- The second incorrect answer.\n",
"\n",
"Your output should mirror this structure:\n",
"[\n",
" [\"Generated Question 1\", \"Correct Answer 1\", \"Incorrect Answer 1.1\", \"Incorrect Answer 1.2\"],\n",
" [\"Generated Question 2\", \"Correct Answer 2\", \"Incorrect Answer 2.1\", \"Incorrect Answer 2.2\"],\n",
" ...\n",
"]\n",
"\n",
"It is crucial that you adhere to this format as it's optimized for further Python processing.\n",
"\n",
"\"\"\"\n",
"\n",
"system_message_prompt = SystemMessagePromptTemplate.from_template(template)\n",
"human_message_prompt = HumanMessagePromptTemplate.from_template(\"{text}\")\n",
"chat_prompt = ChatPromptTemplate.from_messages(\n",
" [system_message_prompt, human_message_prompt]\n",
")\n",
"chain = LLMChain(\n",
" llm=ChatOpenAI(openai_api_key=OPENAI_API_KEY),\n",
" prompt=chat_prompt,\n",
")\n",
"quiz_data = chain.run(transcript)\n",
"print(type(quiz_data))\n",
"print(quiz_data)"
]
},
{
"cell_type": "markdown",
"id": "033e47fa",
"metadata": {},
"source": [
"## 4. Transform output"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "b062f162",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'list'>\n",
"[['What is the purpose of the video?', 'To demonstrate how to use Python inside Excel', 'To explain the limitations of using Python in Excel', 'To showcase different data visualization libraries'], ['What is the advantage of using pandas in Python?', 'It makes certain calculations with dates and times easier', 'It allows for the creation of fancy charts', 'It speeds up the calculation process in Excel'], ['How can you display a statistical summary of a dataframe in Excel?', \"By selecting 'Excel value' from the drop-down list\", 'By clicking on the preview icon', 'By right-clicking on the dataframe object'], [\"What is the purpose of the 'Calc_Method' cell?\", 'To specify the aggregation method for the top 5 selling products', 'To determine the color scheme for the charts', 'To calculate the month-over-month growth rate'], ['What are some limitations of using Python in Excel?', 'Animated charts and external file connections are not supported', 'It only works on Windows and with Excel Desktop 365 Beta Channel', 'Only libraries supported by Anaconda can be used']]\n"
]
}
],
"source": [
"import ast\n",
"\n",
"quiz_data_clean = ast.literal_eval(quiz_data)\n",
"print(type(quiz_data_clean))\n",
"print(quiz_data_clean)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
} |