English 中文(简体)
2. 重机包——数据机适用功能的问题
原标题:Bigframes package - Problem with Dataframe apply function

我是来自奥古拉普利斯的<>大范围>包裹的新用户。 我正试图操纵装自Bigquery的数据。

我正试图执行某些法典,但我正面临一个无法解决的问题。

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.

你们能否帮助我这样做?

感谢。

法典例

# example
def condition(row):
    print(row )
    if 1 <= row["month"] <= 6:
        return f"{row[ year ]:02}S1{row[ CODPY ]}{row[ CODDE ]}"
    else:
        return f"{row[ year ]:02}S2{row[ CODPY ]}{row[ CODDE ]}"

valodetail_df[ IDT ] = 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()}
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  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 
问题回答




相关问题
Get webpage contents with Python?

I m using Python 3.1, if that helps. Anyways, I m trying to get the contents of this webpage. I Googled for a little bit and tried different things, but they didn t work. I m guessing that this ...

What is internal representation of string in Python 3.x

In Python 3.x, a string consists of items of Unicode ordinal. (See the quotation from the language reference below.) What is the internal representation of Unicode string? Is it UTF-16? The items ...

What does Python s builtin __build_class__ do?

In Python 3.1, there is a new builtin function I don t know in the builtins module: __build_class__(...) __build_class__(func, name, *bases, metaclass=None, **kwds) -> class Internal ...

what functional tools remain in Python 3k?

I have have read several entries regarding dropping several functional functions from future python, including map and reduce. What is the official policy regarding functional extensions? is lambda ...

Building executables for Python 3 and PyQt

I built a rather simple application in Python 3.1 using PyQt4. Being done, I want the application to be distributed to computers without either of those installed. I almost exclusively care about ...

热门标签