Reputation: 273
I used .write_ipc
from Polars to store as a feather file. It turns out that the numerical strings have been saved as integers.
So I need to convert the columns with integers to strings either before saving as feather or after reading from feather. How do I do that with Polars?
Upvotes: 3
Views: 17501
Reputation: 14730
Are you sure? This snippets succeeds so that means data types are preserved.
import polars as pl
import io
df = pl.DataFrame({
"numeric_strs": ["1", "2", "3"],
"numeric_ints": [1, 2, 3]
})
f = io.BytesIO()
df.write_ipc(f)
f.seek(0)
assert pl.read_ipc(f).dtypes == [pl.String, pl.Int64]
To answer your question you can cast polars data types:
# cast to a string column
df.with_columns(pl.col("numeric_ints").cast(pl.String))
Upvotes: 7