Great video, but I have one question which is that how do I group multiple columns together and plot them as one histogram? Say if I want to plot the distribution of user stats by type, but my data has the columns: January Phone call, February Phone call, January Web visit, February Web visits, and I want the histogram to see the Phone calls as one group and Web visits as another group, how could I achieve that? Thank you!
@TheAIandDSChannel Жыл бұрын
Thank you for the comment. One approach would be to extract the columns which you want to group together, which in this case is a new column that has the aggregated values of both the columns of all the phone calls and website visits. And then using this data, plot a histogram. phone_call_cols = ['January Phone call', 'February Phone call'] web_visit_cols = ['January Web visit', 'February Web visit'] df['Phone calls'] = df[phone_call_cols].sum(axis=1) df['Web visits'] = df[web_visit_cols].sum(axis=1) plt.hist([df['Phone calls'], df['Web visits']], bins=10, label=['Phone calls', 'Web visits']) plt.xlabel('User Stats') plt.ylabel('Frequency') plt.legend() plt.show() hope that helps.
@dustbites3557 Жыл бұрын
@@TheAIandDSChannel I'll give this a try! Thank you very much!!