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()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。