Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.between#

Series.between(left,right,inclusive='both')[source]#

Return boolean Series equivalent to left <= series <= right.

This function returns a boolean vector containingTrue wherever thecorresponding Series element is between the boundary valuesleft andright. NA values are treated asFalse.

Parameters:
leftscalar or list-like

Left boundary.

rightscalar or list-like

Right boundary.

inclusive{“both”, “neither”, “left”, “right”}

Include boundaries. Whether to set each bound as closed or open.

Changed in version 1.3.0.

Returns:
Series

Series representing whether each element is between left andright (inclusive).

See also

Series.gt

Greater than of series and other.

Series.lt

Less than of series and other.

Notes

This function is equivalent to(left<=ser)&(ser<=right)

Examples

>>>s=pd.Series([2,0,4,8,np.nan])

Boundary values are included by default:

>>>s.between(1,4)0     True1    False2     True3    False4    Falsedtype: bool

Withinclusive set to"neither" boundary values are excluded:

>>>s.between(1,4,inclusive="neither")0     True1    False2    False3    False4    Falsedtype: bool

left andright can be any scalar value:

>>>s=pd.Series(['Alice','Bob','Carol','Eve'])>>>s.between('Anna','Daniel')0    False1     True2     True3    Falsedtype: bool

[8]ページ先頭

©2009-2025 Movatter.jp