📜  Python|熊猫系列.size

📅  最后修改于: 2022-05-13 01:55:37.382000             🧑  作者: Mango

Python|熊猫系列.size

Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。

Pandas 系列是带有轴标签的一维 ndarray。标签不必是唯一的,但必须是可散列的类型。该对象支持基于整数和基于标签的索引,并提供了许多用于执行涉及索引的操作的方法。

Pandas Series.size属性返回给定系列对象的基础数据中的元素数量。

示例 #1:使用Series.size属性查找给定系列对象的基础数据中的元素数。

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series(['New York', 'Chicago', 'Toronto', 'Lisbon', 'Rio'])
  
# Creating the row axis labels
sr.index = ['City 1', 'City 2', 'City 3', 'City 4', 'City 5'] 
  
# Print the series
print(sr)

输出 :

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

# return the number of elements
sr.size

输出 :

正如我们在输出中看到的, Series.size属性返回了 5,表示给定系列对象中有 5 个元素。示例 #2:使用Series.size属性查找给定系列对象的基础数据中的元素数。

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series(['1/1/2018', '2/1/2018', '3/1/2018', '4/1/2018'])
  
# Creating the row axis labels
sr.index = ['Day 1', 'Day 2', 'Day 3', 'Day 4']
  
# Print the series
print(sr)

输出 :

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

# return the number of elements
sr.size

输出 :

正如我们在输出中看到的, Series.size属性返回了 4,表示给定的系列对象中有 4 个元素。