Pandas 数据帧le()方法

原文:https://www.studytonight.com/pandas/pandas-dataframe-le-method

在本教程中,我们将学习 PandasDataFrame.le()的方法。此方法用于获取小于或等于的 dataframe 和其他元素(二元运算符 get)。它返回 bool 的数据帧,这是比较的结果。

下图显示了DataFrame.le()方法的语法。

句法

DataFrame.le(other, axis='columns', level=None)

因素

其他:可以是任何单个或多个元素的数据结构,也可以是类似列表的对象,例如标量、序列、序列或数据帧。

轴:“0”代表索引,“1”代表列,默认为列。表示是按索引轴比较还是按列轴比较。

级别:代表 int 或 label。它跨级别广播,匹配传递的多索引级别上的索引值。

示例:使用DataFrame.le()方法将数据帧与常数进行比较

这里,我们使用返回 bool 类型数据帧的DataFrame.le()方法与scalar进行比较。

#importing pandas as pd
import pandas as pd
#importing numpy as np
import numpy as np
#creating the DataFrame
df=pd.DataFrame({"A":[200,500],"B":[60,250],"C":[150,1]})
print("--------The DataFrame is---------")
print(df)
print("----After applying le function-----")
print(df.le(200))

-数据帧为- A B C 0 200 60 150 1 500 250 1 -应用 le 函数后- A B C 0 真真真 1 假真

示例:使用DataFrame.le()方法将数据帧与系列进行比较

这里,我们使用DataFrame.le()方法将数据帧与Series进行比较。见下面的例子。

#importing pandas as pd
import pandas as pd
#creating the DataFrame
df=pd.DataFrame({"A":[200,500],"B":[60,250],"C":[150,1]})
print("--------The DataFrame is---------")
print(df)
series = pd.Series([150, 200,150]) 
print("----After applying le function-----")
print(df.le(series,axis=0))

-数据帧为- A B C 0 200 60 150 1 500 250 1 -应用 le 函数后- A B C 0 假真 1 假真 2 假假假假

示例:使用DataFrame.le()方法将数据帧与其他数据帧进行比较

这里,我们使用DataFrame.le()方法将数据帧与other DataFrame进行比较。见下面的例子。

#importing pandas as pd
import pandas as pd
#creating the DataFrame
df_1=pd.DataFrame({"A":[200,500],"B":[60,250],"C":[150,1]})
print("--------The first DataFrame is---------")
print(df_1)
df_2=pd.DataFrame({"A":[200,550],"B":[65,251],"C":[100,10]})
print("--------The second DataFrame is---------")
print(df_2)
print("----After applying le function-----")
print(df_1.le(df_2))

-第一个数据帧是- A B C 0 200 60 150 1 500 250 1 -第二个数据帧是- A B C 0 200 65 100 1 550 251 10 -应用 le 函数后- A B C 0 True True False 1 True True True

结论:

在本教程中,我们学习了 PandasDataFrame.le()方法。我们学习了语法、参数,并将该方法应用于数据帧,从而理解 DataFrame.le()方法。