Pandas 索引是一個不變的ndarray,它實現了有序的,可切片的集合。它是存儲所有 Pandas 對象的軸標簽的基本對象。
Pandas Index.size
屬性返回給定Index對象的基礎數據中的元素數。
用法: Index.size
參數:沒有
返回:索引中的元素數量
範例1:采用Index.size
屬性以查找給定Index對象的基礎數據中的元素數。
# 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對象中的元素數。
相關用法
- 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 Index.size。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。