def to_data(df, data_type):
    data_type = data_type.strip().lower()

    if data_type == "csv":
        with io.StringIO() as csv:
            df.to_csv(csv)
            return csv.getvalue()

    elif data_type == "html":
        return df.to_html()

    elif data_type == "json":
        df.insert(0, 'idx', df.index.map(str))
        return df.to_json(orient="records", force_ascii=False)

    elif data_type == "table":
        idx = df.index
        if not df.empty and isinstance(idx[0], datetime.datetime):
            idx = idx.map(lambda x: x.strftime("%Y-%m-%d"))
        else:
            idx = idx.map(str)
        df.insert(0, 'idx', idx)

        res = {
            "columns": list(df.keys()),
            "values": json.loads(df.to_json(orient="records",
                                            force_ascii=False)),
            "metadata": df._metadata
        }

        return json.dumps(res)
Create a command to list the names of ports on a bridge
dataset/ETHPy150Open eleme/polaris/polaris/convert.py/to_data--crossover with--dataset/ETHPy150Open openstack/neutron/neutron/agent/ovsdb/api.py/API.list_ports