IndexError: tuple index out of range
Closed this issue · 4 comments
Hey, nice work, you're ready for Cambridge :)
I've implemented your code and the sentiment analysis of the tweets works well, but then I get the following error:
Traceback (most recent call last):
File "deploy.py", line 621, in
orientation = main(target, num);
File "deploy.py", line 570, in main
scatters = plt.scatter(C1OUT, C2OUT, c=OBJ, cmap='RdYlGn', vmin=0, vmax=1)
File "/home/reactionhashs/anaconda2/envs/politicalbots/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2793, in scatter
verts=verts, edgecolors=edgecolors, data=data, **kwargs)
File "/home/reactionhashs/anaconda2/envs/politicalbots/lib/python3.6/site-packages/matplotlib/init.py", line 1785, in inner
return func(ax, *args, **kwargs)
File "/home/reactionhashs/anaconda2/envs/politicalbots/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 4189, in scatter
n_elem = c_array.shape[0]
IndexError: tuple index out of range
What's up with that? What am I doing wrong?
Cheers,
Hi there, thanks for the feedback. It seems to be a problem with matplotlib, not my code itself. What are the exact arguments you’re passing the program so I can try to reproduce the error?
Sure. I am using the example you provided.
(politicalbots) reactionhashs@o:~/politicalbots/eleicao$ python3.6 deploy.py -t potus -b left -c 100
[*] Target: potus (Washington, D.C.) 24432251 followers
[*] Benefit left wing
[*] Collecting ~100 Tweets
Tweets len ID Date Likes RTs SP SS
0 The American people have spoken. President @re... 139 1060282807115792384 2018-11-07 21:28:14 12846 2923 0 0
1 ....We thank Attorney General Jeff Sessions fo... 138 1060256623439110146 2018-11-07 19:44:12 67929 16740 -1 0
2 We are pleased to announce that Matthew G. Whi... 232 1060256619383193601 2018-11-07 19:44:11 90798 24493 1 0
3 Following yesterday’s election, President Trum... 161 1060254106730807297 2018-11-07 19:34:12 8808 1887 1 0
4 President Trump Hosts a Press Conferencehttps:... 148 1060214638204211200 2018-11-07 16:57:22 6808 2123 0 0
5 WATCH LIVE at 11:30 a.m. ET as President Trump... 123 1060193916732010499 2018-11-07 15:35:01 3173 762 1 0
6 October wasn't just a good month for U.S. jobs... 186 1059939490150707200 2018-11-06 22:44:01 9312 2416 1 0
7 4.5 MILLION JOBS created since Election Day 20... 170 1059921120827187201 2018-11-06 21:31:02 12899 3655 -1 0
8 Americans are WORKING and WINNING again: Since... 251 1059905009440178176 2018-11-06 20:27:00 10143 2873 1 0
9 "The proof is in the poll numbers." Americans ... 296 1059869286062325761 2018-11-06 18:05:03 5742 1601 1 0
10 More than improvement. More than promising sig... 218 1059838826791821312 2018-11-06 16:04:01 8395 2499 1 0
11 In 2016, liberals confidently predicted the Tr... 296 1059614092254683136 2018-11-06 01:11:00 10729 3074 1 0
12 Since President @realDonaldTrump took office, ... 211 1059554457556606981 2018-11-05 21:14:02 9179 2408 0 1
13 President @realDonaldTrump’s policies are maki... 194 1059513959416545281 2018-11-05 18:33:07 9437 2516 1 0
14 Wages are on the rise across America. But medi... 161 1059222792963538946 2018-11-04 23:16:07 8967 2547 1 0
15 The thriving U.S. economy is making a real dif... 260 1059190553286467584 2018-11-04 21:08:01 6068 1653 1 0
16 Georgia households are seeing outstanding bene... 146 1059170194407464961 2018-11-04 19:47:07 10682 3035 1 0
17 Jobs and wages are looking bright in the Sunsh... 226 1058818873036804097 2018-11-03 20:31:05 11129 3077 1 0
18 President @realDonaldTrump heads out west toda... 213 1058737084859592704 2018-11-03 15:06:06 10117 2645 1 0
19 President @realDonaldTrump is en route to Indi... 191 1058480902353969152 2018-11-02 22:08:07 8329 2026 1 0
20 The U.S. economy is on !pic.twitter.com/vs0Y5L... 50 1058452205324386304 2018-11-02 20:14:05 8931 2571 0 0
21 4.5 million jobs added since Election Day 201... 223 1058441613725327362 2018-11-02 19:32:00 11432 4364 1 0
22 Today's new jobs numbers are a home run for Am... 290 1058411924495482880 2018-11-02 17:34:01 4747 1276 1 0
23 President @realDonaldTrump is reimposing all s... 212 1058379415179149312 2018-11-02 15:24:50 18467 5113 -1 0
24 Another GREAT month for U.S. jobs! 250k added ... 177 1058353083367989249 2018-11-02 13:40:12 16020 4213 1 0
25 To halt the dangerous influx and to establish ... 221 1058137964256157696 2018-11-01 23:25:24 12786 3661 -1 0
26 President @realDonaldTrump is wheels up to Mis... 131 1058121779208687616 2018-11-01 22:21:05 6686 1554 0 0
27 “These caravans and illegal migrants are drawn... 144 1058105743080153088 2018-11-01 21:17:22 11891 3491 -1 0
28 Illegal immigration affects the lives of all A... 340 1058100070158098433 2018-11-01 20:54:49 94078 29102 -1 0
29 President Trump delivers an update on the cris... 290 1058099217120612353 2018-11-01 20:51:26 17903 4928 0 0
.. ... ... ... ... ... ... .. ..
70 I would like to begin today’s remarks by provi... 305 1055872564386398209 2018-10-26 17:23:31 56960 13570 0 0
71 #BullyingPreventionMonth reminds us that we ha... 217 1055851549858000896 2018-10-26 16:00:00 30392 6756 1 0
72 TUNE IN shortly as President Trump delivers re... 145 1055850481082343424 2018-10-26 15:55:46 4404 1174 -1 0
73 .@POTUS’ America First agenda is creating oppo... 299 1055847810866839552 2018-10-26 15:45:09 10378 2491 1 0
74 I will be speaking at the Young Black Leadersh... 132 1055846847502258178 2018-10-26 15:41:19 82594 16379 -1 0
75 Last quarter's expectations-beating 3.5% growt... 251 1055846262879277057 2018-10-26 15:39:00 4647 1200 1 0
76 Just in: Never underestimate the economic boom... 166 1055836968041492481 2018-10-26 15:02:04 14182 3398 1 0
77 Today’s discussion with local leaders in Missi... 261 1055568237470068736 2018-10-25 21:14:13 6568 1187 1 0
78 17 Congressional Review Acts\n$4.1B Saved\n\n#... 74 1055578474570792961 2018-10-25 21:54:54 6567 1826 0 0
79 Tonight, President Donald J. Trump, joined by ... 232 1055618279706898433 2018-10-26 00:33:04 8903 2090 0 0
80 The Service Members who died that day included... 246 1055600267331285002 2018-10-25 23:21:30 56529 13255 1 0
81 In 1983, roughly 1,800 Marines were in Beirut ... 229 1055599805395812352 2018-10-25 23:19:40 47373 11598 -1 0
82 We are gathered together on this solemn occasi... 281 1055598350228246528 2018-10-25 23:13:53 65714 16077 1 0
83 Watch LIVE as President Trump delivers remarks... 162 1055583558427963392 2018-10-25 22:15:06 4126 936 1 0
84 President @realDonaldTrump is fighting to:\n L... 121 1055542837515898881 2018-10-25 19:33:18 11966 2983 0 0
85 ...I agree with their stance 100%, and the Uni... 205 1055531231495024642 2018-10-25 18:47:11 52853 12309 -1 0
86 Just spoke with Prime Minister @GiuseppeConteI... 169 1055531230022766592 2018-10-25 18:47:10 61706 14369 -1 0
87 Thanks to a new law signed by President Trump,... 164 1055535307695816704 2018-10-25 19:03:22 12774 3352 1 0
88 Since the day President @realDonaldTrump took ... 172 1055531741920792578 2018-10-25 18:49:12 9122 2278 1 0
89 Spoke with French President @EmmanuelMacron th... 215 1055529948046331904 2018-10-25 18:42:05 43552 8830 1 0
90 This afternoon, President @realDonaldTrump hea... 132 1055515158720798720 2018-10-25 17:43:19 6952 1700 -1 0
91 “Remarks by President Trump on a Year of Histo... 149 1055494636775657478 2018-10-25 16:21:46 40956 9913 1 0
92 If you have info that could assist the @FBI in... 276 1055467271471222784 2018-10-25 14:33:01 8365 4057 0 0
93 Don’t forget #TakeBackDay on Saturday, Oct 27t... 124 1055460251460354048 2018-10-25 14:05:08 12252 3127 1 0
94 The safety of the American People is my highes... 217 1055170989682757632 2018-10-24 18:55:42 84446 22053 -1 0
95 I agree wholeheartedly!https://twitter.com/VP/... 74 1055127893112696832 2018-10-24 16:04:27 101813 22622 0 0
96 We are a great Sovereign Nation. We have Stron... 119 1055065538890735616 2018-10-24 11:56:41 127707 30508 1 0
97 For those who want and advocate for illegal im... 204 1055064484644089856 2018-10-24 11:52:29 129295 36940 1 0
98 I agree with President Obama 100%!pic.twitter.... 60 1054874705491120133 2018-10-23 23:18:23 230643 83299 0 0
99 Politics aside, socialism belongs in the dustb... 119 1054850960793759744 2018-10-23 21:44:01 6112 2035 0 0
[100 rows x 8 columns]
Percentage of positive tweets: 59.0%
Percentage of neutral tweets: 17.0%
Percentage de negative tweets: 24.0%
Average subjectivity: 2.0%
Detected 13 mentions.
Hillary sentiment: 0
Trump sentiment: 0
Cruz sentiment: 0
Bernie sentiment: 0
Obama sentiment: 0
Rpublican sentiment: 0
Democrat sentiment: 0
Guns sentiment: 0
Immigration sentiment: -0.10055803571428572
Employment sentiment: 0.23352298495155638
Inflation sentiment: 0
Minimum Wage Up sentiment: 0
Abortion sentiment: 0
Govenment Spending sentiment: 0
Taxes Up sentiment: 0
Taxes Down sentiment: 0
Death penalty sentiment: 0
Health care sentiment: 0
LGBT sentiment: 0
Environment sentiment: 0
Welfare sentiment: 0
Social sentimnt: 0
Labor Union sentiment: 0
Drugs sentiment: 0
War sentiment: -0.009999999999999998
Traceback (most recent call last):
File "deploy.py", line 621, in <module>
orientation = main(target, num);
File "deploy.py", line 570, in main
scatters = plt.scatter(C1OUT, C2OUT, c=OBJ, cmap='RdYlGn', vmin=0, vmax=1)
File "/home/reactionhashs/anaconda2/envs/politicalbots/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2793, in scatter
verts=verts, edgecolors=edgecolors, data=data, **kwargs)
File "/home/reactionhashs/anaconda2/envs/politicalbots/lib/python3.6/site-packages/matplotlib/__init__.py", line 1785, in inner
return func(ax, *args, **kwargs)
File "/home/reactionhashs/anaconda2/envs/politicalbots/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 4189, in scatter
n_elem = c_array.shape[0]
IndexError: tuple index out of range
You have compatibility issues with matplotlib in your virtual environment. Try with pip install -r requirements.txt
in another venv. Sorry for the inconvenience.
Gonna try it out. Thanks for taking the time.
Edit: Yes, now it works fine. Thanks!