issouluch
issouluch

Reputation: 85

Multi plot on a data frame with pandas

I'm asking you my question here because after a long time on the internet, I didn't found anything. Here's the problem: I'm working on a data science project and I want to put some results on a plot.

I have a data frame which is group by 2 attributes (as you can see on the picture). Those two attributes are "id_campaign" and "dayofweek", and all I want is to put on the same graph in order to see if there is any trend. I have enough reputation points to put a picture now :D!

So here is my data frame, you will understand more easily i think

my df

Upvotes: 2

Views: 771

Answers (1)

laurak
laurak

Reputation: 363

It's hard to know exactly what you are trying to do w/o an example. Here are some plots I use when looked at "grouped by" data:

# imports
import matplotlib.pyplot as plt

Bar plot of average of column_c by column_a

df.groupby('column_a').column_c.mean().plot(kind='bar')
plt.ylabel('Average of Column C Per Column A')

Bar plot of total of column_c by column_a

df.groupby('column_a').column_c.sum().plot(kind='bar')
plt.ylabel('Total of Column C Per Column A')

Grouped histograms (shows the distribution for each group)

df.column_c.hist(by=df.column_a)
df.column_c.hist(by=df.column_a, sharex=True)  # common X axis
df.column_c.hist(by=df.column_a, sharex=True, sharey=True)  # common X and Y axis

Boxplot of column_c by column_a (shows five-number summary and outliers)

df.boxplot(column='column_c', by='column_a')

Scatterplot matrix of all numerical columns

pd.scatter_matrix(df)

Scatterplot matrix of specific numerical columns

pd.scatter_matrix(df[['column_1', 'column_2', 'column_3']])

Upvotes: 2

Related Questions