数据框中每列和每行的百分位数

问题描述 投票:-2回答:1

我有一个看起来像下图的csv。我想计算从B2到X2的每一行的百分位数(10,50,90),并在新列中添加最终百分位数。基本上,我希望在整个可用记录期间找到平均值(std,cv,sp_tim .....)的第10个百分点。 enter image description here

到目前为止,我创建了以下代码行以在python中将其作为数据帧格式读取。

da = pd.read_csv('Project/11433300_annual_flow_matrix.csv', index_col=0, parse_dates=True)
pandas python-3.6 percentile
1个回答
1
投票

如果我已正确理解您的问题,那么以下代码可能对您有所帮助:

我已经使用了一些虚拟数据,并对它进行了类似的处理,你正在寻找它

aq = [1, 2, 2, 3, 3, 4, 4, 5, 7, 8, 10, 11]
aw = [91, 25, 13, 53, 95, 94, 75, 35, 57, 88, 111, 12]
df = pd.DataFrame({'aq': aq, 'aw': aw})

n = df.shape[0]
p = 0.1 #for 10th percentile
position = np.ceil(n*p)
position = int(position)
df.iloc[position,]

请看看,如果这对你有用,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.