Snowflake: Python Example

Python

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.

import hsfs
import snowflake.connector
connection = hsfs.connection()
# get a reference to the feature store, you can access also shared feature stores by providing the feature store name
fs = connection.get_feature_store()
connector = fs.get_storage_connector("sfconnector")
Connected. Call `.close()` to terminate connection gracefully.
sfConnectorOptions = connector.snowflake_connector_options()
ctx = snowflake.connector.connect(**sfConnectorOptions)
import pandas as pd
# Query Snowflake Data
cs=ctx.cursor()
allrows=cs.execute("""select CUSTOMER_ID,GENDER,SENIOR_CITIZEN,PARTNER,DEPENDENTS,TENURE,PHONE_SERVICE,
                             MULTIPLE_LINES,INTERNET_SERVICE,ONLINE_SECURITY,ONLINE_BACKUP,DEVICE_PROTECTION,
                             TECH_SUPPORT,STREAMING_TV,STREAMING_MOVIES,CONTRACT,PAPERLESS_BILLING,  
                             PAYMENT_METHOD,MONTHLY_CHARGES,TOTAL_CHARGES,CHURN from CUSTOMER_CHURN """).fetchall()

churn = pd.DataFrame(allrows)
churn.columns=['Customer_Id','Gender','Senior_Citizen','Partner','Dependents','Tenure','Phone_Service',
               'Multiple_Lines','Internet_Service','Online_Security','Online_Backup','Device_Protection',
               'Tech_Support','Streaming_Tv','Streaming_Movies','Contract','Paperless_Billing',
               'Payment_Method','Monthly_Charges','Total_Charges', 'Churn?']

pd.set_option('display.max_columns', 500)     # Make sure we can see all of the columns
pd.set_option('display.max_rows', 10)         # Keep the output on one page
churn
Customer_Id Gender Senior_Citizen Partner Dependents Tenure Phone_Service Multiple_Lines Internet_Service Online_Security Online_Backup Device_Protection Tech_Support Streaming_Tv Streaming_Movies Contract Paperless_Billing Payment_Method Monthly_Charges Total_Charges Churn?
0 7590-VHVEG Female 0 Yes No 1 No No phone service DSL No Yes No No No No Month-to-month Yes Electronic check 29.85 29.85 No
1 5575-GNVDE Male 0 No No 34 Yes No DSL Yes No Yes No No No One year No Mailed check 56.95 1889.5 No
2 3668-QPYBK Male 0 No No 2 Yes No DSL Yes Yes No No No No Month-to-month Yes Mailed check 53.85 108.15 Yes
3 7795-CFOCW Male 0 No No 45 No No phone service DSL Yes No Yes Yes No No One year No Bank transfer (automatic) 42.3 1840.75 No
4 9237-HQITU Female 0 No No 2 Yes No Fiber optic No No No No No No Month-to-month Yes Electronic check 70.7 151.65 Yes
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
7038 6840-RESVB Male 0 Yes Yes 24 Yes Yes DSL Yes No Yes Yes Yes Yes One year Yes Mailed check 84.8 1990.5 No
7039 2234-XADUH Female 0 Yes Yes 72 Yes Yes Fiber optic No Yes Yes No Yes Yes One year Yes Credit card (automatic) 103.2 7362.9 No
7040 4801-JZAZL Female 0 Yes Yes 11 No No phone service DSL Yes No No No No No Month-to-month Yes Electronic check 29.6 346.45 No
7041 8361-LTMKD Male 1 Yes No 4 Yes Yes Fiber optic No No No No No No Month-to-month Yes Mailed check 74.4 306.6 Yes
7042 3186-AJIEK Male 0 No No 66 Yes No Fiber optic Yes No Yes Yes Yes Yes Two year Yes Bank transfer (automatic) 105.65 6844.5 No

7043 rows × 21 columns