Ask Your Question
2

Compatible data file formats

asked 2013-06-30 16:20:45 +0200

updated 2013-06-30 16:21:39 +0200

What are the compatible file formats if I want to load a data set into Sage? I know that I can load .csv files using Python's csv module or open() method.

Is there any other file format that I can use in Sage?

Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-06-30 16:46:32 +0200

Nathann gravatar image

Well, you would have to be more accurate about WHAT you want to store if you want to know how Sage can store it. There is a very general-purpose format that Sage supports though, but it will mostly be useful if you want to send a "Sage object" to another Sage user.

sage: # Build an object containing whatever you want to store
sage: a = [1, Graph(), Matrix(2,2)]
sage: save(a,"/tmp/my_sage_object.sobj")
sage: load("/tmp/my_sage_object.sobj")
[
                        [0 0]
1, Graph on 0 vertices, [0 0]
]
sage: one,my_graph,my_matrix = load("/tmp/my_sage_object.sobj")

That's a pretty cool feature if you want to store an object.

But if what you had in mind is "how can I exchange data with other persons or load their files", then you have to be much more specific.

Nathann

edit flag offensive delete link more

Comments

Thanks Nathann. Actually what I wanted was to load some values in a file so we can do some plotting, statistics etc (like what we do by opening a .csv file). I wanted to know whether there are any other formats which I can directly load into Sage(e.g. ods, xls,...) Sorry my question is vague.

Tharindu Rusira gravatar imageTharindu Rusira ( 2013-07-01 02:27:11 +0200 )edit
2

answered 2013-06-30 17:25:39 +0200

tmonteil gravatar image

updated 2013-06-30 17:30:15 +0200

Note that open() is a Python function that can open any kind of file. The main issue is then to handle your file so that the data can be used in Sage (i.e. transformed into Sage objects).

Since Sage is written in Python, there are many modules to handle many particular types of file (e.g. if you want to handle an xml file, you can imort and use the xml module, if you want to handle a gpg file, you can install, import and use the gnupg module, and so on). If your file is an ad-hoc (non-standard) text file, you can use various python tools to get interesting data from it (e.g. use the string methods, consider also the re module allows you to filter your file with regular expressions).

So this really depends on your situation. The data from which sotware do you want to deal with ? Which formats does it allow to export ?

edit flag offensive delete link more

Comments

Thanks for the answer. Specifically please let me know if it is possible to directly load a spreadsheet in .xls or .ods format.

Tharindu Rusira gravatar imageTharindu Rusira ( 2013-07-01 02:30:26 +0200 )edit
1

Those formats are dealing with spreadsheet. If you already know how to handle .csv files, i would advise to export your spreadsheet into .csv format and then work with it. To open an .xls file directly, you can install the `xlrd` module: From a shell, run the command: sage -sh Then, this sage-shell: (sage-sh) user@machine$ easy_install xlrd (sage-sh) user@machine$ exit Then, in Sage command-line or notebook: sage: import xlrd For ods files, the `ezodf` seems appropriate, but only works with Python 3 (Sage uses Python 2). You can install and use the `odslib` package (with the same procedure as above).

tmonteil gravatar imagetmonteil ( 2013-07-01 10:02:29 +0200 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2013-06-30 16:20:45 +0200

Seen: 1,219 times

Last updated: Jun 30 '13