Python Pandas replicate rows in dataframe

前端 未结 5 1186
逝去的感伤
逝去的感伤 2020-11-29 20:07

If the data look like:

Store,Dept,Date,Weekly_Sales,IsHoliday
1,1,2010-02-05,24924.5,FALSE
1,1,2010-02-12,46039.49,TRUE
1,1,2010-02-19,41595.55,FALSE
1,1,201         


        
5条回答
  •  臣服心动
    2020-11-29 20:49

    You can put df_try inside a list and then do what you have in mind:

    >>> df.append([df_try]*5,ignore_index=True)
    
        Store  Dept       Date  Weekly_Sales IsHoliday
    0       1     1 2010-02-05      24924.50     False
    1       1     1 2010-02-12      46039.49      True
    2       1     1 2010-02-19      41595.55     False
    3       1     1 2010-02-26      19403.54     False
    4       1     1 2010-03-05      21827.90     False
    5       1     1 2010-03-12      21043.39     False
    6       1     1 2010-03-19      22136.64     False
    7       1     1 2010-03-26      26229.21     False
    8       1     1 2010-04-02      57258.43     False
    9       1     1 2010-02-12      46039.49      True
    10      1     1 2010-02-12      46039.49      True
    11      1     1 2010-02-12      46039.49      True
    12      1     1 2010-02-12      46039.49      True
    13      1     1 2010-02-12      46039.49      True
    

提交回复
热议问题