Spreadsheets as data: spreadsheet handling for humans
Project description
What is this?
Don’t be sad, turn that messy spreadsheet into actual data! This is for people new to programming who need to do stuff with typical messy spreadsheet data.
It’s also for anyone who could use quick clean access to the kind of spreadsheet data passed around in offices.
It’s not for data scientists and huge data sets (fortunately there’s plenty of support for that elsewhere).
How to install
pip3 install sad
How to access the spreadsheet
These examples assume a simple spreadsheet file called hr.csv that contains these values:
Full Name Employee ID Start Date Sue Storm 1000 1/1/18 Kitty Pride 1001 2/5/18
Use this import statement:
from sad import Spreadsheet
The spreadsheet data needs to be in CSV format. Open the file and pass the file object to Spreadsheet.from_csv():
hr_csv = open('hr.csv') sheet = Spreadsheet.from_csv(hr_csv)
Accessing cells by index
The Spreadsheet can be treated as a 2-dimensional array, so if you want the value of the second cell down and third cell over, you can do this:
value = sheet[1][2] print(value)
This prints:
1/1/18
Accessing cells by header name
If you use a header name to get to a cell, the first row of the spreadsheet is assumed to be the headers. To get the same cell as above, you can do this:
value = sheet[1]['Start Date'] print(value)
This also prints:
1/1/18
You may find it more intuitive to get the row first, like so:
employee = sheet[1] print(employee['Start Date']
Even better, you can use header names for both the row and column:
print(sheet['Sue Storm']['Start Date'])
Looping over rows
It’s easy to loop over rows:
for row in sheet: print(row)
This prints:
First Name, Last name, start date Sue, Storm, 1/1/18 Kitty, Pride, 2/5/18
To print every cell in the spreadsheet:
for row in sheet: for cell in row: print(cell)
This prints:
Full Name Employee ID Start Date Sue Storm 1/1/18 Kitty Pride 2/5/18
Looping over columns
You can also loop over columns:
for col in sheet.columns: print(col) print('----')
This prints:
Full Name Sue Storm Kitty Pride ---- Employee ID 1000 1001 ---- Start Date 1/1/18 2/5/18
What’s next?
This first release provides some nice intuitive ways to access spreadsheet data.
Future releases will add support for dealing with typical problems in spreadsheets that were created for humans to read rather than for computers to process.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file sad-1.0.0.tar.gz
.
File metadata
- Download URL: sad-1.0.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95e68321586726896188c7e0e144ab77b712163e0a59ac1a24c93550dc03c71b |
|
MD5 | d57000ee9814df1021dafa1c7f670fb8 |
|
BLAKE2b-256 | 6c923d6d1485f4dbbe52f4fb88881f6a5a37067e566857db72b0015ac3a2bddd |