I would like to store a pandas DataFrame into a CSV file. The DataFrame has two columns: the first column has strings while the second one stores several arrays.
The problem here is that instead of storing an string and an array per row, the CSV file has two strings per row in the following way:
0004d4463b50_01.jpg,"[ 611461 44 613328 ..., 5 1767504 19]"
An example of my code can be found here:
rle = []
# run test loop with a progress bar
for i, (images, _) in enumerate(loader):
# do some stuff here
# 'rle_local' is a ndarray with more than a thousand elemnts
rle.append(rle_local)
# 'names' contain the strings
df = pd.DataFrame({'strings': names, 'arrays': rle})
df.to_csv(file_path, index=False, compression='gzip')
Any ideas on what is wrong here and why it stores strings instead of the bunch of numbers that the arrays contain?
Thanks in advance!
00087a6bd4dc_01.jpg,879386 40 881253 141 883140 205 885009 17 885032 259 886923 308 888839 328 890754 340 892670 347 894587 352 896503 357 898420 360 900336 364 902253 367 904170 370 906086 374 ...First the string and then all the numbers that are contained in the array....instead of the content...were added by you!rleis a python list while its content type isndarray. Seems like it is storing in the file the ndarray__str__method (like if would doprint (rle[0]))