Ejemplo n.º 1
0
def to_excel(net, filename, include_empty_tables=False, include_results=True):
    """
    Saves a pandapower Network to an excel file.

    INPUT:
        **net** (dict) - The pandapower format network

        **filename** (string) - The absolute or relative path to the output file

    OPTIONAL:
        **include_empty_tables** (bool, False) - empty element tables are saved as excel sheet

        **include_results** (bool, True) - results are included in the excel sheet

    EXAMPLE:

        >>> pp.to_excel(net, os.path.join("C:", "example_folder", "example1.xlsx"))  # absolute path
        >>> pp.to_excel(net, "example2.xlsx")  # relative path

    """
    writer = pd.ExcelWriter(filename, engine='xlsxwriter')
    dict_net = io_utils.to_dict_of_dfs(
        net,
        include_results=include_results,
        include_empty_tables=include_empty_tables)
    for item, table in dict_net.items():
        table.to_excel(writer, sheet_name=item)
    writer.save()
Ejemplo n.º 2
0
def to_json(net, filename=None):
    """
        Saves a pandapower Network in JSON format. The index columns of all pandas DataFrames will
        be saved in ascending order. net elements which name begins with "_" (internal elements)
        will not be saved. Std types will also not be saved.

        INPUT:
            **net** (dict) - The pandapower format network

            **filename** (string or file) - The absolute or relative path to the output file or file-like object

        EXAMPLE:

             >>> pp.to_json(net, "example.json")

    """
    dict_net = to_dict_of_dfs(net, include_results=False, create_dtype_df=True)
    dict_net["dtypes"] = collect_all_dtypes_df(net)
    json_string = to_json_string(dict_net)
    if hasattr(filename, 'write'):
        filename.write(json_string)
        return
    with open(filename, "w") as text_file:
        text_file.write(json_string)
Ejemplo n.º 3
0
def to_sql(net, con, include_results=True):
    dodfs = io_utils.to_dict_of_dfs(net, include_results=include_results)
    for name, data in dodfs.items():
        data.to_sql(name, con, if_exists="replace")
Ejemplo n.º 4
0
def to_sql(net, con, include_empty_tables=False, include_results=True):
    dodfs = to_dict_of_dfs(net, include_results=include_results)
    dodfs["dtypes"] = collect_all_dtypes_df(net)
    for name, data in dodfs.items():
        data.to_sql(name, con, if_exists="replace")