Skip to content

Long to wide, filling missing element with nil #287

@KitaitiMakoto

Description

@KitaitiMakoto

Hello,

Can I reshape a long data frame to a wide data frame filling missing element with nil?

When I have long data frame such as:

df = DataFrame.new(
  names: %w[name1 name1 name1 name2 name2 name3 name3 name3],
  NAME: %w[One Two Three One Three One Two Three],
  VALUE: [1.1, 2.1, 3.1, 1.2, 3.2, 1.3, 2.3, 3.3]
)

I want wide data frame as:

wide = DataFrame.new(
  names: %w[name1 name2 name3],
  One: [1.1, 1.2, 1.3],
  Two: [2.1, nil, 2.3],
  Three: [3.1, 3.2, 3.3]
)

How can I do this? to_wide raises error: #to_wide with missing values(DataFrameReshapingTest::to_wide): IndexError: element size differs (3 should be 4)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions