How to access the data in a panel DataFrame?

Hello – I am very new to Holoviz and Panel. I would like to create a dashboard that lets a user select the data file and then creates plots based on the data in the selected file. The code below creates the interactive object.

file_selection = pn.widgets.Select(options=file_choices)

def get_data_from_file(file):
return pd.read_csv(path+file, parse_dates=[‘timestamp’], index_col=‘timestamp’)

interactive_file = hvplot.bind(get_data_from_file, file_selection).interactive()

interactive_file

Now I want to do data manipulation on the data that is stored in the interactive_file object.

type(interactive_file.panel().object())

returns a panel.pane.markup.DataFrame object.

I understand that this is not the same as a pandas DataFrame…but can I access the data stored in this object and use it like a pandas DataFrame?

Can someone point me to example code? Thank you.

interactive_file should still have the DataFrame as the underlaying object. You should be able to access pandas methods with interactive_file. <press tab>.

Hi @Mehmet

Welcome to the community.

You can work with the interactive_file as if it was a DataFrame. Then you can decide whether to display the .widgets, the .panel or both.

Here is an example

import panel as pn
import pandas as pd
import hvplot.pandas

pn.extension()

file_selection = pn.widgets.Select(options=["file1", "file2"])

def get_data_from_file(file):
    return pd.DataFrame({
        file: [1,2]
    })

interactive_file = hvplot.bind(get_data_from_file, file_selection).interactive()

## Here we continue transforming the data
def transform(df):
    return df+2

transformed_df = interactive_file.pipe(transform)

## Layout stuff: You can get the .widgets only or the .panel only
pn.Column("## All", interactive_file, "## Transformed Widgets", transformed_df.widgets(), "## Transformed Panel", transformed_df.panel()).servable()