【问题标题】:Pandas MemoryError on server with more Memory服务器上有更多内存的 Pandas MemoryError
【发布时间】:2015-07-11 09:36:45
【问题描述】:

我有一种方法可以处理 pandas 上的数据帧,它在 2 个不同的系统上表现不同。在尝试加载和使用特定源 csv 时,我在具有 16gb ram 的 Windows Server 机器上出现内存错误,但在只有 12gb 的本地计算机上却没有

def load_table(self, name, source_folder="", columns=None):
    """Load a table from memory or csv by name.

    loads a table from memory or csv. if loaded from csv saves the result
    table to the temporary list. An explicit call to save_table is
    necessary if the results want to survive clearing temporary storage
    @param string name the name of the table to load
    @param string sourceFolder the folder to look for the csv if the table
        is not already in memory
    @return DataFrame returns a DataFrame representing the table if found.
    @raises IOError if table cannot be loaded
    """
    #using copy in these first two to avoid modification of existing data
    #without an explicit save_table
    if name in self.tables:
        result = self.tables[name].copy()
    elif name in self.temp_tables:
        result = self.temp_tables[name].copy()
    elif os.path.isfile(name+".csv"):
        data_frame = pd.read_csv(name+".csv", encoding="utf-8")
        self.save_temp(data_frame, name)
        result = data_frame
    elif os.path.isfile(name+".xlsx"):
        data_frame = pd.read_excel(name+".xlsx", encoding="utf-8")
        self.save_temp(data_frame, name)
        result = data_frame
    elif os.path.isfile(source_folder+name+".csv"):
        data_frame = pd.read_csv(source_folder+name+".csv", encoding="utf-8")
        self.save_temp(data_frame, name)
        result = data_frame
    elif os.path.isfile(source_folder+name+".xlsx"):
        data_frame = pd.read_excel(source_folder+name+".xlsx", encoding="utf-8")
        self.save_temp(data_frame, name)
        result = data_frame

save_temp 是这样的:

def save_temp(self, data_frame, name):
        """ save a table to the temporary storage

        @param DataFrame data_frame, the data frame we are storing
        @param string name, the key to index this value
        @throws ValueError throws an error if the data frame is empty
        """
        if data_frame.empty:
            raise ValueError("The data frame passed was empty", name, data_frame)
        self.temp_tables[name] = data_frame.copy()

有时 memoryError 发生在我尝试在交互式解释器中手动加载此文件的 read_csv 上,该文件有效,然后将其保存到此处引用的表字典中。然后尝试在副本上执行 load_table 错误。

获取手动加载的数据帧并在其上调用 .copy() 也会产生 MemoryError,服务器框上没有文本,但本地没有。

服务器机器运行的是 Windows Server 2012 R2,而我的本地机器是 Windows 7

两者都是 64 位机器

服务器是 2.20GHz,有 2 个处理器,而我的本地机器是 3.4GHz 服务器:16GB 内存 本地:12GB 内存

将 .copy() 更改为 .copy(False) 允许代码在服务器机器上运行,但没有回答为什么首先会在具有更多内存的机器上出现 MemoryError 的问题。

编辑添加: 两者都在使用 熊猫:0.16.0 麻木:1.9.2 服务器显然使用 32 位 python,而我的本地机器是 64 位 2.7.8 两者

【问题讨论】:

  • 可能愚蠢的问题都在运行 64 位 python?他们还运行什么版本的 numpy、pandas?
  • 0.16.0 pandas 在两台机器上,必须检查其余的
  • 本地64位,服务器32位。
  • 那么 32 位 python 很难加载一个大文件,你能在服务器上运行 64 位版本吗?
  • 将尝试在那里获得 64 位 python,有没有一种简单的方法可以用 pip 和 hte 来做到这一点?无法从此框上的网站直接下载。

标签: python memory pandas deep-copy windows-server-2012-r2


【解决方案1】:

所以您的问题是,尽管使用相同版本的 pandas 和 64 位操作系统,但您有 32 位 python,其内存限制为 2gb。

【讨论】:

    猜你喜欢
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 2018-11-29
    • 2016-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多