Hi @blackary - Thanks for the feedback. I tried as you suggested, but it only returned an empty df with the header names, I guess I am not properly passing the arguments to the read_bin()
function that is not able to reference the uploaded file. Could you please have a look at my code below and let me know if you spot what I might be doing wrong?
def read_bin(file):
dt = np.dtype([('col1','d'),('col2','d'),
('col3','d'),('col4','d')])
with NamedTemporaryFile(dir='.',suffix='.bin') as f:
f.write(file.getbuffer())
data = np.fromfile(f.name, dtype=dt, sep='')
df = pd.DataFrame(data)
return df
if options == ls:
if bin_file:
displayBin = st.checkbox('Display File')
if displayBin:
df = read_bin(bin_file)
st.write(df)
I also tried to use shutil
library as suggested here post and it returned an empty df as well: Please see my code here below where I attempted to utilise shutil
.
def read_bin(fl):
dt = np.dtype([('col1','d'),('col2','d'),
('col3','d'),('col4','d')])
with open('par.bin', 'wb') as buffer:
shutil.copyfileobj(fl, buffer)
data = np.fromfile('par.bin', dtype=dt, sep='')
df = pd.DataFrame(data)
return df
if options == ls:
if bin_file:
displayBin = st.checkbox('Display File')
if displayBin:
df = read_bin(bin_file)
st.write(df)
Also, is there no way to read bin files from the uploaded_files
directly just like we can read csv
or other file types without the need for creating a temporary file in buffer?