Skip to content
New issue

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

I have an issue (prettystyler object) #12

Open
mechengineers opened this issue Aug 21, 2023 · 6 comments
Open

I have an issue (prettystyler object) #12

mechengineers opened this issue Aug 21, 2023 · 6 comments

Comments

@mechengineers
Copy link

mechengineers commented Aug 21, 2023

Hi, I am having trouble where i cant get get tables that i want to copy into word. I am just using the test data for now. It is the very last line of code.
I am using Visual studio code.
----------------------------------------INPUT----------------------------------------------------
import pandas as pd
import zentables as zen

zen.set_options(font_family="Times New Roman, serif", font_size=12)

demo_data = pd.read_csv("superstore.csv")
print(demo_data)

P = demo_data[["Segment", "Region"]].value_counts()
print(P)

df = demo_data.pivot_table(
index=["Segment", "Region"],
columns=["Category"],
values="Order ID",
aggfunc="count",
margins=True,
)
df
print(df)

new = df.zen.pretty(font_size=12, font_family="Times New Roman")
print(new)

------------------------------------------------OUTPUT---------------------------------------------

  Row ID        Order ID  Order Date   Ship Date  ...     Sales Quantity Discount    Profit

0 1 CA-2013-152156 11/9/2013 11/12/2013 ... 261.9600 2 0.00 41.9136
1 2 CA-2013-152156 11/9/2013 11/12/2013 ... 731.9400 3 0.00 219.5820
2 3 CA-2013-138688 6/13/2013 6/17/2013 ... 14.6200 2 0.00 6.8714
3 4 US-2012-108966 10/11/2012 10/18/2012 ... 957.5775 5 0.45 -383.0310
4 5 US-2012-108966 10/11/2012 10/18/2012 ... 22.3680 2 0.20 2.5164
... ... ... ... ... ... ... ... ... ...
9989 9990 CA-2011-110422 1/22/2011 1/24/2011 ... 25.2480 3 0.20 4.1028
9990 9991 CA-2014-121258 2/27/2014 3/4/2014 ... 91.9600 2 0.00 15.6332
9991 9992 CA-2014-121258 2/27/2014 3/4/2014 ... 258.5760 2 0.20 19.3932
9992 9993 CA-2014-121258 2/27/2014 3/4/2014 ... 29.6000 4 0.00 13.3200
9993 9994 CA-2014-119914 5/5/2014 5/10/2014 ... 243.1600 2 0.00 72.9480

[9994 rows x 21 columns]
Segment Region
Consumer West 1672
East 1469
Central 1212
Corporate West 960
East 877
Consumer South 838
Corporate Central 673
Home Office West 571
Corporate South 510
Home Office East 502
Central 438
South 272
dtype: int64
Category Furniture Office Supplies Technology All
Segment Region
Consumer Central 255 739 218 1212
East 303 888 278 1469
South 180 505 153 838
West 375 995 302 1672
Corporate Central 137 417 119 673
East 198 520 159 877
South 101 324 85 510
West 210 559 191 960
Home Office Central 89 266 83 438
East 100 304 98 502
South 51 166 55 272
West 122 343 106 571
All 2121 6026 1847 9994
<zentables.zentables.PrettyStyler object at 0x0000024C2997F850>

@digicosmos86
Copy link
Contributor

Hi,

Thanks for using ZenTables! It is right now tested only with Jupyter Notebook/Lab. VSCode is not guaranteed to work (although it should). You don't need to use print() with objects created with df.zen.pretty(). Nor do you need to assign it to a variable. You can just leave this line as the last line in the notebook:

df.zen.pretty(font_size=12, font_family="Times New Roman")

@mechengineers
Copy link
Author

Thanks for the reply,
Am i missing something. I have just went to cmd and used pip install zentables, and pasted this into python editor. If i dont use print nothing comes up in the terminal.

@digicosmos86
Copy link
Contributor

Ah, you need to use Jupyter Notebook or Jupyter Lab. It will not work with the command line because ZenTables is based on the HTML output in Jupyter Notebook/Lab

@mechengineers
Copy link
Author

Great to know. I get this:
TypeError: PrettyStyler._translate() takes from 3 to 6 positional arguments but 7 were given

when using df.zen.pretty.
It both happens though jupyter notebook in vscode using base anaconda as interpreter
And when opening a jupyter lab in the browser.
Do you know of this error, and what programs do you use?

@digicosmos86
Copy link
Contributor

This error happens because the Pandas version is not compatible with zentables. You can try installing an earlier version of Pandas by doing pip install pandas==1.3.1.

Support for latest pandas versions will come out soon.

@mechengineers
Copy link
Author

Sadly i couldnt make it work. I appreciate the help and will try again, less close to a deadline. ;))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants