2016-09-15 101 views
0

我在低內存系統上運行Python。如何測量進口熊貓的內存佔用?

我想知道導入的熊貓是否會顯着增加內存使用量。

目前我只想導入熊貓,以便我可以使用date_range函數。

+2

只需導入它並檢查進程的內存使用前後? – user2357112

+0

也可能值得只導入日期範圍函數,而不是輸入整個名稱空間。 – AZhao

+0

@Ginger你問'import pandas'的內存消耗,對不對?對於這個問題,我的回答http://stackoverflow.com/a/43879963/3012255提供了一個腳本和一個基準測試結果。 –

回答

2

您可以嘗試使用pd.DataFrameinfo()方法,這會讓您瞭解內存使用情況。

In [56]: df = pd.DataFrame(data=np.random.rand(5,5), columns=list('ABCDE')) 

In [57]: df 
Out[57]: 
      A   B   C   D   E 
0 0.229201 0.145442 0.214964 0.205609 0.182592 
1 0.709232 0.714943 0.983360 0.635155 0.949378 
2 0.741204 0.532559 0.646229 0.649971 0.686386 
3 0.073047 0.382106 0.121190 0.721732 0.146408 
4 0.904605 0.115031 0.377635 0.377796 0.005747 

In [58]: df.info() 
<class 'pandas.core.frame.DataFrame'> 
RangeIndex: 5 entries, 0 to 4 
Data columns (total 5 columns): 
A 5 non-null float64 
B 5 non-null float64 
C 5 non-null float64 
D 5 non-null float64 
E 5 non-null float64 
dtypes: float64(5) 
memory usage: 280.0 bytes ## <- check here! 

我希望這有助於!

3

您可能還想使用Memory Profiler來了解分配給Pandas對象的內存量。有幾種Python Memory Profiler可以使用(一個簡單的Google搜索可以給你一個想法)。 PySizer是我剛纔使用的一個。

0

@Ginger我有完全相同的問題。所以我設置了一個簡單的函數來導入熊貓並使用memory-profiler。結論:大約30-36MB的內存被用來在我的機器YMMV上導入熊貓。

看看這篇文章我寫在how much memory pandas import takes,你可以用它來測試你的機器。