title: Merge above and below rows in DataFrame
body: <p>I have a dataframe, but I need to perform some cleaning, in some cases the values from above and below rows in column &quot;Code&quot; are separated, is there any way to merge these rows? df - is what I have, and df1 what I need to have (the values can be both in numeric and string format).</p>
  <pre><code>import pandas as pd
  import numpy as np 
  
  
  df = pd.DataFrame({&quot;DT&quot;:[np.nan,65,np.nan, 65,45,np.nan,34,np.nan],
        &quot;Code&quot;:[56,np.nan,&quot;TD&quot;,&quot;TR&quot;,52,1,np.nan,76],
        &quot;DV&quot;:[np.nan,&quot;CAT&quot;,np.nan,&quot;B54&quot;,&quot;T65&quot;,np.nan,765,np.nan],
        &quot;GT&quot;:[np.nan,76,np.nan,np.nan,np.nan,np.nan,65,np.nan]})
  
  
  df1 = pd.DataFrame({&quot;DT&quot;:[65,65,45,34],
        &quot;Code&quot;:[&quot;56 TD&quot;,&quot;TR&quot;,52,&quot;1 76&quot;],
        &quot;DV&quot;:[&quot;CAT&quot;,&quot;B54&quot;,&quot;T65&quot;,765],
        &quot;GT&quot;:[76,np.nan,np.nan,65]})
  </code></pre>