Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas repeat rows n times

test.loc[test.index.repeat(test.times)]

  id  times
0  a      2
0  a      2
1  b      3
1  b      3
1  b      3
2  c      1
3  d      5
3  d      5
3  d      5
3  d      5
3  d      5
Comment

how to repeat a row in pandas

newdf = pd.DataFrame(np.repeat(df.values, 3, axis=0))
newdf.columns = df.columns
print(newdf)
Comment

PREVIOUS NEXT
Code Example
Python :: fill column based on values of another column 
Python :: python using end keyword 
Python :: python np.sum 
Python :: python linter 
Python :: name columns pandas 
Python :: python change label text 
Python :: star program in python using for loop 
Python :: retry on exception python 
Python :: accuracy for each class 
Python :: rotate array in python 
Python :: lru_cache 
Python :: pandas set one column equal to another 
Python :: what is modulus in python 
Python :: customise the django rest api view 
Python :: django not migrating 
Python :: Python Generators with a Loop 
Python :: how to concatenate two strings in python 
Python :: Model In View Django 
Python :: python for loop range 
Python :: python conditionals 
Python :: python dataframe sort by column name 
Python :: how to add array and array in python 
Python :: from html to jupyter notebook 
Python :: explicitly free memory in Python code 
Python :: how to run python in the browser 
Python :: streamlit add chart 
Python :: insert into string python 
Python :: loop in python 
Python :: keras.callbacks.History 
Python :: classification algorithms pythonb´ 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =