logo
Tags down

shadow

Applying stats.percentileofscore to every row by column


By : Jojo Jacob
Date : October 17 2020, 06:10 PM
will be helpful for those in need Series.rank
with pct=True, this is the equivalent of stats.percentileofscore with the default kind='rank'
code :
df[0].rank(pct=True)*100
#0     14.285714
#1     35.714286
#2     71.428571
#3     35.714286
#4     85.714286
#5     57.142857
#6    100.000000
#Name: 0, dtype: float64
from scipy import stats

for idx, val in df[0].iteritems():
    print(f'{val}: {stats.percentileofscore(df[0], score=val)}')

#1 : 14.285714285714286
#5 : 35.714285714285715
#34 : 71.42857142857143
#5 : 35.714285714285715
#67 : 85.71428571428571
#8 : 57.142857142857146
#98 : 100.0


Share : facebook icon twitter icon

Getting PostgreSQL percent_rank and scipy.stats.percentileofscore results to match


By : Sushma Girish
Date : March 29 2020, 07:55 AM
Any of those help You can use scipy.stats.rankdata. The following example reproduces the result shown at http://docs.aws.amazon.com/redshift/latest/dg/r_WF_PERCENT_RANK.html:
code :
In [12]: import numpy as np

In [13]: from scipy.stats import rankdata

In [14]: values = np.array([15, 20, 20, 20, 30, 30, 40])
In [15]: rank = rankdata(values, method='min')

In [16]: rank
Out[16]: array([1, 2, 2, 2, 5, 5, 7])
In [17]: (rank - 1) / (len(values) - 1)
Out[17]: 
array([ 0.        ,  0.16666667,  0.16666667,  0.16666667,  0.66666667,
        0.66666667,  1.        ])
In [87]: import numpy as np

In [88]: from scipy.stats import percentileofscore

In [89]: values = np.array([15, 20, 20, 20, 30, 30, 40])

In [90]: n = len(values)
In [91]: [n*percentileofscore(values, val, kind='strict')/100/(n-1) for val in values]
Out[91]: 
[0.0,
 0.16666666666666666,
 0.16666666666666666,
 0.16666666666666666,
 0.66666666666666663,
 0.66666666666666663,
 1.0]

What is the significance of t-stats value while applying ttest_ind on two pandas series?


By : xiaodiu
Date : March 29 2020, 07:55 AM
should help you out As you can read here, the scipy.stats.ttest_ind has two outputs
The calculated t-statistic. The two-tailed p-value.

Weighted version of scipy percentileofscore


By : MannyFreshCode
Date : March 29 2020, 07:55 AM
hop of those help? I'd like to pass weights to scipy.stats.percentileofscore. For example: , This should do the job.
code :
import numpy as np

def weighted_percentile_of_score(a, weights, score, kind='weak'):
    npa = np.array(a)
    npw = np.array(weights)

    if kind == 'rank':  # Equivalent to 'weak' since we have weights.
        kind = 'weak'

    if kind in ['strict', 'mean']:
        indx = npa < score
        strict = 100 * sum(npw[indx]) / sum(weights)
    if kind == 'strict':
        return strict

    if kind in ['weak', 'mean']:    
        indx = npa <= score
        weak = 100 * sum(npw[indx]) / sum(weights)
    if kind == 'weak':
        return weak

    if kind == 'mean':
        return (strict + weak) / 2


a = [1, 2, 3, 4]
weights = [2, 2, 3, 3]
print(weighted_percentile_of_score(a, weights, 3))  # 70.0 as desired.
[weighted_percentile_of_score(a, weights, val) for val in a]
# [20.0, 40.0, 70.0, 100.0]

Python numpy percentile vs scipy percentileofscore


By : user3154361
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I think you're not quite understanding what percentileofscore and percentile actually do. They are not inverses of each other.
code :
ap = np.asarray(sorted(df))
Nx = df.shape[0]

indices = z1 / 100 * (Nx - 1)
indices_below = np.floor(indices).astype(int)
indices_above = indices_below + 1

weight_above = indices - indices_below
weight_below = 1 - weight_above

x1 = ap[b] * weight_below   # 57.50000000000004
x2 = ap[a] * weight_above   # 12.499999999999956

x1 + x2
70.0

Pandas describe vs scipy.stats percentileofscore with NaN?


By : 万明辉
Date : March 29 2020, 07:55 AM
may help you . scipy.stats.percentileofscore does not ignore nan, nor does it check for the value and handle it in some special way. It is just another floating point value in your data. This means the behavior of percentileofscore with data containing nan is undefined, because of the behavior of nan in comparisons:
Related Posts Related Posts :
  • Python hex string encoding
  • Get week start date from week number
  • How to use imports from requirements.txt in python
  • Removing tab indent in ipython shell
  • I need to remove duplicates from a list but add the numeric value in them
  • Delay default arguments being read until function is called
  • Interpolate / fillna with a decay formula in pandas
  • What python package can translate Greek letter to ASCII requivalent?
  • How to get output of OS command from Jupyter notebook?
  • Printing AND writing the RIGHTLY formatted number
  • How do I create a shortcut to import most used python modules?
  • Matplotlib: Show selected date labels on x axis
  • Understanding memoization in Python
  • why does the len function return 2 on some iterations when they are all the same length?
  • Change in preference value does not affect the results of Affinity propagation Clustering
  • returning values inside a function
  • Why cant I use a variable in str slicing?
  • Section divider in Spyder
  • Conditional statement in selenium if element does not exists
  • Pandas : how to select index/row label in dataframe that matches a condition
  • What does zero do in A[0] in this code? Why not empty or another number?
  • Google App Engine urlfetch PayloadTooLargeError: Request exceeds 10 MiB limit for URL
  • Is there a way to set up optional arguments to bypass input arguments?
  • Suppress OpenMP debug messages when running Tensorflow on CPU
  • How to do GridSearchCV for F1-score in classification problem with scikit-learn?
  • Why does .pop() eventually stop and not keep removing items from a list until the list is empty?
  • How do I acess my Spider data from my main.py script?
  • Python Pandas Expand a Column of List of Lists to Two New Column
  • Overhead of python multiprocessing initialization is worse than benefits
  • Python Joining List and adding and removing characters
  • Adding an lxml library to project
  • Concatenating tensors in Tensorflow with None axis
  • Need help understanding why i get attribute error
  • How to force a MIDI device to report control status?
  • What does *** mean in Python -3?
  • How to get GFCC instead of MFCC in python?
  • How do I print a number n times in python?
  • How do i split a string wherever there are digits?
  • List Comprehension Python Prime numbers
  • "list index out of range" when reading data from file
  • What's the correct datetime format for the specified date string?
  • I cannot import CSV file?
  • Matplotlib pyplot plots look different after calling pandas profiling. How can I fix this?
  • Stopping all the instances of a specific region
  • Deal with Birtish summer time
  • Unable to use ColorWheel without loading kv (AttributeError)
  • What are these characters called: 。. !?etc Trying to split sentences stops working with non standard characters
  • rand.randint returning same number over and over?
  • Find longest sequence that does not contain a certain number
  • How do I convert a map object to list and also assign to a variable
  • sympy error: 'Symbol' object has no attribute 'pi'
  • How to remove words without vowels from a list in python
  • Downloading python to macbook
  • TypeError: __init__() missing 1 required positional argument: 'units'
  • Check if a class is a dataclass in Python
  • Unable to scrape google news heading via their class
  • Array of structs with dynamic allocation runs very slow in C in comparison to Python
  • Python Pandas - find all unique combinations of rows of a DataFrame without repeating values in the columns
  • How do I change the numbers in a cell to the word 'Bus' in Pandas Python
  • 'ascii' codec can't encode character : ordinal not in range (128)
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk