简体   繁体   English

如何用熊猫将数据框填充四次

[英]How ffill a dataframe forward four times with pandas

So if I have a dataframe like such: 因此,如果我有一个像这样的数据框:

  A  B  C
  1  1  1
  2  2  2
  3  3  3

I want to achieve this: 我想实现这一目标:

  A   B   C
  1   1   1
  1   1   1
  1   1   1
  1   1   1
  2   2   2
  2   2   2
  2   2   2
  2   2   2
  3   3   3
  3   3   3
  3   3   3
  3   3   3
  3   3   3

I know that this will probably involve ffill and the general process as describes in my question, but if there is a simpler way to do this, I'm perfectly happy with that. 我知道这可能涉及填充和我的问题中所述的一般过程,但是如果有更简单的方法可以做到这一点,我对此非常满意。 I just want the quickest and easiest way, because my script will be repeating this many times. 我只想要最快,最简单的方法,因为我的脚本将重复多次。

Thanks for all the help! 感谢您的所有帮助!

I think this is repeat not ffill 我认为这是repeatffill

df.reindex(df.index.repeat(4))
Out[63]: 
   A  B  C
0  1  1  1
0  1  1  1
0  1  1  1
0  1  1  1
1  2  2  2
1  2  2  2
1  2  2  2
1  2  2  2
2  3  3  3
2  3  3  3
2  3  3  3
2  3  3  3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM