How to get away with a multidimensional index in pandas

前端 未结 2 1527
暖寄归人
暖寄归人 2021-01-02 12:33

In Pandas, what is a good way to select sets of arbitrary rows in a multiindex?

df = pd.DataFrame(columns=[\'A\', \'B\', \'C\'])
df[\'A\'] = [\'a\', \'a\', \         


        
2条回答
  •  醉酒成梦
    2021-01-02 13:30

    In newer versions of pandas you can simply use .iloc for row indexing.

    df = pd.DataFrame(columns=['A', 'B', 'C'])
    df['A'] = ['a', 'a', 'b', 'b']
    df['B'] = [1,2,3,4]
    df['C'] = [1,2,3,4]
    df.iloc[[0, 3]][['A', 'B']]
    

提交回复
热议问题