The gt_duplicate_column() function takes an existing GT object and creates a duplicate (without styling) of the specified column. The duplicated column can be renamed using either dupe_name or by appending text to the original column name, and positioned at a specific location in the table.
Parameters
gt:GT
A GT object to modify.
column:SelectExpr
The column to duplicate. Can be a column name or index.
after:str | None=None
The column after which to place the duplicated column. If None, the duplicated column will be moved to the end of the table.
append_text:str | None='_dupe'
Text to append to the original column name for the duplicate. Only used if dupe_name is not provided. Defaults to "_dupe".
dupe_name:str | None=None
The name for the duplicated column. If provided, this overrides append_text.
Returns
:GT
A GT object with the duplicated column added.
Examples
from great_tables import GTfrom great_tables.data import gtcarsimport gt_extras as gtegtcars_mini = gtcars[["mfr", "model", "year", "hp"]].head(5)gt = GT(gtcars_mini)# Duplicate with custom name and positiongt.pipe( gte.gt_duplicate_column, column="hp", after="year",)
mfr
model
year
hp_dupe
hp
Ford
GT
2017
647.0
647.0
Ferrari
458 Speciale
2015
597.0
597.0
Ferrari
458 Spider
2015
562.0
562.0
Ferrari
458 Italia
2014
562.0
562.0
Ferrari
488 GTB
2016
661.0
661.0
Note
Styles generated by GT.tab_style() will not be duplicated. This may be accommodated in the future.