Skip to content
Advertisement

Replicate rows in a pandas dataframe based on the column values of another dataframe

JavaScript

Is there a way I can replicate the number of rows in matches_df based on the row value 10 which is present in booklines.

The end result is the matches df replicated ten times like this. I am looking for a programatic way of doing this instead of manually adding in the ten like so.

matches_df.append([matches_df]*10,ignore_index=True)

enter image description here

Advertisement

Answer

Use:

JavaScript

Or:

JavaScript

If same number of rows in both DataFrames and need use Nums column for replicate use Index.repeat with DataFrame.loc:

JavaScript

JavaScript

Last for default index use:

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