{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"**Reddit Sentimental Analysis**","metadata":{}},{"cell_type":"markdown","source":"**Importing necessary library**","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd \nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-09-18T06:42:00.002348Z","iopub.execute_input":"2022-09-18T06:42:00.002769Z","iopub.status.idle":"2022-09-18T06:42:00.008683Z","shell.execute_reply.started":"2022-09-18T06:42:00.002729Z","shell.execute_reply":"2022-09-18T06:42:00.007497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Data : Stocks**","metadata":{}},{"cell_type":"code","source":"# The statements are taken from the following url:https://www.reddit.com/r/StockMarket/ for Aug22-Sep22 period\nstocks=[\n    \"Interest rate is going up in two weeks,rent is over the top high,and there's no inventory on homes\",\n    \"when you see charts anywhere\",\n    \"S$P500 is down 20% YTD.I wish houses price were low atleast 20%\",\n    \"A major Fed rate hike risk deflation\",\n    \"FedEx warning drives worst decline in stocks,deepens slowdown fear\",\n    \"Jim Cramer predicts FedEx will have a great year amid strong e-commerce sales\",\n    \"The stock market will fall another 26% if the Fed sparks a recession in its fight against inflation,Goldman Sachs\",\n    \"Just Barely a Green Day but I'll take it\",\n    \"All of my current position for the 215k challenge youtube portfolio! It's been a hell of a ride so far\",\n    \"Wall St on course for bad week in months amid mounting slowdown fears \"\n]","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.041865Z","iopub.execute_input":"2022-09-18T06:42:00.042252Z","iopub.status.idle":"2022-09-18T06:42:00.048152Z","shell.execute_reply.started":"2022-09-18T06:42:00.042221Z","shell.execute_reply":"2022-09-18T06:42:00.047270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Data: Cryptocurrency**","metadata":{}},{"cell_type":"code","source":"# The statements are taken from the following url:https://www.reddit.com/r/CryptoCurrency/ for Aug22-Sep22 period\ncryptocurrencies=[\n    \"'No one is profitable:'GPU Mining faces dark days ahead\",\n    \"Joe Biden Just sends a stark warning to bitcoin and crypto after $ 2trillion price crash\",\n    \"I started accepting moons at my business as a payment method\",\n    \"It looks like Ethereum is now deflationary as the burns rate is at least 5% higher than the reward\",\n    \"Bitcoin better than physical property for  commoners, says Michael Saylor\",\n    \"Ethereum Classic's Hashrate surged  by 280% following merger\",\n    \"Over $320,000,000 liquidated in bitcoin and crypto in just 24 hours, with ethreum most impacted\",\n    \"Financial experts says instititions still invest in crypto regardless of downturn\",\n    \"Binance  CEo praises Biden digital assets policy report amid  industry critcism\",\n    \"Cryptocurrency is virtual property that is  protected by law ,chinese law court rules\"\n]","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.091918Z","iopub.execute_input":"2022-09-18T06:42:00.093130Z","iopub.status.idle":"2022-09-18T06:42:00.098967Z","shell.execute_reply.started":"2022-09-18T06:42:00.093085Z","shell.execute_reply":"2022-09-18T06:42:00.097691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"number_of_statements = len(stocks)\nprint(number_of_statements)\nnumber_of_sentence = len(cryptocurrencies)\nprint(number_of_sentence)","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.100905Z","iopub.execute_input":"2022-09-18T06:42:00.102053Z","iopub.status.idle":"2022-09-18T06:42:00.115826Z","shell.execute_reply.started":"2022-09-18T06:42:00.102012Z","shell.execute_reply":"2022-09-18T06:42:00.114790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"happy_words_stock=['great','Green','excited','happy','wonderful','amazing','best']","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.141995Z","iopub.execute_input":"2022-09-18T06:42:00.143046Z","iopub.status.idle":"2022-09-18T06:42:00.148880Z","shell.execute_reply.started":"2022-09-18T06:42:00.142996Z","shell.execute_reply":"2022-09-18T06:42:00.147615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sad_words_stock=['down','risk','decline','fall','worst','bad']","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.162264Z","iopub.execute_input":"2022-09-18T06:42:00.162959Z","iopub.status.idle":"2022-09-18T06:42:00.167404Z","shell.execute_reply.started":"2022-09-18T06:42:00.162923Z","shell.execute_reply":"2022-09-18T06:42:00.166399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"happy_words_cryptocurrency=['accepting','higher','better','surged','great','protected']","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.262169Z","iopub.execute_input":"2022-09-18T06:42:00.262838Z","iopub.status.idle":"2022-09-18T06:42:00.268753Z","shell.execute_reply.started":"2022-09-18T06:42:00.262791Z","shell.execute_reply":"2022-09-18T06:42:00.267523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sad_words_cryptocurrency=['dark','crash','impacted','criticism','warning']","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.301961Z","iopub.execute_input":"2022-09-18T06:42:00.302412Z","iopub.status.idle":"2022-09-18T06:42:00.307105Z","shell.execute_reply.started":"2022-09-18T06:42:00.302370Z","shell.execute_reply":"2022-09-18T06:42:00.306199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_stock = stocks[0]\nsample_stock","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.317007Z","iopub.execute_input":"2022-09-18T06:42:00.317602Z","iopub.status.idle":"2022-09-18T06:42:00.323444Z","shell.execute_reply.started":"2022-09-18T06:42:00.317568Z","shell.execute_reply":"2022-09-18T06:42:00.322423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"is_stock_happy = False\n\nfor word in happy_words_stock:\n    if word in sample_stock:\n        is_stock_happy = True","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.342060Z","iopub.execute_input":"2022-09-18T06:42:00.342515Z","iopub.status.idle":"2022-09-18T06:42:00.347536Z","shell.execute_reply.started":"2022-09-18T06:42:00.342474Z","shell.execute_reply":"2022-09-18T06:42:00.346414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"is_stock_happy","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.381940Z","iopub.execute_input":"2022-09-18T06:42:00.382426Z","iopub.status.idle":"2022-09-18T06:42:00.390069Z","shell.execute_reply.started":"2022-09-18T06:42:00.382384Z","shell.execute_reply":"2022-09-18T06:42:00.388934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Number of happy stocks**","metadata":{}},{"cell_type":"code","source":"number_of_happy_stocks = 0\n\nfor stock in stocks:\n    for word in happy_words_stock:\n        if word in stock:\n            is_stock_happy = True\n            number_of_happy_stocks += 1 ","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.422304Z","iopub.execute_input":"2022-09-18T06:42:00.422767Z","iopub.status.idle":"2022-09-18T06:42:00.428387Z","shell.execute_reply.started":"2022-09-18T06:42:00.422729Z","shell.execute_reply":"2022-09-18T06:42:00.427285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Number of happy stocks:\",number_of_happy_stocks)","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.435378Z","iopub.execute_input":"2022-09-18T06:42:00.435797Z","iopub.status.idle":"2022-09-18T06:42:00.442570Z","shell.execute_reply.started":"2022-09-18T06:42:00.435761Z","shell.execute_reply":"2022-09-18T06:42:00.441300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"is_stock_sad = False\n\nfor word in sad_words_stock:\n    if word in sample_stock:\n        is_stock_sad = True","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.461866Z","iopub.execute_input":"2022-09-18T06:42:00.462288Z","iopub.status.idle":"2022-09-18T06:42:00.467931Z","shell.execute_reply.started":"2022-09-18T06:42:00.462253Z","shell.execute_reply":"2022-09-18T06:42:00.466557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"is_stock_sad","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.502050Z","iopub.execute_input":"2022-09-18T06:42:00.502480Z","iopub.status.idle":"2022-09-18T06:42:00.509085Z","shell.execute_reply.started":"2022-09-18T06:42:00.502440Z","shell.execute_reply":"2022-09-18T06:42:00.508028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Number of sad stocks**","metadata":{}},{"cell_type":"code","source":"number_of_sad_stocks = 0\n\nfor stock in stocks:\n    for word in sad_words_stock:\n        if word in stock:\n            is_stock_sad = True\n            number_of_sad_stocks += 1 ","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.511503Z","iopub.execute_input":"2022-09-18T06:42:00.511931Z","iopub.status.idle":"2022-09-18T06:42:00.520778Z","shell.execute_reply.started":"2022-09-18T06:42:00.511896Z","shell.execute_reply":"2022-09-18T06:42:00.519762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Number of sad stock:\",number_of_sad_stocks)","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.522823Z","iopub.execute_input":"2022-09-18T06:42:00.523190Z","iopub.status.idle":"2022-09-18T06:42:00.537507Z","shell.execute_reply.started":"2022-09-18T06:42:00.523130Z","shell.execute_reply":"2022-09-18T06:42:00.536089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_crypto = cryptocurrencies[2]\nsample_crypto","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.544018Z","iopub.execute_input":"2022-09-18T06:42:00.544431Z","iopub.status.idle":"2022-09-18T06:42:00.550393Z","shell.execute_reply.started":"2022-09-18T06:42:00.544393Z","shell.execute_reply":"2022-09-18T06:42:00.549553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"is_cryptocurrency_happy = False\n\nfor word in happy_words_cryptocurrency:\n    if word in sample_crypto:\n        is_cryptocurrency_happy = True","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.556958Z","iopub.execute_input":"2022-09-18T06:42:00.557354Z","iopub.status.idle":"2022-09-18T06:42:00.563135Z","shell.execute_reply.started":"2022-09-18T06:42:00.557294Z","shell.execute_reply":"2022-09-18T06:42:00.561994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"is_cryptocurrency_happy","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.602164Z","iopub.execute_input":"2022-09-18T06:42:00.603289Z","iopub.status.idle":"2022-09-18T06:42:00.610153Z","shell.execute_reply.started":"2022-09-18T06:42:00.603239Z","shell.execute_reply":"2022-09-18T06:42:00.608995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Number of happy cryptocurrency**","metadata":{}},{"cell_type":"code","source":"number_of_happy_cryptocurrency = 0\n\nfor cryptocurrency in cryptocurrencies:\n    for word in happy_words_cryptocurrency:\n        if word in cryptocurrency:\n            is_cryptocurrency_happy = True\n            number_of_happy_cryptocurrency += 1","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.613005Z","iopub.execute_input":"2022-09-18T06:42:00.613658Z","iopub.status.idle":"2022-09-18T06:42:00.620992Z","shell.execute_reply.started":"2022-09-18T06:42:00.613613Z","shell.execute_reply":"2022-09-18T06:42:00.619559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Number of happy cryptocurrency:\",number_of_happy_cryptocurrency)","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.627165Z","iopub.execute_input":"2022-09-18T06:42:00.627608Z","iopub.status.idle":"2022-09-18T06:42:00.633749Z","shell.execute_reply.started":"2022-09-18T06:42:00.627564Z","shell.execute_reply":"2022-09-18T06:42:00.632850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Number of sad cryptocurrency**","metadata":{}},{"cell_type":"code","source":"is_cryptocurrency_sad = False\n\nfor word in sad_words_cryptocurrency:\n    if word in sample_stock:\n        is_cryptocurrency_sad = True","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.661879Z","iopub.execute_input":"2022-09-18T06:42:00.662268Z","iopub.status.idle":"2022-09-18T06:42:00.667281Z","shell.execute_reply.started":"2022-09-18T06:42:00.662236Z","shell.execute_reply":"2022-09-18T06:42:00.665869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"number_of_sad_cryptocurrency = 0\n\nfor cryptocurrency in cryptocurrencies:\n    for word in sad_words_cryptocurrency:\n        if word in cryptocurrency:\n            is_cryptocurrency_sad = True\n            number_of_sad_cryptocurrency += 1 ","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.673229Z","iopub.execute_input":"2022-09-18T06:42:00.673651Z","iopub.status.idle":"2022-09-18T06:42:00.679674Z","shell.execute_reply.started":"2022-09-18T06:42:00.673617Z","shell.execute_reply":"2022-09-18T06:42:00.678813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Number of sad cryptocurrency:\",number_of_sad_cryptocurrency)","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.683020Z","iopub.execute_input":"2022-09-18T06:42:00.683806Z","iopub.status.idle":"2022-09-18T06:42:00.691124Z","shell.execute_reply.started":"2022-09-18T06:42:00.683767Z","shell.execute_reply":"2022-09-18T06:42:00.690300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Total fraction of happy and sad stocks** ","metadata":{}},{"cell_type":"code","source":"happy_stocks = number_of_happy_stocks/number_of_statements\nhappy_stocks","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.722031Z","iopub.execute_input":"2022-09-18T06:42:00.722496Z","iopub.status.idle":"2022-09-18T06:42:00.729087Z","shell.execute_reply.started":"2022-09-18T06:42:00.722460Z","shell.execute_reply":"2022-09-18T06:42:00.728176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sad_stocks = number_of_sad_stocks/number_of_statements\nsad_stocks","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.731068Z","iopub.execute_input":"2022-09-18T06:42:00.731827Z","iopub.status.idle":"2022-09-18T06:42:00.740901Z","shell.execute_reply.started":"2022-09-18T06:42:00.731786Z","shell.execute_reply":"2022-09-18T06:42:00.739596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Total fraction of happy and sad cryptocurrency**","metadata":{}},{"cell_type":"code","source":"happy_cryptocurrency = number_of_happy_cryptocurrency/number_of_sentence\nhappy_cryptocurrency","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.743327Z","iopub.execute_input":"2022-09-18T06:42:00.743729Z","iopub.status.idle":"2022-09-18T06:42:00.753616Z","shell.execute_reply.started":"2022-09-18T06:42:00.743694Z","shell.execute_reply":"2022-09-18T06:42:00.752671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sad_cryptocurrency = number_of_sad_cryptocurrency/number_of_sentence\nsad_cryptocurrency","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.755008Z","iopub.execute_input":"2022-09-18T06:42:00.755341Z","iopub.status.idle":"2022-09-18T06:42:00.764356Z","shell.execute_reply.started":"2022-09-18T06:42:00.755293Z","shell.execute_reply":"2022-09-18T06:42:00.763177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Conclusion**","metadata":{}},{"cell_type":"code","source":"if happy_stocks>happy_cryptocurrency and sad_stocks<sad_cryptocurrency:\n    print(\"Stock market has more positive sentiments\")\nelse:\n    print(\"Cryptocurrency market has more positive sentiments\")","metadata":{"execution":{"iopub.status.busy":"2022-09-18T06:42:00.781867Z","iopub.execute_input":"2022-09-18T06:42:00.783029Z","iopub.status.idle":"2022-09-18T06:42:00.789110Z","shell.execute_reply.started":"2022-09-18T06:42:00.782977Z","shell.execute_reply":"2022-09-18T06:42:00.787949Z"},"trusted":true},"execution_count":null,"outputs":[]}]}