Nov-03-2023, 03:01 PM
Well, can you try the below code I hope you can get the result you are looking for.
Quote:import polars as plThanks
# Create a sample DataFrame
data = {
"A": [1, 2, 3],
"B": [4, 5, 6]
}
df = pl.DataFrame(data)
# Create new columns
new_columns = {
"X": [7, 8, 9],
"Y": [10, 11, 12]
}
# Insert the new columns at the start of the DataFrame
index_to_insert = 0 # Insert at the start
df = df.insert_at_idx(index_to_insert, new_columns)
# Print the updated DataFrame
print(df)