This blog will show the code with the help of which i’ve done sentiment analysis and also made an wordcloud after filtration of language. Applicable for all language.
In [3]:
import tweepy
from tweepy import OAuthHandler
import os
import re
In [5]:
consumer_key = "--------------------------------"
consumer_secret_key = "-------------------------------------"
access_token = "-----------------------------------------------------"
access_secret = "------------------------------------------"
auth = OAuthHandler(consumer_key, consumer_secret_key )
auth.set_access_token(access_token ,access_secret )
api = tweepy.API(auth, wait_on_rate_limit=True)
In [6]:
result = []
#for tweet in tweepy.Cursor(api.search, q = "", lang = "en", since = "2018-10-1" ).items(200):
tweet = api.user_timeline(screen_name= "@RahulGandhi", count = 200, lang = ['en']) #maximum 200 are allowed
#print(tweet.created_at, tweet.text)
for t in tweet:
result.append(t.text)
#api.GetUserTimeline(Screen_name= "")
result
Out[6]:
['I am sorry to hear about the passing of Shivakumar Swami Ji, Pontiff of the Siddaganga Mutt. Swami Ji was respected… https://t.co/S3d2nUjRMQ', 'Your Highness,\n\nThe cries for help are the cries of millions of unemployed youth; of farmers in distress; of oppres… https://t.co/iUnBfgQmOZ', "I'm upset to hear Arun Jaitley Ji is not well. We fight him on a daily basis for his ideas. However, I and the Cong… https://t.co/q5ibj6Q3d9", "I want to congratulate our PM, on winning the world famous “Kotler Presidential Award”! \n\nIn fact it's so famous it… https://t.co/R60U3iJFT0", 'I wish you all a very Happy Pongal!\n\n #HappyPongal2019', 'My condolences to the family of veteran Congress leader Shri Shivajirao Deshmukh Ji who passed away earlier today.… https://t.co/e3ynhaLFeA', 'When the scales of justice are tampered with, anarchy reigns. \n\nThis PM will stop at nothing, stoop to anything & d… https://t.co/4LiWQHgCCb', 'I am humbled by the love of the Indian community here in the UAE & their infectious enthusiasm & energy that helped… https://t.co/K2GVH2E042', 'It was a pleasure to meet with Sultan bin Muhammad Al-Qasimi, the ruler of the Emirate of Sharjah. We had a cordial… https://t.co/DM5PlQZyem', 'लोहड़ी के शुभ अवसर पर समस्त देशवासियों को हार्दिक बधाई|', 'It was a pleasure to meet Sheikh Nahyan Bin Mubarak Al Nahyan in Abu Dhabi today, at the lunch he hosted for our de… https://t.co/iGnJz7bqwb', 'I want to thank all those who worked tirelessly behind the scenes to make all the programs in Dubai yesterday a hug… https://t.co/EuL22EFOOX', 'This evening I had an excellent meeting with the Vice President & Prime Minister of UAE, @HHShkMohd, the architect… https://t.co/L9WyBky2df', 'Fear is now rampaging through Mr Modi’s mind. He can’t sleep. He stole 30,000Cr from the IAF and gave it to Anil Am… https://t.co/9zIrNB9GHy', '1. Why is the PM in such a tearing hurry to sack the CBI Chief? \n\n2. Why will he not allow the CBI Chief to present… https://t.co/21IScSu7Ve', 'With all due respect Modi Ji, in our culture respect for women begins at home. \n\nStop shaking. Be a man and answer… https://t.co/xIlNU61cLO', 'आज जयपुर में किसानों से मुलाक़ात हुई|\n\nमैंने स्पष्ट रूप से कहा है कि क़र्ज़ा माफ़ी से किसानों को मदद ज़रूर मिलेगी प… https://t.co/W6rkuSEk15', 'The truth of Rafale will destroy Mr Modi. It’s only a question of time before full evidence of his role in the thef… https://t.co/byNIy6IbcA', 'The PM pays 20,000 Cr. to Dassault before a single RAFALE is delivered but refuses to pay HAL 15,700 Cr. it is owed… https://t.co/FFalXVNGqX', 'Congratulations to #TeamIndia and Captain @imVkohli on the series win in Australia. You make us all proud. Well don… https://t.co/9mw519FfvH', 'That HAL doesn’t have enough cash to pay salaries, isn’t surprising. \n\nAnil Ambani has Rafale. He now needs HAL’s b… https://t.co/zVYGSSsXaa', 'When you tell one lie, you need to keep spinning out more lies, to cover up the first one. \n\nIn her eagerness to de… https://t.co/qkD3r39OwL', 'Congress built the India growth story. Modi has used Demonetisation and the Gabbar Singh Tax to completely destroy… https://t.co/AC3m1CXUpr', "RM spoke for 2 hrs. in Parliament, but she couldn't answer the 2 simple questions I asked her. \n\nWatch & SHARE this… https://t.co/Nb11h8WkMI", 'In addition to corruption, the PM should be investigated for weakening national security by giving the Rafale contr… https://t.co/NoRwkdTTuF', 'Modi ji this is looking very bad. Can you please get your mouthpiece, Jetley, to spin this?\n\nhttps://t.co/IA5VeFmAXU', 'So it seems our PM has fled Parliament & his own open book Rafale exam & is instead lecturing students at Lovely Un… https://t.co/TBybFK5aQJ', 'The Missing Q3!\n\nI had held back Q3 because Madam Speaker had said, “no talking about the Goa tape”! But the missin… https://t.co/RXCarm1ev4', 'Tomorrow, the PM faces an Open Book #RafaleDeal Exam in Parliament. \n\nHere are the exam questions in advance:\n\nQ1.… https://t.co/JXqvFooYRw', 'पूरे देश को, 2019 की बहुत शुभकामनाएँ। \n\nमेरी ख़्वाहिश है कि नया साल देश के लिए, किसानों और युवाओं के लिए, व्यापारि… https://t.co/viHeyWbLel', 'I wish you all, a Happy New Year!', 'चौकीदार का भेष, \nचोरों का काम।\nबैंकों के 41,167 करोड़,\nसौंपे जिगरी दोस्तों के नाम।\n\n41,167 करोड़ में:\n\n👉 MNREGA पू… https://t.co/QHQkfhZJck', 'At the Vibrant Gujarat Summit 2019, cynical sponsors no longer want to associate themselves with an event presided… https://t.co/jQNJajk8Ek', 'I had an excellent meeting today with the Prime Minister of Bhutan, Dr Lotay Tshering. We discussed the political s… https://t.co/ENsJvLZEuZ', 'On #CongressFoundationDay let us celebrate & acknowledge the selfless service & contributions of millions of Congre… https://t.co/qpGBOA9hXL', '15 miners have been struggling for air in a flooded coal mine for two weeks. \n\nMeanwhile, PM struts about on Bogibe… https://t.co/Hpjd9C0D9e', 'Vanakam Puducherry!\n\nThat’s NoMo’s answer to the struggling middle class. \n\nForget a press conference he can’t even… https://t.co/DzSE3RZFPN', 'Merry Christmas to you all! https://t.co/MdIVF1VO3n', 'हमारे किसानों के आने वाले कल को सुरक्षित करने के लिए मैं वो हर कोशिश करने वाला हूँ जिससे उनका भविष्य सुरक्षित बने|… https://t.co/DQZwTSLEMG', 'NO ONE KILLED...\n\nHaren Pandya.\n\nTulsiram Prajapati.\n\nJustice Loya.\n\nPrakash Thombre. \n\nShrikant Khandalkar.\n\nKause… https://t.co/bazXbVXGDH', 'Converting India into a police state isn’t going to solve your problems, Modi Ji. \n\nIt’s only going to prove to ov… https://t.co/Rc2wRhbFtU', 'The Congress Party has finally jolted Narendra Ji from his deep slumber on Gabbar Singh Tax. \n\nThough still drowsy,… https://t.co/1g7Vdd0wAq', "It's done! \n\nRajasthan, Madhya Pradesh & Chhattisgarh have waived farm loans.\n\nWe asked for 10 days. \n\nWe did it in 2.", "The Congress party has managed to wake the CM's of Assam & Gujarat from their deep slumber. \n\nPM is still asleep. We will wake him up too.", 'हमने जो कहा, वो कर के दिखाया है| \nप्रधानमंत्री को इससे सीख लेनी चाहिए| \nप्रधानमंत्री ये जान लें, जब तक वो पुरे देश… https://t.co/3irwQ58YEY', 'Great teams deliver exceptional results.\n\nI want to thank Team AICC - our General Secretaries, State-In-Charges, S… https://t.co/7XDB65OeoC', 'मध्य प्रदेश के मुख्यमंत्री ने किसानों का कर्ज माफ कर दिया है| \n\nअब राजस्थान और छत्तीसगढ़ की बारी है| https://t.co/jwDJoLShbp', 'छत्तीसगढ़ वासियों का धन्यवाद| \n\nकंधे से कंधा मिला कर हम अब नए छत्तीसगढ़ का निर्माण करेंगे| \n\nकिसानों, नौजवानों और म… https://t.co/WMtbSKTR4t', 'CM, Madhya Pradesh, waives farm loans. \n\n1 done. \n\n2 to go.', 'मध्यप्रदेश वासियों का हार्दिक अभिनंदन| \n\nआपने सत्य और प्यार के रास्ते पर चलने वाली कांग्रेस पार्टी को विजयी बना कर… https://t.co/q3EsLzCFOx', 'कांग्रेस पार्टी पर विश्वास करने के लिए राजस्थान वासियों का हृदय से आभार। \n\nकांग्रेस के कार्यकर्ताओं और नेताओं को उन… https://t.co/qLkkkDNW1X', 'The statue of Kalaignar Karunanidhi, one of India’s great sons, was unveiled in Chennai today. \n\nI thank Shri M K S… https://t.co/iZ6Kv081uV', 'On the 1st anniversary of taking over as Congress President, I reiterate my commitment to building a strong, united… https://t.co/ms4DsE9AyG', 'No matter how brilliant your mind or strategy, if you’re playing a solo game, you’ll always lose out to a team.\n\n–… https://t.co/dYtyH9OukS', 'The united colours of Rajasthan! https://t.co/D1mjKaaBsa', 'The two most powerful warriors are patience and time.\n\n- Leo Tolstoy https://t.co/MiRq2IlrIg', "With the RBI Governor's resignation one more independent institution has fallen. The BJP has demolished every templ… https://t.co/euSQ598Q2l", 'कांग्रेस पार्टी और उसके नेताओं ने हमेशा सच्चे और निडर पत्रकारिता का साथ दिया है| \n\nउसी परंपरा पर चलते हुए, आज, "नव… https://t.co/GYOx81yvCW', 'यह मनोरंजक वीडियो श्री 36 द्वारा प्रस्तुत किया गया है! मुझे आशा है कि आप इसे देखकर आनंद लेंगे! कृपया इसे अपने परिवा… https://t.co/woIygeK9oH', 'Shri Stalin & senior members of the DMK, visited Sonia Ji in Delhi today, to wish her on her birthday. We had a war… https://t.co/EF711l76hX', 'Spoken like a true soldier General. India is so proud of you. Mr 36 has absolutely no shame in using our military a… https://t.co/pAdcZGowvQ', 'Congress party workers, it’s time to be vigilant. \n\nIn MP, EVMs behaved strangely after polling:\n\nSome stole a sch… https://t.co/I3RvCRQ40E', 'किशनगंज से कांग्रेस पार्टी के लोकप्रिय सांसद, मौलाना असरारुल हक साहब, के निधन की ख़बर सुनकर बेहद दुःख हुआ। \n\nमैं अस… https://t.co/e4HFqW4pOL', '"जो इतिहास भूल जाते हैं वह इतिहास नही बनाते"\n\nबाबा साहेब भीमराव अम्बेडकर जी को उनके महापरिनिर्वाण दिवस पर शत् शत् न… https://t.co/BI8YoBcgiR', 'Dear Mr Modi,\n\nNow that campaigning is over, hope you can spare some time for your part-time job as PM. \n\nBtw its b… https://t.co/9ummzczxwn', 'बुलन्दशहर में पुलिस अधिकारी सुबोध सिंह की अराजक भीड़ द्वारा हत्या दर्दनाक और शर्मनाक है।\n\nमोदी-योगी राज में पुलिस… https://t.co/b05B71EQYu', 'అరెస్టులతో కాంగ్రెస్\u200c ప్రభంజనాన్ని టీఆర్\u200cఎస్\u200c అడ్డుకోలేదు. కేసీఆర్\u200c నిరంకుశ ధోరణికి పరాకాష్టే రేవంత్\u200cరెడ్డి అరెస్… https://t.co/nTovQx4Ihk', 'चौकीदार ने सुप्रीम कोर्ट के एक न्यायमूर्ति को कोर्ट-पुतली बना लिया था।\n\nचौकीदार का दुर्भाग्य है कि देश में ईमानदार… https://t.co/30jqMvIhv3', '8 months before they were allowed to flee, the IT dept. wrote a 10,000 pg report on Chota Modi & Choksi’s massive f… https://t.co/kB2dDUpqKr', 'मोदीजी दो हिंदुस्तान बना रहे हैं। \n\nएक अनिल अम्बानी का हिंदुस्तान। \nजिसे बिना कुछ किए, बिना एक हवाई जहाज बनाए मोदी… https://t.co/EVCooZrtpH', 'BJP `B`టీం TRS.KCR తెలంగాణ\u200cలో మోడీ ర\u200cబ్బ\u200cర్\u200cస్టాంప్\u200c.\n\nఓవైసీకి చెందిన ఎంఐఎం బీజేపీ `C`టీంగా వ్య\u200cవ\u200cహ\u200cరిస్తూ BJP/TRS… https://t.co/rIIciG4SfL', 'TRS is the BJP\'s "B" team & KCR operates as Mr Modi\'s, Telangana Rubber Stamp. \n\nOwaisi\'s, AIMIM is the BJP\'s "C" t… https://t.co/8ZOYLYJ4ug', 'Telangana was born of idealism & great dreams. But, 4 yrs. of TRS/BJP incompetence, arrogance & corruption has made… https://t.co/qsaOWPn8ie', 'Modi-Master of Data Manipulation. https://t.co/e1n1JXeTxE', 'राजस्थान के लोगों से मिलने आ रहा हूँ| आज उदयपुर, भीलवाड़ा, चित्तौड़गढ़ एवं हनुमानगढ़ में जनसभाएं होगें। राजस्थान प्… https://t.co/bSdjUdqIaR', 'किसान देश पर भार नहीं हैं। \nकिसान देश का सार हैं| \n\nदेश का किसान संकट में है| \nउनकी उम्मीद टूट रही है। \nउनके दिल… https://t.co/E9m3Nk2EgB', 'Demo like Rafale was a crime against India & a huge scam. Parrikar distanced himself from Rafale to save his skin.… https://t.co/TuMIYobFDu', 'राजस्थान के इस सज्जन ने देश के दिल की बात कह दी है| सुनिए, गाना ज़ुबान पर चढ़ जाएगा !\n#AccheDin? https://t.co/db5ecN0qOQ', 'On the second day of my tour of Telangana, I will address public meetings at Bhupalpally, Armoor, and Pargi. You ca… https://t.co/EKLds4u7QA', 'My appeal to the voters of Mizoram:\n\nYour vote is not just your constitutional right, it is a blessing & a weapon.… https://t.co/aJF8cYpewm', 'मध्यप्रदेश के मतदाताओं से विनम्र आग्रह।\n\nवोट प्रजातंत्र की सबसे बड़ी ताक़त है।\nआज अपना वोट ज़रूर डालें क्योंकि,\n‘व… https://t.co/A9gKkyBJ3c', 'I am in Telangana on a two day tour. Today I will address public meetings at Kosgi & Madhira. There are also corner… https://t.co/8FBdh2xqGF', 'भारत का संविधान हमारे संघर्ष और अस्तित्व दोनों की पहचान है| \n\nयह हमारा दर्शन है| हमारा अभिमान है| \n\nहमारे रग-रग में… https://t.co/841tIZ9iOJ', 'अजमेर स्थित ख्वाजा गरीब नवाज की दरगाह पर शीश झुका कर, आज की राजस्थान यात्रा की शुरुआत होगी| वहाँ से पुष्कर, ब्रह्मा… https://t.co/ooOgWczbWt', 'It is a day of tragedy for the Congress party, with another senior, loved & respected member of our family in Karna… https://t.co/1FJrj9KCJA', 'In the passing of Ambareesh Ji, the Congress family has lost a valuable member. He was a famous son of Karnataka, w… https://t.co/V4QN5Vbics', 'हमारे चौकीदार की चोरी ने, फ्रांस की सरकार को मुश्किल में डाल दिया हैं। \n\nराफेल सौदे को लेकर अब फ्रांस की जनता जाँच… https://t.co/p47Msxvg1C', "I'm sorry to hear about the terrible bus accident in Mandya district of Karnataka in which over 20 people are feare… https://t.co/SBkHs6n0S2", 'मध्य प्रदेश दौरे का दूसरा दिन है| आज, सागर, दमोह और टीकमगढ़ में जनसभाएं होंगे| मध्य प्रदेश से जुड़ी कोई बात अगर… https://t.co/n70SYxyXyn', 'राफेल घोटाला मोदीजी के कारनामों की झलक भर है।\n\nसेनाओं को लूटने के लिए उन्होंने चुनिंदा अफसरों, मंत्रियों, उद्योगपति… https://t.co/AtE8ZMUMNp', 'सी पी जोशी जी का बयान कांग्रेस पार्टी के आदर्शों के विपरीत है। पार्टी के नेता ऐसा कोई बयान न दें जिससे समाज के किसी… https://t.co/63UOcrZJRT', 'मध्यप्रदेश के लोगों से मिलने आ रहा हूँ| आज विदिशा के बासौदा, भोजपुर के मंडीदीप और बुधनी के नसरूल्लागंज में जनसभाएं… https://t.co/umURyDOo52', 'आप सभी को गुरुपर्व की हार्दिक शुभकामनाएं। \n\nगुरु नानक देव जी की पवित्र शिक्षाओं से हमारे जीवन में ज्ञान, करुणा और… https://t.co/Mj6tVcBZvp', 'The Gita says you can never escape the truth and so it has always been. \n\nSandeep Tamgadge has called Amit Shah a “… https://t.co/qQ9LxgayLF', 'मध्य प्रदेश में हुए बस हादसे की ख़बर सुनकर बहुत ही दुख पहुँचा है| \n\nईश्वर से प्रार्थना है कि जो जख्मी हैं उन्हें ज… https://t.co/DxvsBGuXal', 'नोटबंदी ने करोड़ों किसानों का जीवन नष्ट कर दिया हैं। \n\nअब उनके पास बीज-खाद खरीदने के लिए पर्याप्त पैसा भी नहीं है।… https://t.co/wmDIDJwvRI', 'ईद-ए-मिलाद-उन-नबी के खुशी के मौके पर, देशवासियों को हार्दिक शुभकामनाएं| \n\n#EidMiladUnNabi https://t.co/EInmFlIUpR', 'With the passing of Shri M.I. Shanavas, two term Lok Sabha MP from Wayanad, Kerala, the Congress family has lost a… https://t.co/VsNLEFdGX5', 'Today I’m in Mizoram! The North East of India has always had a close connect with the Congress party. I look forwar… https://t.co/qlgQ5UCsIZ', "दिल्ली में 'चौकीदार ही चोर' नामक एक क्राइम थ्रिलर चल रहा है| \n\nनए एपिसोड में CBI के DIG द्वारा एक मंत्री, NSA, कानू… https://t.co/EyYXQK6PC4", 'Mr Modi and his coterie of cronies, continue to destroy every institution they can get their hands on. Today, throu… https://t.co/kc7oGABJuV', 'Forgiveness is a virtue of the brave. \n\nIndira Gandhi https://t.co/1soJmsU93E', 'कल छत्तीसगढ़ में मैंने प्रेस के सदस्यों से बातचीत की। उस बातचीत का एक छोटा वीडियो देखें। \nएक दिन मुझे यकीन है कि ह… https://t.co/VgcHsIrkXY', 'क्या आपने माल्या, ‘मेहुल भाई’, नीरव मोदी को गेहूँ उगाते देखा है?\n\nमोदीजी किसान का अपमान मत करो।\n\nपहले आपने नोटबंदी… https://t.co/SFG3XVJ6ov', 'छत्तीसगढ़ आ रहा हूँ| आज, कोरिया जिले के बैकुंठपुर, जशपुर जिले के बगीचा, और सरगुजा जिले के दरिमा में जनसभाएं होंगी|… https://t.co/GjUPEMbWDY', 'श्री छप्पन और उनके मंत्रियों ने छात्रों को दिखाया है कि भाजपा में मंत्रीमंडल का शीघ्र द्वार फ़र्ज़ी डिग्री दिखा कर… https://t.co/loKhVnUizI', 'मध्य प्रदेश का दौरा आज से आरंभ हो रहा है| आज, सागर जिले के देवरी, सिवनी जिले के बरघाट एवं मंडला जिले में जनसभाएं… https://t.co/CAlcGlasvT', 'Another RAFALE Skeleton!\n\nMr Modi personally increased the benchmark price of RAFALE jets by 3 Billion Euros (₹22,7… https://t.co/2UcZ9Sgxc0', 'The latest skeleton to tumble out of the RAFALE cupboard: \n\nNO Guarantee by the French Govt. backing the deal. \n\nB… https://t.co/20COp17PZI', 'अंग्रेज़ों और शोषण के ख़िलाफ़ आंदोलन करनेवाले स्वतंत्रता सेनानी एवं आदिवासी अधिकारों के प्रेरणाश्रोत बिरसा मुंडा हम… https://t.co/TIv7qWCxq8', 'मेरे दो-दिवसीय छत्तीसगढ़ दौरे का आज दूसरा दिन है| कोरबा, बिलासपुर, कबीरधाम और दुर्ग के लोगों से मिलने आ रहा हूँ| https://t.co/ax0z58F3OZ', 'On the birth anniversary of Pt. Jawaharlal Nehru, the best way for us to honour him, is by rededicating ourselves t… https://t.co/EfvOsbFvxy', 'सुप्रीम कोर्ट में मोदीजी ने मानी अपनी चोरी।\n\nहलफ़नामे में माना कि उन्होंने बिना वायुसेना से पूछे कांट्रैक्ट बदला और… https://t.co/8r8bzOkitW', 'जीवनदायी सूर्य और प्रकृति की उपासना के महापर्व छठ पर देशवासियों को अनंत शुभकामनाएँ!\n\nव्रत, समानता और संयम से मनाए… https://t.co/KPWSPYOZoL', 'छत्तीसगढ़ के महासमुंद, बलौदाबाजार, जांजगीर-चाम्पा और खरसिया में, आज, जनसभाएं होगें| फ़ेसबुक के साथी, Facebook Live… https://t.co/yvKpa0Tx0R', 'The PM’s latest Demonetisation barf is, “Shell Firms”.\n\nIronically, the only “Shell” firms identified after the gre… https://t.co/urA7qx3reI', 'Jack Dorsey, the Co Founder & CEO of Twitter dropped in to chat this morning. Twitter has grown into the most domin… https://t.co/JigOAouQuC', 'I’m sorry to hear about the passing of Union Minister, Shri Ananth Kumar ji, in Bengaluru, earlier this morning. My… https://t.co/uf3PIzCbiC', 'The PM knows.\nAnil Ambani knows.\nHollande & Macron know.\nEvery journalist now knows. \nDefence Ministry babus know.… https://t.co/9KDawDd0NJ', '2014-ठग विद्या 1: मुझे प्रधानमंत्री बनाओ, मैं 2 करोड़ रोज़गार दिलाऊँगा| \n\n2016-ठग विद्या 2: नोटबंदी में मेरा साथ… https://t.co/GY2oXxMaiM', 'छत्तीसगढ़ का दो-दिवसीय दौरा आज से आरंभ हो रहा है| आज का अपना कार्यक्रम आपके साथ साझा कर रहा हूँ| \n\nFACEBOOK-LIVE के… https://t.co/vEVIjwFopq', 'नोटबंदी सोच-समझ कर किया गया एक क्रूर षड्यंत्र था। यह घोटाला प्रधानमंत्री के सूट-बूट वाले मित्रों का काला-धन सफेद कर… https://t.co/lOxM6KMMpt', 'देशवासियों को दीपावली की हार्दिक शुभकामनाएँ| आप सभी के जीवन में सुख और आनंद हो, इसकी मैं कामना करता हूँ।\n\nMy best w… https://t.co/sqMniPz3sU', 'Congratulations to all the workers & leaders of the Congress party in Karnataka on the decisive victory of the Cong… https://t.co/woGQAIhQuR', 'Rs 36,00,00,00,00,000 \n\nThat’s how much the PM needs from the RBI to fix the mess his genius economic theories have… https://t.co/l2seDgLr37', 'वायुसेना को राफ़ेल में लूटने के बाद, अब फ़सल बीमा के नाम पर किसानों को लूटा जा रहा है| \n\nमक़सद एक है: सूट-बूट वाले… https://t.co/yliAz3BuXJ', 'The greatness of a nation can be judged by the way its animals are treated. \n\nMahatma Gandhi\n\n#Avni', 'वादा था 2 करोड़ रोजगार का, मगर UP में 68,500 सहायक शिक्षकों की भर्ती सही से कराए जाने की माँग कर रहे युवाओं के साथ… https://t.co/3uuBe5DK0c', '284 Cr of Rafale kick-back money has been traced to an Anil Ambani owned company. \n\nThe stench of corruption is lea… https://t.co/VKoeNeWwY4', 'I had a good meeting today with Shri Chandrababu Naidu. Amongst other things, we discussed the issue of opposition… https://t.co/P4joy2FY6w', 'स्थापना दिवस के अवसर पर पंजाब, हरियाणा, मध्य प्रदेश, छत्तीसगढ़, कर्नाटक, केरल राज्यों और लक्षद्वीप संघ राज्य क्षेत्… https://t.co/gAwjwL5OrN', 'Ironic that a statue of Sardar Patel is being inaugurated, but every institution he helped build is being smashed.… https://t.co/PFYeEn3mT0', 'Sardar Patel was a patriot, who fought for a independent, united & secular India. A man with a steely will, tempere… https://t.co/PzOIxtKYB9', 'Remembering Dadi today with a deep sense of happiness. She taught me so much and gave me unending love. She gave so… https://t.co/YWrF8GI0es', 'छत्तीसगढ़ के दंतेवाड़ा में हुए नक्सली हमले की ख़बर से मुझे बहुत दुःख पहुंचा है| शहीद हुए 2 पुलिसकर्मी और दूरदर्शन… https://t.co/6UkiUdqii3', 'Nice that Mr Patel is finally defending the #RBI from Mr 56. Better late then never. India will never allow the BJP… https://t.co/Evucz9dNFU', 'मध्य प्रदेश का दो-दिवसीय दौरा आज से आरंभ हो रहा है| सबसे पहले भगवान शिव के दर्शन के लिए महाकालेश्वर मंदिर जा रहा… https://t.co/fhQjKUsr6G', 'For Anil\n\n30,000 CR from Rafale + all procedures bypassed + midnight sacking of CBI director. \n\nFor Forces \n\nNo ORO… https://t.co/MoW8X2DCZw', 'To the thousands of Indians who came out onto the streets today to say NO to corruption, NO to stopping the CBI fro… https://t.co/BAKu4sYg0n', 'सरकार लाख कोशिश कर ले, सच को क़ैद नहीं कर पाएगी| पुरे देश में जनता सड़कों पर आ प्रधान मंत्री को असलियत का आईना दिखा… https://t.co/3xXqCZ8E9v', 'Join us today at 11 AM as we march from Dayal Singh College on Lodhi Road to the CBI HQ, to protest the PM’s disgra… https://t.co/JwVVhLreTy', 'राफेल घोटाले की जाँच ना हो पाए इसलिए प्रधान मंत्री ने CBI प्रमुख को असंवैधानिक तरीक़े से हटा दिया| CBI को पूरी तरह… https://t.co/MzbvvQvcOv', 'Tomorrow, outside CBI offices nationwide, the Congress party will protest the PM’s disgraceful attempt to prevent a… https://t.co/h5UuRZFivH', 'PM removed the CBI Director to stop him from investigating Rafale. \n\nMr 56 broke the law when he bypassed CJI & LOP… https://t.co/eTbYFYD5Y0', 'CBI चीफ आलोक वर्मा राफेल घोटाले के कागजात इकट्ठा कर रहे थे। उन्हें जबरदस्ती छुट्टी पर भेज दिया गया। \n\nप्रधानमंत्री… https://t.co/33ZiPw5Tj0', 'मेरा दो-दिवसीय राजस्थान दौरा, आज, झालावाड़ के लोगों से मिलकर आरंभ होगा| झालावाड़ के बाद रामगंज मंडी पहुँचूँगा| फिर,… https://t.co/LEtnjDvSJh', 'RTI में प्रधान मंत्री को कहना चाहिए कि मैं उन्हें साथ ले जाता हूँ जिन्हें अगर मैं नहीं ले गया तो पुलिस ले जाएगी|… https://t.co/miJQstVlSq', 'Arun Jaitlie’s daughter was on the payroll of thief Mehul Choksi. Meanwhile her FM daddy sat on his file & allowed… https://t.co/79jzl8T6go', 'The PM’s blue-eyed boy, Gujarat cadre officer, of Godra SIT fame, infiltrated as No. 2 into the CBI, has now been c… https://t.co/o2SzcGy3jv', 'छत्तीसगढ़ आ रहा हूँ| जन-सभा के माध्यम से रायपुर के प्रगतिशील लोगों से दोपहर 3:30 बजे मुलाक़ात का सौभाग्य मिलेगा| फि… https://t.co/uIx8v9fMZ3', 'https://t.co/oitcfRCAlE', 'I look forward to meeting the great people of Telangana at my 3 public meetings in the state today. For those who c… https://t.co/Xlit0aETAH', 'अमृतसर में हुए ट्रेन हादसे की ख़बर से बहुत आहत हूँ| मेरी संवेदनाएं इस हादसे में मारे गए और पीड़ितों के परिवारों के… https://t.co/ekPWFBrLuS', 'The train accident in Punjab in which over 50 people have died is shocking. I urge the state government & Congress… https://t.co/x8REkRzHgv', 'Happy Dussehra to each and every one of you!', 'I’m sorry to hear about the passing of Shri N D Tiwari ji an important and illustrious member of the Congress famil… https://t.co/1xAxfYNslr', 'Thanks to the PM’s massive corruption, the best pilots in the world now have unlimited access to French junkyards f… https://t.co/RIuG3vo7em', 'https://t.co/efiVtvhSHm', 'मध्य प्रदेश की बुज़दिल सरकार के बेरहम प्रहार में मारे गए दलित युवकों और पीड़ितों के परिवार से मिल अपना शोक जाहिर कि… https://t.co/zUiFAud1M0', 'चौकीदार ने भाषण खूब दिया,\nपेट का आसन भूल गये।\n\nयोग-भोग सब खूब किया,\nजनता का राशन भूल गये।\n\nhttps://t.co/RTlyKbKeZl', 'हिंदुस्तान के दिल, मध्य-प्रदेश, में आ रहा हूँ| आज, दतिया, डबरा और ग्वालियर में जन-सभा और रोड-शो के माध्यम से आपसे… https://t.co/qylNef75u6', 'संत गोपालदास का बिगड़ता स्वास्थ, राष्ट्र के लिए चिंता का विषय है| गंगा में खनन पर रोक लगाने के लिए वो 24 जून से उप… https://t.co/FbHyamOueA', 'Excerpts from my informal interaction with the Press after the meeting in Bengaluru, with present & past employees… https://t.co/4m2wM9nC5q', "HAL is India's strategic asset. The future of India's aerospace industry has been destroyed by snatching #Rafale fr… https://t.co/YMH6I5Io4D", "It’s about time everyone learns to treat women with respect and dignity. \n\nI’m glad the space for those who don't,… https://t.co/xG5XtCR8Ol", 'माँ गंगा के सच्चे बेटे प्रो जीडी अग्रवाल नहीं रहे। गंगा को बचाने के लिए उन्होंने स्वयं को मिटा दिया।\n\nहिंदुस्तान को… https://t.co/O47QMSMVVM', 'The #GreatRafaleCoverUp has begun. To try and show the deal is legit, Raksha Mantri will need to generate minutes o… https://t.co/eGA626YlMo', 'The Supreme Court has asked for the #RAFALE decision making process. It’s quite simple really...\n\nThe PM decided.… https://t.co/PtdJHtwo33', 'सही फ़रमाया, जनता भी यही सोचती है कि सरकार ने लोगों के सपनों और उनके भरोसे को अपने लोभ का शिकार बनाया है| https://t.co/zhlKTrKHgU', 'ग़रीबी से बड़ी कोई दहशत नहीं है| गुजरात में हो रहे हिंसा की जड़ वहाँ के बंद पड़े कारख़ाने और बेरोज़गारी है| \n\nव्यव… https://t.co/Gr0vqAywhy', 'On #AirForceDay I salute the brave men and women of the Indian Airforce. Their valour and commitment is an inspirat… https://t.co/RNpqKOi3hP', 'When your BFF is the PM, you can get the 1,30,000 Cr. Rafale deal, even without relevant experience. But wait. Ther… https://t.co/1pb1rV0CnU', 'आदरणीय श्री मोदीजी, आम जनता पेट्रोल-डीजल के आसमान छूते दामों से बहुत ज्यादा परेशान है. \n\nआप कृपया पेट्रोल-डीजल को GST के दायरे में ले आइए।', "#Breaking: Rupee slips to 73.77\n\nIt's not breaking - it's Broken.\n\n#Rupee", 'रुपया गया 73 पार\nमहँगाई मचाए हाहाकार\n\nतेल-गैस में लगी है आग\nबाजार में मची भागम-भाग\n\nओ 56 इंच सीने वाले \nकब तक चलेगा… https://t.co/YQzPWaK3oi', "Modi's Operandi for handing out India's biggest defence contracts:\n\n1. Be a defaulter of 45,000Cr.\n\n2. Owe money to… https://t.co/TpBjutMjlN", '#BreakingNews\n\nविश्व अहिंसा दिवस पर BJP का दो-वर्षीय गांधी जयंती समारोह शांतिपूर्वक दिल्ली आ रहे किसानों की बर्बर… https://t.co/LyTU2yw9Bc', 'जय जवान-जय किसान के नारे के साथ देश की अगुवाई करने वाले श्री लाल बहादुर शास्त्री जी वास्तव में एक कर्मयोगी थे। \n\nउ… https://t.co/wLrv8fzcEf', 'Gandhiji is not an immobile statue, he is a living set of ideas and values flowing through India. \n\nTruth and non-v… https://t.co/ZtTq1RT3AW', "Modi's India-\n\nFor Common Man: Notebandi-line up and put ur money in banks. All ur details into Aadhar. U can't use… https://t.co/xypQJn5LOs", 'नदियाँ हिंदुस्तान को जीवन देती हैं। नदियाँ हमारे बीते कल, हमारे आज और हमारे भविष्य का आइना हैं। \n\nडा. जीडी अग्रवाल… https://t.co/9AzidjFVNF', 'मोदीजी, आपकी चहेती निजी कम्पनी ILFS डूबने वाली है। आप LIC का पैसा लगाकर उसे बचाना चाहते हो।क्यों? \n\nLIC देश के भरो… https://t.co/wGH4ZbIH92', 'लाइटस, कैमरा, स्कैम\n\nसीन 1: 2007, CM मोदी IL&FS कंपनी को 70,000 करोड़ का प्रोजेक्ट GIFT CITY देते हैं। आजतक कुछ काम… https://t.co/RxhRTkHaXt', 'साहेब का कमाल देखो \nराफेल का घोटाल देखो \nरुपए की टेढ़ी चाल देखो \nतेल में उछाल देखो \n\nमुंबई में-\nपेट्रोल-₹90.75\nडीजल… https://t.co/sH4S8bY2D8', 'मंदसौर में सत्ताधारी पार्टी के छात्र नेताओं द्वारा एक गुरु का अपमान। \n\nगुरु ब्रह्मा गुरु विष्णु गुरु देवो महेश्वर… https://t.co/Vc3gcFHU7p', 'देश का चौकीदार ‘खुल जा सिमसिम’ कब कहता है? \n\nअनिल अम्बानी को राफेल घोटाले में 1,30,000 Cr.\n\n50 करोड़ भारतीयों को Ay… https://t.co/LIursBBHQf', 'मोदी-अंबानी का देखो खेल \nHAL से छीन लिया राफेल \nधन्नासेठों की कैसी भक्ति \nघटा दिया सेना की शक्ति \nजिस अफसर ने चोरी… https://t.co/LowFdz8h09', 'For Congress, Aadhaar was an instrument of empowerment. \n\nFor the BJP, Aadhaar is a tool of oppression and surveill… https://t.co/Y9u1qo9WbV', "PM'S-KILL India Program \n\n30,000 Cr stolen from HAL and given to a man with no SKILLS in making aircraft. \n\nMeanwhi… https://t.co/q7cuuyxf28", 'Manmohan Singh Ji’s birthday is an opportunity for us to appreciate and remember his many years of selfless service… https://t.co/pSDHlDKlQX', 'To every Air Force officer and Jawan who has served India. To the family of every martyred Indian fighter pilot. To… https://t.co/hRQjahe47v', 'अमेठी जिले के छोटे-छोटे दुकानदारों और किसानों ने, महिलाओं और ठेले-खोमचे-गुमटी वालों ने केरला के बाढ़-पीड़ितों का द… https://t.co/2mYi3Unv8d', "The sad truth about India's Commander in Thief. https://t.co/USrxqlJTWe", 'Mr Jetlie’s speciality is his ability to spin “2 truths”, or lies, with fake self righteousness & indignation to d… https://t.co/VTYOKgZrhf', 'The PM and Anil Ambani jointly carried out a One Hundred & Thirty Thousand Crore, SURGICAL STRIKE on the Indian Def… https://t.co/jS6AenSAgE', 'The PM personally negotiated & changed the #Rafale deal behind closed doors. Thanks to François Hollande, we now kn… https://t.co/P0lRflVz0l', 'The RM (Rafale Minister) tasked with defending corruption has been caught lying again. The former HAL Chief, T S Ra… https://t.co/UVRt56Bz9b', 'आज राजस्थान के डूंगरपुर ज़िला में कांग्रेस के कार्यकर्ताओं और नेताओं के साथ मिलकर आने वाले चुनाव की तैयारीयों में… https://t.co/BvAbbh9AKV', 'Anil’s tragic death in the sewers of Delhi & photographs of his grieving son have made headlines worldwide. Our PM’… https://t.co/xUR8wJ8lRo', 'नरेंद्र मोदी की हुकूमत में तानाशाही एक पेशा बन गया है| बिलासपुर में रमन सिंह की सरकार द्वारा कांग्रेस कार्यकर्ताओं… https://t.co/nONSjMumcp']
In [19]:
result2 = []
for i in range(0, len(result)):
txt = ' '.join(word for word in result[i].split() if not word.startswith("https:")) #removes link
result2.append(txt)
# result3 = ' '.join(word for word in result2)
# result3
In [29]:
def rmv_hindi(test):
result4 = []
for w in result2:
p = re.compile(r'[a-zA-Z]+') #removes hindi words see its a;ternative in twitter analysis fol.
q = p.findall(w)
result4.append(" ".join(q))
result4 = [y for y in result4 if y != ''] #removes all spaceelement
return result4
In [30]:
l = rmv_hindi(result2)
In [31]:
from textblob import TextBlob, Word
from textblob.sentiments import NaiveBayesAnalyzer
In [34]:
#sentiment analysis
dataset = []
#reviewing
for i in range(len(l)):
textB = TextBlob(l[i])
sentiment = textB.sentiment.polarity
#dataset.append(sentiment)
if sentiment< 0.0:
sentiment = "Negative"
dataset.append(sentiment)
elif sentiment > 0:
sentiment = "Positive"
dataset.append(sentiment)
elif sentiment == 0:
sentiment = "Neutral"
dataset.append(sentiment)
In [50]:
#dataset
In [39]:
dataset.count('Positive')
Out[39]:
44
In [40]:
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
In [41]:
p = dataset.count("Positive")
n = dataset.count("Negative")
n0 = dataset.count("Neutral")
In [42]:
label = "Positive Sen.", "Negative Sen.", "Neutral"
size = [p, n, n0]
explode = (0.0, 0.0, 0.1)
colors = ["yellowgreen", "lightcoral", "gold"]
In [43]:
plt.pie(size, explode = explode, colors = colors, labels = label, autopct='%1.1f%%', shadow=True,startangle = 140)
plt.axis("Equal")
plt.title("Tweet analysis of @RahulGandhi")
plt.show()
In [44]:
#import modules for word cloud
from wordcloud import WordCloud, STOPWORDS
from PIL import Image
import numpy as np
In [58]:
#this function creates an wordcloud and saves it to local drive
#to create an word cloud pass an string
def create_word_cloud(text):
#provide image from your drive
mask = np.array(Image.open("rahulg.PNG")) #mask is the shape in which we want wordcloud to be,
stopwords = set(STOPWORDS)
wc = WordCloud(background_color = 'white', mask= mask, max_words = 200, stopwords = stopwords)
wc.generate(text)
wc.to_file(os.path.join('C:\\Users\\Public','rahul-words.png')) #os.path.join helps to save the faile at desired location
In [59]:
#calling the above funtion for wordcloud
create_word_cloud(' '.join(l))
In [ ]:
