Pandas Equivalent of R's which()

前端 未结 6 1610
广开言路
广开言路 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:57

    A nice simple and neat way of doing this is the following:

    SlicedData1 = df[df.colname>somenumber]]
    

    This can easily be extended to include other criteria, such as non-numeric data:

    SlicedData2 = df[(df.colname1>somenumber & df.colname2=='24/08/2018')]
    

    And so on...

提交回复
热议问题