Data Inspection -2

Back To Index

Aim : Inspect variables: ‘marital’, ‘job’

0_data_inspection_2
In [3]:
###################################################
#  Filename : 0_data_inspection_2                 #
#  Purpose : To demonstrate data inspection       #
#   using Euler toolkit                           #
#            1. Inspect variable 'marital'        # 
#            2. Inspect variable 'job'            #
#  Author : Niel S.                               #
#  (c) The English Tea Company LLC                #
###################################################

#Following lines add Euler into the search path
import sys
sys.path.append('C:\\Users\\singa72\\Desktop\\Euler\\')
from Euler import Euler as Eu

data_folder = 'C:\\Users\\singa72\\Desktop\\Tutorial2\\bank-additional\\bank-additional\\'
data_work   = data_folder+'data_work.db'

#M A I N   F U N C T I O N
def main():
    conn = Eu.connection(data_work)
    try:        
        sql = '''
        SELECT sql FROM sqlite_master
        WHERE tbl_name = 'bank' AND type = 'table'
        ''' 
        Eu.run(sql,conn)
        
        #Calling inspect marital function
        inspect_marital(conn)
        
        #Exercise: Following function needs fixing
        inspect_job(conn)
        
    except Exception as err:
        Eu.print_error(err)
    finally:
        conn.close()

def inspect_marital(conn):
    '''
    This function examines
    the variable 'marital'
    '''
    try:
        #A look at the 'marital'
        sql = '''
        select distinct marital from bank
        '''
        Eu.run(sql,conn)
                
        #Order the results by descending order of people
        sql = '''
        select marital,
        count(*) n_people 
        from bank
        group by marital 
        order by n_people desc
        '''
        Eu.run(sql,conn)
    except Exception as err:
        Eu.print_error(err)


def inspect_job(conn):
    '''
    This function examines
    the variable 'job'
    '''
    try:
        """
        Exercise: Fix this function
            so that it runs.
        """
        
        #A look at the 'marital'
        sql = '''
        select distinct ?var? from bank
        '''
        Eu.run(sql,conn)
                
        #Order the results by descending order of people
        sql = '''
        select ?var?,count(*) n_people from bank
        group by ?var? order by n_people desc
        '''
        Eu.run(sql,conn)
    except Exception as err:
        Eu.print_error(err)
        


if __name__ == '__main__':
    main()
************************************************
*                    EULER                     *
*    A SQLITE POWERED DATA SCIENCE TOOLKIT     *
*          SINGH.AP79@GMAIL.NOSPAM.COM         *
************************************************

===
sql
===
CREATE TABLE bank ( 
age       VARCHAR,
 job       VARCHAR,
 marital       VARCHAR,
 education       VARCHAR,
 deflt       VARCHAR,
 housing       VARCHAR,
 loan       VARCHAR,
 contact       VARCHAR,
 month       VARCHAR,
 day_of_week       VARCHAR,
 duration       VARCHAR,
 campaign       VARCHAR,
 pdays       VARCHAR,
 previous       VARCHAR,
 poutcome       VARCHAR,
 emp_var_rate       VARCHAR,
 cons_price_idx       VARCHAR,
 cons_conf_idx       VARCHAR,
 euribor_m       VARCHAR,
 nr_employed       VARCHAR,
 y       VARCHAR
 )
===

=======
marital
=======
married
single
divorced
unknown
=======

================
marital,n_people
================
married,24928
single,11568
divorced,4612
unknown,80
================



****Exception Encountered****

Not Happy With 

        select distinct ?var? from bank
        
  File "C:\Users\singa72\Desktop\Euler\Euler.py", line 171, in run
    results = conn.cursor().execute(query)


****Exception Encountered****

Not Happy With 

        select ?var?,count(*) n_people from bank
        group by ?var? order by n_people desc
        
  File "C:\Users\singa72\Desktop\Euler\Euler.py", line 171, in run
    results = conn.cursor().execute(query)
ERROR (Euler.run):  near "?": syntax error
ERROR (Euler.run):  near "?": syntax error

Back To Index