The title has become difficult to understand, but it is the same article. Sweat
In conclusion, In access by brackets (square brackets) ** If there is only one bracket, it can be retrieved as a Series, and if the brackets are stacked, it can be retrieved as a DataFrame. ** **
#Can be taken with Series
df["col"] # df.Same for col
#Can be taken with DataFrame
df[["col"]]
It is possible to convert what was taken out by Series to DataFrame, but it is easy to stack brackets.
If you specify multiple columns and get it, it is essential to overlap the brackets, so you can always get it with DataFrame.
df[["col1", "col2", "col3"]] #Can be taken with DataFrame
In addition, as a case where it is inconvenient to get it in Series, there is a case where it is input to the prediction model of sklearn. When creating a model with one variable, the following error will be output by inputting with Series.
ValueError: Expected 2D array, got 1D array instead:
~~
Reshape your data either using array.reshape(-1, 1) ~~
that's all.
Recommended Posts