Pandas: Why are double brackets needed to select column after boolean indexing

前端 未结 4 1164
南笙
南笙 2021-01-29 20:08

For a df table like below,

   A B C D
0  0 1 1 1
1  2 3 5 7
3  3 1 2 8

why are the double brackets needed for selecting specific columns after

4条回答
  •  悲哀的现实
    2021-01-29 21:02

    Because inner brackets are just python syntax (literal) for list.

    The outer brackets are the indexer operation of pandas dataframe object.

    In this use case inner ['A', 'B'] defines the list of columns to pass as single argument to the indexer operation, which is denoted by outer brackets.

提交回复
热议问题