cjgorricho
cjgorricho

Reputation: 21

Is there an equivalent to pandas dtypes command in polars?

I want to obtain the types of columns in a data frame together with columns name, but polars only gives me the types.

I have tried with df.dtypes, df.dtypes(). I expect to get the name of each column and next to it the type.

Upvotes: 2

Views: 763

Answers (1)

ritchie46
ritchie46

Reputation: 14730

You can use .collect_schema() on DataFrame and LazyFrame objects.

For DataFrames, it is also available under the .schema attribute.

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)]))}

Upvotes: 3

Related Questions