INNER CODE UNIT · Python
_infer_datatypes
aeturrell/skimpy · src/skimpy/__init__.py:72
def _infer_datatypes(df: pd.DataFrame) -> pd.DataFrame:
"""Infers the, and applies new, datatypes of dataframe columns.
Args:
df (pd.DataFrame): User data that we'd like to infer types on.
Returns:
pd.DataFrame: Same dataframe, but typed wherever possible.
"""
df_types = (
pd.DataFrame(df.apply(pd.api.types.infer_dtype, axis=0))
.reset_index()
.rename(columns={"index": "column", 0: "type"})
)
loop_types = df_types.values.tolist()
for col in loop_types:
if col[1] == "string":
data_type = "string"