[英]What is the easiest way to load a filtered .tda file using pandas?
熊貓具有出色的.read_table()
函數,但大文件會導致MemoryError。
由於只需要加載滿足特定條件的線,因此我正在尋找一種僅加載那些條件的線。
這可以使用一個臨時文件來完成:
with open(hugeTdaFile) as huge:
with open(hugeTdaFile + ".partial.tmp", "w") as tmp:
tmp.write(huge.readline()) # the header line
for line in huge:
if SomeCondition(line):
tmp.write(line)
t = pandas.read_table(tmp.name)
有辦法避免使用臨時文件嗎?
您可以使用chunksize參數返回迭代器
看到這個: http : //pandas.pydata.org/pandas-docs/stable/io.html#iterating-through-files-chunk-by-chunk
(或者,您可以將它們寫到新的csvs或HDFStores或其他內容中)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.