Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.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
Pandas 将存储在dataframe中的百分位值应用于数组_Pandas_Python 3.5 - Fatal编程技术网

Pandas 将存储在dataframe中的百分位值应用于数组

Pandas 将存储在dataframe中的百分位值应用于数组,pandas,python-3.5,Pandas,Python 3.5,我有一个百分位数据框df,如下所示: col1 col2 GDStart 2019-09-02 100 11 2019-09-03 60 16 2019-09-04 60 67 我有另一个数组数据: array([1.65 , 1.68 , 1.755, 1.76 , 1.63 ])

我有一个百分位数据框
df
,如下所示:

            col1   col2     
GDStart                                                                   
2019-09-02  100    11  
2019-09-03   60    16  
2019-09-04   60    67  
我有另一个数组
数据

array([1.65 , 1.68 , 1.755, 1.76 , 1.63 ])
我需要使用
df
中的信息执行以下操作,以获取百分位数据帧
dt

import numpy as np

            col1                       col2     
GDStart                                                                   
2019-09-02  np.percentile(data, 100)   np.percentile(data, 11)
2019-09-03  np.percentile(data, 60)    np.percentile(data, 16)  
2019-09-04  np.percentile(data, 60)    np.percentile(data, 67)  

我不知道如何将
数据帧
映射到
np.百分位数

IIUC,您可以使用
应用

df = df.apply(lambda x: np.percentile(data, x))

output:

            col1    col2
GDStart     
2019-09-02  1.76    1.6388
2019-09-03  1.71    1.6428
2019-09-04  1.71    1.7310

IIUC您可以使用
apply

df = df.apply(lambda x: np.percentile(data, x))

output:

            col1    col2
GDStart     
2019-09-02  1.76    1.6388
2019-09-03  1.71    1.6428
2019-09-04  1.71    1.7310

使用listcomp和
np.transpose

df[:] = np.transpose([np.percentile(data, df[col]) for col in df])

Out[546]:
            col1    col2
GDStart
2019-09-02  1.76  1.6388
2019-09-03  1.71  1.6428
2019-09-04  1.71  1.7310

使用listcomp和
np.transpose

df[:] = np.transpose([np.percentile(data, df[col]) for col in df])

Out[546]:
            col1    col2
GDStart
2019-09-02  1.76  1.6388
2019-09-03  1.71  1.6428
2019-09-04  1.71  1.7310

是否要使用所有5个数组数据来计算每列的百分比?是的,基本上使用
df
中的数据来计算
数据的百分比
是否要使用所有5个数组数据来计算每列的百分比?是,基本上使用
df
中的数据来计算
数据的百分比
是否有必要使用
['col1','col2']
您不能在datetime列上应用百分比。
datetime
列是索引。不过,您是对的,不需要选择列,我会更新答案是否有必要使用
['col1','col2']
您不能在datetime列上应用百分位数。
datetime
列是索引,但是哦,您是对的,不需要选择列,我会更新答案