Python Pandas - 顯示 RangeIndex 的跨度引數值


要在 Pandas 中顯示 RangeIndex 的 step 引數值,請使用 **index.step** 屬性。

首先,匯入所需的庫 -

import pandas as pd

RangeIndex 是 Int64Index 的一種節省記憶體的特殊情況,僅限於表示單調範圍。使用 start、stop 和 step 建立一個範圍索引。name 是要儲存在索引中的名稱。

index = pd.RangeIndex(start=10, stop=30, step=2, name="data")

顯示 step 引數值 -

print("\nRangeIndex step value...\n",index.step)

示例

以下為程式碼 -

import pandas as pd

# RangeIndex is a memory-saving special case of Int64Index limited to representing monotonic ranges.
# Create a range index with start, stop and step
# The name is the name to be stored in the index.
index = pd.RangeIndex(start=10, stop=30, step=2, name="data")

# Display the RangeIndex
print("RangeIndex...\n",index)

# Display the start parameter value
print("\nRangeIndex start value...\n",index.start)

# Display the step parameter value
print("\nRangeIndex step value...\n",index.step)

輸出

這將產生以下輸出 -

RangeIndex...
RangeIndex(start=10, stop=30, step=2, name='data')

RangeIndex start value...
10

RangeIndex step value...
2

更新於: 14-Oct-2021

213 次瀏覽

開啟你的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.