janitor.also

janitor.also(df: pandas.core.frame.DataFrame, func: Callable, *args, **kwargs) → pandas.core.frame.DataFrame[source]

Add an arbitrary function with no return value to run in the pyjanitor method chain. This returns the input dataframe instead, not the output of func.

This method does not mutate the original DataFrame.

Example usage:

df = (
    pd.DataFrame(...)
    .query(...)
    .also(lambda df: print(f"DataFrame shape is: {df.shape}"))
    .transform_column(...)
    .also(lambda df: df.to_csv("midpoint.csv"))
    .also(
        lambda df: print(
            f"Column col_name has these values: {set(df['col_name'].unique())}"
        )
    )
    .group_add(...)
)
Parameters
  • df – A pandas dataframe.

  • func – A function you would like to run in the method chain. It should take one DataFrame object as a parameter and have no return. If there is a return, it will be ignored.

  • args – Optional arguments for func.

  • kwargs – Optional keyword arguments for func.

Returns

The input pandas DataFrame.