How do I interpret this notation?

后端 未结 2 1044
囚心锁ツ
囚心锁ツ 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 03:05

    Pandas DataFrames allow you to index using boolean arrays which is how s is being used inside []. The value of the Series is True or False as you can see, so we're selecting the values of s where s is True. The purpose of this code is to get columns where the datatype is object, you can do it with the function pandas.DataFrame.select_dtypes instead:

    list(X_train.select_dtypes(include=['object']).columns)
    

提交回复
热议问题