Pandas - df.loc assigning NaN when used to replace columns based on a different df
<p>I'm trying to assign values of some columns based on another column mapping them by one single key. The problem is that I don't think the mapping is being used correctly, because it is assigning NaN to the columns.</p>

<p>I should be mapping them by 'SampleID'.</p>

<p>Here is the DF I want to assign values to</p>

<pre><code>&gt;&gt;&gt; df.ix[new_df['SampleID'].isin(pooled['SampleID']), cols]
        Volume_Received  Quantity  massug
88280               2.0      15.0     1.0
88282               3.0      55.0     5.0
88284               2.5      46.2     3.0
88286               2.0      98.0     5.0
229365              2.0       8.4     3.0
229366              3.0      15.9     3.0
229367              1.5       7.7     2.0
233666              1.5      50.8     3.0
233667              4.0      60.2     5.0
</code></pre>

<p>This is the new value I have for them</p>

<pre><code>&gt;&gt;&gt; numerical
           Volume_Received  Quantity  massug
SampleID                                      
sample8             10.0      75.0     5.0
sample70            15.0     275.0    25.0
sample72            12.5     231.0    15.0
sample89             6.0     294.0    15.0
sample90             4.0      16.8     6.0
sample96             6.0      31.8     6.0
sample97             3.0      15.4     4.0
sample99             3.0     101.6     6.0
sample100            8.0     120.4    10.0
</code></pre>

<p>I'm using this command to assign the values:</p>

<pre><code>df.ix[df['SampleID'].isin(pooled['SampleID']), cols] = numerical[cols]
</code></pre>

<p>Where pooled is basically <code>pooled = df[df['type'] == 'Pooled']</code> and <code>cols</code> is a list with the three columns shown above. After I run the code above I receive NaN in all the values. I think I'm telling pandas to get values where it does not exist because of the mapping and it's returning something null which is being converted to NaN (assumption). </p>

<p>index does not match,</p>

<p>you can use </p>

<pre><code>df.ix[df['SampleID'].isin(pooled['SampleID']), cols] = numerical[cols].values
</code></pre>

<p>only if the size are exactly the same!</p>

python pandas