Get help from the marimo community

Updated last week

Converting csv to dataframe

At a glance

The community member is looking to include a feature in their notebook where a user can import a CSV file and have it automatically converted into a dataframe. They are using mo.ui.file_browser and want to know if there is a way to extract the file path from the FileInfo object.

In the comments, another community member suggests that the file path can be accessed directly using fb.value[0].path, where fb is the mo.ui.file_browser instance. They also provide an alternative approach using mo.ui.file to select the CSV file, and then use pl.read_csv(f.value[0].contents) to read the file contents into a dataframe.

The answer provided by another community member confirms the suggested approach of using fb.value[0].path to get the file path, and also includes the alternative method using mo.ui.file.

I would like to inlcude a feature in my notebook where a user imports a csv and it turns into a dataframe. I'm using mo.ui.file_browser. Is there a way to extract the filepath from FileInfo?
Marked as solution
i think you can get it directly
Plain Text
fb = mo.ui.file_browser()
fb.value[0].path  # gives you path

btw, you can also do this with mo.ui.file
Plain Text
f = mo.ui.file(kind="button", filetypes=[".csv"])

mo.stop(len(f.value) == 0, mo.md("Dataframe viewer"))
df = pl.read_csv(f.value[0].contents)
View full solution
S
1 comment
i think you can get it directly
Plain Text
fb = mo.ui.file_browser()
fb.value[0].path  # gives you path

btw, you can also do this with mo.ui.file
Plain Text
f = mo.ui.file(kind="button", filetypes=[".csv"])

mo.stop(len(f.value) == 0, mo.md("Dataframe viewer"))
df = pl.read_csv(f.value[0].contents)
Add a reply
Sign up and join the conversation on Discord