简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM