1

I want to expand a dataframe which only has 1 line to hundreds of times (330 exactly)of it. Is there any way to do that easily? All lines are the same.

A dataframe like this:

     f_date     f_open  f_close  f_high  f_low  f_volume  pre_date  pre_open  \
0  2019-01-21    24.5     24.5    24.5   24.5       0.0  2019-01-18     24.55

   pre_close  pre_high  pre_low  today_open  today_volumn  today_close  \
0       24.5     24.62    24.11        24.5           0.0         24.5

   pre_rate
0       0.0

I want to make it 330 times bigger and all lines are the same.

romlym
  • 561
  • 1
  • 7
  • 26

2 Answers2

3

Here's a simple way:

pd.concat([df] * 330)
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
2
pd.concat([df]*330, ignore_index=True)

the default ignore_index is set to False so if you don't set it to True you will have duplicate index "0" 330 times

nassim
  • 1,547
  • 1
  • 14
  • 26