I have some data in CSV format that I want to pull into an Excel spreadsheet and then create some standard set of graphs for. Since the data is originally generated in a Python app, I was hoping to simply extend the app so that it could do all the post processing and I wouldn't have to do it by hand. Is there an easy interface with Python to work with and manipulate Excel spreadsheets? Any good samples of doing this? Is this Windows only (I'm primarily working on a Mac and have Excel, but could do this on Windows if necessary).
xlutils (and the included packages xlrd and xlwt) should allow your Python program to handily do any creation, reading and manipulation of Excel files you might want!
On Windows you could use the pywin32 package to create an Excel COM Object and then manipulate it from a script. You need to have an installed Excel on that machine though. I haven't done this myself so I can't give you and details but I've seen this working so can at least confirm that it's possible. No idea about OS X, unfortunately.
Related
I've been scrolling for a while but couldn't find a solution or advice to my particular problem. I'm new to Python and to pandas module/model testing, and I started studying machine learning and predictive time series recently.
I'm currently using python and pandas on Windows Powershell and Visual Studio Code. I have an RRD database exported from a virtual linux machine, from which i should take the data (it only has a date and value columns) to create and validate a model. The thing is that pandas doesn't read RRD files, and its XML file has a weird format. This is what i already tried:
-Installing RRDTool from pip to make a script to save the data to a CSV: kept getting errors regarding RRDTool libraries and header. If i go over to https://oss.oetiker.ch/rrdtool/ like the error suggests, last downloadable Cygwin Windows version is really old (2005 and 2007). Is rrdtool deprecated from windows?
-Trying some scripts from here to open XML files and parse through its code: failled because rrd xml file has a weird format to match rrd file.
-Trying to manually adapt the xml file to be parsable: this file has over 50000 rows and i would need to do this again in the future, so it is not desirable.
Also i read that there are pearl scripts for rrd2csv but also require rrd installed (and i don't know pearl).
Is there any way to export a rrd to csv on python - windows? or should I abandon it and try to do it on python - linux, for example?
Thanks for your time reading this.
I am working on a legacy python system, which accepts dataframe and extracts certain numeric measures out of it. It then uses a excel template, creates a table based on the template and outputs the screenshot of it as a png. Through out this, it uses various windows specific packages like pywin32 and com objects.
We are now planning to move the system to linux from Windows and as part of it, trying to get rid of windows packages. Can anyone help me how can I create something as shown in the image using python packages or libraries without using excel templates and pywin packages?
Since its confidential, I cannot show the exact output, but it would look something in line with the attached image. The highlighted parts are the conditional formats on each column based on a threshold.
I want to be able to access .xlsx files from Python 2.5.
Newest version of xlrd support .xlsx but not Python 2.5, and older versions of xlrd support Python 2.5 but not .xlsx.
I can't make openpyxl work. (See related question Install Openpyxl on python2.5 on Windows)
Finally I'm trying running Excel using win32, but it collides with existing instances of Excel open, it's a bit hackish.
Are there other alternatives?
There is one I know of : Pywin32. The latest version(build 219 from May 2014) is compatible all the way back to Python 2.3, you must just download the right version.
Now, the big trouble with Pywin32 is that it's badly documented and that without prior knowledge of COM/Visual Basic it's a pain to start rolling. Once you do and can just copy/paste macro code generated by excel it gets far easier.
This is what you want to do to get rolling :
import win32com.client
excel = win32com.client.Dispatch('Excel.Application')
If you then type, say excel.Workbooks.Add() you create a grand new excel workbook(you need to assign that to a variable to use it). So yeah, there is an alternative, but there is a learning curve involved.
PS :
You'll want to check out the Workbooks and Worksheets methods.
I'd like to be able to include python code snippets in Excel (ideally, in a nice format -- all colors/formats should be kept the same).
What would be the best way to go about it?
EDIT: I just want to store python code in an Excel spreadsheet for an easy overview -- I am not going to run it -- just want it to be nicely visible/formatted as part of an Excel worksheet.
I think that gist (from github) is precisely what you are looking for. From the description:
Gist is a simple way to share snippets
and pastes with others. All gists are
git repositories, so they are
automatically versioned, forkable and
usable as a git repository.
While Excel itself doesnot support other scripting Langauges than VBA, the open source OpenOffice and LibreOffice packages - which include a spreadsheet - can be scriptable with Python. Still, they won't allow Python code to be pasted on teh cells out of the box - but it is possible to write Python code which can act on the spredsheet contents (and do all the other things Python can do).
Is there any existing Python library that can validate data in Excel format? Or what kind of keyword should I use to search such an open source project? Thanks.
[Disclosure: I'm the author of xlrd]
xlrd allows you to extract data from XLS files. XLSX support is in alpha testing; e-mail me if you need it. You get told precisely what is in each cell (Excel cell type and value). It runs on Python 2.1 to 2.7 on any platform. You don't need Windows. You don't need Excel to be installed on your machine. Start with the tutorial found here.
I`m not sure what are you looking for, but there are three libraries that, in combination, can read and write excel files:
xlrd
xlwt
xlutils
They read and save binary excel archives both in windows and linux. There are functions for formatting data and styles.
If you want to check if some data column is in a given format you can do it with these libs (basically with xlrd).