{ "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", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
UDIFAILURE_SCORE
044630.988231
144180.985929
210170.984222
344220.984187
444810.983519
545110.983505
683990.982481
745340.982299
844060.982265
944360.982169
1045020.982113
1144490.982031
1244420.981653
1345370.981439
1444100.981367
1542840.980647
1644010.979968
176040.979874
\n", "
" ], "text/plain": [ " UDI FAILURE_SCORE\n", "0 4463 0.988231\n", "1 4418 0.985929\n", "2 1017 0.984222\n", "3 4422 0.984187\n", "4 4481 0.983519\n", "5 4511 0.983505\n", "6 8399 0.982481\n", "7 4534 0.982299\n", "8 4406 0.982265\n", "9 4436 0.982169\n", "10 4502 0.982113\n", "11 4449 0.982031\n", "12 4442 0.981653\n", "13 4537 0.981439\n", "14 4410 0.981367\n", "15 4284 0.980647\n", "16 4401 0.979968\n", "17 604 0.979874" ] }, "metadata": {}, "execution_count": 6 } ] } ] }