align rows by date in pandas dataframe
<p>An excerpt of the Dateframe could look like this (it's certainly much larger):</p>

<pre><code>            Date1        Log1     Date2     Log2    Date3       Log3   
 Index
   0       01.01.2000    1000   02.01.2000  2000   01.01.2000   3000
   1       02.01.2000    1050   03.01.2000  1950   02.01.2000   3020
   2       03.01.2000    1100   04.01.2000  2000   03.01.2000   3000
</code></pre>

<p>Is there a quick way to align the rows so that the dates (here in Columns <code>Date3</code> and <code>Log3</code>) match with those in column <code>Date1</code>?</p>

<pre><code>            Date1        Log1     Date2     Log2    Date3       Log3   
 Index
   0       01.01.2000    1000   NaN                01.01.2000   3000
   1       02.01.2000    1050   02.01.2000  2000   02.01.2000   3020
   2       03.01.2000    1100   03.01.2000  1950   03.01.2000   3000
</code></pre>

<p>Many thanks in advance</p>

<p>I am assuming you only want to keep values from ['Date2', 'Log2'] and ['Date3', 'Log3'] when the dates have a match in Date1.</p>

<p>You can read the different columns into separate dataframes and use <code>merge</code>. Then filter to only keep rows where the Date1 column is not null.</p>

<pre><code>df
&gt;&gt;&gt;
        Date1  Log1       Date2  Log2       Date3  Log3
0  01.01.2000  1000  02.01.2000  2000  01.01.2000  3000
1  02.01.2000  1050  03.01.2000  1950  02.01.2000  3020
2  03.01.2000  1100  04.01.2000  2000  03.01.2000  3000

df1 = df[['Date1', 'Log1']]
df2 = df[['Date2', 'Log2']]
df3 = df[['Date3', 'Log3']]

df_out = df1.merge(df2, how='outer', left_on='Date1', right_on='Date2')
df_out = df_out.merge(df3, how='outer', left_on='Date1', right_on='Date3')
df_out = df_out[df_out['Date1'].notnull()]

df_out
&gt;&gt;&gt;
        Date1    Log1       Date2    Log2       Date3    Log3
0  01.01.2000  1000.0         NaN     NaN  01.01.2000  3000.0
1  02.01.2000  1050.0  02.01.2000  2000.0  02.01.2000  3020.0
2  03.01.2000  1100.0  03.01.2000  1950.0  03.01.2000  3000.0
</code></pre>

python pandas dataframe