Create Excel-like SUMIFS in Pandas

后端 未结 2 639
南旧
南旧 2021-01-13 00:37

I recently learned about pandas and was happy to see its analytics functionality. I am trying to convert Excel array functions into the Pandas equivalent to au

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-13 00:54

    I'm sure there is a better way, but this did it in a loop:

    for idx, eachRecord in reportAggregateDF.T.iteritems():
    reportAggregateDF['PORT_WEIGHT'].ix[idx] = reportAggregateDF['SEC_WEIGHT_RATE'][(reportAggregateDF['PORT_ID'] == portID) &            
        (reportAggregateDF['SEC_ID'] == 0) &            
        (reportAggregateDF['GROUP_LIST'] == " ") &             
        (reportAggregateDF['START_DATE'] == reportAggregateDF['START_DATE'].ix[idx]) &             
        (reportAggregateDF['END_DATE'] == reportAggregateDF['END_DATE'].ix[idx])].sum()
    

提交回复
热议问题