Pandas: when can I directly assign to values array
<p>I was messing with pandas in the interpreter and the following behavior took me by surprise:</p>

<pre><code>&gt;&gt;&gt; data2 = [[1, np.nan], [2, -17]]
&gt;&gt;&gt; f2 = pd.DataFrame(data2)
&gt;&gt;&gt; f2
   0     1
0  1   NaN
1  2 -17.0
&gt;&gt;&gt; f2.values[1, 1] = -99.0
&gt;&gt;&gt; f2
   0     1
0  1   NaN
1  2 -17.0
&gt;&gt;&gt; type(f2.values[0, 0]), type(f2.values[1, 0])
(&lt;class 'numpy.float64'&gt;, &lt;class 'numpy.float64'&gt;)
</code></pre>

<p>I am unable to assign directly to the underlying array using the values attribute.  However, if I explicitly start with floats, I can:</p>

<pre><code>&gt;&gt;&gt; data = [[1.0, np.nan], [2.0, -17.0]]
&gt;&gt;&gt; f = pd.DataFrame(data)
&gt;&gt;&gt; f
     0     1
0  1.0   NaN
1  2.0 -17.0
&gt;&gt;&gt; f.values[1, 1] = -99.0
&gt;&gt;&gt; f
     0     1
0  1.0   NaN
1  2.0 -99.0
</code></pre>

<p>Does anyone know a rule that would have allowed me to predict this?  I feel like I must be missing something obvious.</p>

<p>using .values returns a numpy array. so whatever you do after doing <code>df.values</code> will be exactly like using a numpy array.</p>

<p>using<code>df.iloc[i,i]</code> allows you to set values or extract value using an integer position</p>

python pandas