Before and after transformation
Visualization
Plots the normal distribution before and after a certain transformation (sqrt, log, etc.)
Filename pattern: .ipynb, .py
import pandas as pd
params = {'dataframe': mpg_df,
'column': 'acceleration',
'bins': 15,
'equation': np.sqrt,
'y_label': 'acceleration histogram'}
def before_after_transform(dataframe, column, bins, equation, y_label):
fig, axis = plt.subplots(1, 2, figsize=(8, 3), sharey=True)
dataframe[column].hist(ax=axis[0], bins=bins)
dataframe[column].apply(equation).hist(ax=axis[1], bins=bins)
# Set labels
axis[0].set_xlabel(column)
axis[1].set_xlabel(f'log of {column}')
axis[0].set_ylabel(y_label)
return plt.show()
before_after_transform(**params)