-1

I have a data fram in one of the columns there are NAN between two elements. how I can fill this NAN by an element before them?

Df['col1]:

                                             A
                                              NaN
                                             NaN
                                            NaN
                                              B
                                             NaN
                                             NaN
                                            NaN

output:

                                             A
                                             A
                                            A
                                            A
                                              B
                                            B
                                             B
                                           B

1 Answers1

1

Use the fillna method, specified as a forward-fill:

df.fillna(method='ffill')
HMReliable
  • 871
  • 5
  • 11