We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currently, I use pandoc to embed results of tableone to markdown file.
But if we export csv, there are duplicated names for index and column part, so I want tabulate method to include pretty style of csv export.
tabulate
mean currently csv export becomes like
Missing Overall ----------------- ---- --------- ------------ n 1000 Age, mean (SD) 0 65.0 (17.2) SysABP, mean (SD) 291 114.3 (40.2) Height, mean (SD) 475 170.1 (22.1) Weight, mean (SD) 302 82.9 (23.8) ICU, n (%) CCU 0 162 (16.2) ICU, n (%) CSRU 202 (20.2) ICU, n (%) MICU 380 (38.0) ICU, n (%) SICU 256 (25.6) MechVent, n (%) 0 0 540 (54.0) MechVent, n (%) 1 460 (46.0) LOS, mean (SD) 0 14.2 (14.2) death, n (%) 0 0 864 (86.4) death, n (%) 1 136 (13.6)
but want to delete duplicated ICU, MechVent, and death
The text was updated successfully, but these errors were encountered:
I suggest like this way.
data preparation and defin MyTableOne.
# import libraries from tableone import TableOne import pandas as pd from io import StringIO import csv import copy class MyTableOne(TableOne): def to_pretty_csv(self, path : str = None): tableone = copy.deepcopy(self.tableone) tableone.columns = tableone.columns.droplevel(0) s = tableone.to_csv() f = StringIO(s) reader = csv.reader(f, delimiter=',') dup = [] new_rows = "" for row in reader: r0 = row[0] if r0 == "": pass elif r0 not in dup: dup.append(r0) else: row[0] = "" new_rows += ",".join(row) + "\n" if path is None: return new_rows else: with open(path, "w") as f: f.write(new_rows) # load sample data into a pandas dataframe url="https://raw.githubusercontent.com/tompollard/data/master/primary-biliary-cirrhosis/pbc.csv" data=pd.read_csv(url) table = MyTableOne(data, groupby=["status"],label_suffix=True)
and processing part. Look for "sex" index, this code can delete there.
print(table.to_pretty_csv())
Sorry, something went wrong.
More elegant with this Pandas multi-index to csv file
No branches or pull requests
Currently, I use pandoc to embed results of tableone to markdown file.
But if we export csv, there are duplicated names for index and column part,
so I want
tabulate
method to include pretty style of csv export.mean currently csv export becomes like
but want to delete duplicated ICU, MechVent, and death
The text was updated successfully, but these errors were encountered: