python有条件地合并数据

2024-03-29 07:57:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个具有相同列的panda表,如果circuit列中的数据为None,id想做的是合并这些列

>> site_routing_data[0]
   circuit errors        route            site           mask      next_hop error
0     MPLS   None   10.10.1.0        Manchester  255.255.255.0    172.5.1.5   NaN
1     MPLS   None   10.10.2.0        London      255.255.255.0    172.5.1.5   NaN
2     None   None   10.10.3.0        Birmingham  255.255.255.0    172.5.1.5   NaN
3     MPLS   None   10.10.4.0        Sheffield   255.255.255.0    172.5.1.5   NaN

>> site_routing_data[1]
   circuit errors        route            site           mask      next_hop error
0     FTTC   None   10.10.1.0        Manchester  255.255.255.0    172.10.1.6   NaN
1     FTTC   None   10.10.2.0        London      255.255.255.0    172.10.1.7   NaN
2     FTTC   None   10.10.3.0        Birmingham  255.255.255.0    172.10.1.8   NaN
3     FTTC   None   10.10.4.0        Sheffield   255.255.255.0    172.10.1.9   NaN

我想将这两个合并在一起,但只替换表0中对circuit列具有None值的任何记录。最后一张桌子看起来像

   circuit errors        route            site           mask      next_hop error
0     MPLS   None   10.10.1.0        Manchester  255.255.255.0    172.5.1.5   NaN
1     MPLS   None   10.10.2.0        London      255.255.255.0    172.5.1.5   NaN
2     FTTC   None   10.10.3.0        Birmingham  255.255.255.0    172.10.1.8  NaN
3     MPLS   None   10.10.4.0        Sheffield   255.255.255.0    172.5.1.5   NaN

谢谢


Tags: nonesitemaskerrornanroutenextlondon