Extract left and right limit from a Series of pandas Intervals

前端 未结 3 1907
终归单人心
终归单人心 2021-01-02 13:42

I want to get interval margins of a column with pandas intervals and write them in columns \'left\', \'right\'. Iterrows does not work (documentation says it would not be us

3条回答
  •  梦毁少年i
    2021-01-02 14:17

    A simple way is to use apply() method:

        data['left'] = data['intervals'].apply(lambda x: x.left)
        data['right'] = data['intervals'].apply(lambda x: x.right)
        data
    
        intervals      left     right
        0   (85, 94]     85      94
        1   (95, 104]    95     104
        ...
        8   (165, 174]  165     174
    

提交回复
热议问题