Pandas 数据帧ge()
方法
原文:https://www.studytonight.com/pandas/pandas-dataframe-ge-method
在本教程中,我们将学习 PandasDataFrame.ge()
的方法。此方法用于获取大于或等于的 dataframe 和其他元素(二元运算符 get)。它返回 bool 类型的数据帧,这是比较的结果。
下面是DataFrame.ge()
方法的语法。
句法
DataFrame.ge(other, axis='columns', level=None)
因素
其他:标量、序列、序列或数据帧。任何单个或多个元素数据结构,或类似列表的对象。
轴: {0 或‘索引’,1 或‘列’,默认‘列’。是按索引(0 或“索引”)还是按列(1 或“列”)进行比较。
级别: int 或 label。跨级别广播,匹配传递的多索引级别上的索引值。
示例 1:使用DataFrame.ge()
方法比较数据帧
这里,我们使用返回 bool 类型数据帧的DataFrame.ge()
方法与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 ge function-----")
print(df.ge(200))
一旦我们运行该程序,我们将获得以下输出。
-数据帧为- A B C 0 200 60 150 1 500 250 1 -应用 ge 方法后- A B C 0 真假假 1 真假
示例 2:使用DataFrame.ge()
方法比较数据帧
这里,我们使用DataFrame.ge()
方法与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 ge function-----")
print(df.ge(series,axis=0))
一旦我们运行该程序,我们将获得以下输出。
-数据帧为- A B C 0 200 60 150 1 500 250 1 -应用 ge 方法后- A B C 0 真假真 1 真假 2 假假假假
示例 3:使用DataFrame.ge()
方法比较数据帧
在这里,我们用DataFrame.ge()
方法与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 ge function-----")
print(df_1.ge(df_2))
一旦我们运行该程序,我们将获得以下输出。
-第一个数据帧是- A B C 0 200 60 150 1 500 250 1 -第二个数据帧是- A B C 0 200 65 100 1 550 251 10 -应用 ge 方法后- A B C 0 真假真 1 假假假假
结论:
在本教程中,我们学习了 PandasDataFrame.ge()
方法。我们学习了语法和参数,通过在数据帧上应用这种方法,我们理解了 DataFrame.ge()
方法。