[Python] Export panda dataframe after grouping data groupby() into google spreadsheet in...

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    I use google colaboration to do data grouping for a very large data (180 k row, 40 columns). I manage to do the grouping like below

    df_1 = df.groupby(['LOCATION','TYPE',pd.cut(df['GRT'], [0, 3500, 8000, 14000, 18000, 26000, 40000, 75000, 300000])])['REVENUE'].sum().reset_index(name="sum")


    But when I want to export, I was failed. Below is my script

    gc = gspread.authorize(creds)
    spreadsheet = gc.open_by_key('1a1aaaaaaaaaaaaaaaaa')
    target = spreadsheet.get_worksheet_by_id(1174387715)
    target.update(None,df_1)


    Here is the error message

    ValueError Traceback (most recent call last)

    <ipython-input-53-e8e474ea1e57> in <cell line: 4>()
    2
    3 target = spreadsheet.get_worksheet_by_id(1174387715)
    ----> 4 target.update(None,df_1)

    2 frames

    /usr/local/lib/python3.10/dist-packages/pandas/core/generic.py in __nonzero__(self)
    1517 @final
    1518 def __nonzero__(self) -> NoReturn:
    -> 1519 raise ValueError(
    1520 f"The truth value of a {type(self).__name__} is ambiguous. "
    1521 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."

    ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().




    Is there any steps that I was missing? I have followed other similar topic here but it is different with my question here.

    Continue reading...

Compartilhe esta Página