Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python-polars horizontally stack dataframe columns

how to horizontally stack data frame columns. the code below shows two data frames, I want to stack col 2 from df2 with col 1 from df1. how can I do this?

import polars as pl
df1 = pl.DataFrame(
    {
        "col1": ["a", "b", "c", "d"]    }
)


df2 = pl.DataFrame(
    {
        "col2": ["1", "2", "3", "4"]
    }
)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

df1 = pl.DataFrame(
    {
        "col1": ["a", "b", "c", "d"]    }
)


df2 = pl.DataFrame(
    {
        "col2": ["1", "2", "3", "4"]
    }
)

pl.concat([df1, df2], how="horizontal")
shape: (4, 2)
┌──────┬──────┐
│ col1 ┆ col2 │
│ ---  ┆ ---  │
│ str  ┆ str  │
╞══════╪══════╡
│ a    ┆ 1    │
├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ b    ┆ 2    │
├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ c    ┆ 3    │
├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ d    ┆ 4    │
└──────┴──────┘

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading