Python Pandas - 返回與當前相同的區間陣列,但在指定的一側閉合
要返回與當前相同的區間陣列,但在指定的一側閉合,請使用 **array.set_closed()** 並將引數設定為 **both**。
首先,匯入所需的庫 -
import pandas as pd
從類似陣列的分裂中構造一個新的 IntervalArray -
array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5])
顯示區間 -
print("Our IntervalArray...\n",array)與當前相同的區間陣列,但在指定的一側閉合 -
print("\nAn identical IntervalArray closed on the specified side...\n", array.set_closed('both'))示例
以下是程式碼 -
import pandas as pd
# Construct a new IntervalArray from an array-like of splits
array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5])
# Display the IntervalArray
print("Our IntervalArray...\n",array)
print("\nAn identical IntervalArray closed on the specified side...\n", array.set_closed('both'))輸出
這將生成以下程式碼 -
Our IntervalArray... <IntervalArray> [(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]] Length: 5, dtype: interval[int64, right] An identical IntervalArray closed on the specified side... <IntervalArray> [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]] Length: 5, dtype: interval[int64, both]
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP