This repository has been archived by the owner on Mar 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
data_cleaning.ipynb.orig
2413 lines (2413 loc) · 92.3 KB
/
data_cleaning.ipynb.orig
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
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Parsing and Cleaning PHEME RNR Dataset Events\n",
"\n",
"This notebook cleans tweet level data generated from `lib/pheme_parsing.py` and aggregates this tabular, individual data to tabular thread-level data. It also provides a useful sanity check after making modifications to `lib/pheme_parsing.py`. \n",
"\n",
"## Instructions\n",
"1. Update the variable `event` in the cell below with one of the following events:\n",
" 1. germanwings-crash\n",
" 1. ferguson\n",
" 1. ottawashooting\n",
" 1. sydneysiege\n",
" 1. charliehebdo\n",
"1. Run all the cells in this notebook to generate thread-level CSV files in the `data/threads` directory."
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [],
"source": [
"# Load dependencies for this Jupyter Notebook\n",
"import pandas as pd\n",
"import numpy as np\n",
"import networkx as nx\n",
"from functools import reduce\n",
"from lib.util import fetch_tweets\n",
"\n",
"event = \"charliehebdo\" # Change this value to clear different PHEME datasets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Parsing and Cleaning Data\n",
"This step takes the raw PHEME rumor dataset and saves it tabular format as CSV file. The original PHEME dataset consists of JSON files organized into directories by event and category (rumor or non-rumor). These three functions below parse the data, save it as a CSV file (if necessary), and load it into this notebook as a Pandas DataFrame from the \"cached\" CSV file."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<span style=\"color:red\">**<<<<<<< local**</span>"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"dataset_name=\"sydneysiege\"\n",
"gw = fetch_tweets(dataset_name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<span style=\"color:red\">**=======**</span>"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [],
"source": [
"gw = fetch_tweets(event)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<span style=\"color:red\">**>>>>>>> remote**</span>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tweet Level Features\n",
"\n",
"| Name/Column | Description | Type | Notes |\n",
"|-------------------|-------------------------------|--------| ------ |\n",
"| is_rumor | Was this classified as rumor | \"bool\" (`int`) | *Classification done by journalists* |\n",
"| thread | Source tweet id | `str` | |\n",
"| in_reply_tweet | Tweet ID in reply to | `str` | |\n",
"| event | Name of the PHEME event | `str` | Corresponds to event in the PHEME dataset |\n",
"| tweet_id | Unique ID for tweet | `str` | This field is the ID referenced in `in_reply_tweet` |\n",
"| is_source_tweet | Was this classified as rumor | \"bool\" (`int`) | |\n",
"| in_reply_user | User ID in reply to | `str` | |\n",
"| user_id | Twitter User's ID | `str` | This field is the ID referenced in `in_reply_user` |\n",
"| tweet_length | Number of characters in tweet | `int` | |\n",
"| urls_count | Number of URLS in tweet | `int` | |\n",
"| hashtags_count | Number of hashtags in tweet | `int` | |\n",
"| retweet_count | Times the tweet was retweeted | `int` | |\n",
"| favorite_count | Number of times favorited | `int` | |\n",
"| mentions_count | Number of users mentioned | `int` | |\n",
"| is_truncated | Is this tweet truncated | \"bool\" (`int`) | Did User type > 140 characters. [See Tweet updates](https://developer.twitter.com/en/docs/tweets/tweet-updates) |\n",
"| created | Datetime Tweet was created | `datetime` | |\n",
"| has_smile_emoji | Does Tweet contain \"\"? | \"bool\" (`int`) | 😊 is the smile emoji |\n",
"| user.tweets_count | User's tweet total, currently | `int` | |\n",
"| user.verified | Is Twitter user verified? | \"bool\" (`int`) | |\n",
"| user.followers_count | Total number of followers | `int` | |\n",
"| user.listed_count | ?? | `int` | | \n",
"| user.friends_count | ?? | `int` | |\n",
"| user.time_zone | Timezone of the user's Twitter account | `str` | |\n",
"| user.desc_length | Length of the user's biographic description | `int` |\n",
"| user.has_bg_img | Does user have a profile background image? | \"bool\" (`int`) |\n",
"| user.default_pric | Does the user have the default profile picture | \"bool\" (`int`) |\n",
"| user.created_at | Date and time Twitter account was activated | `datetime` | |\n",
"| user.utc_dist | TK | `int` | See [this blog post time and the Twitter API](https://zacharyst.com/2017/04/05/assigning-the-correct-time-to-a-twee) |"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Germanwings Crash"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"<<<<<<< local\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 23996 entries, 0 to 23995\n",
"Data columns (total 59 columns):\n",
"is_rumor 23996 non-null int64\n",
"thread 23996 non-null object\n",
"in_reply_tweet 23996 non-null object\n",
"event 23996 non-null object\n",
"tweet_id 23996 non-null object\n",
"is_source_tweet 23996 non-null int64\n",
"in_reply_user 23996 non-null object\n",
"user_id 23996 non-null object\n",
"tweet_length 23996 non-null int64\n",
"symbol_count 23996 non-null int64\n",
"user_mentions 23996 non-null int64\n",
"urls_count 23996 non-null int64\n",
"media_count 23996 non-null int64\n",
"hashtags_count 23996 non-null int64\n",
"retweet_count 23996 non-null int64\n",
"favorite_count 23996 non-null int64\n",
"mentions_count 23996 non-null int64\n",
"is_truncated 23996 non-null int64\n",
"created 23996 non-null float64\n",
"has_smile_emoji 23996 non-null int64\n",
"sensitive 23996 non-null int64\n",
"has_place 23996 non-null int64\n",
"has_coords 23996 non-null int64\n",
"has_quest 23996 non-null int64\n",
"has_exclaim 23996 non-null int64\n",
"has_quest_or_exclaim 23996 non-null int64\n",
"user.tweets_count 23996 non-null int64\n",
"user.verified 23996 non-null int64\n",
"user.followers_count 23996 non-null int64\n",
"user.listed_count 23996 non-null int64\n",
"user.desc_length 23996 non-null int64\n",
"user.handle_length 23996 non-null int64\n",
"user.name_length 23996 non-null int64\n",
"user.notifications 23996 non-null int64\n",
"user.friends_count 23996 non-null int64\n",
"user.time_zone 16388 non-null object\n",
"user.has_bg_img 23996 non-null int64\n",
"user.default_pic 23996 non-null int64\n",
"user.created_at 23996 non-null float64\n",
"user.location 23996 non-null int64\n",
"user.profile_sbcolor 23996 non-null int64\n",
"user.profile_bgcolor 23996 non-null int64\n",
"user.utc_dist 14394 non-null float64\n",
"hasperiod 23996 non-null int64\n",
"number_punct 23996 non-null int64\n",
"negativewordcount 23996 non-null int64\n",
"positivewordcount 23996 non-null int64\n",
"capitalratio 23996 non-null float64\n",
"contentlength 23996 non-null int64\n",
"sentimentscore 23996 non-null float64\n",
"Noun 23996 non-null int64\n",
"Verb 23996 non-null int64\n",
"Adjective 23996 non-null int64\n",
"Pronoun 23996 non-null int64\n",
"FirstPersonPronoun 23996 non-null int64\n",
"SecondPersonPronoun 23996 non-null int64\n",
"ThirdPersonPronoun 23996 non-null int64\n",
"Adverb 23996 non-null int64\n",
"has_url_in_text 23996 non-null int64\n",
"dtypes: float64(5), int64(47), object(7)\n",
"memory usage: 10.8+ MB\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"=======\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 38268 entries, 0 to 38267\n",
"Data columns (total 59 columns):\n",
"is_rumor 38268 non-null int64\n",
"thread 38268 non-null object\n",
"in_reply_tweet 38268 non-null object\n",
"event 38268 non-null object\n",
"tweet_id 38268 non-null object\n",
"is_source_tweet 38268 non-null int64\n",
"in_reply_user 38268 non-null object\n",
"user_id 38268 non-null object\n",
"tweet_length 38268 non-null int64\n",
"symbol_count 38268 non-null int64\n",
"user_mentions 38268 non-null int64\n",
"urls_count 38268 non-null int64\n",
"media_count 38268 non-null int64\n",
"hashtags_count 38268 non-null int64\n",
"retweet_count 38268 non-null int64\n",
"favorite_count 38268 non-null int64\n",
"mentions_count 38268 non-null int64\n",
"is_truncated 38268 non-null int64\n",
"created 38268 non-null float64\n",
"has_smile_emoji 38268 non-null int64\n",
"sensitive 38268 non-null int64\n",
"has_place 38268 non-null int64\n",
"has_coords 38268 non-null int64\n",
"has_quest 38268 non-null int64\n",
"has_exclaim 38268 non-null int64\n",
"has_quest_or_exclaim 38268 non-null int64\n",
"user.tweets_count 38268 non-null int64\n",
"user.verified 38268 non-null int64\n",
"user.followers_count 38268 non-null int64\n",
"user.listed_count 38268 non-null int64\n",
"user.desc_length 38268 non-null int64\n",
"user.handle_length 38268 non-null int64\n",
"user.name_length 38268 non-null int64\n",
"user.notifications 38268 non-null int64\n",
"user.friends_count 38268 non-null int64\n",
"user.time_zone 24681 non-null object\n",
"user.has_bg_img 38268 non-null int64\n",
"user.default_pic 38268 non-null int64\n",
"user.created_at 38268 non-null float64\n",
"user.location 38268 non-null int64\n",
"user.profile_sbcolor 38268 non-null int64\n",
"user.profile_bgcolor 38268 non-null int64\n",
"user.utc_dist 18557 non-null float64\n",
"hasperiod 38268 non-null int64\n",
"number_punct 38268 non-null int64\n",
"negativewordcount 38268 non-null int64\n",
"positivewordcount 38268 non-null int64\n",
"capitalratio 38268 non-null float64\n",
"contentlength 38268 non-null int64\n",
"sentimentscore 38268 non-null float64\n",
"Noun 38268 non-null int64\n",
"Verb 38268 non-null int64\n",
"Adjective 38268 non-null int64\n",
"Pronoun 38268 non-null int64\n",
"FirstPersonPronoun 38268 non-null int64\n",
"SecondPersonPronoun 38268 non-null int64\n",
"ThirdPersonPronoun 38268 non-null int64\n",
"Adverb 38268 non-null int64\n",
"has_url_in_text 38268 non-null int64\n",
"dtypes: float64(5), int64(47), object(7)\n",
"memory usage: 17.2+ MB\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
">>>>>>> remote\n"
]
}
],
"source": [
"gw.info()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `.head` method prints out the 5 first rows in the dataframe"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"<<<<<<< local\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>is_rumor</th>\n",
" <th>thread</th>\n",
" <th>in_reply_tweet</th>\n",
" <th>event</th>\n",
" <th>tweet_id</th>\n",
" <th>is_source_tweet</th>\n",
" <th>in_reply_user</th>\n",
" <th>user_id</th>\n",
" <th>tweet_length</th>\n",
" <th>symbol_count</th>\n",
" <th>...</th>\n",
" <th>sentimentscore</th>\n",
" <th>Noun</th>\n",
" <th>Verb</th>\n",
" <th>Adjective</th>\n",
" <th>Pronoun</th>\n",
" <th>FirstPersonPronoun</th>\n",
" <th>SecondPersonPronoun</th>\n",
" <th>ThirdPersonPronoun</th>\n",
" <th>Adverb</th>\n",
" <th>has_url_in_text</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>544427042616254465</td>\n",
" <td>nan</td>\n",
" <td>sydneysiege</td>\n",
" <td>544427042616254465</td>\n",
" <td>1</td>\n",
" <td>nan</td>\n",
" <td>61436584</td>\n",
" <td>139</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.166667</td>\n",
" <td>5</td>\n",
" <td>6</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" <td>544427042616254465</td>\n",
" <td>5.4442704261625446e+17</td>\n",
" <td>sydneysiege</td>\n",
" <td>545322709756805120</td>\n",
" <td>0</td>\n",
" <td>61436584.0</td>\n",
" <td>887450286</td>\n",
" <td>133</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.000000</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0</td>\n",
" <td>544427042616254465</td>\n",
" <td>5.445083586532475e+17</td>\n",
" <td>sydneysiege</td>\n",
" <td>544508565705072640</td>\n",
" <td>0</td>\n",
" <td>19317766.0</td>\n",
" <td>17872080</td>\n",
" <td>48</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.600000</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0</td>\n",
" <td>544427042616254465</td>\n",
" <td>5.4442704261625446e+17</td>\n",
" <td>sydneysiege</td>\n",
" <td>544505594561167361</td>\n",
" <td>0</td>\n",
" <td>61436584.0</td>\n",
" <td>30726225</td>\n",
" <td>48</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.500000</td>\n",
" <td>3</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0</td>\n",
" <td>544427042616254465</td>\n",
" <td>5.4442704261625446e+17</td>\n",
" <td>sydneysiege</td>\n",
" <td>544506491684659200</td>\n",
" <td>0</td>\n",
" <td>61436584.0</td>\n",
" <td>19317766</td>\n",
" <td>38</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.000000</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 59 columns</p>\n",
"</div>"
],
"text/plain": [
" is_rumor thread in_reply_tweet event \\\n",
"0 0 544427042616254465 nan sydneysiege \n",
"1 0 544427042616254465 5.4442704261625446e+17 sydneysiege \n",
"2 0 544427042616254465 5.445083586532475e+17 sydneysiege \n",
"3 0 544427042616254465 5.4442704261625446e+17 sydneysiege \n",
"4 0 544427042616254465 5.4442704261625446e+17 sydneysiege \n",
"\n",
" tweet_id is_source_tweet in_reply_user user_id tweet_length \\\n",
"0 544427042616254465 1 nan 61436584 139 \n",
"1 545322709756805120 0 61436584.0 887450286 133 \n",
"2 544508565705072640 0 19317766.0 17872080 48 \n",
"3 544505594561167361 0 61436584.0 30726225 48 \n",
"4 544506491684659200 0 61436584.0 19317766 38 \n",
"\n",
" symbol_count ... sentimentscore Noun Verb Adjective \\\n",
"0 0 ... 0.166667 5 6 0 \n",
"1 0 ... 0.000000 5 5 0 \n",
"2 0 ... 0.600000 3 2 0 \n",
"3 0 ... 0.500000 3 0 1 \n",
"4 0 ... 0.000000 3 1 0 \n",
"\n",
" Pronoun FirstPersonPronoun SecondPersonPronoun ThirdPersonPronoun \\\n",
"0 4 2 1 0 \n",
"1 3 2 0 1 \n",
"2 0 1 0 0 \n",
"3 0 0 0 0 \n",
"4 0 0 0 0 \n",
"\n",
" Adverb has_url_in_text \n",
"0 0 0 \n",
"1 0 0 \n",
"2 0 0 \n",
"3 0 0 \n",
"4 0 0 \n",
"\n",
"[5 rows x 59 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"=======\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>is_rumor</th>\n",
" <th>thread</th>\n",
" <th>in_reply_tweet</th>\n",
" <th>event</th>\n",
" <th>tweet_id</th>\n",
" <th>is_source_tweet</th>\n",
" <th>in_reply_user</th>\n",
" <th>user_id</th>\n",
" <th>tweet_length</th>\n",
" <th>symbol_count</th>\n",
" <th>...</th>\n",
" <th>sentimentscore</th>\n",
" <th>Noun</th>\n",
" <th>Verb</th>\n",
" <th>Adjective</th>\n",
" <th>Pronoun</th>\n",
" <th>FirstPersonPronoun</th>\n",
" <th>SecondPersonPronoun</th>\n",
" <th>ThirdPersonPronoun</th>\n",
" <th>Adverb</th>\n",
" <th>has_url_in_text</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>553535765997969408</td>\n",
" <td>nan</td>\n",
" <td>charliehebdo</td>\n",
" <td>553535765997969408</td>\n",
" <td>1</td>\n",
" <td>nan</td>\n",
" <td>1379288282</td>\n",
" <td>144</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.000</td>\n",
" <td>8</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" <td>553535765997969408</td>\n",
" <td>5.535357659979694e+17</td>\n",
" <td>charliehebdo</td>\n",
" <td>553536824673861633</td>\n",
" <td>0</td>\n",
" <td>1379288282.0</td>\n",
" <td>628636580</td>\n",
" <td>135</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>-0.050</td>\n",
" <td>8</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0</td>\n",
" <td>553535765997969408</td>\n",
" <td>5.535357659979694e+17</td>\n",
" <td>charliehebdo</td>\n",
" <td>553545896739086336</td>\n",
" <td>0</td>\n",
" <td>1379288282.0</td>\n",
" <td>514523937</td>\n",
" <td>128</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.000</td>\n",
" <td>10</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0</td>\n",
" <td>553535765997969408</td>\n",
" <td>5.535357659979694e+17</td>\n",
" <td>charliehebdo</td>\n",
" <td>553536468782571520</td>\n",
" <td>0</td>\n",
" <td>1379288282.0</td>\n",
" <td>1623557642</td>\n",
" <td>122</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>-0.125</td>\n",
" <td>6</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0</td>\n",
" <td>553535765997969408</td>\n",
" <td>5.535357659979694e+17</td>\n",
" <td>charliehebdo</td>\n",
" <td>553540960718962690</td>\n",
" <td>0</td>\n",
" <td>1379288282.0</td>\n",
" <td>61921063</td>\n",
" <td>105</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.500</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 59 columns</p>\n",
"</div>"
],
"text/plain": [
" is_rumor thread in_reply_tweet event \\\n",
"0 0 553535765997969408 nan charliehebdo \n",
"1 0 553535765997969408 5.535357659979694e+17 charliehebdo \n",
"2 0 553535765997969408 5.535357659979694e+17 charliehebdo \n",
"3 0 553535765997969408 5.535357659979694e+17 charliehebdo \n",
"4 0 553535765997969408 5.535357659979694e+17 charliehebdo \n",
"\n",
" tweet_id is_source_tweet in_reply_user user_id \\\n",
"0 553535765997969408 1 nan 1379288282 \n",
"1 553536824673861633 0 1379288282.0 628636580 \n",
"2 553545896739086336 0 1379288282.0 514523937 \n",
"3 553536468782571520 0 1379288282.0 1623557642 \n",
"4 553540960718962690 0 1379288282.0 61921063 \n",
"\n",
" tweet_length symbol_count ... sentimentscore Noun Verb \\\n",
"0 144 0 ... 0.000 8 2 \n",
"1 135 0 ... -0.050 8 4 \n",
"2 128 0 ... 0.000 10 2 \n",
"3 122 0 ... -0.125 6 4 \n",
"4 105 0 ... 0.500 4 2 \n",
"\n",
" Adjective Pronoun FirstPersonPronoun SecondPersonPronoun \\\n",
"0 1 1 0 0 \n",
"1 1 1 0 0 \n",
"2 0 1 0 0 \n",
"3 1 3 1 0 \n",
"4 1 2 1 1 \n",
"\n",
" ThirdPersonPronoun Adverb has_url_in_text \n",
"0 2 0 1 \n",
"1 3 0 0 \n",
"2 3 0 0 \n",
"3 2 0 0 \n",
"4 2 0 1 \n",
"\n",
"[5 rows x 59 columns]"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
">>>>>>> remote\n"
]
}
],
"source": [
"gw.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Boolean Columns\n",
"\n",
"The `describe` method will give summary information about each column in the dataframe. Each of these columns, except `is_truncated` should have two unique values.\n",
"\n",
"Just for a sanity check. The cell below converts these boolean columns into value of type `bool` and describes them."
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"<<<<<<< local <modified: text/html, text/plain>\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>is_rumor</th>\n",
" <th>is_source_tweet</th>\n",
" <th>is_truncated</th>\n",
" <th>has_smile_emoji</th>\n",
" <th>user.verified</th>\n",
" <th>user.has_bg_img</th>\n",
" <th>user.default_pic</th>\n",
" <th>sensitive</th>\n",
" <th>has_place</th>\n",
" <th>has_coords</th>\n",
" <th>user.notifications</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>23996</td>\n",
" <td>23996</td>\n",
" <td>23996</td>\n",
" <td>23996</td>\n",
" <td>23996</td>\n",
" <td>23996</td>\n",
" <td>23996</td>\n",
" <td>23996</td>\n",
" <td>23996</td>\n",
" <td>23996</td>\n",
" <td>23996</td>\n",
" </tr>\n",
" <tr>\n",
" <th>unique</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>top</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>freq</th>\n",
" <td>15320</td>\n",
" <td>22775</td>\n",
" <td>23996</td>\n",
" <td>23973</td>\n",
" <td>22943</td>\n",
" <td>21776</td>\n",
" <td>14425</td>\n",
" <td>23933</td>\n",
" <td>23039</td>\n",
" <td>23481</td>\n",
" <td>23996</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" is_rumor is_source_tweet is_truncated has_smile_emoji user.verified \\\n",
"count 23996 23996 23996 23996 23996 \n",
"unique 2 2 1 2 2 \n",
"top False False False False False \n",
"freq 15320 22775 23996 23973 22943 \n",
"\n",
" user.has_bg_img user.default_pic sensitive has_place has_coords \\\n",
"count 23996 23996 23996 23996 23996 \n",
"unique 2 2 2 2 2 \n",
"top True False False False False \n",
"freq 21776 14425 23933 23039 23481 \n",
"\n",
" user.notifications \n",
"count 23996 \n",
"unique 1 \n",
"top False \n",
"freq 23996 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"=======\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>is_rumor</th>\n",
" <th>is_source_tweet</th>\n",
" <th>is_truncated</th>\n",
" <th>has_smile_emoji</th>\n",
" <th>user.verified</th>\n",
" <th>user.has_bg_img</th>\n",
" <th>user.default_pic</th>\n",
" <th>sensitive</th>\n",
" <th>has_place</th>\n",
" <th>has_coords</th>\n",
" <th>user.notifications</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>38268</td>\n",
" <td>38268</td>\n",
" <td>38268</td>\n",
" <td>38268</td>\n",
" <td>38268</td>\n",
" <td>38268</td>\n",
" <td>38268</td>\n",
" <td>38268</td>\n",
" <td>38268</td>\n",
" <td>38268</td>\n",
" <td>38268</td>\n",
" </tr>\n",
" <tr>\n",
" <th>unique</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>top</th>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>freq</th>\n",
" <td>30923</td>\n",
" <td>36189</td>\n",
" <td>38268</td>\n",
" <td>38248</td>\n",