1
$\begingroup$

I want to draw plot by python based on this data

Id     Duration (s)       BinaryLabel
1          5                 correct
2          4                incorrect  
3          2                incorrect  
4          3                incorrect  
5          9                 correct
6          6                 correct
7          12               incorrect  

My data is with 800 rows. and the duration is going from 0 to 55 seconds

My X axis contain duration column and I want it to be divided like: 0-----5-----10------15------20-----...-----55

and the Y should contain the percent of 'correct' values.

I.e. :

from 0 to 5, I will have 25% correct,

from 5 to 10 I will have 100% correct .etc.

$\endgroup$

1 Answer 1

2
$\begingroup$

Maybe you can modify my code:

   import numpy as np

   Duration_ = np.random.choice(range(0,56), 10000)


   Binary_Level = []

   b_ =["correct", "incorrect"]

   Binary_Level = np.random.choice(b_, 10000)

   import pandas as pd

   dd = pd.DataFrame({'Duration_': Duration_, 'Binary_Level': 
      Binary_Level})

   xr_ = list(range(0,56,5))

   y_ = []

   for i in range(0,(len(xr_)-1)):

       a_ = np.logical_and(dd['Duration_'].values>=xr_[i], 
       dd['Duration_'].values<xr_[i+1])
       b_ = np.logical_and(np.logical_and(dd['Duration_'].values>=xr_[i], 
       dd['Duration_'].values<xr_[i+1]),
                               dd['Binary_Level'].values=='correct')
       y_.append(sum(b_)/sum(a_))

    import matplotlib
    matplotlib.pyplot.plot(xr_[1:12], y_)

enter image description here

$\endgroup$
1
  • $\begingroup$ thank bonez001 it works perfectly $\endgroup$
    – Nirmine
    Apr 14, 2019 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.