使用Qcut优化熊猫数据框的四分位数

时间:2019-02-28 02:47:03

标签: python pandas statistics quartile

我正在尝试将数据列转换为隔离数据。这是使用熊猫qcut:

            # Get first column to quartile
            firstCol = df.columns.get_loc(411.447817504) # Get column num of first wavelength

            # We need the list of column titles. 
            cols = df.columns

            # We loop through our 1100 columns to apply quartiling
            for colLoc in range(0,1100):

                # Print what column is being processed
                print(f'Column {colLoc}')
                column_name = cols[firstCol+colLoc]

                # Generate and apply quartiling
                df[column_name] = pd.qcut(df[column_name].astype('float'), 4, ['q1','q2','q3','q4'])

有什么办法可以加快这个过程?可能是通过使用np数组,然后一次将其处理到df中吗?

0 个答案:

没有答案
相关问题