Để có được giới hạn bên trái cho khoảng thời gian, hãy sử dụng thuộc tính khoảng thời gian.left. Đầu tiên, hãy nhập các thư viện được yêu cầu -
import pandas as pd
Sử dụng Dấu thời gian làm giới hạn để tạo khoảng thời gian. Đã đặt khoảng thời gian đã đóng bằng cách sử dụng tham số "đã đóng" với giá trị "trái". Nhận giới hạn bên trái trong khoảng thời gian
interval = pd.Interval(pd.Timestamp('2020-01-01 00:00:00'), pd.Timestamp('2021-01-01 00:00:00'), closed='left')
Hiển thị khoảng thời gian
print("Interval...\n",interval)
Ràng buộc bên trái
print("\nThe left bound for the Interval...\n",interval.left)
Ví dụ
Sau đây là mã
import pandas as pd # Use Timestamps as the bounds to create a time interval # Closed interval set using the "closed" parameter with value "left" # Get the left bound for the interval interval = pd.Interval(pd.Timestamp('2020-01-01 00:00:00'), pd.Timestamp('2021-01-01 00:00:00'), closed='left') # display the interval print("Interval...\n",interval) # display the interval length print("\nInterval length...\n",interval.length) # the left bound print("\nThe left bound for the Interval...\n",interval.left)
Đầu ra
Điều này sẽ tạo ra mã sau
Interval... [2020-01-01, 2021-01-01) Interval length... 366 days 00:00:00 The left bound for the Interval... 2020-01-01 00:00:00