我的问题是:
假设我在pandas中有两个列数相同的数据帧,例如:
A= 1 2
3 4
8 9
以及
^{pr2}$
还有一个布尔向量,长度正好是A+numofb rows=5,其中的1
与B中的rows num相同,在这个例子中意味着两个1
。
假设Bool= 0 1 0 1 0
。在
我的目标是将A和B合并到一个称为C的更大的数据帧中,使B的行与Bool中的1相对应,因此在这个示例中它将给出:
C= 1 2
7 8
3 4
4 0
8 9
你知道怎么做吗?
如果你知道这对我有多大的帮助。
谢谢你的阅读。在
Tags:
一种方法是创建一个具有预期形状的空数据帧,然后将A和B中的值填充到:
这是一个只支持pandas的解决方案,它可以重新索引原始数据帧,然后将它们连接起来:
下面的方法将推广到大于2的组。从开始
我们可以利用
^{pr2}$这给了
^{3}${然后按顺序排列它们的值。这意味着我们可以得到
这正是我们要选择行的iloc顺序(减去1之后)。在
相关问题 更多 >
编程相关推荐