我有以下 sql 查詢。我應該在 python 中實作相同的邏輯。帶有 where 條件的 id 計數除以帶有另一個 where 條件的 id 計數
"count(ticket_id)*100 where ticket_status='PENDING'/count(ticket_id) where ticket_status in ('COMPLETED','CREATED','IN-PROGRESS')"
任何幫助將不勝感激!
uj5u.com熱心網友回復:
如果您有一個名為互動的資料框
對于您提到的這部分查詢,因為它似乎有效直到那里
count(ticket_id)*100 from interactions where ticket_status='PENDING'
蟒蛇部分
interactions[interactions['ticket_status'=='PENDING']].count()*100
uj5u.com熱心網友回復:
您的查詢看起來很奇怪,但這是您要找的嗎?
out = (interactions.loc[interactions['ticket_status'] == 'PENDING', 'ticket_id'].count() * 100 /
interactions.loc[interactions['ticket_status'].isin(('COMPLETED','CREATED','IN-PROGRESS')), 'ticket_id'].count()
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/410773.html
標籤:
