{ "cells": [ { "source": [ "# Python\n", "Additional options are not supported in python. If you have additional options in your connector you need to add then to the \"sfConnectorOptions\" with the correct key name." ], "cell_type": "markdown", "metadata": {} }, { "cell_type": "code", "execution_count": 2, "id": "joined-lodge", "metadata": {}, "outputs": [], "source": [ "import hsfs\n", "import snowflake.connector" ] }, { "cell_type": "code", "execution_count": 2, "id": "interesting-tower", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connected. Call `.close()` to terminate connection gracefully.\n" ] } ], "source": [ "connection = hsfs.connection()\n", "# get a reference to the feature store, you can access also shared feature stores by providing the feature store name\n", "fs = connection.get_feature_store()\n", "connector = fs.get_storage_connector(\"sfconnector\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "alive-rehabilitation", "metadata": {}, "outputs": [], "source": [ "sfConnectorOptions = connector.snowflake_connector_options()" ] }, { "cell_type": "code", "execution_count": 5, "id": "brutal-washer", "metadata": {}, "outputs": [], "source": [ "ctx = snowflake.connector.connect(**sfConnectorOptions)" ] }, { "cell_type": "code", "execution_count": 6, "id": "biblical-wedding", "metadata": {}, "outputs": [ { "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", " \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", " \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", "
Customer_IdGenderSenior_CitizenPartnerDependentsTenurePhone_ServiceMultiple_LinesInternet_ServiceOnline_SecurityOnline_BackupDevice_ProtectionTech_SupportStreaming_TvStreaming_MoviesContractPaperless_BillingPayment_MethodMonthly_ChargesTotal_ChargesChurn?
07590-VHVEGFemale0YesNo1NoNo phone serviceDSLNoYesNoNoNoNoMonth-to-monthYesElectronic check29.8529.85No
15575-GNVDEMale0NoNo34YesNoDSLYesNoYesNoNoNoOne yearNoMailed check56.951889.5No
23668-QPYBKMale0NoNo2YesNoDSLYesYesNoNoNoNoMonth-to-monthYesMailed check53.85108.15Yes
37795-CFOCWMale0NoNo45NoNo phone serviceDSLYesNoYesYesNoNoOne yearNoBank transfer (automatic)42.31840.75No
49237-HQITUFemale0NoNo2YesNoFiber opticNoNoNoNoNoNoMonth-to-monthYesElectronic check70.7151.65Yes
..................................................................
70386840-RESVBMale0YesYes24YesYesDSLYesNoYesYesYesYesOne yearYesMailed check84.81990.5No
70392234-XADUHFemale0YesYes72YesYesFiber opticNoYesYesNoYesYesOne yearYesCredit card (automatic)103.27362.9No
70404801-JZAZLFemale0YesYes11NoNo phone serviceDSLYesNoNoNoNoNoMonth-to-monthYesElectronic check29.6346.45No
70418361-LTMKDMale1YesNo4YesYesFiber opticNoNoNoNoNoNoMonth-to-monthYesMailed check74.4306.6Yes
70423186-AJIEKMale0NoNo66YesNoFiber opticYesNoYesYesYesYesTwo yearYesBank transfer (automatic)105.656844.5No
\n", "

7043 rows × 21 columns

\n", "
" ], "text/plain": [ " Customer_Id Gender Senior_Citizen Partner Dependents Tenure \\\n", "0 7590-VHVEG Female 0 Yes No 1 \n", "1 5575-GNVDE Male 0 No No 34 \n", "2 3668-QPYBK Male 0 No No 2 \n", "3 7795-CFOCW Male 0 No No 45 \n", "4 9237-HQITU Female 0 No No 2 \n", "... ... ... ... ... ... ... \n", "7038 6840-RESVB Male 0 Yes Yes 24 \n", "7039 2234-XADUH Female 0 Yes Yes 72 \n", "7040 4801-JZAZL Female 0 Yes Yes 11 \n", "7041 8361-LTMKD Male 1 Yes No 4 \n", "7042 3186-AJIEK Male 0 No No 66 \n", "\n", " Phone_Service Multiple_Lines Internet_Service Online_Security \\\n", "0 No No phone service DSL No \n", "1 Yes No DSL Yes \n", "2 Yes No DSL Yes \n", "3 No No phone service DSL Yes \n", "4 Yes No Fiber optic No \n", "... ... ... ... ... \n", "7038 Yes Yes DSL Yes \n", "7039 Yes Yes Fiber optic No \n", "7040 No No phone service DSL Yes \n", "7041 Yes Yes Fiber optic No \n", "7042 Yes No Fiber optic Yes \n", "\n", " Online_Backup Device_Protection Tech_Support Streaming_Tv \\\n", "0 Yes No No No \n", "1 No Yes No No \n", "2 Yes No No No \n", "3 No Yes Yes No \n", "4 No No No No \n", "... ... ... ... ... \n", "7038 No Yes Yes Yes \n", "7039 Yes Yes No Yes \n", "7040 No No No No \n", "7041 No No No No \n", "7042 No Yes Yes Yes \n", "\n", " Streaming_Movies Contract Paperless_Billing \\\n", "0 No Month-to-month Yes \n", "1 No One year No \n", "2 No Month-to-month Yes \n", "3 No One year No \n", "4 No Month-to-month Yes \n", "... ... ... ... \n", "7038 Yes One year Yes \n", "7039 Yes One year Yes \n", "7040 No Month-to-month Yes \n", "7041 No Month-to-month Yes \n", "7042 Yes Two year Yes \n", "\n", " Payment_Method Monthly_Charges Total_Charges Churn? \n", "0 Electronic check 29.85 29.85 No \n", "1 Mailed check 56.95 1889.5 No \n", "2 Mailed check 53.85 108.15 Yes \n", "3 Bank transfer (automatic) 42.3 1840.75 No \n", "4 Electronic check 70.7 151.65 Yes \n", "... ... ... ... ... \n", "7038 Mailed check 84.8 1990.5 No \n", "7039 Credit card (automatic) 103.2 7362.9 No \n", "7040 Electronic check 29.6 346.45 No \n", "7041 Mailed check 74.4 306.6 Yes \n", "7042 Bank transfer (automatic) 105.65 6844.5 No \n", "\n", "[7043 rows x 21 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "# Query Snowflake Data\n", "cs=ctx.cursor()\n", "allrows=cs.execute(\"\"\"select CUSTOMER_ID,GENDER,SENIOR_CITIZEN,PARTNER,DEPENDENTS,TENURE,PHONE_SERVICE,\n", " MULTIPLE_LINES,INTERNET_SERVICE,ONLINE_SECURITY,ONLINE_BACKUP,DEVICE_PROTECTION,\n", " TECH_SUPPORT,STREAMING_TV,STREAMING_MOVIES,CONTRACT,PAPERLESS_BILLING, \n", " PAYMENT_METHOD,MONTHLY_CHARGES,TOTAL_CHARGES,CHURN from CUSTOMER_CHURN \"\"\").fetchall()\n", "\n", "churn = pd.DataFrame(allrows)\n", "churn.columns=['Customer_Id','Gender','Senior_Citizen','Partner','Dependents','Tenure','Phone_Service',\n", " 'Multiple_Lines','Internet_Service','Online_Security','Online_Backup','Device_Protection',\n", " 'Tech_Support','Streaming_Tv','Streaming_Movies','Contract','Paperless_Billing',\n", " 'Payment_Method','Monthly_Charges','Total_Charges', 'Churn?']\n", "\n", "pd.set_option('display.max_columns', 500) # Make sure we can see all of the columns\n", "pd.set_option('display.max_rows', 10) # Keep the output on one page\n", "churn" ] }, { "cell_type": "code", "execution_count": null, "id": "elder-carnival", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" } }, "nbformat": 4, "nbformat_minor": 5 }