Skip to content
Advertisement

Pandas – Repeat row if found in list and count

Need help in repeating rows if found in list.

  • If found value in list increment count
  • If more than one instance found then repeat the row by incrementing count

Dataframe:

JavaScript

Df looks like:

JavaScript

Input list:

JavaScript

In need output like:

JavaScript

Tried something like this to get first matching index so I can repeat the row but not sure how to do it.

JavaScript

Advertisement

Answer

You can use:

JavaScript

Output:

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