Skip to content

Instantly share code, notes, and snippets.

@nkhine
Created September 7, 2018 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkhine/c4b7c9a98fced7d306b1ae6199ba075c to your computer and use it in GitHub Desktop.
Save nkhine/c4b7c9a98fced7d306b1ae6199ba075c to your computer and use it in GitHub Desktop.
pyexcel
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyexcel as p
>>> dict_list=[{'alfa':['001','2'], 'beta':['001','3'], 'gamma':['001','2']},
... {'alfa':['002','6'], 'beta':['002','4'], 'omega':['002','7']}]
>>>
>>> s = p.Sheet()
>>> for d in dict_list:
... s.row += p.get_sheet(adict=d, transpose_after=True)
...
>>> s.colnames = ['WORD', 'TXT', 'FREQ']
>>> s
pyexcel sheet:
+-------+-----+------+
| WORD | TXT | FREQ |
+=======+=====+======+
| alfa | 001 | 2 |
+-------+-----+------+
| beta | 001 | 3 |
+-------+-----+------+
| gamma | 001 | 2 |
+-------+-----+------+
| alfa | 002 | 6 |
+-------+-----+------+
| beta | 002 | 4 |
+-------+-----+------+
| omega | 002 | 7 |
+-------+-----+------+
>>> s.save_as('output.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment