From 157175c08d09a751031ef7013f5f65a8c3186b93 Mon Sep 17 00:00:00 2001 From: Shivani Yadav Date: Mon, 13 May 2024 14:58:04 +0530 Subject: [PATCH] Added Modified File --- Movie_review_imdb_scrapping.ipynb | 76 +++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/Movie_review_imdb_scrapping.ipynb b/Movie_review_imdb_scrapping.ipynb index 6389ebfa..c89119c8 100644 --- a/Movie_review_imdb_scrapping.ipynb +++ b/Movie_review_imdb_scrapping.ipynb @@ -22,16 +22,42 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: textblob in c:\\users\\umesh\\anaconda3.x\\lib\\site-packages (0.18.0.post0)\n", + "Requirement already satisfied: nltk>=3.8 in c:\\users\\umesh\\anaconda3.x\\lib\\site-packages (from textblob) (3.8.1)\n", + "Requirement already satisfied: click in c:\\users\\umesh\\anaconda3.x\\lib\\site-packages (from nltk>=3.8->textblob) (8.0.4)\n", + "Requirement already satisfied: joblib in c:\\users\\umesh\\anaconda3.x\\lib\\site-packages (from nltk>=3.8->textblob) (1.2.0)\n", + "Requirement already satisfied: regex>=2021.8.3 in c:\\users\\umesh\\anaconda3.x\\lib\\site-packages (from nltk>=3.8->textblob) (2022.7.9)\n", + "Requirement already satisfied: tqdm in c:\\users\\umesh\\anaconda3.x\\lib\\site-packages (from nltk>=3.8->textblob) (4.65.0)\n", + "Requirement already satisfied: colorama in c:\\users\\umesh\\appdata\\roaming\\python\\python311\\site-packages (from click->nltk>=3.8->textblob) (0.4.6)\n" + ] + }, + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'textblob'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[5], line 7\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mrandom\u001b[39;00m \n\u001b[0;32m 6\u001b[0m get_ipython()\u001b[38;5;241m.\u001b[39msystem(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mpip install textblob\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m----> 7\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mtextblob\u001b[39;00m\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'textblob'" + ] + } + ], "source": [ "\n", "import pandas as pd\n", "import numpy as np\n", "import itertools #to create efficent looping to fetch more data in a go\n", "import re \n", - "import random " + "import random \n", + "from textblob import TextBlob" ] }, { @@ -778,6 +804,48 @@ " g.close()" ] }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'TextBlob' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[6], line 22\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[38;5;66;03m# Example usage:\u001b[39;00m\n\u001b[0;32m 21\u001b[0m text \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mI absolutely loved this movie! It was fantastic.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m---> 22\u001b[0m sentiment \u001b[38;5;241m=\u001b[39m \u001b[43manalyze_sentiment\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtext\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 23\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSentiment:\u001b[39m\u001b[38;5;124m\"\u001b[39m, sentiment)\n\u001b[0;32m 24\u001b[0m \u001b[38;5;66;03m# Assuming df is your DataFrame containing the reviews\u001b[39;00m\n", + "Cell \u001b[1;32mIn[6], line 10\u001b[0m, in \u001b[0;36manalyze_sentiment\u001b[1;34m(text)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21manalyze_sentiment\u001b[39m(text):\n\u001b[0;32m 2\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;124;03m Analyzes the sentiment of the input text.\u001b[39;00m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;124;03m \u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[38;5;124;03m - 'neutral' if sentiment polarity == 0\u001b[39;00m\n\u001b[0;32m 9\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 10\u001b[0m blob \u001b[38;5;241m=\u001b[39m \u001b[43mTextBlob\u001b[49m(text)\n\u001b[0;32m 11\u001b[0m polarity \u001b[38;5;241m=\u001b[39m blob\u001b[38;5;241m.\u001b[39msentiment\u001b[38;5;241m.\u001b[39mpolarity\n\u001b[0;32m 13\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m polarity \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", + "\u001b[1;31mNameError\u001b[0m: name 'TextBlob' is not defined" + ] + } + ], + "source": [ + "def analyze_sentiment(text):\n", + " \"\"\"\n", + " Analyzes the sentiment of the input text.\n", + " \n", + " Returns:\n", + " - 'positive' if sentiment polarity > 0\n", + " - 'negative' if sentiment polarity < 0\n", + " - 'neutral' if sentiment polarity == 0\n", + " \"\"\"\n", + " blob = TextBlob(text)\n", + " polarity = blob.sentiment.polarity\n", + " \n", + " if polarity > 0:\n", + " return 'positive'\n", + " elif polarity < 0:\n", + " return 'negative'\n", + " else:\n", + " return 'neutral'\n", + "\n", + "# Assuming df is your DataFrame containing the reviews\n", + "df['sentiment'] = df['user_review'].apply(analyze_sentiment)\n" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -818,7 +886,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.1" + "version": "3.11.4" }, "orig_nbformat": 4 },