Pandas 係列是帶有軸標簽的一維ndarray。標簽不必是唯一的,但必須是可哈希的類型。該對象同時支持基於整數和基於標簽的索引,並提供了許多方法來執行涉及索引的操作。
Pandas Series.memory_usage()
函數返回該係列的內存使用情況。內存使用情況可以選擇包括索引和對象dtype元素的貢獻。
用法: Series.memory_usage(index=True, deep=False)
參數:
index:指定是否包括係列索引的內存使用情況。
deep:如果為True,則通過查詢對象dtypes進行係統級內存消耗來深入檢查數據,並將其包含在返回值中。
返回:消耗的字節數。
範例1:采用Series.memory_usage()
函數查找給定係列對象的內存使用情況。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([10, 25, 3, 25, 24, 6])
# Create the Index
index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']
# set the index
sr.index = index_
# Print the series
print(sr)
輸出:
現在我們將使用Series.memory_usage()
函數查找給定係列對象的內存使用情況。
# return the memory usage
result = sr.memory_usage()
# Print the result
print(result)
輸出:
正如我們在輸出中看到的,Series.memory_usage()
函數已成功返回給定係列對象的內存使用情況。
範例2:采用Series.memory_usage()
函數查找給定係列對象的內存使用情況。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([19.5, 16.8, None, 22.78, 16.8, 20.124, None, 18.1002, 19.5])
# Print the series
print(sr)
輸出:
現在我們將使用Series.memory_usage()
函數查找給定係列對象的內存使用情況。
# return the memory usage
result = sr.memory_usage()
# Print the result
print(result)
輸出:
正如我們在輸出中看到的,Series.memory_usage()
函數已成功返回給定係列對象的內存使用情況。
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Timestamp.tz用法及代碼示例
- Python Pandas Series.str.contains()用法及代碼示例
- Python Pandas dataframe.std()用法及代碼示例
- Python Pandas Timestamp.dst用法及代碼示例
- Python Pandas dataframe.sem()用法及代碼示例
- Python Pandas DataFrame.ix[ ]用法及代碼示例
- Python Pandas.Categorical()用法及代碼示例
- Python Pandas.apply()用法及代碼示例
- Python Pandas TimedeltaIndex.contains用法及代碼示例
- Python Pandas Timestamp.now用法及代碼示例
- Python Pandas Series.str.pad()用法及代碼示例
- Python Pandas Series.take()用法及代碼示例
- Python Pandas dataframe.all()用法及代碼示例
- Python Pandas series.str.get()用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Series.memory_usage()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。