Last active
July 1, 2022 15:53
-
-
Save jkommera/6765657ad290381a6361500fb1738b10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": { | |
| "hide_input": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import psycopg2\n", | |
| "import pandas\n", | |
| "import pandas.io.sql as psql\n", | |
| "import configparser\n", | |
| "import os" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import pandas as pd\n", | |
| "import numpy as np" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import seaborn as sns\n", | |
| "import matplotlib.pyplot as plt\n", | |
| "import numpy as np" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import plotly.express as px" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def fetchDBCredentials(dbcred_file):\n", | |
| " conf = configparser.ConfigParser()\n", | |
| " conf.read(dbcred_file)\n", | |
| " host = conf.get('database_creds','host')\n", | |
| " port = conf.get('database_creds','port')\n", | |
| " user = conf.get('database_creds','user')\n", | |
| " database = conf.get('database_creds','database')\n", | |
| " password = conf.get('database_creds','password')\n", | |
| " conn_str = \"\"\"dbname='{database}' user='{user}' host='{host}' port='{port}' password='{password}'\"\"\".format(\n", | |
| " database=database,\n", | |
| " host=host,\n", | |
| " port=port,\n", | |
| " user=user,\n", | |
| " password=password)\n", | |
| " return conn_str" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "gpdb_cred_file = os.path.join(os.path.expanduser('C:\\\\Users\\\\jkommera\\\\'), '.dslab_user.cred.txt')\n", | |
| "conn_gpdb = psycopg2.connect(fetchDBCredentials(gpdb_cred_file))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "df=psql.read_sql(\"\"\"SELECT * FROM jkommera.online_persistence_for_charts_details;\"\"\",conn_gpdb)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 8, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "iso_code_data=pd.read_csv('countries_codes_and_coordinates.csv') # country iso 3 codes" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "## Student persistence over terms enrolled" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 8, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "terms_temp_df=df.copy()\n", | |
| "terms_temp_df=terms_temp_df[terms_temp_df['num_sems_enrolled'].notna()]\n", | |
| "terms_temp_df.loc[terms_temp_df['num_sems_enrolled'] >=12, 'num_sems_enrolled'] = '>12'\n", | |
| "terms_temp_df['num_sems_enrolled']=terms_temp_df['num_sems_enrolled'].astype(str) ## not working" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 10, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "terms_enrolled_df = terms_temp_df.groupby('num_sems_enrolled')['persistence_term_1_desc'].value_counts(normalize=True)\n", | |
| "terms_enrolled_df = terms_enrolled_df.mul(100).round(2).rename('Percentage').reset_index()\n", | |
| "terms_enrolled_df.columns=['Terms Enrolled','next_term_enrollement','percentage']" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 11, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| " <script type=\"text/javascript\">\n", | |
| " window.PlotlyConfig = {MathJaxConfig: 'local'};\n", | |
| " if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n", | |
| " if (typeof require !== 'undefined') {\n", | |
| " require.undef(\"plotly\");\n", | |
| " define('plotly', function(require, exports, module) {\n", | |
| " /**\n", | |
| "* plotly.js v1.52.2\n", | |
| "* Copyright 2012-2020, Plotly, Inc.\n", | |
| "* All rights reserved.\n", | |
| "* Licensed under the MIT license\n", | |
| "*/\n", |
Sign in
to join this conversation on GitHub.