def format_us_zipcode(zipcode):
    """NiH US postcodes have wildly inconsistent formatting,
    leading to geocoding errors. If the postcode if greater
    than 5 chars, it should be in the format XXXXX-XXXX,
    or XXXXX, even if the first 5 chars require zero-padding."""
    ndigits = len(zipcode)
    # Only apply the procedure to numeric postcodes like
    if not zipcode.isnumeric():
        return zipcode
    # e.g 123456789 --> 12345-6789
    # or    3456789 --> 00345-6789
    if ndigits > 5:
        start, end = zipcode[:-4].zfill(5), zipcode[-4:]
        return f'{start}-{end}'
    # e.g 12345 --> 12345
    # or    345 --> 00345
    else:
        return zipcode.zfill(5)