How to use multiple files loaded with file_uploader

Hi,
I would like to know how can I access the files uploaded with st.file_uploader.
I wrote these lines of code:

 with st.sidebar:
     path = st.file_uploader("Choose a CSV file", accept_multiple_files=True)
     for uploaded_file in path:
         uploaded_file = pd.read_csv(uploaded_file, sep=';', decimal=',')

I am trying to load 4 .csv files. They are loaded but then I don’t know how can I access them to keep working on those files.
For example, one of those files is called “vertical.csv”. How can I use that specific file after being imported?

if you set accept_multiple_files = True
you will get a list of files.
so if you want to deal the files, you can do like this:

for i in range(len(path)):
    df = pd.read_csv(path[i])
    st.table(df)

you will see 4 csv files be printed in your browser.

2 Likes

Thank you for your answer.
I tried to use your code but it didn’t work very well. The following error was shown EmptyDataError: No columns to parse from file.
I know that if I set accept_multiple_files = True I will get a list of files. The problem is, for example, I load 4 .csv files. Then I want to get access to each file. For example, one is called “vertical.csv”. How can I access that specific file to remove its first column? Is there any way to choose the file by its name after load all the files?

you can get the file name by do this:
st.write(path[i].name)

1 Like

Thank you very much

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.