Answers for "repeat rows in a pandas dataframe based on column value"

0

repeat rows in a pandas dataframe based on column value

df.reindex(df.index.repeat(df.persons))
Out[951]: 
   code  .     role ..1  persons
0   123  .  Janitor   .        3
0   123  .  Janitor   .        3
0   123  .  Janitor   .        3
1   123  .  Analyst   .        2
1   123  .  Analyst   .        2
2   321  .   Vallet   .        2
2   321  .   Vallet   .        2
3   321  .  Auditor   .        5
3   321  .  Auditor   .        5
3   321  .  Auditor   .        5
3   321  .  Auditor   .        5
3   321  .  Auditor   .        5
Posted by: Guest on July-06-2021

Code answers related to "repeat rows in a pandas dataframe based on column value"

Browse Popular Code Answers by Language