I wanted to subset columns which may or may not be adjacent to each other. In this pilot case, there are only 39 columns, so writing out full column names are possible but tedious. What I'm trying to do is only subset column based on indices.
df_sub = df.iloc[:,[10,11,29:37]]
But I get this error:
File "<ipython-input-46-d9362578c302>", line 1
df_sub = df.iloc[:,[10,11,29:37]]
^
SyntaxError: invalid syntax
Isn't there a way to subset columns with column indices which may not be next to each other?
Searching on google to do something like this only showed me methods on subsetting based on column names, index that are next to each other, or entering each indices separately e.g., here. What if there's a mixture with 100s of columns?