fvg*_*fvg 3 python types dataframe feather python-polars
我用.write_ipcPolars 存储为羽毛文件。原来数字串已经被保存为整数了。
因此,我需要在保存为feather之前或从feather读取之后将带有整数的列转换为字符串。我该如何使用 Polar 来做到这一点?
你确定吗?此片段成功,这意味着数据类型被保留。
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.Utf8, pl.Int64]
Run Code Online (Sandbox Code Playgroud)
要回答您的问题,您可以转换极坐标数据类型:
# cast to a string column
df.with_column(pl.col("numeric_ints").cast(pl.Utf8))
Run Code Online (Sandbox Code Playgroud)