Pandas Equivalent of R's which()

前端 未结 6 1575
广开言路
广开言路 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 05:03

    And if you need an additional statement panda.Series allows you to do Operations between Series (+, -, /, , *).

    Just multiplicate the indexes:

    idx1 = df['lat'] == 49
    idx2 = df['lng'] > 15 
    idx = idx1 * idx2
    
    new_df = df[idx] 
    

提交回复
热议问题