1

I made program that takes csv files and count mean values. I try to make interface in streamlit. I try to use solution from my program

data = st.file_uploader("Wybierz pliki CSV:",type = 'csv', accept_multiple_files=True)
for file in data:
   Table = pd.read_csv(file, sep=',')
   DF1 = pd.DataFrame(Table)
   DFL = pd.concat([DFL,DF1], sort=False)

When i try to print this using st.dataframe(DFL) I get this error:

StreamlitAPIException: ("Could not convert '06028001018' with type str: tried to convert to int64", 'Conversion failed for column LPROS1 with type object')

Anyone know how to concat it ?

maciej.o
  • 127
  • 1
  • 13

3 Answers3

2

StreamlitAPIException: ("Could not convert '06028001018' with type str: tried to convert to int64", 'Conversion failed for column LPROS1 with type object')

It’s a bug that came with streamlit 0.85.0. pyarrow has an issue with numpy.dtype values (which df.dtypes returns).

As a workaround you can add the below lines to your code

DF2 = DFL.astype(str)
st.dataframe(DFL2)

or try other suggested workaround from here

How to fix StreamlitAPIException: ("Expected bytes, got a 'int' object", 'Conversion failed for column FG% with type object')

Ailurophile
  • 2,552
  • 7
  • 21
  • 46
1

Try this way:

data = st.file_uploader("Wybierz pliki CSV:",type = 'csv', 
accept_multiple_files=True)
Table = []
for file in data:
    if file.endswith(".csv"):
         Table.append(pd.read_csv(file)

df = pd.concat(Table, sort=False)
Egor K
  • 15
  • 3
  • I try your code but i get the same error. – maciej.o Mar 16 '22 at 12:51
  • Try without .endswith(".csv") – Egor K Mar 16 '22 at 12:53
  • I tryed but i get error :StreamlitAPIException: ("Could not convert '06028001018' with type str: tried to convert to int64", 'Conversion failed for column LPROS1 with type object'). It is the same error as at the begining. – maciej.o Mar 16 '22 at 13:06
0

Recheck your error message.

StreamlitAPIException: ("Could not convert '06028001018' with type str: tried to convert to int64", 'Conversion failed for column LPROS1 with type object')

It is about the data type in column LPROS1.

ferdy
  • 4,396
  • 2
  • 4
  • 16
  • Ok but I don't convert this column, I don't know why streamlit try to convert it. I just want to make one big DF. – maciej.o Mar 23 '22 at 13:07