[英]RangeIndex with non-integer step
是否有像 RangeIndex 這樣的熊貓索引子類允許非整數步長? 就像是:
import pandas as pd
pd.RangeIndex(start=0, stop=10, step=.1) # TypeError: Wrong type <class 'float'> for value 0.1
文檔中列出的類似乎不夠用。 IntervalIndex 處理任意范圍,但不明確存儲步長(我打算稍后在我的代碼中訪問)。
您想要一個Float64Index
,但是沒有參數來定義開始/停止/步驟。
最好的可能是使用numpy.arange
:
idx = pd.Index(np.arange(0,10,0.1))
輸出(四舍五入顯示):
Float64Index([ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0,
3.0, 3.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0,
4.0, 4.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0,
7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 8.0, 8.0,
8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 9.0, 9.0,
9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 10.0, 10.0, 10.0, 10.0,
10.0],
dtype='float64')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.