S.V*_*S.V 5 python intervals pandas
有没有更好的方法来检查 pandas Series 值是否在 pandas Interval 中:
import pandas as pd, numpy as np
x = pd.Series(np.linspace(4.0,7.8,num=20))
i = pd.Interval(5.0, 6.0, closed='left')
result = (i.left<=x) & (x<i.right)
Run Code Online (Sandbox Code Playgroud)
是否可以不太明确地计算结果,即无需访问i.left, i.right, i.closed?x.isin(i)类似或 的东西x in i。
感谢您的帮助!
您可以pandas.cut()为此使用:
bins=[5.0,6.0]
pd.cut(x,bins,right=False).dropna()
5 [5.0, 6.0)
6 [5.0, 6.0)
7 [5.0, 6.0)
8 [5.0, 6.0)
9 [5.0, 6.0)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1519 次 |
| 最近记录: |