Skip to content
Advertisement

Fastest way to check pandas dataframe and show other elements in the other columns at the same row

If there is a list of words to check…

JavaScript

and a data frame like

JavaScript

What is the fastest way to find the corresponding scores for each word in the given word list?

For example, 40, 20, 10 for 'word3'.

Advertisement

Answer

To elaborate on comments above:

JavaScript

Output:

JavaScript

If you don’t want to set Word as index, you can also use .iloc:

JavaScript

Output:

JavaScript

Note the main difference between the two (other than the fact that you can specify column name with loc) is that locis inclusive of the last term when you specify a range.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement