question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pandas : to_csv() got an unexpected keyword argument

See original GitHub issue
df.to_csv('transactions.x', header=False, doublequote=False)

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’

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.

Output of pd.show_versions()

pandas: 0.19.2 nose: None pip: 9.0.1 setuptools: 35.0.1 Cython: None numpy: 1.12.1 scipy: 0.19.0 statsmodels: None xarray: None IPython: None sphinx: None patsy: None dateutil: 2.6.0 pytz: 2017.2 blosc: None bottleneck: 1.2.0 tables: 3.4.2 numexpr: 2.6.2 matplotlib: None openpyxl: None xlrd: 1.0.0 xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: None httplib2: None apiclient: None sqlalchemy: 1.1.9 pymysql: None psycopg2: None jinja2: None boto: None pandas_datareader: None

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
TomAugspurgercommented, Apr 28, 2017

Would df happen to be a Series instead of a DataFrame? Their writers aren’t 100% equivalent.

0reactions
jackalhancommented, Apr 28, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pandas : to_csv() got an unexpected keyword argument
While I am trying to use some of the parameters in dataframe to_csv function, it throws an TypeError, such as ...
Read more >
TypeError: to_csv() got an unexpected keyword argument 'cols ...
running this in a terminal, I get the following failure: Traceback (most recent call last): File "getdata.py", line 60, in main() File ...
Read more >
Pandas : to_csv() got an unexpected keyword argument-pandas
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...
Read more >
pandas.DataFrame.to_csv — pandas 0.18.1 documentation
DataFrame. to_csv. File path or object, if None is provided the result is returned as a string.
Read more >
init__() got an unexpected keyword argument 'line_terminator'
__init__() got an unexpected keyword argument 'line_terminator' ... This is the error message I got when trying the .to_csv command.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found