Metadata-Version: 2.1
Name: sheetcalc
Version: 0.1.6
Summary: extract insights from 2d tables
Home-page: https://github.com/satapathy/pypi-sheetcalc
Author: S Satapathy
Author-email: shubhakant.satapathy@gmail.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown

# sheetcalc
Extract insights from two dimentional tables. Load data into table one by one, or in bulk using import features.
Use grouping features to aggregate by one or more columns similar to SQL.


### Import Package

```python
from sheetcalc import Table
```

### Create Table Instance
```python
tbl = Table ('table-name', 'optional table description')
```

#### Create Columns
```python
tbl.add_column ()
tbl.add_column ('Amt')
```
When no column name is supplied, a name will be autogenerated as 'Column_n' where 'n' is the Column number.  Column names do not need to be pre-defined. Default names get generated dynamically when loading rows when a new column is detected.

### Add Rows into Table

Add rows one at a time
```python
tbl.add_row (['John', 100, 'Business'])
tbl.add_row (['Mary', 35,  'Personal'])
tbl.add_row (['Rob' , 2,   'Business'])
tbl.add_row (['John', 15,  'Personal'])
tbl.add_row (['Mary', 10,  'Personal'])
tbl.add_row (['Ken',  10])
tbl.add_row (['Ken',  10,  'Personal'])
```
or add rows from comma delimitted file with a header row
```python
tbl.load_from_delimited_file ('/home/user/data.csv')
```

or from file delimitted by any char, e.g tab
```python
tbl.load_from_delimited_file ('/home/user/data.csv', '\t')
```

or from a file without a header row
```python
tbl.load_from_delimited_file ('/home/user/data.csv', ',', False)
```

### Grouping Data and Aggregating Results

Group values by one or more columns
```python
keymap, valuemap, skipped = tbl.group_by (
	'Column_1, Column_3',
	'Sum (Amt), min(Amt), count (Amt)'
)
```
Return values:
- **keymap** Hashmap from system Generated hashkey to Grouping Values
- **valuemap** Hashmap from system Generated hashkey to Aggretate results
- **skipped** - Rows not included in the groping operation. This includes failed rows.

You can correlate the values between the two returned Hashmaps 'keymap' and 'valuemap' using their hashkeys. The hashkeys are simply comma separated values of data in Grouping Columns. Therefore, in case of Single Column Grouping (and other situations when a comma separated list is sufficient) you can safely discard the returned 'keymap' and use only 'valuemap'.


**Supported Aggregation Functions**
- count
- min
- max
- sum

### Print Results and Statistics

Raw Print including Data
```python
print (values)
or
print (json.dumps (valuemap, default=lambda o: o.__dict__, sort_keys=True, indent=4))
```

Print Processing Runtimes and other Statistics
```python
print (tbl.stats)
or
print (json.dumps (tbl.stats, default=lambda o: o.__dict__, sort_keys=True, indent=4))
```


