3

Simply put, magic function %precision does not respect floating point precision for output of a simple variable.

#Configure matplotlib to run on the browser
%matplotlib notebook
%precision 3

from ipywidgets import widgets
from IPython.display import display

import pandas as pd
import numpy as np
import matplotlib as mpl
mpl.get_backend() #Import pyplot scripting layer as plt
import matplotlib.pyplot as plt
import ipywidgets as widgets

np.random.seed(12345)
np.set_printoptions(precision=3)
df = pd.DataFrame([np.random.normal(32000,200000,3650), 
                   np.random.normal(43000,100000,3650), 
                   np.random.normal(43500,140000,3650), 
                   np.random.normal(48000,70000,3650)], 
                  index=[1992,1993,1994,1995]).T
df_stats = df.describe()

a=8/11

The output is simply 0

Please assist.

Neel
  • 413
  • 1
  • 6
  • 14
  • In Python 2, `8/11` is an integer. Same for `8//11` in Py3. – hpaulj Sep 06 '17 at 21:03
  • if you mean the result for `a`, I get `0.727` in Python 3 – pylang Sep 07 '17 at 00:23
  • @pylang, the output of a is 0. The output should be as you stated, 0.727, but it is display just 0 i.e. no floating points – Neel Sep 07 '17 at 11:23
  • I tried changing the Kernel to default Python 3 and it seems to work. The only change i've made to the current environment was install ipywidgets – Neel Sep 07 '17 at 11:34
  • @hpaulj, you were right. Python 2 requires special import, https://stackoverflow.com/questions/2958684/python-division – Neel Sep 07 '17 at 15:08
  • Yeah. Division works differently in Python 2. Glad you worked it out. – pylang Sep 08 '17 at 00:08

1 Answers1

1

It looks like this post is a modified replica of Python division.

I used the following to assist,

from __future__ import division

Have an excellent day and thanks for the help!

Neel
  • 413
  • 1
  • 6
  • 14