Ask Your Question
0

Best way to read an external data file

asked 2020-05-06 06:00:43 +0200

Cyrille gravatar image

What is the best way to read an external data file and to have the datas in sagemath format ? Should I add an add-on ?

edit retag flag offensive close merge delete

Comments

2

It depends on the file format and there are thousands of them. Can you be more specific on the kind of data which is contained in the file?

Sébastien gravatar imageSébastien ( 2020-05-06 09:46:07 +0200 )edit
2

You can try to import pandas, and use the package on the fly. More cannot be said with the few information we have. Please try to ask specific questions, and in the point they are sagemath-specific (and not rather pythonic, as it is the case in this case) please give details, best also using (minimal, pointed, working) sage code.

dan_fulea gravatar imagedan_fulea ( 2020-05-14 16:17:38 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-05-15 08:34:18 +0200

Sébastien gravatar image

updated 2020-05-15 08:37:22 +0200

The choice that ipython made when they created the ipython notebook format .ipynb (the notebook was later renamed Jupyter, but the notebook extension .ipynb was kept) is to store the notebook as a json format file. For example one may try to read a jupyter notebook as a json file as follows:

sage: import json
sage: with open('Untitled.ipynb','r') as f:
....:     d = json.load(f)

One obtains a Python dictionnary to work with:

sage: type(d)
<class 'dict'>
sage: d.keys()
dict_keys(['cells', 'metadata', 'nbformat', 'nbformat_minor'])

So, to answer the question, a Jupyter notebook is in fact an "external data file" and it is the "best" in the sense that it can store any data or objects or images or whatever created in SageMath. Of course, it is not practical or optimal if one wants to store more specific data, but then the question also needs to be more specific.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-05-06 06:00:43 +0200

Seen: 573 times

Last updated: May 15 '20