Python|熊猫 dataframe.ne()
Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。
Pandas dataframe.ne()函数检查数据框元素与常量、系列或其他数据框元素的不等式。如果比较的两个值不相等,则返回 true,否则返回 false。
Syntax: DataFrame.ne(other, axis=’columns’, level=None)
Parameters :
other : Series, DataFrame, or constant
axis : For Series input, axis to match Series index on
level :Broadcast across a level, matching Index values on the passed MultiIndex level
Returns : result : DataFrame
示例 #1:使用 ne()函数检查系列和数据帧之间的不等式。
Python3
# importing pandas as pd
import pandas as pd
# Creating the first dataframe
df1=pd.DataFrame({"A":[14,4,5,4,1],
"B":[5,2,54,3,2],
"C":[20,20,7,3,8],
"D":[14,3,6,2,6]})
# Print the dataframe
df1
Python3
# importing pandas as pd
import pandas as pd
# create series
sr = pd.Series([3, 2, 4, 5, 6])
# Print series
sr
Python3
# evaluate inequality over the index axis
df.ne(sr, axis = 0)
Python3
# importing pandas as pd
import pandas as pd
# Creating the first dataframe
df1=pd.DataFrame({"A":[14,4,5,4,1],
"B":[5,2,54,3,2],
"C":[20,20,7,3,8],
"D":[14,3,6,2,6]})
# Creating the second dataframe with Na
value
df2=pd.DataFrame({"A":[12,4,5,None,1],
"B":[7,2,54,3,None],
"C":[20,16,11,3,8],
"D":[14,3,None,2,6]})
# Print the second dataframe
df2
Python3
# passing df2 to check for inequality with the df1 dataframe.
d1f.ne(df2)
让我们创建系列
Python3
# importing pandas as pd
import pandas as pd
# create series
sr = pd.Series([3, 2, 4, 5, 6])
# Print series
sr
让我们使用 dataframe.ne()函数来评估不等式
Python3
# evaluate inequality over the index axis
df.ne(sr, axis = 0)
输出 :
所有真值单元格表示比较中的值彼此不相等,而所有假值单元格表示比较中的值彼此相等。示例 #2:使用 ne()函数检查两个数据帧的不等式。一个数据帧包含 NA 值。
Python3
# importing pandas as pd
import pandas as pd
# Creating the first dataframe
df1=pd.DataFrame({"A":[14,4,5,4,1],
"B":[5,2,54,3,2],
"C":[20,20,7,3,8],
"D":[14,3,6,2,6]})
# Creating the second dataframe with Na
value
df2=pd.DataFrame({"A":[12,4,5,None,1],
"B":[7,2,54,3,None],
"C":[20,16,11,3,8],
"D":[14,3,None,2,6]})
# Print the second dataframe
df2
让我们使用 dataframe.ne()函数。
Python3
# passing df2 to check for inequality with the df1 dataframe.
d1f.ne(df2)
输出 :
所有真值单元格表示比较中的值彼此不相等,而所有假值单元格表示比较中的值彼此相等。