!sudo apt-get update
!sudo apt-get install -y libssl-dev libffi-dev
!pip install --upgrade snowflake-connector-python[pandas]
#We've included an example below to help you get started.
Query_1 = """
SELECT * FROM All_Records_Joined;"""
All_Records_Joined = pd.read_sql(Query_1, conn)
Query_2 = """
SELECT * FROM COMPLETED_DATA_VIEW
"""
Completed_Data_View = pd.read_sql(Query_2, conn)
Query_3 = """
SELECT * FROM Market_Awareness_monthly_growth
"""
Market_Awareness_monthly_growth = pd.read_sql(Query_3, conn)
Query_4 = """
SELECT * FROM Market_Awareness_monthly_growth_rate_pct
"""
Market_Awareness_monthly_growth_rate_pct = pd.read_sql(Query_4, conn)
Query_5 = """
SELECT * FROM Product_Monthly_Growth
"""
Product_Monthly_Growth = pd.read_sql(Query_5, conn)
Query_6 = """
SELECT * FROM divestment_dealership_aggregation
"""
divestment_dealership_aggregation = pd.read_sql(Query_6, conn)
# missing Product_Monthly_Growth_Qtr
import seaborn as sns
import matplotlib.pyplot as plt
Drilling into Slate's Data with Python + Snowflake πβοΈ
All_Records_Joined.columns
Completed_Data_View.columns
Market_Awareness_monthly_growth.columns
Market_Awareness_monthly_growth_rate_pct.columns
Product_Monthly_Growth.columns
divestment_dealership_aggregation.columns
popular_car1=Product_Monthly_Growth.groupby(['MARKETING_DIVISION','MODEL'],as_index=False).sum('PROFITABILITY')
#as_index=False makes the things i grouped back into columns instead of the index
popular_car1.sort_values('PROFITABILITY', ascending=False)
# i think this is best answer by the qtr analysis,
#but for now i will use my monthly data
# would this best be answered by profitabilty total or avg_profit_margin... and WHY?
popular_szn=Product_Monthly_Growth.groupby(['MONTH'],as_index=False).sum('PROFITABILITY')
#as_index=False makes the things i grouped back into columns instead of the index
popular_szn.sort_values('PROFITABILITY', ascending=False)
# Are there any *car products* that have *low growth rates *
# in certain market segments we should consider divesting?
#car model or lux, growth rate, location-- aka marketing division
Product_Monthly_Growth.columns
Product_Monthly_Growth.head(4)
Divestment_geo=Product_Monthly_Growth.groupby(['MARKETING_DIVISION','MODEL'],as_index=False).sum('MONTHLY_GROWTH_RATE')
Divestment_geo2=Divestment_geo.sort_values('MONTHLY_GROWTH_RATE', ascending=True).head(5)
Divestment_geo2
sns.barplot(data=Divestment_geo2,x='MODEL',y='MONTHLY_GROWTH_RATE',hue='MARKETING_DIVISION')
plt.show()
divestment_dealership_aggregation.columns
Divestment_Dealerships=divestment_dealership_aggregation.groupby(['MARKETING_DIVISION','STATE','DEALERSHIP_ID'],as_index=False).mean('AVG_PROFITABILITY_MARGIN_PCT')
Divestment_Dealerships2=divestment_dealership_aggregation.sort_values('AVG_PROFITABILITY_MARGIN_PCT', ascending=True).head(10)
Divestment_Dealerships2
sns.barplot(data=Divestment_Dealerships2,x='DEALERSHIP_ID',y='AVG_PROFITABILITY_MARGIN_PCT',hue='STATE')
sns.set(font_scale = 0.60)
plt.xticks(rotation=90)
plt.show()