I have a dataframe that has x-many columns (x varies by the input of the user). I want to be able to plot all of the columns in each dataframe to a single histogram.
Some of the code for this loop looks like this so far:
for var_name in variables:
df_var = (rand_sample.filter(like=str(var_name))) # filter on each variable for comparison
print(df_var)
# Plot Frequency
fig = plt.subplots(figsize=(12, 8))
plt.hist([df_var], alpha=0.35, bins=bin_size)
plt.title(str(j), fontsize=18)
plt.xlabel('Porosity Density', fontsize=15)
plt.ylabel('Frequency', fontsize=15)
plt.grid(True)
plt.show()
Where variables
is a list previously made with wanted strings that I'm filtering to group together in df_var
.
I get the error:
ValueError: cannot copy sequence with size 107574 to array axis with dimension 2
Which means there are 2 columns
trying to be plotted as 1 column
here - I understand this; I just don't know how to write the code to make plt.hist([df_var]...)
work for any number of columns.