Question
If possible, convert the sqlite3 portion of the script below into a python script that does the exact same thing (can use any python libraries).
If possible, convert the sqlite3 portion of the script below into a python script that does the exact same thing (can use any python libraries). The Python script would be referencing a Pandas Data Frame with the same data and structure as the database the sql refers to. The original assignment question read as follows: "Add to each customer's record whether the customer has any form of each of the following credit cards: AMEX, Discover, VISA, and Mastercard. Create for each type of card whether a customer has one with a "Y" or a "N". Document your creation of these codes by showing how they are related to the code values in the data."
Here is the SQLITE3 query that should be converted into a python script.
# PART 3.b) Indicate whether customer has Visa, Mastercard, AMEX, Disc with a Y' or "N. Can be 4 columns #create a query to display the creditcard details and execute cursor cur concursor() # curser required to execute a SQL statement or query cur.execute(""" SELECT acctno, CASE WHEN ((amex_prem IS NOT NULL AND amex prem- 'Y") or (amex_reg is not null and amex_reg-'Y")) THEN 'Y ELSE 'N END AS AMEX, CASE WHEN ((visa-prem IS NOT NULL AND visa-prem='Y') or (visa_reg is not null and visa_reg-'Y")) THEN 'Y ELSE N END AS VISA, CASE WHEN ((mc_prem IS NOT NULL AND mc_prem-'Y') or (mc_reg is not null and mc_reg-'Y')) THEN Y ELSE 'N END AS MASTER CASE WHEN ((disc_prem IS NOT NULL AND disc_prem-'Y") or (disc reg is not null and disc reg='Y')) THEN Y ELSE 'N END AS DISCOVERY FROM customer" " ") #curfetchaLL() will fetche the rows from the cursor df-creditcard = pd . DataFrame(cur .fetchall()) #get the column names from cursor using cur.description and add to the datatraem field names = [ifaj for i in cur.description df creditcard . columns field names In [58]: df_creditCard ut [58] acctno AMEX VISA MASTER DISCOVERY 0 SSYSPDHQH 1WQSDDAWQS HHSSPSD 3 PHLHSYLWP 4 PSDSQYYDW # PART 3.b) Indicate whether customer has Visa, Mastercard, AMEX, Disc with a Y' or "N. Can be 4 columns #create a query to display the creditcard details and execute cursor cur concursor() # curser required to execute a SQL statement or query cur.execute(""" SELECT acctno, CASE WHEN ((amex_prem IS NOT NULL AND amex prem- 'Y") or (amex_reg is not null and amex_reg-'Y")) THEN 'Y ELSE 'N END AS AMEX, CASE WHEN ((visa-prem IS NOT NULL AND visa-prem='Y') or (visa_reg is not null and visa_reg-'Y")) THEN 'Y ELSE N END AS VISA, CASE WHEN ((mc_prem IS NOT NULL AND mc_prem-'Y') or (mc_reg is not null and mc_reg-'Y')) THEN Y ELSE 'N END AS MASTER CASE WHEN ((disc_prem IS NOT NULL AND disc_prem-'Y") or (disc reg is not null and disc reg='Y')) THEN Y ELSE 'N END AS DISCOVERY FROM customer" " ") #curfetchaLL() will fetche the rows from the cursor df-creditcard = pd . DataFrame(cur .fetchall()) #get the column names from cursor using cur.description and add to the datatraem field names = [ifaj for i in cur.description df creditcard . columns field names In [58]: df_creditCard ut [58] acctno AMEX VISA MASTER DISCOVERY 0 SSYSPDHQH 1WQSDDAWQS HHSSPSD 3 PHLHSYLWP 4 PSDSQYYDWStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started