I have a datafarme with the following set up.
Product Clol1 Col2 Col3
pen 2 5 8
paper 6 7 4
shrpener 0 7 9
I want create list with the values for the index. = "paper". Out put would be [6,7,4]
How can I do it?
You could transpose your DataFrame and then select the desired column (ex row):
transposed_df = df.transpose()
result = transposed_df['paper']
使用DataFrame.loc
按标签选择行并将Series
转换为列表,我认为转置不是必需的(而且速度也更慢):
out = df.loc['paper'].tolist()
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.