Skip to content

Instantly share code, notes, and snippets.

@patrickbrus
Created May 28, 2021 14:12
Show Gist options
  • Save patrickbrus/edf0e20b88ef5b6efd8f00793cf3547f to your computer and use it in GitHub Desktop.
Save patrickbrus/edf0e20b88ef5b6efd8f00793cf3547f to your computer and use it in GitHub Desktop.
# create a list of categorical features to loop over
list_categorical_features = df.columns[(df.dtypes == np.object).values].to_list()
# create a list of numerical features to loop over
list_numerical_features = df.columns[np.logical_not((df.dtypes == np.object).values)].to_list()
# plot on histogram for each numerical feature
for numerical_feature in list_numerical_features:
plt.title(f"Histogram of {numerical_feature}")
plt.hist(df[numerical_feature])
plt.show()
# call value_counts for each categorical feature
for cat_feature in list_categorical_features:
print(df[cat_feature].value_counts())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment