我有一個方法在兩個不同的系統上的行爲不同的熊貓上使用數據幀。雖然試圖加載並與特定的源CSV我得到一個Windows Server計算機上的內存錯誤與RAM和16GB,但不是我的本地計算機只用12有更多內存的服務器上的熊貓MemoryError
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 numpy的:1.9.2 顯然是使用32位的蟒蛇,而我的本地機器是64位 2.7.8兩個
可能是愚蠢的問題都運行64位Python?他們正在運行什麼版本的numpy,熊貓? – EdChum
0.16.0兩臺機器上的熊貓,必須在本地檢查其餘的 – lathomas64
64bit,在服務器上檢查32bit。 – lathomas64