【发布时间】:2019-01-22 04:42:24
【问题描述】:
我有一个 df,在一列中有数百行,遵循这种模式:
col1
1.12/17/18
2.10/10
3.Best Movie
4.This is the best movie ever...
5.
6.
7.1/1/2019
8.02/10
9.Worst Movie
10.This movie was awful...
我想知道是否有办法将 4 行范围内的每一行转置到它们自己的列中,然后将下一个 4 范围堆叠在新列的下方?
所以最终的输出是这样的:
Date Rating Title Review
12/17/18 10/10 Best Movie This is the best movie ever...
1/1/2019 02/10 Worst Movie This movie was awful...
关于如何更改 df 以实现这一点的任何建议?
【问题讨论】:
-
我会添加到@alistaire 的解决方案,您可能希望首先过滤掉空行(在您的示例中为 5-6)。
-
非常类似于这个老问题 - stackoverflow.com/questions/14582422/…