Я использую следующую удаленную функцию. Эта функция преобразует bpd.Series в bpd.DataFrame, а затем в df pandas.
Код: Выделить всё
@bpd.remote_function(bpd.Series, int, reuse=False, packages=["pyfixest","pandas"])
def get_residuals(input_df):
import pyfixest as pf
import pandas as pd
input_df = input_df.to_frame().to_pandas()
m1 = pf.feols("spotify_streams ~ song_age_days | isrc", data=input_df)
return m1.resid()
#return input_df["spotify_streams"]
Код: Выделить всё
df = bpd.read_gbq(sql, use_cache = False) #Get the data here, works fine.
df["residual"] = df[
["spotify_streams","song_age_days","isrc"]
].apply(get_residuals, axis=1)
Код: Выделить всё
NameError: `song_age_days` is not present in the dataset or evaluation context.
Код: Выделить всё
File \"\", line 9, in get_residuals\n File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/pandas/core/generic.py\", line 6204, in __getattr__\n return object.__getattribute__(self, name)\nAttributeError: 'Series' object has no attribute 'to_pandas'\n"}
.
Подробнее здесь: https://stackoverflow.com/questions/789 ... emote-func