How do I interpret this notation?

后端 未结 2 999
囚心锁ツ
囚心锁ツ 2021-01-24 02:40

How and why does the notation s[s] work?

I\'m taking one of the micro-courses from kaggle.com and they use the notation s[s] as shown below. I have not

2条回答
  •  温柔的废话
    2021-01-24 02:51

    This is quite complicated.

    X_train is a pandas data frame.

    X_train.dtypes is returning a pandas Series, where the index (name of each row) is equal to the column name.

    We now do == on the Series which returns a new series, with the value true or false. So it looks like:

    a True b False c True

    Now we get to the x[x] which says to remove the 'false' values, giving a new Series:

    a True c True

    Now we do .index and turn it into a list to give

    ['a', 'c' ]

提交回复
热议问题