-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPysheet.html
153 lines (102 loc) · 16.5 KB
/
Pysheet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: class Pysheet</title>
</head><body bgcolor="#f0f0f8">
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Pysheet">class <strong>Pysheet</strong></a></font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Pysheet - A library to read, write and manipulate spreadsheets<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Pysheet-__add__"><strong>__add__</strong></a>(self, other, mergeHeaders<font color="#909090">=False</font>)</dt><dd><tt>merges two Pysheets together</tt></dd></dl>
<dl><dt><a name="Pysheet-__delitem__"><strong>__delitem__</strong></a>(self, key)</dt><dd><tt>deletes a row from the dictionary</tt></dd></dl>
<dl><dt><a name="Pysheet-__getitem__"><strong>__getitem__</strong></a>(self, key, default<font color="#909090">=None</font>)</dt><dd><tt>gets the row of an ID from the dictionary</tt></dd></dl>
<dl><dt><a name="Pysheet-__init__"><strong>__init__</strong></a>(self, filename<font color="#909090">=None</font>, delimiter<font color="#909090">=None</font>, iterable<font color="#909090">=None</font>, idColumn<font color="#909090">=None</font>, skip<font color="#909090">=0</font>, skipColR<font color="#909090">=0</font>, skipColL<font color="#909090">=0</font>, noHeader<font color="#909090">=False</font>, rstack<font color="#909090">=False</font>, cstack<font color="#909090">=False</font>, trans<font color="#909090">=False</font>)</dt><dd><tt>initializes the object and reads in a sheet from a file or an iterable.<br>
Optionally specify the column number that contains the unique IDs (starting from 0)</tt></dd></dl>
<dl><dt><a name="Pysheet-__iter__"><strong>__iter__</strong></a>(self)</dt><dd><tt>returns an iterator over the ID:row items in the csv</tt></dd></dl>
<dl><dt><a name="Pysheet-__len__"><strong>__len__</strong></a>(self)</dt><dd><tt>returns the length of the header row in the dictionary</tt></dd></dl>
<dl><dt><a name="Pysheet-__setitem__"><strong>__setitem__</strong></a>(self, key, row)</dt><dd><tt>changes the row of an ID in the dictionary</tt></dd></dl>
<dl><dt><a name="Pysheet-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>returns a string representation of this object</tt></dd></dl>
<dl><dt><a name="Pysheet-addCell"><strong>addCell</strong></a>(self, key, header<font color="#909090">=None</font>, value<font color="#909090">=None</font>, mode<font color="#909090">='overwrite'</font>, collapse<font color="#909090">=';'</font>)</dt><dd><tt>adds a single cell in the dictionary. mode can be 'smart_append'<br>
(adds a value if not already present), 'append', 'overwrite' and<br>
'add' (performs plus operation if values are numeric)</tt></dd></dl>
<dl><dt><a name="Pysheet-clear"><strong>clear</strong></a>(self)</dt><dd><tt>clears the object</tt></dd></dl>
<dl><dt><a name="Pysheet-consolidate"><strong>consolidate</strong></a>(self, consolidations, cleanUp<font color="#909090">=False</font>, mode<font color="#909090">='smart_append'</font>)</dt><dd><tt>consolidates columns according to keywords. consolidations is a 2D list of<br>
[[header, keyword, keyword, ...], ...]<br>
Use cleanUp=True to delete the consolidated columns after consolidation<br>
mode is one of: 'smart_append' (appends new value if not already present),<br>
'append', 'overwrite' and 'add' (adds up values if numeric)</tt></dd></dl>
<dl><dt><a name="Pysheet-containsColumn"><strong>containsColumn</strong></a>(self, header)</dt><dd><tt>True if header exists in the csv header list</tt></dd></dl>
<dl><dt><a name="Pysheet-contract"><strong>contract</strong></a>(self, mode<font color="#909090">='overwrite'</font>)</dt><dd><tt>concatenates columns that have the same header. mode can be:<br>
'append', 'overwrite', 'smart_append' (consolidates values if not already present)<br>
or 'add' (performs plus operation for numeric values)</tt></dd></dl>
<dl><dt><a name="Pysheet-excluded"><strong>excluded</strong></a>(self, key)</dt><dd><tt>returns True if an item's exclusion header is non-blank</tt></dd></dl>
<dl><dt><a name="Pysheet-expand"><strong>expand</strong></a>(self)</dt><dd><tt>blank-pads to make all rows as long as the headers</tt></dd></dl>
<dl><dt><a name="Pysheet-getCell"><strong>getCell</strong></a>(self, key, header)</dt><dd><tt>gets a cell by key and header name</tt></dd></dl>
<dl><dt><a name="Pysheet-getColumns"><strong>getColumns</strong></a>(self, cols<font color="#909090">=None</font>, blanks<font color="#909090">=False</font>, exclude<font color="#909090">=True</font>)</dt><dd><tt>extracts columns and corresponding IDs from the dictionary (with column headers)<br>
returns requested columns, row-by-row. Supports operators like cols='age>20'.<br>
To get multiple columns e.g. set cols=[3,6,5]<br>
Valid column operators: > (greater than), < (less than), = (equals), ! (does not equal),<br>
~ (contains), =UNIQUE (will only keep one of each duplicate in the column)<br>
blanks=False will remove rows that contain *any* blank column entries whatsoever<br>
exclude=True will skip rows that have a value in the __exclude__ column<br>
Default is return all columns</tt></dd></dl>
<dl><dt><a name="Pysheet-getColumnsContaining"><strong>getColumnsContaining</strong></a>(self, items)</dt><dd><tt>returns indices of columns contains anything in list of items</tt></dd></dl>
<dl><dt><a name="Pysheet-getColumnsWithBlanks"><strong>getColumnsWithBlanks</strong></a>(self)</dt><dd><tt>returns indices of columns containing blank values</tt></dd></dl>
<dl><dt><a name="Pysheet-getHeaders"><strong>getHeaders</strong></a>(self, idCol<font color="#909090">=True</font>, index<font color="#909090">=False</font>)</dt><dd><tt>returns the headers of the columns in the dictionary<br>
(indices instead if index=True)</tt></dd></dl>
<dl><dt><a name="Pysheet-getIds"><strong>getIds</strong></a>(self)</dt><dd><tt>returns all keys of the dictionary, except the header<br>
key and any IDs starting with '__'</tt></dd></dl>
<dl><dt><a name="Pysheet-getRow"><strong>getRow</strong></a>(self, key, default<font color="#909090">=None</font>)</dt><dd><tt>gets the row of an ID from the dictionary</tt></dd></dl>
<dl><dt><a name="Pysheet-getRowsContaining"><strong>getRowsContaining</strong></a>(self, items)</dt><dd><tt>returns IDs of columns containing anything in list of items</tt></dd></dl>
<dl><dt><a name="Pysheet-getRowsWithBlanks"><strong>getRowsWithBlanks</strong></a>(self)</dt><dd><tt>returns IDs of rows containing blank values</tt></dd></dl>
<dl><dt><a name="Pysheet-grab"><strong>grab</strong></a>(self, key<font color="#909090">=None</font>, header<font color="#909090">=None</font>, level<font color="#909090">=None</font>)</dt><dd><tt>grabs a cell (key + header), a whole row (just key), or all keys that<br>
correspond to 'level' (header + level) from the dictionary. level='ALL' is valid</tt></dd></dl>
<dl><dt><a name="Pysheet-headerIndex"><strong>headerIndex</strong></a>(self, header)</dt><dd><tt>returns the index of a header in the dictionary</tt></dd></dl>
<dl><dt><a name="Pysheet-height"><strong>height</strong></a>(self)</dt><dd><tt>returns the number of rows in the dictionary</tt></dd></dl>
<dl><dt><a name="Pysheet-insertColumn"><strong>insertColumn</strong></a>(self, header, index<font color="#909090">=None</font>, init<font color="#909090">=None</font>)</dt><dd><tt>inserts a blank column in the dictionary at index (default=1)<br>
initializes with self.<strong>_BLANK_VALUE</strong></tt></dd></dl>
<dl><dt><a name="Pysheet-isBlank"><strong>isBlank</strong></a>(self, cell)</dt><dd><tt>returns True if cell is considered blank</tt></dd></dl>
<dl><dt><a name="Pysheet-isEmpty"><strong>isEmpty</strong></a>(self)</dt><dd><tt>returns True if this sheet is blank</tt></dd></dl>
<dl><dt><a name="Pysheet-keys"><strong>keys</strong></a>(self, headers<font color="#909090">=True</font>, exclude<font color="#909090">=True</font>, lockedRows<font color="#909090">=True</font>)</dt><dd><tt>returns a list of the keys in the dictionary.<br>
headers=True adds columnheaders to the list returned<br>
exclude=True skips rows with a non-blank __exclude__ column<br>
lockedRows=True also returns rows whose ID starts with '__'</tt></dd></dl>
<dl><dt><a name="Pysheet-levels"><strong>levels</strong></a>(self, column, hasHeader<font color="#909090">=False</font>)</dt><dd><tt>returns a tuple containing (the discreet items or 'levels', is a numeric list?,<br>
the number of levels)</tt></dd></dl>
<dl><dt><a name="Pysheet-load"><strong>load</strong></a>(self, iterable, idColumn<font color="#909090">=None</font>, skip<font color="#909090">=0</font>, skipColR<font color="#909090">=0</font>, skipColL<font color="#909090">=0</font>, noHeader<font color="#909090">=False</font>, rstack<font color="#909090">=False</font>, cstack<font color="#909090">=False</font>, trans<font color="#909090">=False</font>)</dt><dd><tt>creates a Pysheet object from an iterable.<br>
Optionally specify the column number that contains the unique IDs (starting from 0)</tt></dd></dl>
<dl><dt><a name="Pysheet-loadFile"><strong>loadFile</strong></a>(self, filename, idColumn<font color="#909090">=None</font>, skip<font color="#909090">=0</font>, skipColR<font color="#909090">=0</font>, skipColL<font color="#909090">=0</font>, noHeader<font color="#909090">=False</font>, rstack<font color="#909090">=False</font>, cstack<font color="#909090">=False</font>, trans<font color="#909090">=False</font>)</dt><dd><tt>loads the sheet into a dictionary where the IDs in the first column are<br>
mapped to their rows. Optionally specify the column number that contains<br>
the unique IDs (starting from 0)</tt></dd></dl>
<dl><dt><a name="Pysheet-mergedValue"><strong>mergedValue</strong></a>(self, cellA, cellB, mode<font color="#909090">='smart_append'</font>)</dt><dd><tt>returns the merged value of two cells, according to mode:<br>
'smart_append' (appends new value if not already present), 'append',<br>
'overwrite', 'add' (adds up values if numeric) or 'mean' (numeric average)</tt></dd></dl>
<dl><dt><a name="Pysheet-parseColumns"><strong>parseColumns</strong></a>(self, cols)</dt><dd><tt>parses the input column specification. For example expands ["5","1-3","Age>13"]<br>
to [[5,1,2,3,9],['','','','','>'],['','','','',13]]<br>
Returns list of corresponding [[header index, ...], [operator, ...], [argument, ...]]</tt></dd></dl>
<dl><dt><a name="Pysheet-pop"><strong>pop</strong></a>(self, x, default<font color="#909090">=None</font>)</dt><dd><tt>pops an item out of the dictionary</tt></dd></dl>
<dl><dt><a name="Pysheet-produceColumn"><strong>produceColumn</strong></a>(self, col<font color="#909090">=0</font>, blanks<font color="#909090">=True</font>, exclude<font color="#909090">=True</font>)</dt><dd><tt>extracts a column and corresponding IDs from the dictionary (no column headers)<br>
returns a 2D list where [0] is a list of IDs and [1] is the requested column<br>
Input a list of columns to make a hybrid column eg. col=[3,6,5]<br>
blanks=False will remove rows that contain *any* blank column entries whatsoever<br>
exclude=True will skip rows that have a value in the __exclude__ column<br>
Default is return a list of a list of IDs</tt></dd></dl>
<dl><dt><a name="Pysheet-removeCell"><strong>removeCell</strong></a>(self, key, header<font color="#909090">=None</font>)</dt><dd><tt>deletes a cell or a row from the dictionary</tt></dd></dl>
<dl><dt><a name="Pysheet-removeColumns"><strong>removeColumns</strong></a>(self, cols)</dt><dd><tt>removes columns from the dictionary by index (not by header name), starting from 0</tt></dd></dl>
<dl><dt><a name="Pysheet-removeMissing"><strong>removeMissing</strong></a>(self, rows<font color="#909090">=False</font>)</dt><dd><tt>removes rows or columns (default) with empty fields and returns what was removed</tt></dd></dl>
<dl><dt><a name="Pysheet-rename"><strong>rename</strong></a>(self, newName, header<font color="#909090">=None</font>, key<font color="#909090">=None</font>)</dt><dd><tt>renames a column header, or a row key (not both)</tt></dd></dl>
<dl><dt><a name="Pysheet-save"><strong>save</strong></a>(self, output<font color="#909090">=None</font>, delimiter<font color="#909090">=','</font>, saveHeaders<font color="#909090">=True</font>, replaceHeaders<font color="#909090">=None</font>, trans<font color="#909090">=False</font>)</dt><dd><tt>saves the current state of the dictionary as a delimited text file</tt></dd></dl>
<dl><dt><a name="Pysheet-setCell"><strong>setCell</strong></a>(self, key, header, value)</dt><dd><tt>sets a cell value by key and header name<br>
updates dictionary keys as necessary</tt></dd></dl>
<dl><dt><a name="Pysheet-setRow"><strong>setRow</strong></a>(self, key, row)</dt><dd><tt>changes the row of an ID in the dictionary</tt></dd></dl>
<dl><dt><a name="Pysheet-zeroFill"><strong>zeroFill</strong></a>(self, zero<font color="#909090">=0</font>)</dt><dd><tt>fills blank cells with zero</tt></dd></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>delimiter</strong> = None</dl>
<dl><dt><strong>filename</strong> = None</dl>
<dl><dt><strong>idColumn</strong> = 0</dl>
</td></tr></table>
</body></html>