Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用numpy计算表格上的第95个百分位数?_Python_Numpy_Percentile - Fatal编程技术网

Python 如何使用numpy计算表格上的第95个百分位数?

Python 如何使用numpy计算表格上的第95个百分位数?,python,numpy,percentile,Python,Numpy,Percentile,我正在尝试使用numpy计算表中的第95个百分位和其他百分位。但是,我似乎不清楚执行此操作的功能,因为它需要一个数组才能工作: >>> a = np.array([[10, 7, 4], [3, 2, 1]]) >>> a array([[10, 7, 4], [ 3, 2, 1]]) >>> np.percentile(a, 50) 这将是阵列上第50个百分位的方式 我的桌子是这样的: Date Hou

我正在尝试使用numpy计算表中的第95个百分位和其他百分位。但是,我似乎不清楚执行此操作的功能,因为它需要一个数组才能工作:

>>> a = np.array([[10, 7, 4], [3, 2, 1]])
>>> a
array([[10,  7,  4],
       [ 3,  2,  1]])
>>> np.percentile(a, 50)
这将是阵列上第50个百分位的方式

我的桌子是这样的:

Date        Hour    Month       Value
9/1/2019    0:00    SEPTEMBER   377.3333333
9/1/2019    0:00    SEPTEMBER   268.8
9/1/2019    0:00    SEPTEMBER   400.8
9/1/2019    0:00    SEPTEMBER   279.1304348
9/1/2019    0:05    SEPTEMBER   440
9/1/2019    0:05    SEPTEMBER   228
9/1/2019    0:05    SEPTEMBER   350
9/1/2019    0:05    SEPTEMBER   283.2
9/1/2019    0:10    SEPTEMBER   385.3333333
9/1/2019    0:10    SEPTEMBER   240
9/1/2019    0:10    SEPTEMBER   347.5
9/1/2019    0:10    SEPTEMBER   175.2
9/1/2019    0:15    SEPTEMBER   440
9/1/2019    0:15    SEPTEMBER   202.8
9/1/2019    0:15    SEPTEMBER   204
9/1/2019    0:15    SEPTEMBER   182.4
...
9/2/2019    0:00    SEPTEMBER   416
9/2/2019    0:00    SEPTEMBER   134.4
9/2/2019    0:00    SEPTEMBER   370
...
直到九月底

我想计算每5分钟间隔的第95个百分位数

最终结果应该是:

Time    September
0:00    95th Value
0:05    95th Value
0:10    95th Value
0:15    95th Value
..

导入re
作为pd进口熊猫
数据=''2019年9月1日0:00 9月377.3333
2019年9月1日0:00 2008年9月268日
2019年9月1日0:00 9月400.8日
2019年9月1日0:00九月279.1304348
2019年9月1日0:05 440年9月
2019年9月1日0:05 9月228日
2019年9月1日0:05 9月350日
2019年9月1日0:05九月283.2
2019年9月1日0:10 9月385.3333
2019年9月1日0时10分240
2019年9月1日0:10 9月347.5日
2019年9月1日0时10分175.2
2019年9月1日0:15 440年9月
2019年9月1日0时15分202.8
2019年9月1日0:15 204年9月15日
2019年9月1日0:15 182.4
2019年9月1日0:20 2016年9月16日
2019年9月1日0时20分134.4
2019年9月1日0:20 370年9月20日
2019年9月2日0:05九月145.9
2019年9月2日0:05 360“
data=[data.split('\n')中x的重新拆分('[]+',x)]
df=pd.DataFrame(数据,列=['date'、'hour'、'month'、'value']
df['value']=df['value'].aType(浮点)
打印(df.groupby(['date','hour'])。值。分位数(0.95))

你能用熊猫代替numpy吗?如果在数据帧中加载表,解决方案就是
dataframe.groupby(['Hour',Month'])['Value'].quantile(0.95)
。您知道如何将结果再次转换为数据帧吗?与其打印,不如将groupby语句赋给变量,然后对该变量调用.to_frame()方法。我使用了reset.index()。这会产生同样的结果吗?或者如果我继续下去,你认为我会有问题。