我在脚本a中有这个"np.where“,但是当它返回格式改变时,
我该如何解决这个问题呢?我想在数据中得到回报。
In [22]: new[["DME","Ent. Prog."]]
Out[22]:
DME Ent. Prog.
0 2021-07-15
1 2021-07-15
... ... ...
7481 2021-07-13
7482 2021-07-13
[7483 rows x 2 columns]
In [23]: new["DME"] = np.where(new['Ent. Prog.'] == '', new["DME"],new['Ent. Prog.'])
In [24]: new[["DME","Ent. Prog."]]
Out[24]:
DME Ent. Prog.
0 1626307200000000000
1 1626307200000000000
... ... ...
7481 1626134400000000000
7482 1626134400000000000
[7483 rows x 2 columns]
new["DME"] = np.where(new['Ent. Prog.'] == '', new["DME"],new['Ent. Prog.'])发布于 2021-07-12 21:18:10
原因是datetimes没有填充第二列,可能的解决方案是转换这两列并测试misisng值:
new['DME'] = pd.to_datetime(new['DME'])
new['Ent. Prog.'] = pd.to_datetime(new['Ent. Prog.'])
new["DME"] = np.where(new['Ent. Prog.'].isna(), new["DME"],new['Ent. Prog.'])或者用Series.fillna中的另一列替换缺少的值
new["DME"] = new['Ent. Prog.'].fillna(new['DME'])https://stackoverflow.com/questions/68348052
复制相似问题