Repository navigation
Idea: index + join #22
Copy link
Copy link
Open
Description
Hi Zaki,
I would like to propose the following enhancements:
- new
indexoption that can be passed tonew() - 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
# ----------------------------------------------------------
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
zmughal commentedon Aug 17, 2015
I like it! Setting the
indexin the constructor was in the back of mind, but I've been busy.Regarding
join, we definitely need that. I would like to take the behaviour of R and Pandas and bring that in to Data::Frame so that we don't have to change it later (and thus break code). Ajoinwith no other arguments would probably be best as a "natural join" where all matching columns in each Data::Frame are part of the join (see the dplyr documentation).kmx commentedon Sep 15, 2015
Just for record, here is my proof of concept:
The output:
kmx commentedon Oct 5, 2015
Hi Zaki,
UPDATE on this issue: after some experiments with your
Data::Frame+ adding join functionality I have decided that it would be easier to implement a separate proof of concept module which is not "full" Data Frame but "only" a Time Series object - which means the index is mandatory and must always be aPDL::DateTimeobject (because it is my use case).The code is available here https://gist.github.com/kmx/c46859f002b93a6c3683 - it is called
PDL::TSbut it is currently just a code (no tests, no doc, no plan for CPAN release). But at least it might be an inspiration if you want to add similar functionality toData::Frame.--kmx