Python Pandas - 返回底层索引数据中的字节数
pythonpandasserver side programmingprogramming更新于 2025/12/30 23:40:17
要返回底层索引数据中的字节数,请使用 index.nbytes 属性。
首先,导入所需的库 −
import pandas as pd
创建索引 −
index = pd.Index([15, 25, 35, 45, 55])
显示索引 −
print("Pandas Index...\n",index)
获取数据中的字节数 −
print("\nReturn the bytes...\n",index.nbytes)
示例
以下是代码 −
import pandas as pd
# 创建索引
index = pd.Index([15, 25, 35, 45, 55])
# 显示索引
print("Pandas Index...\n",index)
# 返回表示 Index 中数据的数组
print("\n数组...\n",index.values)
# 返回底层形状的元组数据
print("\n底层数据形状的元组...\n",index.shape)
# 获取数据中的字节
print("\n返回字节...\n",index.nbytes)
输出
将产生以下代码 −
Pandas Index... Int64Index([15, 25, 35, 45, 55], dtype='int64') 数组... [15 25 35 45 55] 底层数据形状的元组... (5,) 返回字节... 40
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

