h2oai / h2oai/datatable

[FR] Access newly created column within i,j,by, sort

Open
#2,506 2 comments 0 reactions 0 assignees View on GitHub
new feature
Dominant language
C++
Stars
1.9k
Forks
164
Avg merge
7h 31m
Merged PRs (30d)
1

Description

- Access newly created column(s) within i, j, by, sort

`Example data:`

from datatable import dt, f, by

grades = [48, 99, 75, 80, 42, 80, 72, 68, 36, 78]

data = {'ID': ["x%d" % r for r in range(10)],
'Gender': ['F', 'M', 'F', 'M', 'F',
'M', 'F', 'M', 'M', 'M'],
'ExamYear': [2007, 2007, 2007, 2008, 2008,
2008, 2008, 2009, 2009, 2009],
'Class': ['algebra', 'stats', 'bio', 'algebra',
'algebra', 'stats', 'stats', 'algebra',
'bio', 'bio'],
'Participated': ['yes', 'yes', 'yes', 'yes', 'no',
'yes', 'yes', 'yes', 'yes', 'yes'],
'Passed': ['yes' if x > 50 else 'no' for x in grades],
'Employed': [True, True, True, False,
False, False, False, True, True, False],
'Grade': grades}

df = dt.Frame(data)

- Within j : This will allow for intermediate outputs, and make code cleaner and more reproducible, even giving the opportunity to reduce the number of nested aggregations or calculations. If possible, refer to the same column multiple times within j.

df[:,{'grade':dt.mean(f.Grade), 'new_avg':f.grade + 10},'Gender']

- Within by and sort : # sort the entire frame in descending order with `new_avg`, or group with it :

df[:,{'grade':dt.mean(f.Grade), 'new_avg':f.grade + 10},'Gender', dt.sort(-f.new_avg)]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.