0
測試數據:修改功能,以評估對行的所有值
import pandas as pd
import numpy as np
from itertools import combinations
df2 = pd.DataFrame(
{'AAA' : [4,5,6,7,9,10], 'BBB' : [10,20,30,40,11,10],'CCC' : [100,50,25,10,10,11],'DDD' : [100,50,25,10,10,11]});
thresh = 10
我的功能:
def closeCols2(df):
for k1,k2 in combinations(df.keys(),2):
if abs(df[k1] - df[k2]) < thresh:
return max(df[k1],df[k2])
這給我出一排如果兩個最大值以下的輸出列在門限內:
df2.apply(closeCols2, axis=1)
0 10
1 50
2 30
3 10
4 11
5 10
dtype: int64
但第1行上的列DDD
(100)和CCC
(100)也具有在thresh
內的值,並且這些未被評估。我如何修改我的功能來捕捉這個?