0

I've got a dataframe with three columns, which I'd like to plot into a chart. I need the chart to show how many (or what's the %) of "Yes" rows from the whole "coverage". I struggle with creating a chart as these are non-numeric values. Can anyone advise, please?

parent      rule        coverage
AFKS RM     AFKS RM     Yes
AFLT RM     AFLT RM     Yes
AGRO LI     NaN         No
AKRN RM     AKRN RM     Yes
ALRS RM     ALRS RM     Yes
BANE RM     BANE RM     Yes

I looked at one of the other answers in Stackoverflow and tried the below but it gives me "TypeError: Empty 'DataFrame': no numeric data to plot".

grouped = df.groupby(['coverage'])['parent'] grouped.sum().plot(kind='bar')

I also tried to calculate percentage of coverage, but not sure how if that's the right way and how to plot from here.

df = df[result['coverage']=='Yes'].count() /df['coverage'].count()
4
  • It seems that the question is not presented correctly. The problem here is not really the non-numeric aspect of your data that can be easily replaced by True/False or 1/0. Commented Jun 8, 2017 at 12:57
  • Can you elaborate a bit on what is the problem then? Happy to change the wording of question if you explain a bit. Commented Jun 8, 2017 at 13:03
  • I think that (1) you should be more specific about the type of chart you want. (2) you should simplify your problem to help people understanding it very quickly (we dont need to know what is parent/rule, AFKS....) (3) you can give more functional pieces of code so that we can try reproducing the errors... (nb that's not me who downvoted your question) Commented Jun 8, 2017 at 14:29
  • 1
    Noted, thanks. Will be more specific next time. Commented Jun 9, 2017 at 15:51

1 Answer 1

2

The easiest way to find percentage is to use mean:

(df.loc[:,'coverage'] == 'Yes').mean()

Output:

0.83333333333333337

Plotting:

df.groupby('coverage')['coverage'].count().plot.pie(autopct='%.2f',figsize=(5,5)) enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.