Skip to content

Creating a DataFrame from Dicts can lead to missing columns in the DataFrame or an error depending on the order of the data #367

Open
@stensmo

Description

@stensmo

using DataFrames

car1=Dict("id"=>"f3eb12eb-3135-4a0b-a2fd-4ccbb981974e", "name"=>"Fiat","engine"=>Dict("id"=>"0e2e1a0d-c7ea-446a-b4c0-6c1fc441bd73", "cylinders"=>4, "horsepower"=>125))
car2=Dict("id"=>"8ee4e187-5890-4953-98cf-b97bb819befb", "engine"=>Dict("id"=>"da8fc4c5-ba57-40d9-84ba-097f23070e55", "cylinders"=>6, "horsepower"=>170))


cars=[car2;car1]

carsDF_temp=DataFrame(cars)

In this case, the column "name" is missing from the DataFrame.

using DataFrames

car1=Dict("id"=>"f3eb12eb-3135-4a0b-a2fd-4ccbb981974e", "name"=>"Fiat","engine"=>Dict("id"=>"0e2e1a0d-c7ea-446a-b4c0-6c1fc441bd73", "cylinders"=>4, "horsepower"=>125))
car2=Dict("id"=>"8ee4e187-5890-4953-98cf-b97bb819befb", "engine"=>Dict("id"=>"da8fc4c5-ba57-40d9-84ba-097f23070e55", "cylinders"=>6, "horsepower"=>170))


cars=[car1;car2]

carsDF_temp=DataFrame(cars)



This throws an error.

The order of the data is the only difference

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions