ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 14 Dec 2015 20:42:08 +0100Sage and Excel: export / import files via Windowshttps://ask.sagemath.org/question/31565/sage-and-excel-export-import-files-via-windows/Hi,
Please help. The purpose is to export easily a csv file from Sage to Excel (Windows) and via versa. I use VirtualBox. The reason is that Sage is excellent to calculate and Excel is (sometimes) handy to report.
I followed the instructions of [4. Sharing files between Sage and Windows](http://wiki.sagemath.org/SageAppliance#Sharing_files_between_Sage_and_Windows), but I do not understand the last instruction "The files will be in /media/sf_<<volume name>>".
An example code of reading and writing to a shared map would be great. Thanks!rolandMon, 14 Dec 2015 20:42:08 +0100https://ask.sagemath.org/question/31565/export data in MS Excel filehttps://ask.sagemath.org/question/10335/export-data-in-ms-excel-file/Hi experts!
Im running a code that generate three differents Numpy arrays (L1, L2 and L3) for every for-cycle (there is N cycles), so I get 3N arrays.
I wanna save these NP arrays in a MS excel file (.xls or other).
My questions are:
1) How can i generate this excel file?
2) How can I read the Excel file generated in a script?
Waiting for your answers.
Thanks a lot!
mresimulatorTue, 09 Jul 2013 12:20:37 +0200https://ask.sagemath.org/question/10335/Save data to text file - List_plot(...).save(Path, Name..)?https://ask.sagemath.org/question/9108/save-data-to-text-file-list_plotsavepath-name/Hey,
Is there a way to save data in list plot as a text file in stead/ in addition to showing it with .show() ?
In this way - I want to export the data from my list, say to Excel or Matlab in order to plot it using their tools. I wish the data would be arrange in the text file in a list of values that I could then copy (for example) to the Excel table.
Thanking u on advance! ErezMon, 25 Jun 2012 04:42:16 +0200https://ask.sagemath.org/question/9108/Writing data to filehttps://ask.sagemath.org/question/8332/writing-data-to-file/This is all in the Sage Notebook:
I want to store some data in a file, Excel or Access or something, because that's what I know. I am using statements like o.write("something" + ", " + "something" + "\r") and I'm doing this in a loop. I'm writing it to a txt file. So, Sage does its thing and there's the little "stuff.txt" link I can click on afterward. I click on it and it looks just how I want it. Then, using Firefox 6.whatever is out these days, I do file save as and save it as stuff.txt. I open it and there are no line breaks at all and the data is pretty much useless. I also tried "\n" and same thing.
I found a sort of solution, because I could use "stuff.csv" instead and it mostly works right. The problem there is, I have data which has commas in it. So, I was hoping to do a .txt file using tab delimited so the commas in the data didn't cause problems. But, the above problem for .txt files exists and I don't know how to fix it.
Oh, also just copying and pasting the data from the file Sage creates (before saving it using Firefox) didn't work today when I had nearly 300,000 lines of data. Excel/Access have the "[Not responding]" message, even though Excel and Access can easily handle 300,000 lines of data. Perhaps it is the clipboard is not big enough for that? I don't know.
Any ideas? Thanks for your help!G-SageMon, 19 Sep 2011 23:01:20 +0200https://ask.sagemath.org/question/8332/import data .xlshttps://ask.sagemath.org/question/8106/import-data-xls/Hi I would like to run this python script in sage (simple example):
def import_xls(filename, worksheet=1):
import xlrd
book = xlrd.open_workbook(filename)
sh = book.sheet_by_index(worksheet - 1)
data = []
for i in range(sh.ncols):
data.append(sh.col_values(i))
print 'Worksheet Names: %s; Rows: %s; Columns: %s'%(sh.name, sh.nrows, sh.ncols)
return data
def export_xls(data, filename):
import xlwt
wb = xlwt.Workbook()
ws = wb.add_sheet('Sheet1')
for i in range(len(data)):
for k in range(len(data[i])):
ws.write(i,k,str(data[i][k]))
return wb.save(filename)
from cvxopt import matrix
from cvxopt import solvers
from numpy import array
from numpy import zeros
A = import_xls('sample.xls', worksheet=1)
b = import_xls('sample.xls', worksheet=2)
c = import_xls('sample.xls', worksheet=3)
# linear programming model
A = matrix(A)
b = matrix(b)
c = matrix(c)
sol=solvers.lp(c,A,b)
print sol['x']
x = sol['x']
But it returns the following error:
ImportError: No module named xlrd
Can you help me? Thanks a lot
massimiliano manfrenFri, 06 May 2011 14:43:33 +0200https://ask.sagemath.org/question/8106/