<jupyter_start><jupyter_text>This file shows how to read the data from the database to a pandas dataframe<jupyter_code># All the imports
import pandas as pd
import sqlalchemy
import os, sys
import matplotlib.pyplot as plt
# Import the config
import config
# Create a database engine - this is used to connect to the database
db_connection_string = "postgresl://" + config.DB_USER + ":" + config.DB_PWD + "@" + config.DB_ADDRESS + ":" + config.DB_PORT + "/" + config.DB_NAME
# Example db_connection_string - "postgresql://tsdb_user:husky123@localhost:5432/demand_acep"
db = sqlalchemy.create_engine(db_connection_string)
# Create the meter_collection for the meters from our config file
meter_collection = {}

for meter_name in config.METER_CHANNEL_DICT:
    for year in config.DATA_YEARS:
        # Get the table name - which is of the format - "metername_year" and then read from the database into pandas dataframe
        # "*" selects all columns, column names can be specified if not all columns are desired
        meter_collection[meter_name + "_" + str(year)] = pd.read_sql('select * from public."' + meter_name + "_" + str(year) + '"', db)
meter_collection.keys()
meter_collection['PkFltM1Ant_2017'].info()
plt.plot(meter_collection['PkFltM1Ant_2017']['Vab'])
# Saving the data as csv
for meter in meter_collection:
    meter_collection[meter].to_csv(meter + ".csv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10113960113960115, 'fraction_numerical': 0.012108262108262107, 'mean_word_length': 5.004273504273504, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '547387', 'license': 'MIT', 'n_tokens_mistral': 463, 'n_tokens_neox': 435, 'n_words': 134, 'path': 'scripts/read_sql.ipynb', 'repo_name': 'reconjohn/demand_acep', 'size': '1404'}