неподдерживаемые типы операндов для *: 'float' и 'Decimal' в Pyspark - PullRequest
0 голосов
/ 21 октября 2019

У меня есть функция для получения описания статистики + квантилей в pyspark. пока это мой код.

def basic_stats(df_in, columns, deciles=False):
    """
    Function to union the basic stats results and deciles
    :param df_in: the input dataframe
    :param columns: the cloumn name list of the numerical variable
    :param deciles: the deciles output
    :return : the numerical describe info. of the input dataframe
     """
    if deciles:
        percentiles = np.array(range(0, 110, 10))
    else:
        percentiles = [25, 50, 75]

    percs = np.transpose([np.percentile(df_in.select(x).collect(), percentiles) for x in columns])
    percs = pd.DataFrame(percs, columns=columns)
    percs['summary'] = [str(p) + '%' for p in percentiles]
    spark_describe = df_in.describe().toPandas()
    new_df = pd.concat([spark_describe, percs],ignore_index=True)
    new_df = Decimal(new_df.round(2))
    return new_df[['summary'] + columns]

num_cols = [item[0] for item in df.dtypes if item[1].startswith(("decimal", "bigint", "float"))]
basic_stats(df, num_cols, deciles=True)

Моя проблема в том, что я получаю следующую ошибку:

неподдерживаемые типы операндов для *: 'float' и 'Десятичное число '**

Я не понимаю, почему это не должно работать!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...