Key Investment Insights
<|endoftext|>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 1 12:03:08 2018
This script contains functions used to extract data from the MIMIC-III database
and save it as a .csv file. The functions are designed to be called from the
main script, run.py.
The functions in this script require the following libraries:
- pandas
- numpy
- psycopg2
- getpass
- os
"""
# Import libraries
import pandas as pd
import numpy as np
import psycopg2
import getpass
import os
# Define functions
def get_data(query):
"""
This function connects to the MIMIC-III database and executes a SQL query
to extract data. The function returns the data as a pandas dataframe.
The function requires the following libraries:
- psycopg2
- getpass
Parameters
----------
query : str
SQL query to extract data from the MIMIC-III database.
Returns
-------
df : pandas dataframe
Data extracted from the MIMIC-III database as a pandas dataframe.
"""
# Get username and password
username = input('Enter username: ')
password = getpass.getpass('Enter password: ')
# Connect to the database
try:
conn = psycopg2.connect(dbname='mimic', user=username, password=password)
except:
print('Could not connect to database')
# Execute the SQL query
cur = conn.cursor()
cur.execute(query)
# Get column names
col_names = [desc[0] for desc in cur.description]
# Get data
data = cur.fetchall()
# Close the connection
conn.close()
# Convert to dataframe
df = pd.DataFrame(data
Management Rights Multiplier: 4.57
ROI Estimate: 21.90%