reindex_rows_and_cols#

caf.toolkit.pandas_utils.df_handling.reindex_rows_and_cols(df, index, columns, fill_value=nan, **kwargs)[source]#

Reindex a pandas DataFrame, making sure index/col types don’t clash.

Type checking wrapper around df.reindex(). If the type of the index or columns of df does not match the types given in index or columns, the index types will be cast to the desired types before calling the reindex.

Parameters:
  • df (DataFrame) – The pandas.DataFrame that should be re-indexed

  • index (list[Any]) – The index to reindex df to.

  • columns (list[Any]) – The columns to reindex df to.

  • fill_value (Any) – Value to use for missing values. Defaults to NaN, but can be any “compatible” value.

  • kwargs – Any extra arguments to pass into df.reindex()

Returns:

The given df, re-indexed to the index and columns given, including typing

Return type:

reindexed_df