I was doing a Python exercises and I got the wrong answer (in red). I’m a bit confused about subsetting with and without loc[ ]. Please enlighten me. Thank you.
Advertisement
Answer
The df.loc[:, ['alignment', 'character']]
itself is a dataframe. What you’re doing wrong is passing it inside df
.
I suggest you to look around at the related pandas documentation.