我用pandas做了一个环形缓冲区,但是内存的使用一直在增长。我做错什么了?在
以下是代码(从问题的第一篇文章开始编辑):
import pandas as pd
import numpy as np
import resource
tempdata = np.zeros((10000,3))
tdf = pd.DataFrame(data=tempdata, columns = ['a', 'b', 'c'])
i = 0
while True:
i += 1
littledf = pd.DataFrame(np.random.rand(1000, 3), columns = ['a', 'b', 'c'])
tdf = pd.concat([tdf[1000:], littledf], ignore_index = True)
del littledf
currentmemory = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
if i% 1000 == 0:
print 'total memory:%d kb' % (int(currentmemory)/1000)
我得到的是:
^{pr2}$不确定是否与此有关:
https://github.com/pydata/pandas/issues/2659
在MacBook Air上测试了Python
与其使用concat,为什么不就地更新数据帧?
i % 10
将确定您向每个更新写入的1000行槽。在相关问题 更多 >
编程相关推荐