How to replace NaNs by preceding values in pandas DataFrame?

前端 未结 9 2095
無奈伤痛
無奈伤痛 2020-11-22 06:04

Suppose I have a DataFrame with some NaNs:

>>> import pandas as pd
>>> df = pd.DataFrame([[1, 2, 3], [4, None, None], [None, N         


        
9条回答
  •  心在旅途
    2020-11-22 06:40

    ffill now has it's own method pd.DataFrame.ffill

    df.ffill()
    
         0    1    2
    0  1.0  2.0  3.0
    1  4.0  2.0  3.0
    2  4.0  2.0  9.0
    

提交回复
热议问题