-
aluckdog
由于NaN/NaN给出NaN, 并且NaN>1是假的,在除法之后,您可以尝试NaN用 2 填充值,例如或用任何大于 1 的数字填充值,使用fillna, 来屏蔽你想要的:df1.div(df2).fillna(2)例子:df1=pd.DataFrame({'X':[np.nan,2],'Y':[2,1]})df1# X Y#0 NaN 2#1 2.0 1df2=pd.DataFrame({'X':[np.nan,2],'Y':[1,7]})df2# X Y#0 NaN 1#1 2.0 7df1.div(df2) # X Y#0 NaN 2.000000#1 1.0 0.142857df1.div(df2).fillna(2)>1# X Y#0 True True#1 False False
-
慕尼黑8549860
也许为它写一个函数而不是像这样划分它们(稍微伪代码)def nanChecker(a, b): if a == NaN && b == NaN: return true return false
-
慕虎7371278
这很容易,使用元素明智的操作import pandas as pd data1 = [(None, 2), (2, 1)]data2 = [(None, 1), (2, 7)]dataFrame1 = pd.DataFrame(data=data1)dataFrame2 = pd.DataFrame(data=data2)divisionResults = dataFrame1.div(dataFrame2)resultFrame = (divisionResults>1) | (dataFrame1.isnull() & (dataFrame2.isnull()))