1

I would like to assign agent_code to specific number of rows in df2.

df1 df1

df2 df2

Thank you.

df3 (Output) Output

Fred
  • 13
  • 2
  • Does this answer your question? [Repeat rows in a pandas DataFrame based on column value](https://stackoverflow.com/questions/47336704/repeat-rows-in-a-pandas-dataframe-based-on-column-value) – SultanOrazbayev Nov 09 '22 at 07:11

1 Answers1

0

First make sure in both DataFrames is default index by DataFrame.reset_index with drop=True, then repeat agent_code, convert to default index and last use concat:

df1 = df1.reset_index(drop=True)
df2 = df2.reset_index(drop=True)

s = df1['agent_code'].repeat(df1['number']).reset_index(drop=True)
df3 = pd.concat([df2, s], axis=1)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252