New to panel = looking to load CSV file into dataframe / Pandas

Hi i have seen a few instances of how to use the file loader to pull CSV into a panel dataframe (HOXBRO had an easy one)… Ideally, i would like to pull it into a DataFrame in pandas so i can manipulate it better - is there an easy way to do that or should i just do all the manipulations on the panel dataframe? Im moving a application that was using pandas to panel… sorry for such a novice question, maybe its the bind aspect thats messing me up…

workflow would be user picks the CSV
loads into the program
dataframe manipulations
output to panel - into an existing tab layout as one of the tabs…(which should be in a tabulator). seems here if i have the tab created, i cant seem to get the data to appear here…

Does this help?
https://hvplot.holoviz.org/user_guide/Interactive.html

Hi @jsegrich

I is not clear to me how exactly you want to pull CSV into a dataframe. But here is an example that uses the FileInput widget and Tabulator table.

This enables the user to input a csv file and view it in a table.

from io import StringIO

import pandas as pd
import panel as pn


def to_dataframe(value):
    if not value or not isinstance(value, bytes):
        return pd.DataFrame()

    string_io = StringIO(value.decode("utf8"))
    return pd.read_csv(string_io)


file_input = pn.widgets.FileInput(sizing_mode="fixed")
table = pn.widgets.Tabulator(pn.bind(to_dataframe, file_input))

layout = pn.Column(file_input, table)

if pn.state.served:
    pn.extension("tabulator", sizing_mode="stretch_width")

    pn.template.FastListTemplate(site="Panel", title="CSV FileInput", main=[layout]).servable()

trees.csv (849 Bytes)

Versions: Panel=1.1.1

@Marc thank so much - this gets me most of the way. issue i am having now is that i have a tab layout with these tables and wanted to “refresh” the table when loaded - feels like i need to recreate the tab vs changing the underlying dataframe? when its not in a TAB, it does seem to refresh with load

1 Like

Hi @jsegrich

If you could provide a minimum, reproducible example of the issue we could take a look. Would that be possible?