title: How to use ffill() for n number of columns in column header
body: <p>Need to fill NaN values from previous row value for n number of columns</p>
  
  <p>I am trying to achieve the below through Pandas Dataframe.</p>
  
  <ol>
  <li><p>Creating lists of rows and joining these to make a combined column in row header.</p></li>
  <li><p>Next I have to use ffill() to fill the NaN values from previous row. For this I'm trying to use if condition based on r_col (columns in row header) and c_col (columns in column header) parameters, but here it is not a best approach as c_col and r_col can be n number of columns and rows.</p></li>
  </ol>
  
  <p>Below is my code for the same logic.</p>
  
  <pre><code>cols = df.iloc[:r_col].astype(str).apply(lambda x: x.name + '__' + '__'.join(x))   
  
  df.columns = cols
  
  if (r_col == 2):
      for a in range(0, c_col+1):
          df = df.iloc[:,:].rename(columns={'Unnamed: ' + str(a) + '__nan':'Column' + str(a)}).ffill()
  
  if (r_col == 3):
      for a in range(0, c_col+1):
          df = df.iloc[:,:].rename(columns={'Unnamed: ' + str(a) + '__nan__nan':'Column' + str(a)}).ffill()        
  </code></pre>
  
  <p>I need to fill NaN values for n number of columns in Column header means based on c_col parameter and which should be performed after the line "df.column = cols".</p>