Package: whyqd
whyqd: simplicity, transparency, speedWhat is it?More research, less wranglingwhyqd(/wɪkɪd/) is a curatorial toolkit intended to produce well-structured and predictable
data for research analysis.It provides an intuitive method for creating schema-to-schema crosswalks for restructuring messy data to conform to a
standardised metadata schema. It supports rapid and continuous transformation of messy data using a simple series of
steps. Once complete, you can import wrangled data into more complex analytical or database systems.whyqdplays well with your existing Python-based data-analytical tools. It usesRayandModinas a drop-in replacement forPandasto support
processing of large datasets, andPydanticfor data models.Each definition is saved asJSON Schema-compliantfile. This permits others to read and
scrutinise your approach, validate your methodology, or even use your crosswalks to import and transform data in
production.Once complete, a transform file can be shared, along with your input data, and anyone can import and validate your
crosswalk to verify that your output data is the product of these inputs.Why use it?whyqdallows you to get to work without requiring you to achieve buy-in from anyone or change your existing code.If you don't want to spend days or weeks slogging through data when all you want to do is test whether your source
data are even useful. If you already have a workflow and established software which includes Python and pandas, and
don't want to change your code every time your source data changes.If you want to go from aCthulhu datasetlike this:UNDP Human Development Index 2007-2008: a beautiful example of messy data.To this:country_nameindicator_namereferenceyearvalues0Hong Kong, China (SAR)HDI ranke2008211SingaporeHDI ranknan2008252Korea (Republic of)HDI ranknan2008263CyprusHDI ranknan2008284Brunei DarussalamHDI ranknan2008305BarbadosHDI ranke,g,f200831With a readable set of scripts to ensure that your process can be audited and repeated:schema_scripts=[f"UNITE > 'reference' <{REFERENCE_COLUMNS}","RENAME > 'country_name' < ['Country']","PIVOT_LONGER > ['indicator_name', 'values'] < ['HDI rank', 'HDI Category', 'Human poverty index (HPI-1) - Rank;;2008', 'Human poverty index (HPI-1) - Value (%);;2008', 'Probability at birth of not surviving to age 40 (% of cohort);;2000-05', 'Adult illiteracy rate (% aged 15 and older);;1995-2005', 'Population not using an improved water source (%);;2004', 'Children under weight for age (% under age 5);;1996-2005', 'Population below income poverty line (%) - $1 a day;;1990-2005', 'Population below income poverty line (%) - $2 a day;;1990-2005', 'Population below income poverty line (%) - National poverty line;;1990-2004', 'HPI-1 rank minus income poverty rank;;2008']","SEPARATE > ['indicator_name', 'year'] < ';;'::['indicator_name']","DEBLANK","DEDUPE",]Thenwhyqdmay be for you.How does it work?Crosswalks are mappings of the relationships between fields defined in different metadataschemas. Ideally, these are one-to-one, where a field in
one has an exact match in the other. In practice, it's more complicated than that.Your workflow is:Define a single destination schema,Derive a source schema from a data source,Review your source data structure,Develop a crosswalk to define the relationship between source and destination,Transform and validate your outputs,Share your output data, transform definitions, and a citation.It starts like this:importwhyqdasqdInstalland then read thequickstart.There are four worked tutorials to guide you through typical scenarios:Aligning multiple sources of local government data from a many-headed Excel spreadsheet to a single schemaPivoting wide-format data into archival long-formatWrangling Cthulhu data without losing your mindTransforming data containing American dates, currencies as strings and misaligned columnsInstallationYou'll need at least Python 3.9, then install with your favourite package manager:pipinstallwhyqdTo derive a source schema from tabular data, import fromDATASOURCE_PATH, define itsMIMETYPE, and derive a schema:importwhyqdasqddatasource=qd.DataSourceDefinition()datasource.derive_model(source=DATASOURCE_PATH,mimetype=MIMETYPE)schema_source=qd.SchemaDefinition()schema_source.derive_model(data=datasource.get)schema_source.fields.set_categories(name=CATEGORY_FIELD,terms=datasource.get_data())schema_source.save()Get started...ChangelogThe version history can be found in thechangelog.Background and fundingwhyqdwas created to serve a continuous data wrangling process, including collaboration on more complex messy
sources, ensuring the integrity of the source data, and producing a complete audit trail from data imported to our
database, back to source. You can see the product of that atopenLocal.uk.whyqdreceived initial fundingfrom the European Union's Horizon 2020 research and innovation programme under grant agreement No 101017536. Technical
development support is fromEOSC Futurethrough theRDA Open Call mechanism, based on evaluations of
external, independent experts.The 'backronym' forwhyqd/wɪkɪd/ isWhythawk Quantitative Data,Whythawkis an open data science and open research technical consultancy.LicenceThewhyqdPython distributionis licensed under the terms of theBSD 3-Clause license. All documentation is released underAttribution 4.0 International (CC BY 4.0).whyqdtradenames and
marks are copyrightWhythawk.