我有一个从csv读取的数据帧。你知道吗
time node txrx src dest txid hops
0 34355146 2 TX 2 1 1 NaN
1 34373907 1 RX 2 1 1 1.0
2 44284813 2 TX 2 1 2 NaN
3 44302557 1 RX 2 1 2 1.0
4 44596500 3 TX 3 1 2 NaN
5 44630682 1 RX 3 1 2 2.0
6 50058251 2 TX 2 1 3 NaN
7 50075994 1 RX 2 1 3 1.0
8 51338658 3 TX 3 1 3 NaN
9 51382629 1 RX 3 1 3 2.0
我需要能够创建一个新的数据帧,它接受TX/RX行中的值,为每一对创建一行:
df应如下所示:
tx_time rx_time src dest txid hops
0 34355146 34373907 2 1 1 1
1 44284813 44302557 2 1 2 1
2 44596500 44630682 3 1 2 2
3 50058251 50075994 2 1 3 1
4 51338658 51382629 3 1 3 2
我知道如何做步骤(3),但我有点困在如何尝试(1)和(2)。建议?你知道吗
一种
defaultdict
方法从OP的角度来看,这可能会更快。
如果速度很重要,请检查。基督教青年会。你知道吗
使用concat虽然我认为@Wen使用pivot的解决方案会更有效
你得到了吗
通过使用
pivot_table
或者使用
unstack
PS:使用
.rename(columns={})
重命名我没有添加到这里,因为会使代码太长。。。你知道吗相关问题 更多 >
编程相关推荐