我想获取数据框中的列类型以及列名称,但 Polars 只提供类型。
我尝试过 df.dtypes、df.dtypes()。我希望获得每列的名称及其旁边的类型。
您可以在
.collect_schema()
和 DataFrame
对象上使用 LazyFrame
。
对于 DataFrame,它也可在
.schema
属性下使用。
import polars as pl
from datetime import time
df = pl.DataFrame({
"a": [1, 2, 3],
"b": [True, False, True],
"c": [[{"a": time(12, 1, 1)}], None, None]
})
df.schema
{'a': Int64, 'b': Boolean, 'c': List(Struct([Field('a': Time)]))}