python memory usage_Python Pandas Index.memory_usage()用法及代码示例
Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態系統。 Pandas是其中的一種,使導入和分析數據更加容易。
Pandas Index.memory_usage()函數返回索引的內存使用情況。它返回索引中存在的所有單個標簽所使用的內存總和。
用法: Index.memory_usage(deep=False)
參數:
deep:深入反思數據,詢問對象dtype以獲取系統級內存消耗
返回:使用的字節
范例1:采用Index.memory_usage()函數查找Index對象使用的總內存。
# importing pandas as pd
import pandas as pd
# Creating the Index
idx = pd.Index(['Labrador', 'Beagle', 'Mastiff', 'Lhasa', 'Husky', 'Beagle'])
# Print the Index
idx
輸出:
現在我們將使用Index.memory_usage()函數查找idx對象的內存使用情況。
# finding the memory used by the idx object
idx.memory_usage()
輸出:
該函數返回的值48表示正在使用48個字節的內存。
范例2:采用Index.memory_usage()函數檢查MultiIndex對象的內存使用情況。
# importing pandas as pd
import pandas as pd
# Creating the MutiIndex
midx = pd.MultiIndex.from_arrays([['Mon', 'Tue', 'Wed', 'Thr'], [10, 20, 30, 40]],
names =('Days', 'Target'))
# Print the MultiIndex
midx
輸出:
現在,我們將檢查midx對象使用的內存量。
# return the total memory used by the multi-index object
midx.memory_usage()
輸出:
從輸出中可以看到,該函數返回了180,表示midx對象正在使用180個字節的內存。
總結
以上是生活随笔為你收集整理的python memory usage_Python Pandas Index.memory_usage()用法及代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: layui多个file与提交同时进行_如
- 下一篇: 下载python需要注意什么_用户在对P