text_plain_output_1.png image_output_1.png
import sqlite3

import matplotlib.pyplot as plt
import numpy as np
import sqlite3
from sklearn import tree
def sql_query(s):
    """Return results for a SQL query.
    Arguments:
    s (str) -- SQL query string
    Returns:
    (list) -- SQL query results
    """
    conn = sqlite3.connect('../input/database.sqlite')
    c = conn.cursor()
    c.execute(s)
    result = c.fetchall()
    conn.close()
    return result
def print_details():
    """Print database details including table names and the number of rows.
    """
    table_names = sql_query('SELECT name FROM sqlite_master ' + "WHERE type='table' " + 'ORDER BY name;')[0][0]
    print('Names of tables in SQLite database: {0}'.format(table_names))
    num_rows = sql_query('SELECT COUNT(*) FROM loan;')[0][0]
    print('Number of records in table: {0}'.format(num_rows))
def print_column_names():
    """Print the column names in the 'loan' table.
    Note that the "index" column name is specific to Python and is not part of
    the original SQLite database.
    """
    conn = sqlite3.connect('../input/database.sqlite')
    conn.row_factory = sqlite3.Row
    c = conn.cursor()
    c.execute('SELECT * FROM loan LIMIT 2;')
    r = c.fetchone()
    i = 1
    print('Column names:')
    for k in r.keys():
        print('{0:d}\t{1}'.format(i, k))
        i += 1
    conn.close()
print_details()
print_column_names()