{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "pm_snowflake_daily_top18_dec2021_v1.ipynb", "provenance": [], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "metadata": { "id": "xipxpNzPAl8f" }, "source": [ "\n", "!pip install -I numpy==1.19.2\n", "!pip install snowflake-connector-python\n", "import warnings\n", "warnings.filterwarnings(\"ignore\")\n", "!pip install -I pyarrow==5.0.0\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "L0MjBet4Ravf" }, "source": [ "# import basic data science libraries\n", "\n", "import pandas as pd\n", "import numpy as np\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "SxcPzQwFR9Pk" }, "source": [ "\n", "import snowflake.connector\n", "import getpass\n", "\n", "# using a simpler way to use your login info without embedding it in the notebook \n", "# other enterprise connection patterns (e.g., SSO) are in the Snowflake docs: https://docs.snowflake.com/en/user-guide/python-connector-example.html\n", "snowflake_username = getpass.getpass(\"Enter Snowflake Username\")\n", "snowflake_pwd = getpass.getpass(\"Enter Snowflake Password\")\n", "snowflake_acct = 'nna57244.us-east-1'\n", "\n", "print(snowflake_username)\n", "print(snowflake_acct)\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "tOUWxQAy9iqH", "outputId": "df0c5738-f805-4ba7-897b-eec2fc2bfaf0" }, "source": [ "\n", "ctx = snowflake.connector.connect(\n", " user=snowflake_username,\n", " password=snowflake_pwd,\n", " account=snowflake_acct\n", " )\n", "cs = ctx.cursor()\n", "try:\n", "\tcs.execute(\"SELECT current_version()\")\n", "\tone_row = cs.fetchone()\n", "\tprint(one_row[0])\n", "\n", "\tcs.execute(\"USE DATABASE PREDICTIVE_MAINTENANCE\") \n", "\n", "\tquery_output = cs.execute( \"select top 18 UDI, FAILURE_SCORE from DAILY_SCORED_MACHINES ORDER BY FAILURE_SCORE DESC;\" )\n", "\n", "\tdf_snowflake_scored_data = query_output.fetch_pandas_all() \n", "\n", "\n", "finally:\n", " cs.close()\n", "\n", "\n", "\n", "ctx.close()" ], "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "5.43.1\n" ] } ] }, { "cell_type": "code", "source": [ "df_snowflake_scored_data" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 607 }, "id": "e1khUpc6yySY", "outputId": "05362b09-70a6-46aa-9cb8-49e86eb5923c" }, "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", " | UDI | \n", "FAILURE_SCORE | \n", "
---|---|---|
0 | \n", "4463 | \n", "0.988231 | \n", "
1 | \n", "4418 | \n", "0.985929 | \n", "
2 | \n", "1017 | \n", "0.984222 | \n", "
3 | \n", "4422 | \n", "0.984187 | \n", "
4 | \n", "4481 | \n", "0.983519 | \n", "
5 | \n", "4511 | \n", "0.983505 | \n", "
6 | \n", "8399 | \n", "0.982481 | \n", "
7 | \n", "4534 | \n", "0.982299 | \n", "
8 | \n", "4406 | \n", "0.982265 | \n", "
9 | \n", "4436 | \n", "0.982169 | \n", "
10 | \n", "4502 | \n", "0.982113 | \n", "
11 | \n", "4449 | \n", "0.982031 | \n", "
12 | \n", "4442 | \n", "0.981653 | \n", "
13 | \n", "4537 | \n", "0.981439 | \n", "
14 | \n", "4410 | \n", "0.981367 | \n", "
15 | \n", "4284 | \n", "0.980647 | \n", "
16 | \n", "4401 | \n", "0.979968 | \n", "
17 | \n", "604 | \n", "0.979874 | \n", "