Python|熊猫索引. size

原文:https://www.geeksforgeeks.org/python-pandas-index-size/

熊猫索引是一个实现有序的、可切片的集合的不可变数组。它是存储所有熊猫对象的轴标签的基本对象。

Pandas **Index.size**属性返回给定索引对象的基础数据中的元素数量。

语法:索引.大小

参数:

返回:索引中的元素数量

示例#1: 使用Index.size属性查找给定索引对象的基础数据中的元素数量。

# importing pandas as pd
import pandas as pd

# Creating the index
idx = pd.Index(['Melbourne', 'Sanghai', 'Lisbon', 'Doha', 'Moscow', 'Rio'])

# Print the index
print(idx)

输出:

现在我们将使用Index.size属性来查找给定 Index 对象中的元素数量。

# return the number of elements
result = idx.size

# Print the result
print(result)

输出: 正如我们在输出中看到的,Index.size属性已经返回了给定 Index 对象中的元素数量。

示例 2 : 使用Index.size属性查找给定 Index 对象的底层数据中的元素数量。

# importing pandas as pd
import pandas as pd

# Creating the index
idx = pd.Index([900 + 3j, 700 + 25j, 620 + 10j, 388 + 44j, 900])

# Print the index
print(idx)

输出:

现在我们将使用Index.size属性来查找给定 Index 对象中的元素数量。

# return the number of elements
result = idx.size

# Print the result
print(result)

输出: 正如我们在输出中看到的,Index.size属性已经返回了给定 Index 对象中的元素数量。