Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个数据框,当每一行的最后一列中可能有一些 nan 时:
df = A B C D E F 1 2 3 nan nan nan 1 2 3 4 nan nan 1 2 3 4 5 6
我想每行运行 ffill,以获得:
df = A B C D E F 1 2 3 3 3 3 1 2 3 4 4 4 1 2 3 4 5 6
我该怎么做?
谢谢
ffill与axis=1as 参数一起使用:
ffill
axis=1
>>> df.ffill(axis=1).astype(int) A B C D E F 0 1 2 3 3 3 3 1 1 2 3 4 4 4 2 1 2 3 4 5 6