Converts remaining objects columns to str
(df: pd.DataFrame)
| 93 | |
| 94 | |
| 95 | def obj_to_str(df: pd.DataFrame): |
| 96 | """Converts remaining objects columns to str""" |
| 97 | # convert objects to str / NA |
| 98 | df_str = df.select_dtypes("object") |
| 99 | df[df_str.columns] = df_str.astype("string") |
| 100 | |
| 101 | # convert categorical values (as strings if object) |
| 102 | def to_str_cat_vals(x: pd.Series) -> pd.Series: |
| 103 | if x.cat.categories.dtype == np.dtype("object"): |
| 104 | x.cat.categories = x.cat.categories.astype("string") |
| 105 | return x |
| 106 | |
| 107 | df_cat = df.select_dtypes("category") |
| 108 | df[df_cat.columns] = df_cat.apply(to_str_cat_vals) |
| 109 | |
| 110 | |
| 111 | def bipartite_to_bool(df: pd.DataFrame): |