Из Pandas я использовал:
Код: Выделить всё
import polars as pl
import pandas as pd
from scipy.stats import spearmanr
def get_score(df):
return spearmanr(df["prediction"], df["target"]).correlation
df = pd.DataFrame({
"era": [1, 1, 1, 2, 2, 2, 5],
"prediction": [2, 4, 5, 190, 1, 4, 1],
"target": [1, 3, 2, 1, 43, 3, 1]
})
correlations = df.groupby("era").apply(get_score)
Код: Выделить всё
df_pl = pl.from_pandas(df)
correlations = df_pl.group_by("era").map_groups(get_score)
'Не удалось получить атрибут DataFrame '_df'. Убедитесь, что вы возвращаете объект DataFrame.: PyErr { type: , value: AttributeError("объект 'float' не имеет атрибута '_df'"), обратная трассировка: нет
Есть идеи?
Подробнее здесь: https://stackoverflow.com/questions/695 ... ith-polars
Мобильная версия