Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How about this, using <code>pandas</code>:</p> <pre><code>&gt;&gt;&gt; updated = orig.append(new).groupby('Name').last().fillna(0) &gt;&gt;&gt; updated Day1 Day2 Day3 Day4 Name Abe 1 2 4 0 Ben 2 2 1 0 Cat 2 3 2 0 Dan 0 0 6 3 </code></pre> <hr> <p>First, read in the data (this will depend on the details of the format):</p> <pre><code>&gt;&gt;&gt; orig = pd.read_csv("days1.txt", delim_whitespace=True) &gt;&gt;&gt; new = pd.read_csv("days2up.txt", delim_whitespace=True) &gt;&gt;&gt; orig Name Day1 Day2 Day3 0 Abe 1 2 3 1 Ben 2 2 1 2 Cat 2 3 2 &gt;&gt;&gt; new Name Day3 Day4 0 Abe 4 0 1 Dan 6 3 </code></pre> <p>Then append the new data, which automatically extends the columns:</p> <pre><code>&gt;&gt;&gt; orig.append(new) Day1 Day2 Day3 Day4 Name 0 1 2 3 NaN Abe 1 2 2 1 NaN Ben 2 2 3 2 NaN Cat 0 NaN NaN 4 0 Abe 1 NaN NaN 6 3 Dan </code></pre> <p>Combine by the Name column, and take the last valid value (originally I was worried this would lose the Day1 and Day2 information for Abe, but it doesn't):</p> <pre><code>&gt;&gt;&gt; orig.append(new).groupby("Name").last() Day1 Day2 Day3 Day4 Name Abe 1 2 4 0 Ben 2 2 1 NaN Cat 2 3 2 NaN Dan NaN NaN 6 3 </code></pre> <p>Replace the missing values with 0:</p> <pre><code>&gt;&gt;&gt; orig.append(new).groupby("Name").last().fillna(0) Day1 Day2 Day3 Day4 Name Abe 1 2 4 0 Ben 2 2 1 0 Cat 2 3 2 0 Dan 0 0 6 3 </code></pre> <p>And finally write out:</p> <pre><code>&gt;&gt;&gt; updated = orig.append(new).groupby("Name").last().fillna(0) &gt;&gt;&gt; updated.to_csv("updated.csv") &gt;&gt;&gt; !cat updated.csv Name,Day1,Day2,Day3,Day4 Abe,1.0,2.0,4,0.0 Ben,2.0,2.0,1,0.0 Cat,2.0,3.0,2,0.0 Dan,0.0,0.0,6,3.0 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload