Skip to content Skip to sidebar Skip to footer

How To Use Ffill() For N Number Of Columns In Column Header

Need to fill NaN values from previous row value for n number of columns I am trying to achieve the below through Pandas Dataframe. Creating lists of rows and joining these to make

Solution 1:

Try to use df[x].fillna(y) or df[x].fillna(y, inplace=True). Here x is any column of your choice and y is any value of your choice. For example:

10.00012NaN30.03

gives

1 0.0001
2 0.0000
3 0.03

or

list_nan_values = [1,2,3, 21, 44]   # variables list to fill NaN with
nan_locations   = [1,2,8,19,67]     # positional location of NaN in specific column you have selected.for i inrange(len(nan_locations)+1):
    df[i] = df[nan_locations[i]].fillna(list_nan_values[i])

Enjoy.

Post a Comment for "How To Use Ffill() For N Number Of Columns In Column Header"