Pandas dataframe - data type issue
<p>I am trying to create a <code>pd.DataFrame</code>, but I am having trouble getting the data type correct. I have two <code>numpy</code> arrays that are type <code>float</code>.</p>

<p>They were created from a list of coordinates (x &amp; y) as seen here:</p>

<pre><code># Take coordinates from list and convert to a numpy array
x_vector = np.asarray(x_list, dtype=float)
y_vector = np.asarray(y_list, dtype=float)
</code></pre>

<p>For reference here is a sample of what <code>x_vector</code> looks like:</p>

<pre><code>[-2248925.48185815 -2248925.48185815 -2248080.13621823 -2262432.04991849
-2250570.32692157 -2237312.76315587 -2237312.76315587 -2245650.16260083
-2245650.16260083 -2249323.93572129 -2247050.83128422 -2253151.83634956]
</code></pre>

<p>I am pleased with the formatting here, the issue arises when I try to add <code>x_vector</code> and <code>y_vector</code> to the pandas data frame. </p>

<p>My logic is that I have 201 records of lat/lons so my <code>index</code> equals that, then I add <code>columns</code> corresponding to my data, finally I set the <code>dtype</code> to match my coordinates (float).</p>

<p>Here is my code:</p>

<pre><code>df = pd.DataFrame(index=range(1, 202, 1), columns=['lat', 'lon', 'ws_daily_max'], dtype=float)

df['lat'] = y_vector
df['lon'] = x_vector
</code></pre>

<p>However when I print <code>df</code> to the console, I get these values where the decimal place shifted significantly. What went wrong, why did the lat/lon values change? I was expecting them to be the same as the float values above, i.e. (<code>-2248925.48185815</code>)?</p>

<p><code>index         lat           lon      ws_daily_max
1    1.895464e+06 -2.248925e+06           NaN
2    1.895464e+06 -2.248925e+06           NaN</code></p>

<p>I am truly confused as to what happened. No error message printed, but this is <em>not</em> the result I was expecting. Any clarity as to why and how to fix this would be greatly appreciated.</p>

<p>Help me, StackExchange. You're my only hope.</p>

<p>This is the scientific notation of the same number. 1.895464e+06 means 1.895464*10^6 = 1895465. So the decimal place did not shift, just the representation. If you want to change the looks of the numbers, look at <a href="http://pandas.pydata.org/pandas-docs/stable/options.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/options.html</a>. I hope this helps.</p>

python pandas numpy