Pandas Equivalent of R's which()

前端 未结 6 1602
广开言路
广开言路 2020-12-31 04:12

Variations of this question have been asked before, I\'m still having trouble understanding how to actually slice a python series/pandas dataframe based on conditions that

6条回答
  •  失恋的感觉
    2020-12-31 04:59

    Instead of enumerate, I usually just use .iteritems. This saves a .index(). Namely,

    [k for k, v in (df['c'] > t).iteritems() if v]
    

    Otherwise, one has to do

    df[df['c'] > t].index()
    

    This duplicates the typing of the data frame name, which can be very long and painful to type.

提交回复
热议问题