作者m87dd05 (八八里阿巴)
看板Python
標題[問題] Dataframe印出邏輯判斷後的欄位值
時間Mon Jul 10 18:02:40 2017
請問各位如果今天我有df1和df2兩個dataframe
df1:
A B C
0 10 5 2
1 20 10 8
2 30 15 4
df2:
A B C
0 10 5 2
1 20 5 8
2 30 15 4
使用邏輯判斷後可以得到下表這個結果
df1>df2:
A B C
0 F F F
1 F T F
2 F F F
pandas有辦法再進一步的印出 True 是 (B,1)這個欄位嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.32.233.230
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1499680963.A.9FF.html
※ 編輯: m87dd05 (114.32.233.230), 07/10/2017 18:03:19
推 yanchenglin: xx=df1>df2;list(zip(*np.where(xx == True))) 07/11 01:56
→ yanchenglin: list(xx[xx == True].stack().index) 也可以 07/11 01:56
→ m87dd05: 謝謝Y大,不過可以在請問你第二種這是什麼方法嗎? 07/11 11:01