Modify output from series.rolling to 2 decimal points
<p>Using the following data:</p>

<pre><code>                          Open  High    Low Last    Volume
Timestamp                   
2016-06-10 16:10:00 2088.00 2088.0  2087.75 2087.75 1418
2016-06-10 16:11:00 2088.00 2088.0  2087.75 2088.00 450
2016-06-10 16:12:00 2088.00 2088.0  2087.25 2087.25 2898
</code></pre>

<p>I am looking to use a rolling moving average as follows:</p>

<pre><code>data["sma_9_volume"] = data.Volume.rolling(window=9,center=False).mean()
</code></pre>

<p>and this gives me this output:</p>

<pre><code>    Open    High    Low Last    Volume  candle_range    sma_9_close sma_9_volume
Timestamp                               

2014-03-04 09:38:00 1785.50 1785.50 1784.75 1785.25 24  0.75    1785.416667 48.000000
2014-03-04 09:39:00 1785.50 1786.00 1785.25 1785.25 13  0.75    1785.500000 30.444444
2014-03-04 09:40:00 1786.00 1786.25 1783.50 1783.75 28  2.75    1785.333333 30.444444
2014-03-04 09:41:00 1784.00 1785.00 1784.00 1784.25 12  1.00    1785.083333 22.777778
2014-03-04 09:42:00 1784.25 1784.75 1784.00 1784.25 18  0.75    1784.972222 20.222222
2014-03-04 09:43:00 1784.75 1785.00 1784.50 1784.50 10  0.50    1784.888889 20.111111
2014-03-04 09:44:00 1784.25 1784.25 1783.75 1784.00 32  0.50    1784.694444 18.222222
</code></pre>

<p>what is the best way to take the output from:</p>

<pre><code>data["sma_9_volume"] = data.Volume.rolling(window=9,center=False).mean()
</code></pre>

<p>and have the output only return 2 decimal points i.e. <code>48.00</code> instead of <code>48.000000</code></p>

<p>you can use pandas' <code>round</code> function</p>

<p><code>data["sma_9_volume"]=data["sma_9_volume"].round(decimals=2)</code></p>

<p>or directly:</p>

<p><code>data["sma_9_volume"] = data.Volume.rolling(window=9,center=False).mean().round(decimals=2)</code></p>

<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.round.html" rel="nofollow">documentation</a></p>

python pandas