Skip to content

Idea: index + join #22

@kmx

Description

@kmx

Hi Zaki,

I would like to propose the following enhancements:

  • new index option that can be passed to new()
  • new method join

See the code below which demonstrates what I am talking about. In my real use case the index will be a PDL (LongLong) with kind of a timestamps.

At this moment it is just an idea (no patch, no pull request).

use Modern::Perl;
use Data::Frame;
use PDL;

my $df1 = Data::Frame->new( 
            index => pdl(1, 2, 3, 4, 5, 6),
            columns => [
              first  => random(6) * 100,
              second => sequence(6) + 100,
            ],
          );

say $df1;
# ---------------------------------
# index  first              second
# ---------------------------------
#     1  96.8891209914009   100
#     2  76.1503499302307   101
#     3  67.3669555706322   102
#     4  94.2991902576502   103
#     5  97.5514418708361   104
#     6  37.9426436114741   105
# ---------------------------------

my $df2 = Data::Frame->new( 
            index => pdl(0, 1, 2, 4, 5, 6),
            columns => [
              third  => random(6) * 1000,
              fourth => sequence(6) + 1000,
            ],
          );

say $df2;
# --------------------------------
# index  third             fourth
# --------------------------------
#     0  202.939408438848  1000
#     1  758.36712363536   1001
#     2  277.250017476778  1002
#     4  663.52298494806   1003
#     5  186.35758181922   1004
#     6  776.087658553486  1005
# --------------------------------

my $df3 = $df1->join($df2);
say $df3;
# ----------------------------------------------------------
# index  first             second  third             fourth
# ----------------------------------------------------------
#     0  BAD               BAD     202.939408438848  1000
#     1  96.8891209914009  100     758.36712363536   1001
#     2  76.1503499302307  101     277.250017476778  1002
#     3  67.3669555706322  102     BAD               BAD
#     4  94.2991902576502  103     663.52298494806   1003
#     5  97.5514418708361  104     186.35758181922   1004
#     6  37.9426436114741  105     776.087658553486  1005
# ----------------------------------------------------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions