Split and merge pandas dataframe
<p>I am trying to split and merge a Pandas dataframe.</p>

<p>The columns of the original data frame are arranged like so:</p>

<pre><code>dataTime Record1Field1 ... Record1FieldN Record2Field1 ... Record1FieldN
time1    &lt;&lt;     record 1 data         &gt;&gt; &lt;&lt;       record 2 data       &gt;&gt;
</code></pre>

<p>I would like to take split the <code>Record2</code> fields into a separate data frame <code>tempdf</code>, indexed by the dataTime. <code>tempdf</code> will therefore look something like this:</p>

<pre><code>dataTime Record2Field1 ... Record2FieldN
time1    &lt;&lt; record 2 data             &gt;&gt;
</code></pre>

<p>Once <code>tempdf</code> is populated, delete the Record2 columns from the original data frame. The first difficulty I'm having is in creating this <code>tempdf</code> which contains the record 2 data.</p>

<p>Then, I would like to rename the columns in <code>tempdf</code> so that they align with the <code>Record1</code> columns in the original data frame. (This portion I know how to do)</p>

<p>Finally I would like to merge <code>tempdf</code> back into the original data frame.</p>

<p>The end result should look something like this:</p>

<pre><code>dataTime Record1Field1 ... Record1FieldN
time1    &lt;&lt;record 1 data&gt;&gt;
time1    &lt;&lt;record 2 data&gt;&gt;
</code></pre>

<p>So far I haven't determined a good method of doing this. Any help is appreciated! Thanks.</p>

<p>try using <code>concat</code> </p>

<p>So trying something like:</p>

<pre><code>Combined = [DataFrame1,DataFrame2]
Together = pandas.concat(Combined)
</code></pre>

<p>as one of the others commented - <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html" rel="nofollow">merge</a> may be a good option as well.</p>

python pandas dataframe