What exactly does this Python statement do?

Asked

Viewed 62 times

2

I am studying the sklearn module of Python, and I came across this statement:

data = pd.read_csv('car.data')

X = data[[
    'buying',
    'maint',
    'safety'
]].values

What exactly is stored in X? Because the declaration is made with two []?

1 answer

3

In the example you are passing a list of chaves with the names of the columns you want to extract from Dataframe data and from these columns you extract what you have inside as Numpy values through the function pandas.DataFrame.values

What will be stored in 'X' depends on the data that is in the columns (that match the name with the list) of the file you imported.

Because the statement is made with two []?

Why do you want to pass a list (first bracket) to search inside the Dataframe 'date' (second bracket).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.