Renaming and reordering columns¶
Rename columns¶
You can rename the columns in a table by using the Table.rename()
method and specifying the new column names as an array or dictionary mapping old column names to new ones.
table = Table(rows, column_names = ['a', 'b', 'c'])
new_table = table.rename(column_names = ['one', 'two', 'three'])
# or
new_table = table.rename(column_names = {'a': 'one', 'b': 'two', 'c': 'three'})
Reorder columns¶
You can reorder the columns in a table by using the Table.select()
method and specifying the column names in the order you want:
new_table = table.select(['3rd_column_name', '1st_column_name', '2nd_column_name'])