1
我想將一個pandas DataFrame存儲到一個CSV文件中。 DataFrame有兩列:第一列有字符串,而第二列存儲幾個數組。熊貓寫入到csv而不是數組的字符串
這裏的問題是,而不是存儲的字符串,每行一個數組中,CSV文件每行兩個字符串按以下方式:
0004d4463b50_01.jpg,"[ 611461 44 613328 ..., 5 1767504 19]"
我的代碼的例子可以在這裏找到:
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')
對什麼是錯在這裏的任何想法,爲什麼它存儲字符串,而不是數字,陣列包含的一羣?
在此先感謝!
希望的輸出將是'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 ...'首先是字符串,然後是數組中包含的所有數字。 –
我不認爲我能夠通過解析字符串來恢復數組,因爲它存儲'...'而不是內容 –
哦,我明白了,我以爲'...'是由您添加的! – IanS