tompollard / tableone

Create "Table 1" for research papers in Python
https://pypi.python.org/pypi/tableone/
MIT License
161 stars 38 forks source link

to_csv method not working ? #57

Closed christian-geier closed 6 years ago

christian-geier commented 6 years ago

I am trying to have TableOne output the table in an easy to parse format so it can be included in a doc document.

When I call the to_csv method on the TableOne, it throws the error "TableOne object has no attribute 'to_csv'

The package has an example of using to_csv(), I assume it was removed in a prior update / rewrite ?

In that case, what is the recommended method of getting the output in a table format that can be used in ideally LibreOffice ?

alistairewj commented 6 years ago

Hm - any chance that you are not calling it correctly? You're not supposed to call TableOne.to_csv(), but rather create a tableone object with t1 = TableOne(data), then call t1.to_csv(filename) to output it to file.

christian-geier commented 6 years ago

Apologies for the confusion, yes I am calling the method on the object.

My code:

mytable = TableOne(
                    tropomyosin_df_uncitr_tertiles,
                    cols, cat_vars_table, 'uncitrullinated_tertile', cols, pval=True

                    )

mytable.to_csv('uncitrullinated_tertile.csv')

Throws:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-eb2346152f1c> in <module>()
----> 1 mytable.to_csv('uncitrullinated_tertile.csv')

AttributeError: 'TableOne' object has no attribute 'to_csv'
alistairewj commented 6 years ago

Weird! What version of TableOne do you have? If you update do you get the same issue?

tompollard commented 6 years ago

@col-slade it sounds like you are using an older version of the package. In the version that you are using, you would call to_csv() with mytable.tableone.to_csv().

You can check the version with:

import tableone
print(tableone.__version__)

Currently we are on version 0.5.4.

christian-geier commented 6 years ago

Thanks, I had version 0.5.1 installed, running pip install tableone --upgrade installed version 0.5.5 which resolved the issue !