1

I'm trying to view some rows of a pandas data frame. Is there a way to prevent the ">>> ..." from appearing before the headers, so that column names are aligned with the data?

#+NAME: simulate-data
#+BEGIN_SRC python :results output :exports code output :session p1
import pandas as pd
import numpy as np
import datetime as dt

def makeSim(nHosps, nPatients):
    df = pd.DataFrame()
    df['patientid'] = range(nPatients)
    df['hospid'] = np.random.randint(0, nHosps, nPatients)
    df['sex'] = np.random.randint(0, 2, nPatients)
    df['age'] = np.random.normal(65,18, nPatients)
    df['race'] = np.random.randint(0, 4, nPatients)
    df['cptCode'] = np.random.randint(1, 100, nPatients)
    df['rdm30d'] = np.random.uniform(0, 1, nPatients) < 0.1
    df['mort30d'] = np.random.uniform(0, 1, nPatients) < 0.2
    df['los'] = np.random.normal(8, 2, nPatients)
    return df

discharges = makeSim(50, 10000)
discharges.head()

#+END_SRC

#+RESULTS: simulate-data
: 
: >>> >>> >>> >>> ... ... ... ... ... ... ... ... ... ... ... ... >>> >>>    patientid  hospid  sex        age  race  cptCode  rdm30d  mort30d       los
: 0          0      19    1  55.909740     3       84   False    False  5.211757
: 1          1       2    0  81.362813     1       60   False    False  7.442538
: 2          2      14    0  55.769465     3        5    True    False  5.851072
: 3          3      32    1  75.530266     3       79   False    False  8.721435
: 4          4       5    1  94.081585     1       64    True     True  5.895088

1 Answer 1

1

My advice is to use ob-ipython instead. It does not have the issue you describe. The original is at https://github.com/gregsexton/ob-ipython. I have made a lot of improvements to it here: https://github.com/jkitchin/scimax/blob/master/scimax-org-babel-ipython.el.

1
  • ob-ipython solved my problem. Thanks John! May 25, 2017 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.