Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting plaintext for excel with sympy

Most of my schoolwork for numerical analysis is done in excel, so I use excel functions extensively. However, I would like to start incorporating sympy into my workflow.

My question is is there a way to print functions from sympy to make them copy-paste-able to excel? What I end up doing when I get my output in sympy is reformatting it for excel i.e., regroup some terms so they are clearer to excel, and more often, change ** to ^.

I am aware that I can simply use mathematica for this, which prints my output to plaintext (where exponents are by default expressed with ^), but I am wondering if I can do the same with sympy.

like image 443
Juan Miguel Augusto Feria Avatar asked Oct 24 '25 23:10

Juan Miguel Augusto Feria


1 Answers

If mathematica style output is sufficient then the following should do:

import sympy
from sympy.printing import mathematica_code

x = sympy.symbols('x')
sympy.printing.mathematica_code(sympy.integrate(x**2,x))

Documentation here.

There are lots of other printing options which might work even better than mathematica style output.

like image 118
laolux Avatar answered Oct 26 '25 12:10

laolux