# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/souradeepta/Clustering-on-Amazon-Food-Reviews/blob/master/NLP_HW3.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="vrx6202yzAe8" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 122} outputId="d931f165-947e-4609-9c90-290de353fe81"
from google.colab import drive
drive.mount('/content/drive')

# + [markdown] id="I1eVVetMD1DW" colab_type="text"
# https://github.com/labdhi-ghelani/Sentiment-analysis-for-Yelp-review-classification/blob/master/Sentiment-analysis-for-Yelp-review-classification.ipynb

# + id="ZD_6fB8DC3tV" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 51} outputId="a6b0e97a-b707-4cb7-8f37-a8cd35744e2a"
# Load the Pandas libraries with alias 'pd' 
import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

import nltk
from nltk.corpus import stopwords
import string
import nltk
nltk.download('stopwords')

# %matplotlib inline
# %config InlineBackend.figure_format='retina'

# + [markdown] id="auxr8hlA30pU" colab_type="text"
# Loading the data into a pandas dataframe

# + id="HKOCbFiHyn0T" colab_type="code" colab={}


url = "https://raw.githubusercontent.com/souradeepta/Clustering-on-Amazon-Food-Reviews/master/corpus.csv"
# Read data from file 
# (in the same directory that your python process is based)
# Control delimiters, rows, column names with read_csv (see later) 
data = pd.read_csv(url) 


# + [markdown] id="Ou_3ez0J4B92" colab_type="text"
# Previewing the how the dataset looks like. Note pandas always treats the first row as a header

# + id="yMJ1yVYV3mIU" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 204} outputId="1424875d-f644-44b9-f41a-e6c98624c325"
# Preview the first 5 lines of the loaded data 
data.head()

# + [markdown] id="9FFwMe_54Bh-" colab_type="text"
#

# + [markdown] id="sdHP7j9B4N3n" colab_type="text"
# Here we shall again see the number of columns in our dataset as two. First one being the name of the business and second one being the review text

# + id="AWuIAjLt3LGD" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} outputId="aa14e48d-0ae3-4775-94c9-1e0fc640d5c1"
data.columns

# + [markdown] id="WM6NSa5a4ThY" colab_type="text"
# Here we shall see the number of rows in our dataset

# + id="-ppKIC_8yxHl" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} outputId="cb6f0f07-07a1-4636-a3f0-417fe3bd8804"
data.index

# + [markdown] id="oDAQDYaK4rQI" colab_type="text"
# Data frame size returns the number of rows times number of columns

# + id="KpUhpcRk3TUp" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} outputId="4d2dc634-2c79-445c-de2d-d10d26fb0945"
data.size

# + id="iHrbTi44DqW2" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 136} outputId="3becd1db-5f44-4c37-b127-eb3b3b7de6f0"
data.info()

# + [markdown] id="9gyVz6Ni6oFs" colab_type="text"
# For a string object, the result’s index will include count, unique, top, and freq. The top is the most common value. The freq is the most common value’s frequency. 

# + id="aa1FrhQl4lL3" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 173} outputId="d4bc5db4-0b36-44a6-d5a0-4688d3609f39"
data.describe()

# + [markdown] id="CjWoAQps6mlE" colab_type="text"
# Here we see the average length of the review grouped by business name

# + id="35zzI1oq6B_j" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 238} outputId="b1a9a813-3a2c-43a3-b6ea-b06940ad0252"
data.groupby('business_name').review_text.apply(lambda x: x.str.split().str.len().mean())

# + id="aE_yNFbG8Fm7" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 238} outputId="53084c94-4c62-44b5-a57b-9b344ab6f468"
data.review_text.str.len().groupby(data.business_name).mean()

# + id="wbz2Za6i-TuC" colab_type="code" colab={}
data['review_text_length'] = data['review_text'].apply(len)

# + id="HfOYhaxqECLL" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 204} outputId="8b2e4f3f-2947-4e9f-d45a-ef53df8e07d6"
data.head()

# + id="0LHqiC-iEDcr" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 714} outputId="28a8379b-12b8-4866-a678-b7eb55373b7d"
g = sns.FacetGrid(data=data, col='business_name')
g.map(plt.hist, 'review_text_length', bins=50, color='#28546E')
plt.savefig('stars_textlen', dpi=200)

# + id="rl0bYYA2EMgb" colab_type="code" colab={}


StarcoderdataJupyterScriptsDedupFiltered