Last active
May 1, 2020 06:39
-
-
Save ChengzhiZhao/214ebdfadaac0ac7a612750b155aaebb to your computer and use it in GitHub Desktop.
Slickdeals Analytics with Pandas and Plotly
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 plotly.express as px | |
# Parse Data | |
url="https://raw.githubusercontent.com/ChengzhiZhao/jupyter-notebooks/master/slickdeals_data_file.csv" | |
df=pd.read_csv(url,header=None,names=['datetime','store','title','item_url','deal_price','original_price', 'like', 'comments']) | |
df['datetime'] = pd.to_datetime(df['datetime']) | |
# Data Anlytics# | |
# Frequency | |
frequency_frontdeal = df.groupby(['title'])['title'].agg(['count']).reset_index(drop=False).sort_values(by=['count'],ascending=False) | |
fig = px.bar(frequency_frontdeal.head(20), x='title', y='count') | |
fig.show() | |
# Top Deal Trend By Day | |
airpod = df[df['title']=='Apple AirPods Pro w/ Wireless Charging Case'].sort_values(by=['like']) | |
fig = px.line(airpod, x='datetime', y='like') | |
fig.show() | |
# Why the trend looks like this? | |
airpod.groupby('store')['store'].count() | |
# store | |
# Google Shopping 96 | |
# Verizon Wireless 473 | |
# Name: store, dtype: int64 | |
# With store | |
fig = px.line(airpod, x='datetime', y='like',color='store') | |
fig.show() | |
# Likes and Comments relationship | |
top_10_deals = frequency_frontdeal.head(10) | |
top10_df = df[df['title'].isin(top_10_deals['title'].tolist())] | |
transformed_top10_df_like = top10_df[['datetime','title','like']].rename(columns={'like':'count'}) | |
transformed_top10_df_comments = top10_df[['datetime','title','comments']].rename(columns={'comments':'count'}) | |
transformed_top10_df_like['type'] = 'like' | |
transformed_top10_df_comments['type'] = 'comments' | |
transformed_top10_df = pd.concat([transformed_top10_df_like, transformed_top10_df_comments]) | |
fig = px.line(transformed_top10_df, x='datetime', y='count', color='type',facet_row="title") | |
fig.show() | |
# Animation | |
airpod['day'] = df['datetime'].dt.day | |
fig = px.line(airpod, x='datetime', y='like',color='store', animation_frame='day', animation_group='store') | |
fig.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment