参考链接: 带有Pandas的Python:带有示例的DataFrame教程
Python是进行数据分析的一种出色语言,主要是因为以数据为中心的python软件包具有奇妙的生态系统。 Pandas是其中的一种,使导入和分析数据更加容易。
Pandas dataframe.ne()函数使用常量,序列或其他按元素排列的 DataFrame 检查 DataFrame 元素的不等式。如果比较中的两个值不相等,则返回true;否则,返回false。
用法: DataFrame.ne(other, axis=’columns’, level=None)
参数:
other:系列,DataFrame或常量
axis:对于系列输入,轴与系列索引匹配
level:在一个级别上广播,在传递的MultiIndex级别上匹配索引值
返回:结果:DataFrame
范例1:采用ne()用于检查序列和 DataFrame 之间是否不相等的函数。
# 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
让我们创建系列
# importing pandas as pd
import pandas as pd
# create series
sr = pd.Series([3, 2, 4, 5, 6])
# Print series
sr
让我们使用dataframe.ne()评估不平等的功能
# evaluate inequality over the index axis
df.ne(sr, axis = 0)
输出:
所有真值单元格都表示比较中的值彼此不相等,而所有假值单元格都表示比较中的值彼此相等。
范例2:采用ne()用于检查两个datframe是否不相等的函数。一个 DataFrame 包含NA值。
# 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()功能。
# passing df2 to check for inequality with the df1 dataframe.
d1f.ne(df2)
输出:
所有真值单元格都表示比较中的值彼此不相等,而所有假值单元格都表示比较中的值彼此相等。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。