Python equivalent of R c() function, for dataframe column indices?

后端 未结 3 1929
面向向阳花
面向向阳花 2021-01-13 14:56

I would like to select from a pandas dataframe specific columns using column index.

In particular, I would like to select columns index by the column index generate

3条回答
  •  死守一世寂寞
    2021-01-13 15:26

    Putting @hrbrmstr 's comment into an answer, because it solved my issue and I want to make it clear that this question is resolved. In addition, please note that range(a,b) gives the numbers (a, a+1, ..., b-2, b-1), and doesn't include b.

    R's combine function

    c(4,12:26,69:85,96:99,134:928,933:935)
    

    is translated into Python as

    [4] + list(range(12,27)) + list(range(69,86)) + list(range(96,100)) + list(range(134,929)) + list(range(933,936))
    

提交回复
热议问题