Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

PREVIOUS NEXT
Code Example
Python :: abstarct class python 
Python :: how to round to 3 significant figures in python 
Python :: python print variable 
Python :: join in pathlib path 
Python :: if df[col].unique()==2 
Python :: python use variable inside pandas query 
Python :: python zip files 
Python :: adding strings together 
Python :: convert radians to degrees python 
Python :: add favicon in django admin 
Python :: how to concatenate two lists in python 
Python :: Adding new column to existing DataFrame in Pandas using assign method 
Python :: http python lib 
Python :: current page django 
Python :: python how to replace a string in a list 
Python :: sklearn labelbinarizer in pipeline 
Python :: onedrive python upload 
Python :: long in python 
Python :: python destructure object 
Python :: sys.maxsize() in python 
Python :: python format string 
Python :: print only strings in list python 
Python :: discordpy make all inputs lowercase 
Python :: how list ul li with python scraping 
Python :: index and reversing a sub list in python list 
Python :: change a color on touch roblox 
Python :: series floor 
Python :: ndarray python 
Python :: python data insert 
Python :: how to customize simplejwt error response message in django restframework 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =