1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Pandas : to_csv() got an unexpected keyword argument

Discussão em 'Python' iniciado por Stack, Outubro 8, 2024.

  1. Stack

    Stack Membro Participativo

    While I am trying to use some of the parameters in dataframe to_csv function, it throws an TypeError, such as `TypeError: to_csv() got an unexpected keyword argument 'doublequote'

    df.to_csv('transactions.x', header=False, doublequote=False) or df.to_csv('transactions.x', doublequote=False)

    My pandas version is 0.19.2 (Checked with print(pd.__version__)) I am using Python 3.5

    The following official document is based on 0.19.2. Although, I am having type errors, it is stated that these parameters can be used as an optional. http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html

    Do you guys have any idea about it?

    Thank you.

    SOLUTION

    Thanks for brain storming with all commenters.

    After using following the command df = df.groupby(['Transactions'])['Items'].apply(','.join), dataframe becomes series.

    In order to cast series to dataframe, this command df = df.groupby(['Transactions'])['Items'].apply(','.join).to_frame() should be used instead.

    Finally, to export it as a CSV with non-quote style by avoiding escape char, you need to end up with the following command df.to_csv('transactions.x', header=False, quoting=csv.QUOTE_NONE, escapechar=' ') #or whatever escapechar.

    Hopefully, it helps for everyone. Thanks

    Continue reading...

Compartilhe esta Página