[Python] Python equivalence of R's match() for indexing

Discussão em 'Python' iniciado por Stack, Agosto 4, 2025.

  1. Stack

    Stack Membro Participativo

    So i essentially want to implement the equivalent of R's match() function in Python, using Pandas dataframes - without using a for-loop.

    In R match() returns a vector of the positions of (first) matches of its first argument in its second.

    Let's say that I have two df A and B, of which both include the column C. Where

    A$C = c('a','b')
    B$C = c('c','c','b','b','c','b','a','a')


    In R we would get

    match(A$C,B$C) = c(7,3)


    What is an equivalent method in Python for columns in pandas data frames, that doesn't require looping through the values.

    Continue reading...

Compartilhe esta Página