Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.

Commit 8a48a6b

Browse files
committed
correcting a bug with restructure
1 parent 1106df1 commit 8a48a6b

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# dataframe-js
22
**v1.0.0**
33

4+
![](https://travis-ci.org/Gmousse/dataframe-js.svg?branch=feature%2Fsql)
5+
46
## Presentation
57

68
dataframe-js provides another way to work with data in javascript (browser or server side) by using DataFrame, a data structure already used in some languages (Python, R, ...).

examples/titanic_analysis.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,19 @@ DataFrame.fromCSV('http://vincentarelbundock.github.io/Rdatasets/csv/COUNT/titan
138138
// First we join our results.
139139
const ageEffect = survivalMeanByAge.innerJoin(survivalSDByAge, 'age');
140140
ageEffect.show();
141-
// We now transpose the table (with columnNames);
142-
const transposedAgeEffect = ageEffect.tranpose(true).rename('rowNames', '');
141+
// We now remove age column (you will understand why in few lines) and transpose the table (with columnNames);
142+
const transposedAgeEffect = ageEffect.drop('age').transpose(true);
143143
// It's magical, and it looks like that:
144144
transposedAgeEffect.show();
145+
// Now we will use the previously removed age column as columnNames.
146+
// Then we reorganize columns order.
147+
transposedAgeEffect
148+
.renameAll([...ageEffect.toArray('age'), '']).restructure(['', 'child', 'adults', 'yahou']).show()
149+
const transposedAgeEffectWithColumnNames = transposedAgeEffect
150+
.renameAll([...ageEffect.toArray('age'), ''])
151+
.select('', 'child', 'adults');
152+
// Which gives:
153+
transposedAgeEffectWithColumnNames.show();
145154
}
146155
).catch(err => {
147156
console.log(err);

src/dataframe.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class DataFrame {
125125
}
126126

127127
__newInstance__(data, columns) {
128-
if (!arrayEqual(columns, this[__columns__]) || !(data[0] instanceof Row)) {
128+
if (!arrayEqual(columns, this[__columns__], true) || !(data[0] instanceof Row)) {
129129
return new DataFrame(data, this._dropSpacesInColumnNames(columns), ...this.modules);
130130
}
131131
const newInstance = Object.assign(

0 commit comments

Comments
 (0)