Problem with Dataframe apply function
imachraoui opened this issue · 1 comments
imachraoui commented
Hello,
I am a new user of bigframes package.
I was trying to execute some code but I am facing a problem that i am not able to solve.
I am trying to use the apply function on a Dataframe with the parameter axis=1 , but it doesn't seem to work. I always have an error message.
Can you please help me with this?
Thanks.
Regards,
Code example
# example
def condition(row):
print(row )
if 1 <= row["debres_month"] <= 6:
return f"{row['debres_year']:02}S1{row['CODPYC']}{row['CODDEV']}"
else:
return f"{row['debres_year']:02}S2{row['CODPYC']}{row['CODDEV']}"
valodetail_df['IDTDCI'] = valodetail_df.apply(condition,axis=1)
Stack trace
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/core/log_adapter.py", line 44, in wrapper
return method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/dataframe.py", line 3118, in apply
results = {name: func(col, *args, **kwargs) for name, col in self.items()}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/dataframe.py", line 3118, in <dictcomp>
results = {name: func(col, *args, **kwargs) for name, col in self.items()}
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<stdin>", line 3, in condition
File "missing.pyx", line 419, in pandas._libs.missing.NAType.__bool__
TypeError: boolean value of NA is ambiguous
>>> valodetail_df['IDTDCI'] = valodetail_df.apply(condition,axis=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/core/log_adapter.py", line 44, in wrapper
return method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/dataframe.py", line 3118, in apply
results = {name: func(col, *args, **kwargs) for name, col in self.items()}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/dataframe.py", line 3118, in <dictcomp>
results = {name: func(col, *args, **kwargs) for name, col in self.items()}
^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: condition() got an unexpected keyword argument 'axis'
shobsi commented
This is a current work in progress, however I replied on this related stackoverflow post which may be used to unblock for the time being
https://stackoverflow.com/questions/78297873/bigframes-package-problem-with-dataframe-apply-function/78331896#78331896