我想用不同数据帧中的另一列值填充“gvkey”列中的Nan值。在
df
wrds_id isin_code gvkey gvkey_new
0 1004 US0003611052 1004.0 1004.0
1 1005 US1948302047 Nan 1000.0
2 1006 US1948302047 Nan 1004.0
3 1007 US0309541011 Nan 1004.0
4 1007 US0003611052 1004.0 1004.0
5 1008 IL0006046119 Nan 1004.0
6 1008 US0003611052 1004.0 1004.0
7 1009 US4448591028 Nan 1004.0
8 1004 US4448591028 Nan 1004.0
9 1004 US4448591028 Nan 1004.0
10 1013 US0008861017 1013.0 1013.0
11 1013 BE0003755692 Nan 1013.0
12 1013 BE0003755692 Nan 1013.0
使用此帧时,基于isin_代码值,将Nan值替换为第一个数据帧中的gvkey_ciq_新值
^{pr2}$我要制作的最终数据帧
finaldf
wrds_id isin_imp gvkey gvkey_new
0 1004 US0003611052 1004.0 1004.0
1 1005 US1948302047 3176.0 1004.0
2 1006 US1948302047 3176.0 1004.0
3 1007 US0309541011 1485.0 1004.0
4 1007 US0003611052 1004.0 1004.0
5 1008 IL0006046119 2018.0 1004.0
6 1008 US0003611052 1004.0 1004.0
7 1009 US4448591028 5776.0 1004.0
8 1004 US4448591028 5776.0 1004.0
9 1004 US4448591028 5776.0 1004.0
10 1013 US0008861017 1013.0 1013.0
11 1013 BE0003755692 5150.0 1013.0
12 1013 BE0003755692 5150.0 1013.0
如何使用map函数生成数据帧?在
不要使用任何循环。合并数据帧并使用}
numpy.where
和{把事情安排好
合并并计算最后一列
^{pr2}$这给了我:
首先,做一个没有NAN的临时测向。然后可以使用布尔索引:
也许不是最优雅的解决方案,但它应该是有效的。在
编辑:或者在循环中添加类似
^{pr2}$那你就不需要df\U tmp了
相关问题 更多 >
编程相关推荐