我是一名有用的助手,可以为您进行文本翻译。
我有一个非常简单的Python脚本,它读取CSV文件并根据时间戳对行进行排序。但是,该文件足够大(16 GB),导致其读取使用了完全的RAM内存。当它达到100%(即64 GB RAM内存)时,我的系统完全冻结,我被迫重新启动计算机。
以下是代码:
我有一个非常简单的Python脚本,它读取CSV文件并根据时间戳对行进行排序。但是,该文件足够大(16 GB),导致其读取使用了完全的RAM内存。当它达到100%(即64 GB RAM内存)时,我的系统完全冻结,我被迫重新启动计算机。
以下是代码:
import pandas as pd
from time import time
filename = 'AKER_OB.csv'
start_ = time()
file_ = pd.read_csv(filename)
end_ = time()
duration = end_ - start_
print("The duration to load that file : {}".format(duration))
file_.to_datetime(df['TimeStamps'], format="%Y-%m-%d %H:%M:%S").sort_values()
AKER_OB.csv
的头部:
TimeStamp,Bid1,BidSize1,Bid2,BidSize2,Bid3,BidSize3,Bid4,BidSize4,Bid5,BidSize5,Bid6,BidSize6,Bid7,BidSize7,Bid8,BidSize8,Bid9,BidSize9,Bid10,BidSize10,Bid11,BidSize11,Bid12,BidSize12,Bid13,BidSize13,Bid14,BidSize14,Bid15,BidSize15,Bid16,BidSize16,Bid17,BidSize17,Bid18,BidSize18,Bid19,BidSize19,Bid20,BidSize20,Ask1,AskSize1,Ask2,AskSize2,Ask3,AskSize3,Ask4,AskSize4,Ask5,AskSize5,Ask6,AskSize6,Ask7,AskSize7,Ask8,AskSize8,Ask9,AskSize9,Ask10,AskSize10,Ask11,AskSize11,Ask12,AskSize12,Ask13,AskSize13,Ask14,AskSize14,Ask15,AskSize15,Ask16,AskSize16,Ask17,AskSize17,Ask18,AskSize18,Ask19,AskSize19,Ask20,AskSize20
2016-10-08 00:00:00,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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