double bracket integer index in pandas; Is this a legal syntax

Cameron Simpson cs at cskk.id.au
Wed May 3 07:37:24 EDT 2023


On 03May2023 03:41, Artie Ziff <artie.ziff at gmail.com> wrote:
>I am hope that pandas questions are OK here.

There are some pandas users here.

>In a panda lecture, I did not get the expected result.
>I tried this on two different platforms
>(old macOS distro and up-to-date Ubuntu Linux distro, 22.04)
>
>The Linux distro has:
>python                    3.10.11
>pandas                    1.5.2
>conda                     23.3.1
>
>Is this double bracket form, df[[1]], deprecated... maybe?
>
>There is data in a dataframe, df.
>
>>>> subset = df[[1]]

Whether this works depends on the contents of the dataframe. You're 
supplying this index:

     [1]

which is a list of ints (with just one int).

Have a look at this page:
https://pandas.pydata.org/docs/user_guide/indexing.html

If you suppply a list, it expects a list of labels. Is 1 a valid label 
for your particular dataframe?

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list