pythonpython-3.xpandaspycharmpandas-profiling

how to recognize columns numeric and categorical in pandas using pandas profiling . only need dtype code not Analysis code of pandas profiling


I only need code to recognize the dtype of columns as done in pandas profiling (numeric and categorical) could you please extract only that code for me from pandas profiling package code.

series = series.fillna(np.nan)

# get `infer_dtypes` (bool) from config
if config.infer_dtypes:
    # Infer variable types
    vtype = typeset.infer_type(series)
    series = typeset.cast_to_inferred(series)
else:
    # Detect variable types from pandas dataframe (df.dtypes).
    # [new dtypes, changed using `astype` function are now considered]
    vtype = typeset.detect_type(series)

Solution

  • According to Pandas Profiling documentation the dtype of variables are inferred using Visions library Try this sample for columns type recognition:

    from visions.functional import infer_type
    from visions.typesets import CompleteSet
    typeset = CompleteSet()
    print(infer_type(df, typeset))