Skip to content

Instantly share code, notes, and snippets.

@ianmcook
Created August 21, 2024 16:02
Show Gist options
  • Save ianmcook/a04a17e2cc5ce6459049585b610bf0d5 to your computer and use it in GitHub Desktop.
Save ianmcook/a04a17e2cc5ce6459049585b610bf0d5 to your computer and use it in GitHub Desktop.
Union two Ibis tables with columns in different orders
import ibis
import random
con = ibis.connect("duckdb://penguins.ddb")
con.create_table(
"penguins", ibis.examples.penguins.fetch().to_pyarrow(), overwrite = True
)
ibis.options.interactive = True
penguins = con.table("penguins")
penguins.count() # returns 344
penguins
columns = penguins.columns
random.shuffle(columns)
more_penguins = penguins[columns]
more_penguins
double_the_penguins = ibis.union(penguins, more_penguins)
double_the_penguins.count() # returns 688
double_the_penguins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment