简体   繁体   中英

Pandas DataFrame: Suppress scientific notation and manipulate border style at the same time?

I am using the Python packages pyodbc and pandas. I have pulled some data from a SQL query into a dataframe and am attempting to get a tabular view of the dataframe with two characteristics:

  1. Numeric columns are displayed with a specified decimal precision and no scientific notation.
  2. Column borders are thick and black.

Can anyone help me to do this? I am working in Jupyter-Notebook, Python v3.6.5. Here is my code so far. It gives me criterion #2 but not #1. If I run the last line which is currently commented out, I get criterion #1 but not #2.

import pyodbc as po
import pandas as pd
pd.set_option('display.float_format', '{:.5f}'.format)
conn=po.connect(DRIVER = '{SQL Server}',
                      SERVER = 'xxx',
                      DATABASE = 'yyy')
query_VD01="""select 1 union select 0.000001 union select 1000000"""

VD01=pd.read_sql(query_VD01,conn)
VD01.style.set_properties(**{'border-style':'solid'})
#display(VD01)

edit - I want 6 digits of decimal precision. Here is the result of running VD01.head():

0   0.00000
1   1.00000
2   1000000.00000

If I had set display.float_format to {:.6f} I instead get this from VD01.head():

0   0.000001
1   1.000000
2   1000000.000000

chain together the style and you get what you want.

VD01 = pd.DataFrame([0.000001,1.000000,1000000.000000])
VD01.style.format("{:.6f}").set_properties(**{'border-style':'solid'})


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM