!sudo apt-get update
!sudo apt-get install -y libssl-dev libffi-dev
Get:1 http://security.debian.org/debian-security buster/updates InRelease [34.8 kB]
Get:2 http://deb.debian.org/debian buster InRelease [122 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [56.6 kB]
E: Repository 'http://security.debian.org/debian-security buster/updates InRelease' changed its 'Suite' value from 'stable' to 'oldstable'
N: This must be accepted explicitly before updates for this repository can be applied. See apt-secure(8) manpage for details.
N: Repository 'http://deb.debian.org/debian buster InRelease' changed its 'Version' value from '10.9' to '10.13'
E: Repository 'http://deb.debian.org/debian buster InRelease' changed its 'Suite' value from 'stable' to 'oldstable'
N: This must be accepted explicitly before updates for this repository can be applied. See apt-secure(8) manpage for details.
E: Repository 'http://deb.debian.org/debian buster-updates InRelease' changed its 'Suite' value from 'stable-updates' to 'oldstable-updates'
N: This must be accepted explicitly before updates for this repository can be applied. See apt-secure(8) manpage for details.
libffi-dev is already the newest version (3.2.1-9).
libffi-dev set to manually installed.
Suggested packages:
libssl-doc
The following NEW packages will be installed:
libssl-dev
The following packages will be upgraded:
libssl1.1
1 upgraded, 1 newly installed, 0 to remove and 18 not upgraded.
Need to get 3,333 kB of archives.
After this operation, 8,073 kB of additional disk space will be used.
Err:1 http://security.debian.org/debian-security buster/updates/main amd64 libssl1.1 amd64 1.1.1d-0+deb10u6
404 Not Found [IP: 146.75.38.132 80]
Err:2 http://security.debian.org/debian-security buster/updates/main amd64 libssl-dev amd64 1.1.1d-0+deb10u6
404 Not Found [IP: 146.75.38.132 80]
E: Failed to fetch http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.1_1.1.1d-0+deb10u6_amd64.deb 404 Not Found [IP: 146.75.38.132 80]
E: Failed to fetch http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl-dev_1.1.1d-0+deb10u6_amd64.deb 404 Not Found [IP: 146.75.38.132 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
!pip install --upgrade snowflake-connector-python[pandas]
Collecting snowflake-connector-python[pandas]
Downloading snowflake_connector_python-2.9.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21.3 MB)
|ββββββββββββββββββββββββββββββββ| 21.3 MB 41.1 MB/s
Requirement already satisfied, skipping upgrade: idna<4,>=2.5 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (3.4)
Requirement already satisfied, skipping upgrade: oscrypto<2.0.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (1.3.0)
Requirement already satisfied, skipping upgrade: cffi<2.0.0,>=1.9 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (1.15.1)
Requirement already satisfied, skipping upgrade: asn1crypto<2.0.0,>0.24.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (1.5.1)
Requirement already satisfied, skipping upgrade: cryptography<41.0.0,>=3.1.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (36.0.2)
Requirement already satisfied, skipping upgrade: filelock<4,>=3.5 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (3.8.0)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (2022.9.24)
Requirement already satisfied, skipping upgrade: urllib3<1.27,>=1.21.1 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (1.26.12)
Requirement already satisfied, skipping upgrade: pycryptodomex!=3.5.0,<4.0.0,>=3.2 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (3.15.0)
Requirement already satisfied, skipping upgrade: typing-extensions<5,>=4.3 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (4.4.0)
Requirement already satisfied, skipping upgrade: requests<3.0.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (2.28.1)
Requirement already satisfied, skipping upgrade: pyjwt<3.0.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (2.6.0)
Requirement already satisfied, skipping upgrade: pytz in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (2022.5)
Requirement already satisfied, skipping upgrade: charset-normalizer<3,>=2 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (2.1.1)
Requirement already satisfied, skipping upgrade: setuptools>34.0.0 in /root/venv/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (47.1.0)
Requirement already satisfied, skipping upgrade: pyOpenSSL<23.0.0,>=16.2.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (22.0.0)
Collecting pyarrow<8.1.0,>=8.0.0; extra == "pandas"
Downloading pyarrow-8.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.3 MB)
|ββββββββββββββββββββββββββββββββ| 29.3 MB 120.8 MB/s
Requirement already satisfied, skipping upgrade: pandas<1.6.0,>=1.0.0; extra == "pandas" in /shared-libs/python3.7/py/lib/python3.7/site-packages (from snowflake-connector-python[pandas]) (1.2.5)
Requirement already satisfied, skipping upgrade: pycparser in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from cffi<2.0.0,>=1.9->snowflake-connector-python[pandas]) (2.21)
Requirement already satisfied, skipping upgrade: numpy>=1.16.6 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pyarrow<8.1.0,>=8.0.0; extra == "pandas"->snowflake-connector-python[pandas]) (1.21.6)
Requirement already satisfied, skipping upgrade: python-dateutil>=2.7.3 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from pandas<1.6.0,>=1.0.0; extra == "pandas"->snowflake-connector-python[pandas]) (2.8.2)
Requirement already satisfied, skipping upgrade: six>=1.5 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from python-dateutil>=2.7.3->pandas<1.6.0,>=1.0.0; extra == "pandas"->snowflake-connector-python[pandas]) (1.16.0)
Installing collected packages: pyarrow, snowflake-connector-python
Attempting uninstall: pyarrow
Found existing installation: pyarrow 9.0.0
Not uninstalling pyarrow at /shared-libs/python3.7/py/lib/python3.7/site-packages, outside environment /root/venv
Can't uninstall 'pyarrow'. No files were found to uninstall.
Attempting uninstall: snowflake-connector-python
Found existing installation: snowflake-connector-python 2.7.9
Not uninstalling snowflake-connector-python at /shared-libs/python3.7/py/lib/python3.7/site-packages, outside environment /root/venv
Can't uninstall 'snowflake-connector-python'. No files were found to uninstall.
Successfully installed pyarrow-8.0.0 snowflake-connector-python-2.9.0
WARNING: You are using pip version 20.1.1; however, version 22.3.1 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
#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)
MARKETING_DIVISIONobject
Pacific9.2%
South Atlantic9.2%
9 others81.7%
MODELobject
A89.2%
A69.2%
9 others81.7%
75
Pacific
A8
73
Pacific
A6
68
Pacific
A11
84
South Atlantic
A6
67
Pacific
A10
118
West South Central
A8
86
South Atlantic
A8
31
Mid Atlantic
A8
18
East South Central
A6
9
East North Central
A8
# 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)
MONTHint64
1 - 12
TOTAL_VEHICLES_SOLDint64
83708 - 146799
0
1
143456
2
3
130921
6
7
135715
8
9
141541
9
10
108491
11
12
118372
5
6
117149
7
8
124155
4
5
110984
3
4
83708
# 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)
MONTHint64
MARKETING_DIVISIONobject
0
6
South Atlantic
1
7
South Atlantic
2
11
South Atlantic
3
12
South Atlantic
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
MARKETING_DIVISIONobject
MODELobject
95
South Central
A7
65
New England
A9
97
South Central
A9
20
East South Central
A8
94
South Central
A6
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()