Ask Your Question

Revision history [back]

Python modules such as matplotlib, numpy, pandas, etc, don't know about Sage integers. So you have to feed them Python ints.

However, Sage's preparser automatically turns every integer in your input into a Sage integer.

One way to counter that is to append the letter r (for 'raw'), as in:

print data_inf[:3r]

Another way to not have preparsing on is to turn the preparser off:

preparser(False)

Another way is to write your code in a .py file and to load that file. That is, write this in a file, say mycode.py:

import pandas as pd  
fname = 'blah.xlsx'  
data_inf = pd.read_excel(fname)
print data_inf[:3]

and then run the following:

sage: load('mycode.py')

Python modules such as matplotlib, numpy, pandas, etc, don't know about Sage integers. So you have to feed them Python ints.

However, Sage's preparser automatically turns every integer in your input into a Sage integer.

One way to counter that is to append the letter r (for 'raw'), as in:

print data_inf[:3r]

See the effect on ints and floats:

sage: type(1)
<type 'sage.rings.integer.Integer'>
sage: type(1r)
<type 'int'>
sage: type(1.5)
<type 'sage.rings.real_mpfr.RealLiteral'>
sage: type(1.5r)
<type 'float'>

Another way to not have preparsing on is to turn the preparser off:

preparser(False)

Another way is to write your code in a .py file and to load that file. That is, write this in a file, say mycode.py:

import pandas as pd  
fname = 'blah.xlsx'  
data_inf = pd.read_excel(fname)
print data_inf[:3]

and then run the following:

sage: load('mycode.py')