How to: load a CSV file located inside a Python package - gmlc-dispatches/dispatches GitHub Wiki

For this example, the file lmp_forecasts_concat.csv is located in the package idaes.apps.grid_integration.examples.

try:
    # Pyton 3.8+
    from importlib import resources
except ImportError:
    # Python 3.7
    import importlib_resources as resources
    
import pandas as pd


def get_data() -> pd.DataFrame:
    with resources.open_text("idaes.apps.grid_integration.examples", "lmp_forecasts_concat.csv") as f:
        df = pd.read_csv(f)
    return df