Code
import pandas as pd
= pd.read_csv('./resources/gt_input.csv')
df
df
Cat | Field 1 | Field 2 | Field 3 | |
---|---|---|---|---|
0 | A | Lorem | 1236 | 2535.26000 |
1 | B | Ipsum | 50478 | 235.89000 |
2 | C | Solat | 2521 | 5789.56569 |
This is a Quarto book.
import pandas as pd
= pd.read_csv('./resources/gt_input.csv')
df
df
Cat | Field 1 | Field 2 | Field 3 | |
---|---|---|---|---|
0 | A | Lorem | 1236 | 2535.26000 |
1 | B | Ipsum | 50478 | 235.89000 |
2 | C | Solat | 2521 | 5789.56569 |
import pandas as pd
# Function for formatting numbers in Italian format
def italian_format(x):
if isinstance(x, float):
return "{:,.2f}".format(x).replace(",", "X").replace(".", ",").replace("X", ".")
elif isinstance(x, int):
return "{:,}".format(x).replace(",", ".")
else:
return x
# To check if column is numeric
def is_numeric_column(col):
return pd.api.types.is_numeric_dtype(col)
# To have Italian format for numbers and right alignment
def apply_italian_style(df):
= df.style.format(italian_format).hide(axis="index")
styled_df = styled_df.apply(lambda x: ["text-align: right" if is_numeric_column(df[x.name]) else "" for i in x], axis=0)
styled_df return styled_df
# sample dataframe
= pd.read_csv('./resources/gt_input.csv')
df
= apply_italian_style(df)
styled_df styled_df
Cat | Field 1 | Field 2 | Field 3 |
---|---|---|---|
A | Lorem | 1.236 | 2.535,26 |
B | Ipsum | 50.478 | 235,89 |
C | Solat | 2.521 | 5.789,57 |
= FileAttachment("resources/gt_input.csv").csv({ typed: true })
data .table(data,{ locale: "it-IT" }) Inputs
If you want to add a caption to an HTML table, you can put the table in a div and assign it a label (below it’s #tbl-html
), and finally insert the caption after the table.
If you want to add a bootstrap class, just do it in the HTML itself.
Below is an example with both applied.
Name | Age |
John Doe | 30 |
Jane Smith | 25 |
Emily Johnson | 40 |