1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Polars: Enforcing dtypes doesn't work why?

Discussão em 'Python' iniciado por Stack, Setembro 28, 2024 às 15:12.

  1. Stack

    Stack Membro Participativo

    Update: This is no longer the case in Polars. The result is a date type column as expected.


    Why schema specification has no impact? Date of Birth continues to be in string format why?

    import polars as pl

    # Create a dictionary with some dummy data
    data = {
    'Age': [28, 32, 24, 45, 29],
    'Date of Birth': ['1995-03-15', '1989-08-22', '1999-11-05', '1978-02-10', '1994-06-07'],
    'City': ['New York', 'San Francisco', 'London', 'Tokyo', 'Sydney'],
    }

    dtypes = {
    'Age': pl.Int64,
    'Date of Birth': pl.Date,
    'City': pl.String
    }

    # Create the DataFrame with specified data types
    df_listing_data = pl.DataFrame(data, schema=dtypes)


    Date of Birth continues to be in string format why?

    # shape: (5, 3)
    # ┌─────┬───────────────┬───────────────┐
    # │ Age ┆ Date of Birth ┆ City │
    # │ --- ┆ --- ┆ --- │
    # │ i64 ┆ str ┆ str │

    Continue reading...

Compartilhe esta Página