[Python] Map list of elements to category of element in pandas?

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

  1. Stack

    Stack Membro Participativo

    I have been googling a lot, but I still can't find a quick way to do so. Say I have a column in my csv file:

    1. C.Ronald
    2. Conor McGregor
    3. Lionel Messi
    4. LeBron James
    5. Derrick Rose
    6. Tom Brady
    7. ...
    8. ...


    and so on, I want to replace those name as the following three categories through python:

    1. Soccer player
    2. MMA fighter
    3. Soccer player
    4. NBA player
    5. NBA player
    6. NFL plaer
    7. ...
    8. ...


    How can I replace 'C.Ronald','Lionel Messi' and those soccer player's name, in to a class at once, but not one by one, since I have a long column.

    Continue reading...

Compartilhe esta Página