Best way to read an external data file
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 ?
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 ?
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.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2020-05-06 06:00:43 +0100
Seen: 646 times
Last updated: May 15 '20
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?
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.