I am attempting to create a function I can reuse to loop through a list of categorical columns for any given pandas data frame and generate a series of plots to visually get the value_counts() for each column.
I have written a function for this
def get_count_plot(cols_list):
for col in cols_list:
fig = sns.countplot(data=df[col], x=df[col].value_counts())
return fig
This function only returns one plot from a list of several columns. I get no errors on completion of the function.
I have tried adding enumerate() to this function with no luck.
I have used enumerate to do this but with a list of dataframes instead of a list of column names.
def generate_box_plot(list_of_dfs):
for idx, df in enumerate(list_of_dfs):
fig = px.box(df, x='Year', y='Transportation_Cnt', color='Month')
fig.update_xaxes(tickmode='linear')
fig.show()
This script worked just fine, however I am not working with a list of pandas dataframes.
Here is the amended
get_count_plot()And this the amended
get_count_plot()I hope you know to use them and Hope They work for you as expected.