edc-pdutils
Use pandas with the Edc
Using the management command to export to CSV and STATA
The export_models management command requires you to log in with an account that has export permissions.
The basic command requires an app_label (-a) and a path to the export folder (-p)
By default, the export format is CSV but delimited using the pipe delimiter, |.
Export one or more modules
python manage.py export_models -a ambition_subject -p /ambition/export
The -a excepts more than one app_label
python manage.py export_models -a ambition_subject,ambition_prn,ambition_ae -p /ambition/export
Export data in CSV format or STATA format
To export as CSV where the delimiter is |
python manage.py export_models -a ambition_subject -p /ambition/export
To export as STATA dta use option -f stata
python manage.py export_models -a ambition_subject -p /ambition/export -f stata
Export encrypted data
To export encrypted fields include option --decrypt:
python manage.py export_models -a ambition_subject -p /ambition/export --decrypt
Note: If using the --decrypt option, the user account will need PII_EXPORT permissions
Export with a simple file name
To export using a simpler filename that drops the tablename app_label prefix and does not include a datestamp suffix.
Add option --use_simple_filename.
python manage.py export_models -a ambition_subject -p /ambition/export --use_simple_filename
Export for a country only
Add option --country.
python manage.py export_models -a ambition_subject -p /ambition/export --country="uganda"
Export manually
To export Crf data, for example:
from edc_pdutils.df_exporters import CsvCrfTablesExporter
from edc_pdutils.df_handlers import CrfDfHandler
app_label = 'ambition_subject'
csv_path = '/Users/erikvw/Documents/ambition/export/'
date_format = '%Y-%m-%d'
sep = '|'
exclude_history_tables = True
class MyDfHandler(CrfDfHandler):
visit_tbl = f'{app_label}_subjectvisit'
exclude_columns = ['form_as_json', 'survival_status','last_alive_date',
'screening_age_in_years', 'registration_datetime',
'subject_type']
class MyCsvCrfTablesExporter(CsvCrfTablesExporter):
visit_column = 'subject_visit_id'
datetime_fields = ['randomization_datetime']
df_handler_cls = MyDfHandler
app_label = app_label
export_folder = csv_path
sys.stdout.write('\n')
exporter = MyCsvCrfTablesExporter(
export_folder=csv_path,
exclude_history_tables=exclude_history_tables
)
exporter.to_csv(date_format=date_format, delimiter=sep)
To export INLINE data for any CRF configured with an inline, for example:
class MyDfHandler(CrfDfHandler):
visit_tbl = 'ambition_subject_subjectvisit'
exclude_columns = ['form_as_json', 'survival_status','last_alive_date',
'screening_age_in_years', 'registration_datetime',
'subject_type']
class MyCsvCrfInlineTablesExporter(CsvCrfInlineTablesExporter):
visit_columns = ['subject_visit_id']
df_handler_cls = MyDfHandler
app_label = 'ambition_subject'
export_folder = csv_path
exclude_inline_tables = [
'ambition_subject_radiology_abnormal_results_reason',
'ambition_subject_radiology_cxr_type']
sys.stdout.write('\n')
exporter = MyCsvCrfInlineTablesExporter()
exporter.to_csv(date_format=date_format, delimiter=sep)
Settings
EXPORT_FILENAME_TIMESTAMP_FORMAT: True/False (Default: False)
By default a timestamp of the current date is added as a suffix to CSV export filenames.
By default a timestamp of format %Y%m%d%H%M%S is added.
EXPORT_FILENAME_TIMESTAMP_FORMAT may be set to an empty string or a valid format for strftime.
If EXPORT_FILENAME_TIMESTAMP_FORMAT is set to an empty string, “”, a suffix is not added.
For example:
# default
registered_subject_20190203112555.csv
# EXPORT_FILENAME_TIMESTAMP_FORMAT = "%Y%m%d"
registered_subject_20190203.csv
# EXPORT_FILENAME_TIMESTAMP_FORMAT = ""
registered_subject.csv
Metadata
Release files for edc-pdutils 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| edc_pdutils-1.0.2.tar.gz | 59.2 kB | Without provenance | Details for edc_pdutils-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| edc_pdutils-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for edc_pdutils-1.0.2-py3-none-any.whl |
Total release size: 136.6 kB
Release files / edc_pdutils-1.0.2.tar.gz
| Download URL | edc_pdutils-1.0.2.tar.gz |
|---|---|
| Size | 59.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6a343d42323e5daf690a95f3c1ab2e12cd2bdc79bab2e3f5fd3ab1c049cb7ed
|
|
BLAKE2b-256 checksum How to use checksums |
f28475e25e17c2c15603a4a731cdfd01174bcd2ecdc2af5fb5ad6588104aa9a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Release files / edc_pdutils-1.0.2-py3-none-any.whl
| Download URL | edc_pdutils-1.0.2-py3-none-any.whl |
|---|---|
| Size | 77.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d7470252968685dc54900822c42ab03af27be083791d024bda4667fdd318a63
|
|
BLAKE2b-256 checksum How to use checksums |
ff5935ccb5c93251279e9286cf6a1c1d02764d0c687cb14a5e8851f4a4115438
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Security for edc-pdutils 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.