<jupyter_start><jupyter_text>This notebook contains all the analyses associated with the Texas dataset (see tx_process_data.ipynb)<jupyter_code>import numpy as np
import pandas as pd
import plotly

plotly.offline.init_notebook_mode(connected=True)
df = pd.read_pickle('./Texas')<jupyter_output><empty_output><jupyter_text>I. Yelp Ratings Over Time<jupyter_code>df_ino_plano = df[(df['restaurant'] == 'In-N-Out') & (df['outlet'] == 'Plano')][['date','rating','content']].copy()
df_ino_plano_sorted = df_ino_plano.sort_values('date')
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
plotly.offline.init_notebook_mode(connected=True)

import pandas as pd

dallas_uptown = go.Scatter(
    x=df_ino_plano_sorted['date'],
    y=df_ino_plano_sorted['rating'],
    name = "PLano",
    marker={'color': 'red', 'symbol': 104, 'size': "10"},
    line={'color': 'blue'},
    mode = 'lines+markers',
    opacity = 0.8)

data = [dallas_uptown]

layout = dict(
    title='Yelp Ratings Over Time (In-N-Out, Plano, TX) ',
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     label='1m',
                     step='month',
                     stepmode='backward'),
                dict(count=6,
                     label='6m',
                     step='month',
                     stepmode='backward'),
                dict(step='all')
            ])
        ),
        rangeslider=dict(),
        type='date'
    )
)

fig = dict(data=data, layout=layout)
plotly.offline.iplot(fig, show_link=False)
pd.set_option('display.max_colwidth', -1)
df_ino_plano_sorted[(df_ino_plano_sorted['date'] > '2017-3-10') & (df_ino_plano_sorted['date'] < '2017-7-20')][['date','content', 'rating']]<jupyter_output><empty_output><jupyter_text>II. Average Yelp Ratings Over Time<jupyter_code>outlets_ino = df[df['restaurant'] == 'In-N-Out']['outlet'].unique().tolist()
outlets_ino
df_ino = df[df['restaurant'] == 'In-N-Out'].copy()<jupyter_output><empty_output><jupyter_text>- create column of rating means for each outlet<jupyter_code>def get_means(df_local, outlet):
    df_outlet = df_local[df_local.outlet == outlet]
    df_outlet_sort = df_outlet[['outlet','date','year','month','day','rating']].sort_values(['year', 'month', 'day'])
    df_index = df_outlet_sort.reset_index()
    nrow = df_index.shape[0]
    df_index['rating_means'] = df_index['rating'].apply(lambda x: 0*x)
    for i in range(nrow):
        if i == 0:
            df_index['rating_means'].iloc[i] = df_index['rating'].iloc[i]
        else:
            df_index['rating_means'].iloc[i] = (1-1/(i+1))*df_index['rating_means'].iloc[i-1] \
            + df_index['rating'].iloc[i]/(i+1)
    return df_index

dframes = []
for outlet in outlets_ino:
    frame = get_means(df_ino, outlet)
    dframes.append(frame)
df_ino_means = pd.concat(dframes)<jupyter_output>/Applications/anaconda/lib/python3.6/site-packages/pandas/core/indexing.py:179: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy<jupyter_text>a. Average Yelp Ratings - Plano, TX<jupyter_code>df_ino_means[df_ino_means.outlet == 'Plano'][['outlet','date','rating', 'rating_means']].head()
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
plotly.offline.init_notebook_mode(connected=True)

import pandas as pd

plano = go.Scatter(
    x=df_ino_means[df_ino_means.outlet == 'Plano'].date,#.sort_values(),
    y=df_ino_means[df_ino_means.outlet == 'Plano']['rating_means'],
    name = "Plano, X",
    line={'color': 'orange'},
    mode = 'lines+markers',
    opacity = 0.8)

data = [plano]

layout = dict(
    title='Average Yelp Rating Over Time (In-N-Out, Plano, TX)',
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     label='1m',
                     step='month',
                     stepmode='backward'),
                dict(count=6,
                     label='6m',
                     step='month',
                     stepmode='backward'),
                dict(step='all')
            ])
        ),
        rangeslider=dict(),
        type='date'
    )
)

fig = dict(data=data, layout=layout)
plotly.offline.iplot(fig, show_link=False)<jupyter_output><empty_output><jupyter_text>b. Average Yelp Ratings - Dallas Upper Greenville (UG), Dallas North, and Plano<jupyter_code>import plotly
import plotly.plotly as py
import plotly.graph_objs as go
plotly.offline.init_notebook_mode(connected=True)

import pandas as pd

dallas_ug = go.Scatter(
    x=df_ino_means[df_ino_means.outlet == 'Dallas UG'].date,#.sort_values(),
    y=df_ino_means[df_ino_means.outlet == 'Dallas UG']['rating_means'],
    name = "Dallas UG",
    line={'color': 'blue'},
    mode = 'lines+markers',
    opacity = 0.8)

dallas_north = go.Scatter(
    x=df_ino_means[df_ino_means.outlet == 'Dallas North'].date,#.sort_values(),
    y=df_ino_means[df_ino_means.outlet == 'Dallas North']['rating_means'],
    name = "D<NAME>",
    line={'color': 'green'},
    mode = 'lines+markers',
    opacity = 0.8)

plano = go.Scatter(
    x=df_ino_means[df_ino_means.outlet == 'Plano'].date,#.sort_values(),
    y=df_ino_means[df_ino_means.outlet == 'Plano']['rating_means'],
    name = "Plano, TX",
    line={'color': 'orange'},
    mode = 'lines+markers',
    opacity = 0.8)


data = [dallas_ug, dallas_north, plano]

layout = dict(
    title='Average Yelp Ratings Over Time (In-N-Out, Texas)',
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     label='1m',
                     step='month',
                     stepmode='backward'),
                dict(count=6,
                     label='6m',
                     step='month',
                     stepmode='backward'),
                dict(step='all')
            ])
        ),
        rangeslider=dict(),
        type='date'
    )
)

fig = dict(data=data, layout=layout)
plotly.offline.iplot(fig, show_link=False)<jupyter_output><empty_output><jupyter_text>- create date_month variable for the next section<jupyter_code>def get_date_month(x):
    return str(x.year) + '-' + str(x.month)

df['date_month'] = df['date'].apply(lambda x: get_date_month(x))
df['date_month'] = pd.to_datetime(df['date_month'])
df_ino_plano = df[(df['restaurant'] == 'In-N-Out') & (df['outlet'] == 'Plano')]<jupyter_output><empty_output><jupyter_text>III. Number of Reviews Per Month<jupyter_code>import matplotlib.pyplot as plt
plt.style.use('ggplot')

%matplotlib inline
plt.rcParams["figure.figsize"] = (20,3)
group_month_ino_plano = df_ino_plano[['date_month','rating']].groupby(['date_month'])
group_month_ino_plano.count().plot(kind='bar', color='orange', title = 'In-N-Out (Plano, TX)');<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup