-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocialInf_14.html
More file actions
2917 lines (2862 loc) · 228 KB
/
Copy pathSocialInf_14.html
File metadata and controls
2917 lines (2862 loc) · 228 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
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
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.8.26">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>APIs and Sentiment Text Analysis – Reddit Analysis of Cecil B. Moore Library and Carousel House</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
html { -webkit-text-size-adjust: 100%; }
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js" integrity="sha384-ZvpUoO/+PpLXR1lu4jmpXWu80pZlYUAfxl5NsBMWOEPSjUn/6Z/hRTt8+pR6L4N2" crossorigin="anonymous"></script><script src="site_libs/quarto-nav/quarto-nav.js"></script>
<script src="site_libs/quarto-nav/headroom.min.js"></script>
<script src="site_libs/clipboard/clipboard.min.js"></script>
<script src="site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="site_libs/quarto-search/fuse.min.js"></script>
<script src="site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="./">
<script src="site_libs/quarto-html/quarto.js" type="module"></script>
<script src="site_libs/quarto-html/tabsets/tabsets.js" type="module"></script>
<script src="site_libs/quarto-html/axe/axe-check.js" type="module"></script>
<script src="site_libs/quarto-html/popper.min.js"></script>
<script src="site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="site_libs/quarto-html/anchor.min.js"></script>
<link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="site_libs/quarto-html/quarto-syntax-highlighting-587c61ba64f3a5504c4d52d930310e48.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="site_libs/bootstrap/bootstrap.min.js"></script>
<link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="site_libs/bootstrap/bootstrap-ff63373b1067ca6f91cf1456aa1f00a2.min.css" rel="stylesheet" append-hash="true" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "navbar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "end",
"type": "overlay",
"limit": 50,
"keyboard-shortcut": [
"f",
"/",
"s"
],
"show-item-context": false,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-text-placeholder": "",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit",
"search-label": "Search"
}
}</script>
<script src="https://cdn.jsdelivr.net/npm/requirejs@2.3.6/require.min.js" integrity="sha384-c9c+LnTbwQ3aujuU7ULEPVvgLs+Fn6fJUvIGTsuu1ZcCf11fiEubah0ttpca4ntM sha384-6V1/AdqZRWk1KAlWbKBlGhN7VG4iE/yAZcO6NZPMF8od0vukrvr0tg4qY6NSrItx" crossorigin="anonymous"></script>
<script type="application/javascript">define('jquery', [],function() {return window.jQuery;})</script>
</head>
<body class="floating nav-fixed quarto-light">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="navbar navbar-expand-lg " data-bs-theme="dark">
<div class="navbar-container container-fluid">
<div class="navbar-brand-container mx-auto">
<a class="navbar-brand" href="./index.html">
<span class="navbar-title">Reddit Analysis of Cecil B. Moore Library and Carousel House</span>
</a>
</div>
<div id="quarto-search" class="" title="Search"></div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" role="menu" aria-expanded="false" aria-label="Toggle navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav navbar-nav-scroll me-auto">
<li class="nav-item">
<a class="nav-link" href="./index.html">
<span class="menu-text">Home</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="./map.html">
<span class="menu-text">Background</span></a>
</li>
<li class="nav-item">
<a class="nav-link active" href="./SocialInf_14.html" aria-current="page">
<span class="menu-text">Sentiment Analysis</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="./analysis.html">
<span class="menu-text">Results</span></a>
</li>
</ul>
</div> <!-- /navcollapse -->
<div class="quarto-navbar-tools">
</div>
</div> <!-- /container-fluid -->
</nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">On this page</h2>
<ul>
<li><a href="#reddit-post-data-cleaning" id="toc-reddit-post-data-cleaning" class="nav-link active" data-scroll-target="#reddit-post-data-cleaning">Reddit Post Data Cleaning</a></li>
<li><a href="#chat-gpt-api-for-sentiment-analysis" id="toc-chat-gpt-api-for-sentiment-analysis" class="nav-link" data-scroll-target="#chat-gpt-api-for-sentiment-analysis">CHAT GPT API for Sentiment Analysis</a></li>
<li><a href="#wordcloud-of-most-common-words" id="toc-wordcloud-of-most-common-words" class="nav-link" data-scroll-target="#wordcloud-of-most-common-words">WordCloud of Most Common words</a>
<ul class="collapse">
<li><a href="#api-call-for-reddit-on-carousel-house" id="toc-api-call-for-reddit-on-carousel-house" class="nav-link" data-scroll-target="#api-call-for-reddit-on-carousel-house">API CALL FOR REDDIT ON Carousel House</a></li>
</ul></li>
</ul>
</nav>
</nav>
<div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar zindex-bottom">
</div>
<!-- main -->
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">APIs and Sentiment Text Analysis</h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<p>API CALL FOR REDDIT ON CECIL B. MOORE LIBRARY</p>
<section id="importing-requests-for-reddit" class="level4">
<h4 class="anchored" data-anchor-id="importing-requests-for-reddit">Importing Requests for Reddit</h4>
<div id="071326c5" class="cell" data-execution_count="6">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> requests</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>url <span class="op">=</span> <span class="st">"https://www.reddit.com/r/philadelphia/comments/1j9mr1r/north_philly_residents_reject_proposal_to_build/.json"</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>headers <span class="op">=</span> {</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="st">"User-Agent"</span>: <span class="st">"Mozilla/5.0 (research script by u/yourusername)"</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a>r <span class="op">=</span> requests.get(url, headers<span class="op">=</span>headers)</span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(<span class="st">"Status code:"</span>, r.status_code)</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(<span class="st">"Content-Type:"</span>, r.headers.get(<span class="st">"Content-Type"</span>))</span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(<span class="st">"Preview:"</span>)</span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(r.text[:<span class="dv">500</span>])</span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> r.status_code <span class="op">==</span> <span class="dv">200</span> <span class="kw">and</span> <span class="st">"application/json"</span> <span class="kw">in</span> r.headers.get(<span class="st">"Content-Type"</span>, <span class="st">""</span>):</span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a> data <span class="op">=</span> r.json()</span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a><span class="cf">else</span>:</span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true" tabindex="-1"></a> <span class="cf">raise</span> <span class="pp">ValueError</span>(<span class="st">"Response is not JSON"</span>)</span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a><span class="co"># Extract raw comment objects</span></span>
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true" tabindex="-1"></a>comments_raw <span class="op">=</span> data[<span class="dv">1</span>][<span class="st">"data"</span>][<span class="st">"children"</span>]</span>
<span id="cb1-23"><a href="#cb1-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-24"><a href="#cb1-24" aria-hidden="true" tabindex="-1"></a><span class="co"># Save cleaned comment text as `cecillibrary`</span></span>
<span id="cb1-25"><a href="#cb1-25" aria-hidden="true" tabindex="-1"></a>cecillibrary <span class="op">=</span> [</span>
<span id="cb1-26"><a href="#cb1-26" aria-hidden="true" tabindex="-1"></a> item[<span class="st">"data"</span>].get(<span class="st">"body"</span>, <span class="st">""</span>)</span>
<span id="cb1-27"><a href="#cb1-27" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> item <span class="kw">in</span> comments_raw</span>
<span id="cb1-28"><a href="#cb1-28" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> item[<span class="st">"kind"</span>] <span class="op">==</span> <span class="st">"t1"</span> <span class="kw">and</span> item[<span class="st">"data"</span>].get(<span class="st">"body"</span>) <span class="kw">not</span> <span class="kw">in</span> [<span class="st">"[deleted]"</span>, <span class="st">"[removed]"</span>]</span>
<span id="cb1-29"><a href="#cb1-29" aria-hidden="true" tabindex="-1"></a>]</span>
<span id="cb1-30"><a href="#cb1-30" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-31"><a href="#cb1-31" aria-hidden="true" tabindex="-1"></a><span class="co"># Quick sanity check</span></span>
<span id="cb1-32"><a href="#cb1-32" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(<span class="ss">f"Total comments saved: </span><span class="sc">{</span><span class="bu">len</span>(cecillibrary)<span class="sc">}</span><span class="ss">"</span>)</span>
<span id="cb1-33"><a href="#cb1-33" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(cecillibrary[:<span class="dv">5</span>])</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Status code: 200
Content-Type: application/json; charset=UTF-8
Preview:
[{"kind": "Listing", "data": {"after": null, "dist": 1, "modhash": "", "geo_filter": "", "children": [{"kind": "t3", "data": {"approved_at_utc": null, "subreddit": "philadelphia", "selftext": "", "user_reports": [], "saved": false, "mod_reason_title": null, "gilded": 0, "clicked": false, "title": "North Philly residents reject proposal to build new Cecil B. Moore Library that includes housing: \u2018We resoundingly do not want that\u2019", "link_flair_richtext": [{"e": "text", "t": "Politics"}],
Total comments saved: 20
["Not sure how good faith the argument is but some of the quotes from the article prefer having the library for use as a place for kids to keep out of trouble, and by making the project a full redevelopment for the housing and mix use, they'd be without the library. That doesn't sound as unreasonable as the headline would suggest.", "I grew up around the corner from this library and spent a great deal of time in it. It was in need of expansion in the 90s and I really hope the city builds a great library there as the residents really deserve it.\n\nThe article makes it sound like the residents have no real point and are just trying to block housing, but I think they're right on this one. For me, the library was a safe escape from the streets. It can't be that if it is placed within PHA housing -- and I mean that in the nicest way possible.\n\nHaving grown up in N. Philly it isn't a section of the city where there is a lack of land for affordable housing development. I was there for Street's Neighborhood Transformation Initiative where they bulldozed scores of vacant houses to create massive lots. Which was a welcome change as it made walking down many streets safer... Building on lots like those makes more sense to me than this proposal.\n\nThe city needs to increase the options available for kids to have positive places to seek refuge and the city needs to really invest in ways that show black kids, especially, that we're more than just set pieces to entertain others. Meaning, the city can invest in more than the REC center or sports in neighborhoods like N. Philly.\n\nJust my $.02", "Yeah just fix the HVAC and get the library to be re-opened. The residents want their library back. The housing additions feel like a last minute experiment.\n\nWe need more housing but I don't think this proposal was the right approach", 'Why don\'t they just fix the library and put the housing somewhere nearby.\n\nI don\'t necessarily get the need to tie the 2 things together. I\'m not saying it\'s a bad idea but I guess I need the "why" better explained to me.', "After reading the article, the new library with housing was just another option brought up in the meeting by their council representative that residents didn't agree with. The options are:\n\n1. Rebuild to fix the issues with modest updates.\n2. New library with added amenities.\n3. New library with added amenities along with housing above the library similar to this recently build [Brooklyn Library](https://static01.nyt.com/images/2025/03/09/multimedia/24Renters-minier-02-bgwc/24Renters-minier-02-bgwc-superJumbo.jpg?quality=75&amp;auto=webp)\n\nI tend to Agee with the residents that while affordable housing is nice, not necessary to be added to the library since that adds on a lot more process and time for completion of the project. They just want a nice library."]</code></pre>
</div>
</div>
<div id="731b7d3a" class="cell" data-execution_count="7">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> collections <span class="im">import</span> Counter</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>kinds <span class="op">=</span> Counter(item[<span class="st">"kind"</span>] <span class="cf">for</span> item <span class="kw">in</span> comments_raw)</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(kinds)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Counter({'t1': 20})</code></pre>
</div>
</div>
</section>
<section id="breaking-down-reddit-structure" class="level4">
<h4 class="anchored" data-anchor-id="breaking-down-reddit-structure">Breaking Down Reddit Structure</h4>
<div id="8f8e579a" class="cell" data-execution_count="8">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> pandas <span class="im">as</span> pd</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> extract_comments(children, depth<span class="op">=</span><span class="dv">0</span>, parent_id<span class="op">=</span><span class="va">None</span>):</span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> rows <span class="op">=</span> []</span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> item <span class="kw">in</span> children:</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> kind <span class="op">=</span> item.get(<span class="st">"kind"</span>)</span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> data <span class="op">=</span> item.get(<span class="st">"data"</span>, {})</span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> <span class="co"># Skip "more" placeholder objects</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> kind <span class="op">==</span> <span class="st">"more"</span>:</span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a> <span class="cf">continue</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a> <span class="co"># Add this comment</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a> rows.append({</span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a> <span class="st">"id"</span>: data.get(<span class="st">"id"</span>),</span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a> <span class="st">"parent_id"</span>: parent_id,</span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true" tabindex="-1"></a> <span class="st">"author"</span>: data.get(<span class="st">"author"</span>),</span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a> <span class="st">"body"</span>: data.get(<span class="st">"body"</span>),</span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true" tabindex="-1"></a> <span class="st">"score"</span>: data.get(<span class="st">"score"</span>),</span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true" tabindex="-1"></a> <span class="st">"created_utc"</span>: data.get(<span class="st">"created_utc"</span>),</span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true" tabindex="-1"></a> <span class="st">"depth"</span>: depth</span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true" tabindex="-1"></a> })</span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-25"><a href="#cb5-25" aria-hidden="true" tabindex="-1"></a> <span class="co"># --- RECURSE INTO REPLIES ---</span></span>
<span id="cb5-26"><a href="#cb5-26" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> data.get(<span class="st">"replies"</span>) <span class="kw">and</span> <span class="bu">isinstance</span>(data[<span class="st">"replies"</span>], <span class="bu">dict</span>):</span>
<span id="cb5-27"><a href="#cb5-27" aria-hidden="true" tabindex="-1"></a> replies <span class="op">=</span> data[<span class="st">"replies"</span>][<span class="st">"data"</span>][<span class="st">"children"</span>]</span>
<span id="cb5-28"><a href="#cb5-28" aria-hidden="true" tabindex="-1"></a> rows.extend(extract_comments(replies, depth <span class="op">+</span> <span class="dv">1</span>, data.get(<span class="st">"id"</span>)))</span>
<span id="cb5-29"><a href="#cb5-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-30"><a href="#cb5-30" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> rows</span>
<span id="cb5-31"><a href="#cb5-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-32"><a href="#cb5-32" aria-hidden="true" tabindex="-1"></a>comments_root <span class="op">=</span> data[<span class="dv">1</span>][<span class="st">"data"</span>][<span class="st">"children"</span>]</span>
<span id="cb5-33"><a href="#cb5-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-34"><a href="#cb5-34" aria-hidden="true" tabindex="-1"></a>cecillibrary <span class="op">=</span> pd.DataFrame(</span>
<span id="cb5-35"><a href="#cb5-35" aria-hidden="true" tabindex="-1"></a> extract_comments(comments_root)</span>
<span id="cb5-36"><a href="#cb5-36" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb5-37"><a href="#cb5-37" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-38"><a href="#cb5-38" aria-hidden="true" tabindex="-1"></a><span class="co"># Clean removed / deleted comments</span></span>
<span id="cb5-39"><a href="#cb5-39" aria-hidden="true" tabindex="-1"></a>cecillibrary <span class="op">=</span> cecillibrary[</span>
<span id="cb5-40"><a href="#cb5-40" aria-hidden="true" tabindex="-1"></a> cecillibrary[<span class="st">"body"</span>].notna() <span class="op">&</span></span>
<span id="cb5-41"><a href="#cb5-41" aria-hidden="true" tabindex="-1"></a> <span class="op">~</span>cecillibrary[<span class="st">"body"</span>].isin([<span class="st">"[deleted]"</span>, <span class="st">"[removed]"</span>])</span>
<span id="cb5-42"><a href="#cb5-42" aria-hidden="true" tabindex="-1"></a>]</span>
<span id="cb5-43"><a href="#cb5-43" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-44"><a href="#cb5-44" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(<span class="bu">len</span>(cecillibrary))</span>
<span id="cb5-45"><a href="#cb5-45" aria-hidden="true" tabindex="-1"></a>cecillibrary.head()</span>
<span id="cb5-46"><a href="#cb5-46" aria-hidden="true" tabindex="-1"></a><span class="bu">len</span>(cecillibrary)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>67</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="8">
<pre><code>67</code></pre>
</div>
</div>
</section>
<section id="ensuring-replies-are-counted" class="level4">
<h4 class="anchored" data-anchor-id="ensuring-replies-are-counted">Ensuring Replies are counted</h4>
<div id="29383741" class="cell" data-execution_count="9">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="bu">len</span>(cecillibrary)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
<div class="cell-output cell-output-display" data-execution_count="9">
<pre><code>67</code></pre>
</div>
</div>
</section>
<section id="reddit-post-data-cleaning" class="level2">
<h2 class="anchored" data-anchor-id="reddit-post-data-cleaning">Reddit Post Data Cleaning</h2>
<div id="415f2a2f" class="cell" data-execution_count="10">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Remove lowercase,line breaks, and unwanted spaces</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a>cecillibrary[<span class="st">"clean_body"</span>] <span class="op">=</span> (</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> cecillibrary[<span class="st">"body"</span>]</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> .fillna(<span class="st">""</span>)</span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a> .<span class="bu">str</span>.lower()</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a> .<span class="bu">str</span>.replace(<span class="st">"</span><span class="ch">\n</span><span class="st">"</span>, <span class="st">" "</span>, regex<span class="op">=</span><span class="va">False</span>)</span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a> .<span class="bu">str</span>.strip()</span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
<div id="eea91a53" class="cell" data-execution_count="11">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Remove deleted comments</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>cecillibrary <span class="op">=</span> cecillibrary[<span class="op">~</span>cecillibrary[<span class="st">"clean_body"</span>].isin([<span class="st">"[deleted]"</span>, <span class="st">"[removed]"</span>])]</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
<div id="79346139" class="cell" data-execution_count="12">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Remove Urls</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> re</span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a>cecillibrary[<span class="st">"clean_body"</span>] <span class="op">=</span> cecillibrary[<span class="st">"clean_body"</span>].<span class="bu">apply</span>(</span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">lambda</span> x: re.sub(<span class="vs">r"http</span><span class="dv">\S</span><span class="op">+</span><span class="cf">|</span><span class="vs">www</span><span class="ch">\.</span><span class="dv">\S</span><span class="op">+</span><span class="vs">"</span>, <span class="st">""</span>, x)</span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
<div id="8591139e" class="cell" data-execution_count="13">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Remove punctuation</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>cecillibrary[<span class="st">"clean_body"</span>] <span class="op">=</span> cecillibrary[<span class="st">"clean_body"</span>].<span class="bu">str</span>.replace(<span class="vs">r"</span><span class="pp">[^</span><span class="dv">\w\s</span><span class="pp">]</span><span class="vs">"</span>, <span class="st">""</span>, regex<span class="op">=</span><span class="va">True</span>)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
<div id="24f02d0c" class="cell" data-execution_count="14">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Remove extra spaces</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a>cecillibrary[<span class="st">"clean_body"</span>] <span class="op">=</span> cecillibrary[<span class="st">"clean_body"</span>].<span class="bu">str</span>.replace(<span class="vs">r"</span><span class="dv">\s</span><span class="op">+</span><span class="vs">"</span>, <span class="st">" "</span>, regex<span class="op">=</span><span class="va">True</span>)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
</section>
<section id="chat-gpt-api-for-sentiment-analysis" class="level1">
<h1>CHAT GPT API for Sentiment Analysis</h1>
<section id="importing-chatgpt-api" class="level4">
<h4 class="anchored" data-anchor-id="importing-chatgpt-api">Importing ChatGPT API</h4>
<div id="1966c881" class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> os</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a>os.environ[<span class="st">"OPENAI_API_KEY"</span>] <span class="op">=</span> <span class="st">""</span> <span class="op">\</span></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a><span class="co">##Key removed for privacy</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a></span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
</section>
<section id="sentiment-prompt" class="level4">
<h4 class="anchored" data-anchor-id="sentiment-prompt">Sentiment Prompt</h4>
</section>
<section id="batch-size-of-sentiment" class="level4">
<h4 class="anchored" data-anchor-id="batch-size-of-sentiment">Batch Size of Sentiment</h4>
<div id="cb8e4b1d" class="cell" data-execution_count="16">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> openai <span class="im">import</span> OpenAI</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> json</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a>client <span class="op">=</span> OpenAI()</span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> batch_sentiment_with_scores(comments):</span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a> prompt <span class="op">=</span> <span class="st">"""</span></span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a><span class="st">You are a sentiment analysis model.</span></span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-10"><a href="#cb16-10" aria-hidden="true" tabindex="-1"></a><span class="st">For EACH comment, output BOTH:</span></span>
<span id="cb16-11"><a href="#cb16-11" aria-hidden="true" tabindex="-1"></a><span class="st">- "sentiment": one of ["positive", "neutral", "negative"]</span></span>
<span id="cb16-12"><a href="#cb16-12" aria-hidden="true" tabindex="-1"></a><span class="st">- "score": a float from -1 to +1 representing sentiment intensity</span></span>
<span id="cb16-13"><a href="#cb16-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-14"><a href="#cb16-14" aria-hidden="true" tabindex="-1"></a><span class="st">Return ONLY a JSON object in this EXACT format:</span></span>
<span id="cb16-15"><a href="#cb16-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-16"><a href="#cb16-16" aria-hidden="true" tabindex="-1"></a><span class="st">{</span></span>
<span id="cb16-17"><a href="#cb16-17" aria-hidden="true" tabindex="-1"></a><span class="st"> "results": [</span></span>
<span id="cb16-18"><a href="#cb16-18" aria-hidden="true" tabindex="-1"></a><span class="st"> {"index": 0, "sentiment": "positive", "score": 0.72},</span></span>
<span id="cb16-19"><a href="#cb16-19" aria-hidden="true" tabindex="-1"></a><span class="st"> {"index": 1, "sentiment": "negative", "score": -0.44}</span></span>
<span id="cb16-20"><a href="#cb16-20" aria-hidden="true" tabindex="-1"></a><span class="st"> ]</span></span>
<span id="cb16-21"><a href="#cb16-21" aria-hidden="true" tabindex="-1"></a><span class="st">}</span></span>
<span id="cb16-22"><a href="#cb16-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-23"><a href="#cb16-23" aria-hidden="true" tabindex="-1"></a><span class="st">Do NOT include explanations, summaries, markdown, or anything else.</span></span>
<span id="cb16-24"><a href="#cb16-24" aria-hidden="true" tabindex="-1"></a><span class="st">ONLY return valid JSON.</span></span>
<span id="cb16-25"><a href="#cb16-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-26"><a href="#cb16-26" aria-hidden="true" tabindex="-1"></a><span class="st">Here are the comments:</span></span>
<span id="cb16-27"><a href="#cb16-27" aria-hidden="true" tabindex="-1"></a><span class="st">"""</span></span>
<span id="cb16-28"><a href="#cb16-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-29"><a href="#cb16-29" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> i, text <span class="kw">in</span> <span class="bu">enumerate</span>(comments):</span>
<span id="cb16-30"><a href="#cb16-30" aria-hidden="true" tabindex="-1"></a> prompt <span class="op">+=</span> <span class="ss">f"</span><span class="ch">\n</span><span class="ss">Comment </span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">: </span><span class="sc">{</span>text<span class="sc">}</span><span class="ss">"</span></span>
<span id="cb16-31"><a href="#cb16-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-32"><a href="#cb16-32" aria-hidden="true" tabindex="-1"></a> response <span class="op">=</span> client.chat.completions.create(</span>
<span id="cb16-33"><a href="#cb16-33" aria-hidden="true" tabindex="-1"></a> model<span class="op">=</span><span class="st">"gpt-4o-mini"</span>,</span>
<span id="cb16-34"><a href="#cb16-34" aria-hidden="true" tabindex="-1"></a> response_format<span class="op">=</span>{<span class="st">"type"</span>: <span class="st">"json_object"</span>}, <span class="co"># 🔥 forces perfect JSON</span></span>
<span id="cb16-35"><a href="#cb16-35" aria-hidden="true" tabindex="-1"></a> messages<span class="op">=</span>[{<span class="st">"role"</span>: <span class="st">"user"</span>, <span class="st">"content"</span>: prompt}],</span>
<span id="cb16-36"><a href="#cb16-36" aria-hidden="true" tabindex="-1"></a> max_tokens<span class="op">=</span><span class="dv">600</span></span>
<span id="cb16-37"><a href="#cb16-37" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb16-38"><a href="#cb16-38" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-39"><a href="#cb16-39" aria-hidden="true" tabindex="-1"></a> data <span class="op">=</span> json.loads(response.choices[<span class="dv">0</span>].message.content)</span>
<span id="cb16-40"><a href="#cb16-40" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> data[<span class="st">"results"</span>]</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
<div id="91ba5b45" class="cell" data-execution_count="17">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>batch_size <span class="op">=</span> <span class="dv">20</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>labels <span class="op">=</span> []</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a>scores <span class="op">=</span> []</span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a>texts <span class="op">=</span> cecillibrary[<span class="st">"clean_body"</span>].tolist()</span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">0</span>, <span class="bu">len</span>(texts), batch_size):</span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true" tabindex="-1"></a> chunk <span class="op">=</span> texts[i:i<span class="op">+</span>batch_size]</span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true" tabindex="-1"></a> results <span class="op">=</span> batch_sentiment_with_scores(chunk)</span>
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> r <span class="kw">in</span> results:</span>
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true" tabindex="-1"></a> labels.append(r[<span class="st">"sentiment"</span>])</span>
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true" tabindex="-1"></a> scores.append(r[<span class="st">"score"</span>])</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
<div id="2c86505f" class="cell" data-execution_count="18">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>cecillibrary[<span class="st">"sentiment_label"</span>] <span class="op">=</span> labels</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>cecillibrary[<span class="st">"sentiment_score"</span>] <span class="op">=</span> scores</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
<div id="ec1f53f2" class="cell" data-execution_count="19">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>pd.set_option(<span class="st">"display.max_rows"</span>, <span class="va">None</span>)</span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>cecillibrary.head()</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
<div class="cell-output cell-output-display" data-execution_count="19">
<div>
<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">id</th>
<th data-quarto-table-cell-role="th">parent_id</th>
<th data-quarto-table-cell-role="th">author</th>
<th data-quarto-table-cell-role="th">body</th>
<th data-quarto-table-cell-role="th">score</th>
<th data-quarto-table-cell-role="th">created_utc</th>
<th data-quarto-table-cell-role="th">depth</th>
<th data-quarto-table-cell-role="th">clean_body</th>
<th data-quarto-table-cell-role="th">sentiment_label</th>
<th data-quarto-table-cell-role="th">sentiment_score</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>mhegcqo</td>
<td>None</td>
<td>inherendo</td>
<td>Not sure how good faith the argument is but so...</td>
<td>415</td>
<td>1.741794e+09</td>
<td>0</td>
<td>not sure how good faith the argument is but so...</td>
<td>neutral</td>
<td>0.0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>mhgll0i</td>
<td>mhegcqo</td>
<td>CabbageSoupNow</td>
<td>They are completely renovating the library In ...</td>
<td>71</td>
<td>1.741816e+09</td>
<td>1</td>
<td>they are completely renovating the library in ...</td>
<td>negative</td>
<td>-0.5</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>mheuxw8</td>
<td>mhegcqo</td>
<td>lappy-486</td>
<td>Replacing the entire building could take 3-5 y...</td>
<td>50</td>
<td>1.741798e+09</td>
<td>1</td>
<td>replacing the entire building could take 35 ye...</td>
<td>negative</td>
<td>-0.6</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">4</th>
<td>mheisbj</td>
<td>mhegcqo</td>
<td>starshiprarity</td>
<td>There's also a rec center two blocks away. If ...</td>
<td>46</td>
<td>1.741795e+09</td>
<td>1</td>
<td>theres also a rec center two blocks away if la...</td>
<td>neutral</td>
<td>0.0</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">5</th>
<td>mhel5r6</td>
<td>mheisbj</td>
<td>John_EightThirtyTwo</td>
<td>Rec centers are awesome but don't replace libr...</td>
<td>184</td>
<td>1.741796e+09</td>
<td>2</td>
<td>rec centers are awesome but dont replace libra...</td>
<td>neutral</td>
<td>0.0</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div id="e1b55f46" class="cell" data-execution_count="20">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="co">#### Distribution of Sentiment Scores</span></span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
<div id="e6e32d09" class="cell" data-execution_count="21">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> matplotlib.pyplot <span class="im">as</span> plt</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a>plt.figure(figsize<span class="op">=</span>(<span class="dv">10</span>,<span class="dv">6</span>))</span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a>cecillibrary[<span class="st">"sentiment_score"</span>].hist(bins<span class="op">=</span><span class="dv">20</span>, color<span class="op">=</span><span class="st">"steelblue"</span>, edgecolor<span class="op">=</span><span class="st">"black"</span>)</span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a>plt.title(<span class="st">"Distribution of Sentiment Scores"</span>)</span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a>plt.xlabel(<span class="st">"Sentiment Score (-1 = Negative, +1 = Positive)"</span>)</span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a>plt.ylabel(<span class="st">"Number of Comments"</span>)</span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a>plt.grid(alpha<span class="op">=</span><span class="dv">0</span>)</span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a></span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="SocialInf_14_files/figure-html/cell-17-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="sentiment-score-by-comment-depth" class="level4">
<h4 class="anchored" data-anchor-id="sentiment-score-by-comment-depth">Sentiment Score by Comment Depth</h4>
<div id="1651d671" class="cell" data-execution_count="22">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> seaborn <span class="im">as</span> sns</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a>plt.figure(figsize<span class="op">=</span>(<span class="dv">10</span>,<span class="dv">6</span>))</span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a>sns.boxplot(data<span class="op">=</span>cecillibrary, x<span class="op">=</span><span class="st">"depth"</span>, y<span class="op">=</span><span class="st">"sentiment_score"</span>, color<span class="op">=</span><span class="st">"lightgray"</span>)</span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a>plt.title(<span class="st">"Sentiment Score by Comment Depth"</span>)</span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a>plt.xlabel(<span class="st">"Depth (0 = Top-Level, Higher = Replies)"</span>)</span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a>plt.ylabel(<span class="st">"Sentiment Score"</span>)</span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true" tabindex="-1"></a>plt.grid(alpha<span class="op">=</span><span class="dv">0</span>)</span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true" tabindex="-1"></a></span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="SocialInf_14_files/figure-html/cell-18-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="average-sentiment-by-depth" class="level4">
<h4 class="anchored" data-anchor-id="average-sentiment-by-depth">Average Sentiment by Depth</h4>
<div id="00ac3569" class="cell" data-execution_count="23">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>avg_depth <span class="op">=</span> cecillibrary.groupby(<span class="st">"depth"</span>)[<span class="st">"sentiment_score"</span>].mean()</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a>plt.figure(figsize<span class="op">=</span>(<span class="dv">10</span>,<span class="dv">6</span>))</span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a>avg_depth.plot(kind<span class="op">=</span><span class="st">"line"</span>, marker<span class="op">=</span><span class="st">"o"</span>, color<span class="op">=</span><span class="st">"darkred"</span>)</span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a>plt.title(<span class="st">"Average Sentiment by Depth"</span>)</span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a>plt.xlabel(<span class="st">"Depth"</span>)</span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true" tabindex="-1"></a>plt.ylabel(<span class="st">"Mean Sentiment Score"</span>)</span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true" tabindex="-1"></a>plt.grid(alpha<span class="op">=</span><span class="dv">0</span>)</span>
<span id="cb23-9"><a href="#cb23-9" aria-hidden="true" tabindex="-1"></a></span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="SocialInf_14_files/figure-html/cell-19-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="most-positive-comments" class="level4">
<h4 class="anchored" data-anchor-id="most-positive-comments">10 Most Positive Comments</h4>
<div id="49b9a015" class="cell" data-execution_count="24">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>cecillibrary.nlargest(<span class="dv">10</span>, <span class="st">"sentiment_score"</span>)[[<span class="st">"body"</span>, <span class="st">"sentiment_score"</span>]]</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
<div class="cell-output cell-output-display" data-execution_count="24">
<div>
<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">body</th>
<th data-quarto-table-cell-role="th">sentiment_score</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">21</th>
<td>I grew up around the corner from this library ...</td>
<td>0.80</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">38</th>
<td>Thanks for sharing this story. It's good to se...</td>
<td>0.80</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">6</th>
<td>Yup. During the renovations of my town’s libr...</td>
<td>0.70</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">64</th>
<td>Libraries offer lots of things that rec center...</td>
<td>0.55</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>Not sure how good faith the argument is but so...</td>
<td>0.00</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">4</th>
<td>There's also a rec center two blocks away. If ...</td>
<td>0.00</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">5</th>
<td>Rec centers are awesome but don't replace libr...</td>
<td>0.00</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">10</th>
<td>I'm not seeing an objection in the article tha...</td>
<td>0.00</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">12</th>
<td>I agree. The article does't say anything abou...</td>
<td>0.00</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">14</th>
<td>I'll bite. How does housing improve the librar...</td>
<td>0.00</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div id="f8f5565b" class="cell" data-execution_count="25">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> re</span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a>cecillibrary[<span class="st">"body"</span>] <span class="op">=</span> (</span>
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a> cecillibrary[<span class="st">"body"</span>]</span>
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a> .astype(<span class="bu">str</span>)</span>
<span id="cb25-6"><a href="#cb25-6" aria-hidden="true" tabindex="-1"></a> .<span class="bu">str</span>.replace(<span class="vs">r"</span><span class="dv">\s</span><span class="op">+</span><span class="vs">"</span>, <span class="st">" "</span>, regex<span class="op">=</span><span class="va">True</span>) <span class="co"># collapse whitespace</span></span>
<span id="cb25-7"><a href="#cb25-7" aria-hidden="true" tabindex="-1"></a> .<span class="bu">str</span>.replace(<span class="vs">r"</span><span class="ch">\n</span><span class="vs">"</span>, <span class="st">" "</span>, regex<span class="op">=</span><span class="va">True</span>) <span class="co"># remove line breaks</span></span>
<span id="cb25-8"><a href="#cb25-8" aria-hidden="true" tabindex="-1"></a> .<span class="bu">str</span>.replace(<span class="vs">r"</span><span class="ch">\r</span><span class="vs">"</span>, <span class="st">" "</span>, regex<span class="op">=</span><span class="va">True</span>)</span>
<span id="cb25-9"><a href="#cb25-9" aria-hidden="true" tabindex="-1"></a> .<span class="bu">str</span>.strip()</span>
<span id="cb25-10"><a href="#cb25-10" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
<div id="8b130a39" class="cell" data-execution_count="26">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> pandas <span class="im">as</span> pd</span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> textwrap <span class="im">import</span> wrap</span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Top 10 comments</span></span>
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a>t10 <span class="op">=</span> cecillibrary.nlargest(<span class="dv">10</span>, <span class="st">"sentiment_score"</span>)[[<span class="st">"body"</span>, <span class="st">"sentiment_score"</span>]]</span>
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-7"><a href="#cb26-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Wrap text</span></span>
<span id="cb26-8"><a href="#cb26-8" aria-hidden="true" tabindex="-1"></a>t10[<span class="st">"body"</span>] <span class="op">=</span> t10[<span class="st">"body"</span>].<span class="bu">apply</span>(<span class="kw">lambda</span> x: <span class="st">"<br>"</span>.join(wrap(x, width<span class="op">=</span><span class="dv">80</span>)))</span>
<span id="cb26-9"><a href="#cb26-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-10"><a href="#cb26-10" aria-hidden="true" tabindex="-1"></a><span class="co"># Styled table</span></span>
<span id="cb26-11"><a href="#cb26-11" aria-hidden="true" tabindex="-1"></a>styled <span class="op">=</span> (</span>
<span id="cb26-12"><a href="#cb26-12" aria-hidden="true" tabindex="-1"></a> t10.style</span>
<span id="cb26-13"><a href="#cb26-13" aria-hidden="true" tabindex="-1"></a> .set_table_styles([{<span class="st">"selector"</span>:<span class="st">"th"</span>,<span class="st">"props"</span>:[(<span class="st">"font-size"</span>,<span class="st">"12pt"</span>),(<span class="st">"text-align"</span>,<span class="st">"center"</span>)]}])</span>
<span id="cb26-14"><a href="#cb26-14" aria-hidden="true" tabindex="-1"></a> .set_properties(subset<span class="op">=</span>[<span class="st">"body"</span>], <span class="op">**</span>{<span class="st">"font-size"</span>:<span class="st">"11pt"</span>, <span class="st">"text-align"</span>:<span class="st">"left"</span>})</span>
<span id="cb26-15"><a href="#cb26-15" aria-hidden="true" tabindex="-1"></a> .set_properties(subset<span class="op">=</span>[<span class="st">"sentiment_score"</span>], <span class="op">**</span>{<span class="st">"text-align"</span>:<span class="st">"center"</span>})</span>
<span id="cb26-16"><a href="#cb26-16" aria-hidden="true" tabindex="-1"></a> .background_gradient(cmap<span class="op">=</span><span class="st">"Blues"</span>, subset<span class="op">=</span>[<span class="st">"sentiment_score"</span>])</span>
<span id="cb26-17"><a href="#cb26-17" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb26-18"><a href="#cb26-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-19"><a href="#cb26-19" aria-hidden="true" tabindex="-1"></a></span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
</div>
<div id="ab33fd13" class="cell" data-execution_count="27">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> pandas <span class="im">as</span> pd</span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> textwrap <span class="im">import</span> wrap</span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a>cecillibrary[<span class="st">"body"</span>] <span class="op">=</span> (</span>
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true" tabindex="-1"></a> cecillibrary[<span class="st">"body"</span>]</span>
<span id="cb27-6"><a href="#cb27-6" aria-hidden="true" tabindex="-1"></a> .astype(<span class="bu">str</span>)</span>
<span id="cb27-7"><a href="#cb27-7" aria-hidden="true" tabindex="-1"></a> .<span class="bu">str</span>.replace(<span class="vs">r"</span><span class="dv">\s</span><span class="op">+</span><span class="vs">"</span>, <span class="st">" "</span>, regex<span class="op">=</span><span class="va">True</span>)</span>
<span id="cb27-8"><a href="#cb27-8" aria-hidden="true" tabindex="-1"></a> .<span class="bu">str</span>.strip()</span>
<span id="cb27-9"><a href="#cb27-9" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb27-10"><a href="#cb27-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-11"><a href="#cb27-11" aria-hidden="true" tabindex="-1"></a>t10 <span class="op">=</span> cecillibrary.nlargest(<span class="dv">10</span>, <span class="st">"sentiment_score"</span>)[[<span class="st">"body"</span>, <span class="st">"sentiment_score"</span>]]</span>
<span id="cb27-12"><a href="#cb27-12" aria-hidden="true" tabindex="-1"></a>t10.columns <span class="op">=</span> [<span class="st">"Comment"</span>, <span class="st">"Sentiment Score"</span>]</span>
<span id="cb27-13"><a href="#cb27-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-14"><a href="#cb27-14" aria-hidden="true" tabindex="-1"></a>t10[<span class="st">"Comment"</span>] <span class="op">=</span> t10[<span class="st">"Comment"</span>].<span class="bu">apply</span>(<span class="kw">lambda</span> x: <span class="st">"<br>"</span>.join(wrap(x, width<span class="op">=</span><span class="dv">80</span>)))</span>
<span id="cb27-15"><a href="#cb27-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-16"><a href="#cb27-16" aria-hidden="true" tabindex="-1"></a>styled <span class="op">=</span> (</span>
<span id="cb27-17"><a href="#cb27-17" aria-hidden="true" tabindex="-1"></a> t10.style</span>
<span id="cb27-18"><a href="#cb27-18" aria-hidden="true" tabindex="-1"></a> .hide(axis<span class="op">=</span><span class="st">"index"</span>)</span>
<span id="cb27-19"><a href="#cb27-19" aria-hidden="true" tabindex="-1"></a> .set_table_styles([</span>
<span id="cb27-20"><a href="#cb27-20" aria-hidden="true" tabindex="-1"></a> {<span class="st">"selector"</span>: <span class="st">"th"</span>, <span class="st">"props"</span>: [(<span class="st">"font-size"</span>,<span class="st">"12pt"</span>), (<span class="st">"text-align"</span>,<span class="st">"center"</span>)]},</span>
<span id="cb27-21"><a href="#cb27-21" aria-hidden="true" tabindex="-1"></a> {<span class="st">"selector"</span>: <span class="st">"tr"</span>, <span class="st">"props"</span>: [(<span class="st">"border-bottom"</span>, <span class="st">"1px solid #ddd"</span>)]},</span>
<span id="cb27-22"><a href="#cb27-22" aria-hidden="true" tabindex="-1"></a> ])</span>
<span id="cb27-23"><a href="#cb27-23" aria-hidden="true" tabindex="-1"></a> .set_properties(subset<span class="op">=</span>[<span class="st">"Comment"</span>], <span class="op">**</span>{<span class="st">"font-size"</span>:<span class="st">"11pt"</span>, <span class="st">"text-align"</span>:<span class="st">"left"</span>})</span>
<span id="cb27-24"><a href="#cb27-24" aria-hidden="true" tabindex="-1"></a> .set_properties(subset<span class="op">=</span>[<span class="st">"Sentiment Score"</span>], <span class="op">**</span>{<span class="st">"text-align"</span>:<span class="st">"center"</span>})</span>
<span id="cb27-25"><a href="#cb27-25" aria-hidden="true" tabindex="-1"></a> .background_gradient(cmap<span class="op">=</span><span class="st">"Blues"</span>, subset<span class="op">=</span>[<span class="st">"Sentiment Score"</span>])</span>
<span id="cb27-26"><a href="#cb27-26" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb27-27"><a href="#cb27-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-28"><a href="#cb27-28" aria-hidden="true" tabindex="-1"></a>styled_html <span class="op">=</span> styled.to_html()</span>
<span id="cb27-29"><a href="#cb27-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-30"><a href="#cb27-30" aria-hidden="true" tabindex="-1"></a>border_css <span class="op">=</span> <span class="st">"""</span></span>
<span id="cb27-31"><a href="#cb27-31" aria-hidden="true" tabindex="-1"></a><span class="st"><style></span></span>
<span id="cb27-32"><a href="#cb27-32" aria-hidden="true" tabindex="-1"></a><span class="st">table, th, td {</span></span>
<span id="cb27-33"><a href="#cb27-33" aria-hidden="true" tabindex="-1"></a><span class="st"> border: 1px solid #ccc !important;</span></span>
<span id="cb27-34"><a href="#cb27-34" aria-hidden="true" tabindex="-1"></a><span class="st"> border-collapse: collapse !important;</span></span>
<span id="cb27-35"><a href="#cb27-35" aria-hidden="true" tabindex="-1"></a><span class="st"> padding: 6px !important;</span></span>
<span id="cb27-36"><a href="#cb27-36" aria-hidden="true" tabindex="-1"></a><span class="st">}</span></span>
<span id="cb27-37"><a href="#cb27-37" aria-hidden="true" tabindex="-1"></a><span class="st">tr {</span></span>
<span id="cb27-38"><a href="#cb27-38" aria-hidden="true" tabindex="-1"></a><span class="st"> border-bottom: 1px solid #ddd;</span></span>
<span id="cb27-39"><a href="#cb27-39" aria-hidden="true" tabindex="-1"></a><span class="st">}</span></span>
<span id="cb27-40"><a href="#cb27-40" aria-hidden="true" tabindex="-1"></a><span class="st"></style></span></span>
<span id="cb27-41"><a href="#cb27-41" aria-hidden="true" tabindex="-1"></a><span class="st">"""</span></span>
<span id="cb27-42"><a href="#cb27-42" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-43"><a href="#cb27-43" aria-hidden="true" tabindex="-1"></a><span class="cf">with</span> <span class="bu">open</span>(<span class="st">"top10_sentiment.html"</span>, <span class="st">"w"</span>) <span class="im">as</span> f:</span>
<span id="cb27-44"><a href="#cb27-44" aria-hidden="true" tabindex="-1"></a> f.write(border_css <span class="op">+</span> styled_html)</span>
<span id="cb27-45"><a href="#cb27-45" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-46"><a href="#cb27-46" aria-hidden="true" tabindex="-1"></a>styled</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
<div class="cell-output cell-output-display" data-execution_count="27">
<style type="text/css">
#T_a818a th {
font-size: 12pt;
text-align: center;
}
#T_a818a tr {
border-bottom: 1px solid #ddd;
}
#T_a818a_row0_col0, #T_a818a_row1_col0, #T_a818a_row2_col0, #T_a818a_row3_col0, #T_a818a_row4_col0, #T_a818a_row5_col0, #T_a818a_row6_col0, #T_a818a_row7_col0, #T_a818a_row8_col0, #T_a818a_row9_col0 {
font-size: 11pt;
text-align: left;
}
#T_a818a_row0_col1, #T_a818a_row1_col1 {
text-align: center;
background-color: #08306b;
color: #f1f1f1;
}
#T_a818a_row2_col1 {
text-align: center;
background-color: #08519c;
color: #f1f1f1;
}
#T_a818a_row3_col1 {
text-align: center;
background-color: #3181bd;
color: #f1f1f1;
}
#T_a818a_row4_col1, #T_a818a_row5_col1, #T_a818a_row6_col1, #T_a818a_row7_col1, #T_a818a_row8_col1, #T_a818a_row9_col1 {
text-align: center;
background-color: #f7fbff;
color: #000000;
}
</style>
<table id="T_a818a" class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th id="T_a818a_level0_col0" class="col_heading level0 col0" data-quarto-table-cell-role="th">Comment</th>
<th id="T_a818a_level0_col1" class="col_heading level0 col1" data-quarto-table-cell-role="th">Sentiment Score</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td id="T_a818a_row0_col0" class="data row0 col0">I grew up around the corner from this library and spent a great deal of time in<br>
it. It was in need of expansion in the 90s and I really hope the city builds a<br>
great library there as the residents really deserve it. The article makes it<br>
sound like the residents have no real point and are just trying to block<br>
housing, but I think they're right on this one. For me, the library was a safe<br>
escape from the streets. It can't be that if it is placed within PHA housing --<br>
and I mean that in the nicest way possible. Having grown up in N. Philly it<br>
isn't a section of the city where there is a lack of land for affordable housing<br>
development. I was there for Street's Neighborhood Transformation Initiative<br>
where they bulldozed scores of vacant houses to create massive lots. Which was a<br>
welcome change as it made walking down many streets safer... Building on lots<br>
like those makes more sense to me than this proposal. The city needs to increase<br>
the options available for kids to have positive places to seek refuge and the<br>
city needs to really invest in ways that show black kids, especially, that we're<br>
more than just set pieces to entertain others. Meaning, the city can invest in<br>
more than the REC center or sports in neighborhoods like N. Philly. Just my $.02</td>
<td id="T_a818a_row0_col1" class="data row0 col1">0.800000</td>
</tr>
<tr class="even">
<td id="T_a818a_row1_col0" class="data row1 col0">Thanks for sharing this story. It's good to see the neighbors are focused on the<br>
library and the library only, not turning it into some mixed use development.</td>
<td id="T_a818a_row1_col1" class="data row1 col1">0.800000</td>
</tr>
<tr class="odd">
<td id="T_a818a_row2_col0" class="data row2 col0">Yup. During the renovations of my town’s library they created a temporary<br>
library in a leased commercial space. Is it perfect? No? Does it maintain access<br>
to books and services temporarily while they work on a bigger and better library<br>
to provide even better services? Yes. It just takes a bit of creativity.</td>
<td id="T_a818a_row2_col1" class="data row2 col1">0.700000</td>
</tr>
<tr class="even">
<td id="T_a818a_row3_col0" class="data row3 col0">Libraries offer lots of things that rec centers can't. They're both great<br>
options, but they aren't interchangeable.</td>
<td id="T_a818a_row3_col1" class="data row3 col1">0.550000</td>
</tr>
<tr class="odd">
<td id="T_a818a_row4_col0" class="data row4 col0">Not sure how good faith the argument is but some of the quotes from the article<br>
prefer having the library for use as a place for kids to keep out of trouble,<br>
and by making the project a full redevelopment for the housing and mix use,<br>
they'd be without the library. That doesn't sound as unreasonable as the<br>
headline would suggest.</td>
<td id="T_a818a_row4_col1" class="data row4 col1">0.000000</td>
</tr>
<tr class="even">
<td id="T_a818a_row5_col0" class="data row5 col0">There's also a rec center two blocks away. If lack of access to books and work<br>
space is the issue, I'm betting there's a way to work that out</td>
<td id="T_a818a_row5_col1" class="data row5 col1">0.000000</td>
</tr>
<tr class="odd">
<td id="T_a818a_row6_col0" class="data row6 col0">Rec centers are awesome but don't replace libraries. I agree with u/inherendo<br>
that the headline evokes NIMBYism but the article reads more like people not<br>
wanting their library turned into a long-term real-estate project.</td>
<td id="T_a818a_row6_col1" class="data row6 col1">0.000000</td>
</tr>
<tr class="even">
<td id="T_a818a_row7_col0" class="data row7 col0">I'm not seeing an objection in the article that suggests anyone thinks they'd be<br>
without the library. It looks like all the objections are to having additional<br>
housing. But feel free to correct me if I'm misreading something.</td>
<td id="T_a818a_row7_col1" class="data row7 col1">0.000000</td>
</tr>
<tr class="odd">
<td id="T_a818a_row8_col0" class="data row8 col0">I agree. The article does't say anything about losing the library. My guess is<br>
the objection could be about temporarily losing it during construction but<br>
that's all I can think of.</td>
<td id="T_a818a_row8_col1" class="data row8 col1">0.000000</td>
</tr>
<tr class="even">
<td id="T_a818a_row9_col0" class="data row9 col0">I'll bite. How does housing improve the library? I can see the argument for the<br>
library adding value to the housing but vice versa?</td>
<td id="T_a818a_row9_col1" class="data row9 col1">0.000000</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<section id="most-negative-comments" class="level4">
<h4 class="anchored" data-anchor-id="most-negative-comments">10 Most Negative Comments</h4>
<div id="5096f2bd" class="cell" data-execution_count="28">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb28"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a>cecillibrary.nsmallest(<span class="dv">10</span>, <span class="st">"sentiment_score"</span>)[[<span class="st">"body"</span>, <span class="st">"sentiment_score"</span>]]</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</details>
<div class="cell-output cell-output-display" data-execution_count="28">
<div>
<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">body</th>
<th data-quarto-table-cell-role="th">sentiment_score</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">34</th>
<td>Young on speed cameras in school zones: needs ...</td>
<td>-0.90</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">25</th>
<td>Young tanked the community plan and now is hol...</td>
<td>-0.80</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">61</th>
<td>Fuck this stupid ass city man</td>
<td>-0.80</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">65</th>
<td>Libraries aren’t for kids. You know what libra...</td>
<td>-0.75</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">15</th>
<td>Several people and librarians raised some vali...</td>
<td>-0.70</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">26</th>
<td>Have to love blowing up a plan that is already...</td>
<td>-0.70</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">33</th>
<td>Piling on housing is ridiculous, just fix the ...</td>
<td>-0.70</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">60</th>
<td>I figured this might be a legitimate concern a...</td>
<td>-0.70</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">63</th>
<td>There is a rec center a block away im not sayi...</td>
<td>-0.65</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">2</th>
<td>Replacing the entire building could take 3-5 y...</td>