0

I am having trouble understanding the last line of this code. The csv file has several columns, but after the last line, only the data below the columns specified remains. What confuses me is why we use 4 brackets instead of two.

import pandas

data = pandas.read_csv("student-mat.csv", sep=";")

data = data[["G1", "G2", "G3", "studytime", "failures", "absences"]]
Oleg Vorobiov
  • 482
  • 5
  • 14
Peter
  • 59
  • 1
  • 9
  • This is Pandas syntax to select multiple columns. See more [here](https://stackoverflow.com/questions/11285613/selecting-multiple-columns-in-a-pandas-dataframe) – Tom Ron Jul 07 '19 at 07:36

2 Answers2

0

The single bracket will output a Pandas Series, while a double bracket will output a Pandas DataFrame.

bart
  • 1,003
  • 11
  • 24
0

The interior brackets are for list whereas the outer brackets are for indexing operator. Double brackets are needed if you select two or more columns.