Question

Parse a pretty-printed string representation of a DataFrame back into a Polars DataFrame?

I have a string representation of a DataFrame:

shape: (3, 2)
┌───────┬──────┐
│ alpha ┆ beta │
│ ---   ┆ ---  │
│ i32   ┆ i32  │
╞═══════╪══════╡
│ 0     ┆ 1    │
│ 1     ┆ 0    │
│ 2     ┆ 0    │
└───────┴──────┘

Is there any existing functionality in Polars to parse this back into a DataFrame?

 4  34  4
1 Jan 1970

Solution

 5

.from_repr()

df = pl.from_repr("""
shape: (3, 2)
┌───────┬──────┐
│ alpha ┆ beta │
│ ---   ┆ ---  │
│ i32   ┆ i32  │
╞═══════╪══════╡
│ 0     ┆ 1    │
│ 1     ┆ 0    │
│ 2     ┆ 0    │
└───────┴──────┘
""")
2024-07-12
jqurious