Skip to content

Commit

Permalink
add median metod to PDF class
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrasilio committed Oct 31, 2019
1 parent 47654c7 commit f7ee6c7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pypqlx.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,24 @@ def mode(self):
return

def median(self):
pass
median = []
for i in sorted(set(pdf.period)):
cc = np.cumsum(pdf.count[pdf.period == i])
if cc[-1] % 2 == 0: #par
central = int(cc[-1] / 2)
pos = cc[cc >= central][0]
if abs(central - pos) >= 1:
a = pdf.power[pdf.period == i][cc == pos]
else:
a = int((pdf.power[pdf.period == i][cc == pos] +
pdf.power[pdf.period == i][cc > pos][0])/2)
else: # impar
central = int((cc[-1] + 1) / 2) #ok
pos = cc[cc >= central][0]
a = pdf.power[pdf.period == i][cc == pos]
median.append(a)
return


def average(self):
avg = []
Expand Down

0 comments on commit f7ee6c7

Please sign in to comment.