Maternity Services Data Set (MSDS)

Maternity Services Data Set (MSDS)#

This page is a work in progress.

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[1], line 5
      3 sys.path.append(os.path.abspath('../../../../scripts/'))
      4 from data_doc_helper import NHSEDataSet as DS, last_modified
----> 5 ds = DS("MSDS")
      6 last_modified()

File /opt/build/repo/ukllc_book/docs/scripts/data_doc_helper.py:1140, in NHSEDataSet.__init__(self, dataset)
   1138 self.apa_cite, self.dl_cites = cites(self.doi)
   1139 self.latest_v = get_latest_dsvs(self.dataset)
-> 1140 self.participants = cohort_total(self.dataset)

File /opt/build/repo/ukllc_book/docs/scripts/data_doc_helper.py:1129, in NHSEDataSet.__init__.<locals>.cohort_total(ds)
   1127     return "N/A - Dataset comprises of multiple auxiliary tables"
   1128 else:
-> 1129     df = md.get_nhse_cohort_counts(ds)
   1130     df["count"] = df["count"].apply(lambda x: int(x.replace("<10", "0")))
   1131     return str(df["count"].sum())

File /opt/build/repo/ukllc_book/docs/scripts/mdapi_functions.py:64, in get_nhse_cohort_counts(ds)
     62 data = r.text
     63 pj = json.loads(data)
---> 64 return pd.json_normalize(pj)[["cohort", "count"]]

File ~/.local/share/mise/installs/python/3.11.15/lib/python3.11/site-packages/pandas/core/frame.py:3899, in DataFrame.__getitem__(self, key)
   3897     if is_iterator(key):
   3898         key = list(key)
-> 3899     indexer = self.columns._get_indexer_strict(key, "columns")[1]
   3901 # take() does not accept boolean indexers
   3902 if getattr(indexer, "dtype", None) == bool:

File ~/.local/share/mise/installs/python/3.11.15/lib/python3.11/site-packages/pandas/core/indexes/base.py:6115, in Index._get_indexer_strict(self, key, axis_name)
   6112 else:
   6113     keyarr, indexer, new_indexer = self._reindex_non_unique(keyarr)
-> 6115 self._raise_if_missing(keyarr, indexer, axis_name)
   6117 keyarr = self.take(indexer)
   6118 if isinstance(key, Index):
   6119     # GH 42790 - Preserve name from an Index

File ~/.local/share/mise/installs/python/3.11.15/lib/python3.11/site-packages/pandas/core/indexes/base.py:6176, in Index._raise_if_missing(self, key, indexer, axis_name)
   6174     if use_interval_msg:
   6175         key = list(key)
-> 6176     raise KeyError(f"None of [{key}] are in the [{axis_name}]")
   6178 not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique())
   6179 raise KeyError(f"{not_found} not in index")

KeyError: "None of [Index(['cohort', 'count'], dtype='object')] are in the [columns]"

1. Summary#

2. Metrics#

3. Version History#

4. Documentation#

5. Useful Syntax#