Last active
April 27, 2018 15:03
-
-
Save benspargo89/a2a77f1b4b85c445a359092b9d120389 to your computer and use it in GitHub Desktop.
Yelp Data Graphing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pylab as plt | |
import datetime | |
import seaborn as sns | |
all_data = pd.DataFrame(columns=['Rating', 'Status', 'all', 'Company']) | |
dates = pd.read_excel('nowaitdates.xlsx') | |
companies = dates['Company'].tolist() | |
data = pd.read_excel('new.xlsx') | |
for company in companies: | |
date = dates.loc[dates['Company'] == company]['Date'].iloc[0] | |
data['Rating'] = pd.to_numeric(data['Rating'], downcast='float') | |
df = data.loc[data['Company'] == company].drop('Company', axis=1) | |
df = df.groupby([pd.Grouper(freq='MS',key='Date')]).mean().unstack() | |
df = df.reset_index(level=0, drop=True) | |
before_NoWait = df.loc[df.index < date] | |
after_NoWait = df.loc[df.index > date] | |
de = pd.DataFrame(df) | |
de['k'] = df.index | |
de['Status'] = 'Blank' | |
de['Status'].loc[de['k'] >= date] = 'After NoWait Implementation' | |
de['Status'].loc[de['k'] < date] = 'Before NoWait implementation' | |
de.drop(['k'], axis=1, inplace=True) | |
de.columns = ['Rating', 'Status'] | |
de['all'] = '' | |
de['Company'] = company | |
all_data = pd.concat([all_data, de]) | |
####Seaborn | |
sns.set_style("whitegrid") | |
p = sns.boxplot(x = 'Company', y='Rating', hue='Status', data=all_data, palette="Blues", showmeans=True) | |
p.set_xticklabels(p.get_xticklabels(), rotation=-10) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment