熊猫-将多行合并为多列

时间:2020-05-30 14:48:47

标签: python pandas

我已经进行了一些搜索,但是找不到。我可能使用的措词不正确。

这就是我想要做的:

id, C1, C2
0,   1,  2
1,   2,  3
2,   2,  4
3,   5,  6
4,   7,  8
5,   9, 10
6,  11, 12
7,  13, 14

进入此行(将x行(在本例中为3行)转换为多行的1行):

id, C1, C2, C1_1, C2_1, C1_2, C2_2
0,   1,  2,    3,    4,    5,    6
1,   7,  8,    9,   10,   11,   12
2,  13, 14,  Nan,  Nan,  NaN,  NaN

如果我需要删除将导致NaN的行也可以。

我可以编写某种循环,但是似乎有一种很好的熊猫方式,我只是没有找到它。

1 个答案:

答案 0 :(得分:0)

我们需要创建两个类型的id,一个由@register.filter @stringfilter def prepend(str): url = "" #defien your remote url here return "{}{}".format(url, str) 修改,然后做cumcount

pivot_table