how can I call multiple columns from my data frame in pandas

315 Views Asked by At

I'm trying to get the top 10 longest songs in my data frame by calling two columns using the code df.loc[['duration_min','name']].head(). I have already sorted the relevant columns by descending order but when I run the code, I keep getting this error:

KeyError: "None of [Index(['duration_min', 'name'], dtype='object')] are in the [index]"

I was expecting the code to run without any problems

1

There are 1 best solutions below

0
VegTo91 On

Error shows that there are no indices called 'duration_min' and 'name'. You should use:

df[['duration_min', 'name']].head(x) 

with x, an integer.