日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 百分比数据_如何使用python计算数据列相对于另一列的百分比排名

發布時間:2023/12/2 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 百分比数据_如何使用python计算数据列相对于另一列的百分比排名 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這是一個解決方案。

整理訓練數據。然后對驗證數據使用searchsorted。import pandas as pd

import numpy as np

# Generate Dummy Data

df_train = pd.DataFrame({'Values': 1000*np.random.rand(15712)})

#Sort Data

df_train = df_train.sort_values('Values')

# Calculating Rank and Rank_Pct for demo purposes

#but note that it is not needed for the solution

# The ranking of the validation data below does not depend on this

df_train['Rank'] = df_train.rank()

df_train['Rank_Pct']= df_train.Values.rank(pct=True)

# Demonstrate how Rank Percentile is calculated

# This gives the same value as .rank(pct=True)

pct_increment = 1./len(df_train)

df_train['Rank_Pct_Manual'] = df_train.Rank*pct_increment

df_train.head()

Values Rank Rank_Pct Rank_Pct_Manual

2724 0.006174 1.0 0.000064 0.000064

3582 0.016264 2.0 0.000127 0.000127

5534 0.095691 3.0 0.000191 0.000191

944 0.141442 4.0 0.000255 0.000255

7566 0.161766 5.0 0.000318 0.000318

現在使用searchsorted獲取驗證數據的秩比# Generate Dummy Validation Data

df_validation = pd.DataFrame({'Values': 1000*np.random.rand(1000)})

# Note searchsorted returns array index.

# In sorted list rank is the same as the array index +1

df_validation['Rank_Pct'] = (1 + df_train.Values.searchsorted(df_validation.Values))*pct_increment

以下是最終df_驗證數據幀的前幾行:print df_validation.head()

Values Rank_Pct

0 307.378334 0.304290

1 744.247034 0.744208

2 669.223821 0.670825

3 149.797030 0.145621

4 317.742713 0.314218

總結

以上是生活随笔為你收集整理的python 百分比数据_如何使用python计算数据列相对于另一列的百分比排名的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。