<reponame>esjimenezro/trading-bot
import pandas as pd
import sqlite3


def load_data(db_path, table, p_key=None, top=None):
    """
    This function loads the top registers data from table in the DB located in db_path, whose primary key is p_key.
    :param str db_path: DB location path.
    :param str table: Name of the table.
    :param str p_key: Table primary key.
    :param int top: Number of registers to load.
    :return: pd.DataFrame with loaded data.
    """
    with sqlite3.connect(db_path) as conn:
        _ = conn.cursor()
        query = f"""
            SELECT * FROM {table} 
                {f"ORDER BY {p_key} DESC " if p_key is not None else ""}
                {f"LIMIT {top};" if top is not None else ";"}
            """
        extraction_df = pd.read_sql(query, conn)
        extraction_df.sort_values(by=p_key, inplace=True, ascending=True)
        return extraction_df

import pandas as pd
import sqlite3


def load_data(db_path, table, p_key=None, top=None):
    """
    This function loads the top registers data from table in the DB located in db_path, whose primary key is p_key.
    :param str db_path: DB location path.
    :param str table: Name of the table.
    :param str p_key: Table primary key.
    :param int top: Number of registers to load.
    :return: pd.DataFrame with loaded data.
    """
    with sqlite3.connect(db_path) as conn:
        _ = conn.cursor()
        query = f"""
            SELECT * FROM {table} 
                {f"ORDER BY {p_key} DESC " if p_key is not None else ""}
                {f"LIMIT {top};" if top is not None else ";"}
            """
        extraction_df = pd.read_sql(query, conn)
        extraction_df.sort_values(by=p_key, inplace=True, ascending=True)
        return extraction_df
This function loads the top registers data from table in the DB located in db_path, whose primary key is p_key.     :param str db_path: DB location path.     :param str table: Name of the table.     :param str p_key: Table primary key.     :param int top: Number of registers to load.     :return: pd.DataFrame with loaded data. SELECT * FROM {table}                  {f"ORDER BY {p_key} DESC " if p_key is not None else ""}                 {f"LIMIT {top};" if top is not None else ";"}