Sample

Author

Norah Jones

Published

January 2, 2024

Preface

This is a Quarto book.

Standard Python df rendering

Code
import pandas as pd
df = pd.read_csv('./resources/gt_input.csv')

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

Rendering applying some function and style

Code
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):
    styled_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)
    return styled_df

# sample dataframe
df = pd.read_csv('./resources/gt_input.csv')

styled_df = apply_italian_style(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

Observable table

Code
data = FileAttachment("resources/gt_input.csv").csv({ typed: true })
Inputs.table(data,{ locale: "it-IT" })
Table 1: Table from Observable
(a)
(b)

HTML table

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.

Table 2: My html table caption
Name Age
John Doe 30
Jane Smith 25
Emily Johnson 40
Back to top