medicaid_utils.common_utils package

Submodules

medicaid_utils.common_utils.dataframe_utils module

medicaid_utils.common_utils.dataframe_utils.convert_ddcols_to_datetime(df: DataFrame, lst_col) DataFrame[source]

Convert list of columns specified in a dataframe to datetime type :param pandas_df df: dataframe :param list(str) lst_col: list of column names :rtype: None

medicaid_utils.common_utils.dataframe_utils.copy_ddcols(df: DataFrame, lst_col: List[str], lst_new_names: List[str])[source]
medicaid_utils.common_utils.dataframe_utils.export(df: ~dask.dataframe.core.DataFrame, pq_engine: str, output_filename: str, pq_location: str, csv_location: str, lst_datetime_col: ~typing.List[str], is_dask: bool = True, n_rows: int = -1, do_csv: bool = True, df_schema: ~pandas.core.frame.DataFrame = <class 'pandas.core.frame.DataFrame'>, logger_name: str = 'Dataframe utils', rewrite: bool = False, do_parquet: bool = True) None[source]
Parameters:
  • df

  • output_filename

  • pq_location

  • is_dask

Returns:

medicaid_utils.common_utils.dataframe_utils.fix_index(df: DataFrame, index_name: str, drop_column=True) DataFrame[source]
medicaid_utils.common_utils.dataframe_utils.get_first_day_gap(df, index_col, time_col, start_date_col, threshold)[source]
medicaid_utils.common_utils.dataframe_utils.get_reduced_column_names(multiidx_df_columns, combine_levels=False)[source]
medicaid_utils.common_utils.dataframe_utils.prepare_dtypes_for_csv(df_temp: DataFrame, df_schema: DataFrame)[source]
medicaid_utils.common_utils.dataframe_utils.safe_convert_int_to_str(df: DataFrame, lst_col) DataFrame[source]
medicaid_utils.common_utils.dataframe_utils.sas_to_pandas(filename: str)[source]
medicaid_utils.common_utils.dataframe_utils.toggle_datetime_string(df: DataFrame, lst_datetime_col, to_string: bool = True) None[source]

Toggles data columnes in the passed dataframe to string/ datatime types. Inplace updates. :param df: dask dataframe :param to_string bool: True to convert to string, False otherwise :return: None

medicaid_utils.common_utils.recipes module

medicaid_utils.common_utils.recipes.convert_to_int_str(x)[source]
medicaid_utils.common_utils.recipes.is_number(x)[source]
medicaid_utils.common_utils.recipes.log_assert(bool_: bool, message: str = '', logger: str | None = None, logger_name: str = '', verbose: bool = False)[source]

Use this as a replacement for assert if you want the failing of the assert statement to be logged.

medicaid_utils.common_utils.recipes.remove_ignore_if_not_exists(filename: str)[source]
medicaid_utils.common_utils.recipes.remove_tail_dot_zeros(a: str)[source]
medicaid_utils.common_utils.recipes.setup_logger(logger_name, log_file, level=20)[source]

medicaid_utils.common_utils.stats_utils module

medicaid_utils.common_utils.stats_utils.color_positive_green(x)[source]
medicaid_utils.common_utils.stats_utils.compute_contingency_table(pdf, lst_states, lst_metrics, lst_count_metrics, output_fname, pop_col_name='gt_50pc_hrsa_fqhc', dct_labels=None, state_col_name='STATE_CD')[source]
medicaid_utils.common_utils.stats_utils.compute_descriptives(pdf, lst_states, lst_metrics, output_fname, state_col_name='STATE_CD')[source]
medicaid_utils.common_utils.stats_utils.compute_missing_stats(df, output_fname, state_col_name='STATE_CD')[source]
medicaid_utils.common_utils.stats_utils.compute_t_stats(pdf, lst_states, lst_metrics, output_fname, pop_col_name='gt_50pc_hrsa_fqhc', dct_labels=None, state_col_name='STATE_CD')[source]
medicaid_utils.common_utils.stats_utils.cramers_corrected_stat(confusion_matrix)[source]

calculate Cramers V statistic for categorial-categorial association. uses correction from Bergsma and Wicher, Journal of the Korean Statistical Society 42 (2013): 323-328

medicaid_utils.common_utils.stats_utils.get_cont_table_statewise(pdf_included, lst_metrics, pop_col_name, lst_count_metrics, dct_labels, lst_st, state_col_name)[source]
medicaid_utils.common_utils.stats_utils.get_contingency_table(pdf_dataset, lst_categorical_metrics, pop_col_name, lst_numeric_col_to_binarize, dct_labels)[source]
medicaid_utils.common_utils.stats_utils.get_covar_plots(pdf, lst_covar, lst_hist_covar, cut_outliers=False)[source]
medicaid_utils.common_utils.stats_utils.get_descriptives(pdf, lst_st, lst_col, state_col_name)[source]
medicaid_utils.common_utils.stats_utils.get_missingness_stats(df, outputfname)[source]
medicaid_utils.common_utils.stats_utils.get_phi(pdf_x)[source]
medicaid_utils.common_utils.stats_utils.get_ranksum_table(pdf_dataset, lst_metrics, pop_col_name, dct_labels)[source]
medicaid_utils.common_utils.stats_utils.get_ranksum_table_statewise(pdf_included, lst_metrics, pop_col_name, dct_labels, lst_st, state_col_name)[source]
medicaid_utils.common_utils.stats_utils.get_utilisation_histograms(pdf, lst_covar)[source]

medicaid_utils.common_utils.usps_address module

This script shows an example of using requests and the USPS Address Information API. In order to use this, you must first register so you can get your USERID. Your ID must be in the environment variable USPS_USERID. For information on the API see here <https://www.usps.com/business/web-tools-apis/address-information-api.htm>_

class medicaid_utils.common_utils.usps_address.AddressStandardizationWebTool(street, city, state, name=None, suite=None, zip5=None, zip4=None, userid='186UNIVE5985')[source]

Bases: USPSShippingAPI

Object to get a standardized USPS Address.

api = 'Verify'
get_standardized_address()[source]

Returns a standardized format of the object’s address.

class medicaid_utils.common_utils.usps_address.USPSAddress(name='', suite='', street='', city='', state='', zip5='', zip4='')[source]

Bases: object

Representation of an United States Postal Service address.

original()[source]

Return the non-standardized address format

standardized()[source]

Return the standardized address format

zipcode()[source]

Returns the zipcode based on whether or not zip4 is used.

class medicaid_utils.common_utils.usps_address.USPSShippingAPI(api, userid='186UNIVE5985')[source]

Bases: object

Representation of the USPS Shipping API https://www.usps.com/business/web-tools-apis/address-information-api.htm

send_request()[source]

Send the request and return the XML response.

url = 'http://production.shippingapis.com/ShippingAPI.dll'
medicaid_utils.common_utils.usps_address.dump_xml(raw_xml)[source]

Return a string representation of XML with proper intendation

medicaid_utils.common_utils.usps_address.get_text(root, xpath)[source]

Return the text of the XPath element, or None if the element was not found.