[英]Fastest way to check pandas dataframe and show other elements in the other columns at the same row
如果有要检查的单词列表...
word_list = ['word1', 'word2', 'word3']
和一个像
Word,Score_a,Score_b,Score_c
word5,10,15,20
word6,40,60,80
word3,40,20,10
找到给定单词列表中每个单词的对应分数的最快方法是什么?
例如40, 20, 10
'word3'
。
详细说明上面的评论:
df.set_index('Word') #set Word column as index
df.loc['word5', :] # access row
Output:
Score_a 10
Score_b 15
Score_c 20
如果不想将 Word 设置为索引,也可以使用.iloc
:
df.iloc[0, :]
Output:
Word word5
Score_a 10
Score_b 15
Score_c 20
请注意,两者之间的主要区别(除了您可以使用loc
指定列名这一事实之外)是loc
在您指定范围时包含最后一项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.