1
我想应用一个数据帧的特定列向后填充满足以下条件:我有“colum_A”可以假设只有四个值,称为A,B,C,D,向后填充应该工作,如以下:向后填充条件
if the first not NaN is A, then backward_filling with A;
if the first not NaN is B, then backward_filling with B;
if the first not NaN is C, then backward_filling with B;
if the first not NaN is D, then backward_filling with C;
if the column_A only contains NaN, then backward_filling with D
例如:
输入DF:
colum_A
NaN
NaN
B
B
C
C
输出DF:
colum_A
B
B
C
C
D
D
请任何帮助,将不胜感激。 最好的问候, 卡罗
是。有效。许多感谢Jezrael。请问,你能否提供一些关于np.where在这种特殊情况下的更多信息? –
当然,函数['numpy.where'](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html)像其他数组一样工作。我想链接希望更多。 – jezrael
太棒了。非常感谢你。非常感激。 –