I want to replicate rows in a Pandas Dataframe. Each row should be repeated n times, where n is a field of each row.
import pandas as pd what_i_have = pd.D
Not the best solution, but I want to share this: you could also use pandas.reindex() and .repeat():
pandas.reindex()
.repeat()
df.reindex(df.index.repeat(df.n)).drop('n', axis=1)
Output:
id v 0 A 10 1 B 13 1 B 13 2 C 8 2 C 8 2 C 8
You can further append .reset_index(drop=True) to reset the .index.
.reset_index(drop=True)
.index