在极坐标中是否有相当于 pandas dtypes 命令的命令?

问题描述 投票:0回答:1

我想获取数据框中的列类型以及列名称,但 Polars 只提供类型。

我尝试过 df.dtypes、df.dtypes()。我希望获得每列的名称及其旁边的类型。

types python-polars
1个回答
3
投票

您可以在

.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)]))}
© www.soinside.com 2019 - 2024. All rights reserved.