Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.le#

DataFrame.le(other,axis='columns',level=None)[source]#

Get Less than or equal to of dataframe and other, element-wise (binary operatorle).

Among flexible wrappers (eq,ne,le,lt,ge,gt) to comparisonoperators.

Equivalent to==,!=,<=,<,>=,> with support to choose axis(rows or columns) and level for comparison.

Parameters:
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

axis{0 or ‘index’, 1 or ‘columns’}, default ‘columns’

Whether to compare by the index (0 or ‘index’) or columns(1 or ‘columns’).

levelint or label

Broadcast across a level, matching Index values on the passedMultiIndex level.

Returns:
DataFrame of bool

Result of the comparison.

See also

DataFrame.eq

Compare DataFrames for equality elementwise.

DataFrame.ne

Compare DataFrames for inequality elementwise.

DataFrame.le

Compare DataFrames for less than inequality or equality elementwise.

DataFrame.lt

Compare DataFrames for strictly less than inequality elementwise.

DataFrame.ge

Compare DataFrames for greater than inequality or equality elementwise.

DataFrame.gt

Compare DataFrames for strictly greater than inequality elementwise.

Notes

Mismatched indices will be unioned together.NaN values are considered different (i.e.NaN !=NaN).

Examples

>>>df=pd.DataFrame({'cost':[250,150,100],...'revenue':[100,250,300]},...index=['A','B','C'])>>>df   cost  revenueA   250      100B   150      250C   100      300

Comparison with a scalar, using either the operator or method:

>>>df==100    cost  revenueA  False     TrueB  False    FalseC   True    False
>>>df.eq(100)    cost  revenueA  False     TrueB  False    FalseC   True    False

Whenother is aSeries, the columns of a DataFrame are alignedwith the index ofother and broadcast:

>>>df!=pd.Series([100,250],index=["cost","revenue"])    cost  revenueA   True     TrueB   True    FalseC  False     True

Use the method to control the broadcast axis:

>>>df.ne(pd.Series([100,300],index=["A","D"]),axis='index')   cost  revenueA  True    FalseB  True     TrueC  True     TrueD  True     True

When comparing to an arbitrary sequence, the number of columns mustmatch the number elements inother:

>>>df==[250,100]    cost  revenueA   True     TrueB  False    FalseC  False    False

Use the method to control the axis:

>>>df.eq([250,250,100],axis='index')    cost  revenueA   True    FalseB  False     TrueC   True    False

Compare to a DataFrame of different shape.

>>>other=pd.DataFrame({'revenue':[300,250,100,150]},...index=['A','B','C','D'])>>>other   revenueA      300B      250C      100D      150
>>>df.gt(other)    cost  revenueA  False    FalseB  False    FalseC  False     TrueD  False    False

Compare to a MultiIndex by level.

>>>df_multindex=pd.DataFrame({'cost':[250,150,100,150,300,220],...'revenue':[100,250,300,200,175,225]},...index=[['Q1','Q1','Q1','Q2','Q2','Q2'],...['A','B','C','A','B','C']])>>>df_multindex      cost  revenueQ1 A   250      100   B   150      250   C   100      300Q2 A   150      200   B   300      175   C   220      225
>>>df.le(df_multindex,level=1)       cost  revenueQ1 A   True     True   B   True     True   C   True     TrueQ2 A  False     True   B   True    False   C   True    False

[8]ページ先頭

©2009-2025 Movatter.jp