How do I get the percentile for a row in a pandas dataframe?

后端 未结 3 2011
既然无缘
既然无缘 2020-12-30 08:48
Example DataFrame Values -  

0     78
1     38
2     42
3     48
4     31
5     89
6     94
7    102
8    122
9    122  

stats.percentileofscore(temp[\'INCOME\'].v         


        
3条回答
  •  我在风中等你
    2020-12-30 09:24

    Let's consider the below dataframe:

    DataFrame

    In order to get the percentile of a column in pandas Dataframe we use the following code:

     survey['Nationality'].value_counts(normalize='index')
    

    Output:

    USA 0.333333

    China 0.250000

    India 0.250000

    Bangadesh 0.166667

    Name: Nationality, dtype: float64

    In order to get the percentile of a column in pandas Dataframe with respect to another categorical column

    pd.crosstab(survey.Sex,survey.Handedness,normalize = 'index')
    

    The output would be something like given below

    Output

提交回复
热议问题