1,104 views
2 2 votes

Hello,

I am trying to gain insight of the data but having hard time plotting it.

Suppose I have a data frame like below

ID Feature 1 Class
1 a good
2 a good
3 b good
4 b bad
5 a bad
6 a bad
7 b bad

In the above dataframe I have one feature "a" and "b" each has a good and bad class value.

for e.g

feature "a" has 2 good and 2 bad classes 

feature "b" has 1 good and 2 bad classes

  • How do i visualize this and plot it in python ?
  • How would I do it for more than one features in different subplots?

Sorry if this question seems like a very basic question to ask 

0% Accept Rate Accepted 0 answers out of 8 questions

2 Answers

1 1 vote

I figured it out by using the matplot lib. What we do is following
Divide the dataframe in to two

df_good = df[df['Class'] == 'good'] 
df_bad = df[df['Class'] == 'bad']

Then group the dataframes with the desired features

df_good = df_good.groupby('Feature 1')
df_bad = df_bad.groupby('Feature 1')

Then get the size which will give us the series and then plot the bar graph

df_good.size().plot(kind='bar', color='blue', legend=True, label='class = good')
df_bad.size().plot(kind='bar', color='blue', legend=True, label='class = bad')

This worked for me and plotted a nice bar graph.

0 0 votes

I think this url that shows how to aggregate and plot is what you are looking for. You have several options such as showing them in separate bar charts or stacking them up after aggregation. Another option is using multi-level pie chart or sunburst as you can see the example.

Related questions

6 6 votes
1 1 answer
700
700 views
Neo asked Sep 19, 2018
700 views
Hello,If someone can post the video tutorial for Pandas, Numpy and Matplotlib. I would appreciate it. I know that Lynda.com has those videos but I still have to get my Li...
1 1 vote
1 1 answer
677
677 views
Neo asked Oct 19, 2018
677 views
I have a dataframe like belowMT_001 MT_002 hour 2012-01-01 00:15:00 3.807107 22.759602 00:15:00 2012-01-01 00:30:00 5.076142 22.759602 00:30:00 2012-01-01 00:45:00 3.8071...
1 1 vote
1 1 answer
569
569 views
Gabriel777 asked Oct 27, 2018
569 views
Which of the following feature transformations would be a good choice to transform a categorical variable into a matrix binary feature?A. One-hot-encodingB. Principal Com...
0 0 votes
1 1 answer
585
585 views
tofighi asked Oct 18, 2018
585 views
If a big company such as Google behind it, with high probability it is a great library such as TensorFlow. But in general how can I found out?
1 1 vote
1 1 answer
741
741 views