Skip to content

Commit 6d21a47

Browse files
committed
fix conflict
2 parents 7121812 + a2817eb commit 6d21a47

6 files changed

Lines changed: 105 additions & 115 deletions

File tree

README.md

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,60 @@ easy and intuitive. It is heavily inspired by [Pandas](https://pandas.pydata.org
4747
- Robust data preprocessing functions like [OneHotEncoders](https://jsdata.gitbook.io/danfojs/api-reference/general-functions/danfo.onehotencoder), [LabelEncoders](https://jsdata.gitbook.io/danfojs/api-reference/general-functions/danfo.labelencoder), and scalers like [StandardSaler](https://jsdata.gitbook.io/danfojs/api-reference/general-functions/danfo.standardscaler) and [MinMaxScaler](https://jsdata.gitbook.io/danfojs/api-reference/general-functions/danfo.minmaxscaler) are supported on DataFrame and Series
4848

4949

50+
51+
To use danfo.js via script tags, copy and paste the CDN below to your HTML file
52+
53+
```html
54+
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.1.0/dist/index.min.js"></script>
55+
```
56+
57+
### Example Usage in the Browser
58+
59+
```html
60+
61+
<!DOCTYPE html>
62+
<html lang="en">
63+
<head>
64+
<meta charset="UTF-8">
65+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66+
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.1.0/dist/index.min.js"></script>
67+
<title>Document</title>
68+
</head>
69+
70+
<body>
71+
72+
<div id="div1"></div>
73+
<div id="div2"></div>
74+
<div id="div3"></div>
75+
76+
<script>
77+
78+
dfd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
79+
.then(df => {
80+
81+
df['AAPL.Open'].plot("div1").box() //makes a box plot
82+
83+
df.plot("div2").table() //display csv as table
84+
85+
new_df = df.set_index({ key: "Date" }) //resets the index to Date column
86+
new_df.plot("div3").line({ columns: ["AAPL.Open", "AAPL.High"] }) //makes a timeseries plot
87+
88+
}).catch(err => {
89+
console.log(err);
90+
})
91+
92+
</script>
93+
94+
</body>
95+
96+
</html>
97+
```
98+
99+
Output in Browser:
100+
101+
![](assets/browser-out.gif)
102+
103+
50104
## How to install
51105
danfo.js is hosted on NPM, and can installed via package managers like npm and yarn
52106

@@ -120,59 +174,6 @@ Output in Node Console:
120174
![](assets/node-rec.gif)
121175

122176

123-
To use danfo.js via script tags, copy and paste the CDN below to your HTML file
124-
125-
```html
126-
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.0.15/dist/index.min.js"></script>
127-
```
128-
129-
### Example Usage in the Browser
130-
131-
```html
132-
133-
<!DOCTYPE html>
134-
<html lang="en">
135-
<head>
136-
<meta charset="UTF-8">
137-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
138-
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.0.15/dist/index.min.js"></script>
139-
<title>Document</title>
140-
</head>
141-
142-
<body>
143-
144-
<div id="div1"></div>
145-
<div id="div2"></div>
146-
<div id="div3"></div>
147-
148-
<script>
149-
150-
dfd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
151-
.then(df => {
152-
153-
df['AAPL.Open'].plot("div1").box() //makes a box plot
154-
155-
df.plot("div2").table() //display csv as table
156-
157-
new_df = df.set_index({ key: "Date" }) //resets the index to Date column
158-
new_df.plot("div3").line({ columns: ["AAPL.Open", "AAPL.High"] }) //makes a timeseries plot
159-
160-
}).catch(err => {
161-
console.log(err);
162-
})
163-
164-
</script>
165-
166-
</body>
167-
168-
</html>
169-
```
170-
171-
Output in Browser:
172-
173-
![](assets/browser-out.gif)
174-
175-
176177
#### [See the Official Getting Started Guide](https://jsdata.gitbook.io/danfojs/getting-started)
177178

178179
## Documentation

danfojs/src/core/frame.js

Lines changed: 43 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,37 @@ export class DataFrame extends Ndframe {
7979
throw Error("No column found. Axis of 1 must be accompanied by an array of column(s) names")
8080
}
8181
let self = this;
82+
let new_col_data = {}
83+
let new_dtype = []
84+
8285
const index = data.map((x) => {
8386
let col_idx = self.columns.indexOf(x)
8487
if (col_idx == -1) {
8588
throw new Error(`column "${x}" does not exist`)
8689
}
8790
return col_idx
8891
});
89-
const values = this.values
90-
let new_dtype = []
91-
let new_data = values.map(function (element) {
92-
let new_arr = utils.__remove_arr(element, index);
93-
new_dtype = utils.__remove_arr(self.dtypes, index);
94-
return new_arr;
95-
});
92+
93+
this.col_data.forEach((col, idx) => {
94+
if (!index.includes(idx)) {
95+
new_col_data[self.column_names[idx]] = col
96+
new_dtype.push(self.dtypes[idx])
97+
}
98+
})
9699

97100
if (!kwargs['inplace']) {
98-
let old_cols = this.columns
99-
let columns = utils.__remove_arr(this.columns, index);
100-
let df = new DataFrame(new_data, { columns: columns, index: self.index, dtypes: new_dtype })
101-
df.__set_col_property(df, df.col_data, columns, old_cols)
101+
let old_cols = self.columns
102+
let new_columns = Object.keys(new_col_data)
103+
let df = new DataFrame(new_col_data, { index: self.index, dtypes: new_dtype })
104+
df.__set_col_property(df, df.col_data, new_columns, old_cols)
102105
return df
103106

104107
} else {
105-
let new_cols = utils.__remove_arr(this.columns, index);
106-
let old_cols = this.columns
107-
this.columns = new_cols
108-
this.row_data_tensor = tf.tensor(new_data);
109-
this.data = new_data
110-
this.__set_col_types(new_dtype, false)
111-
this.__set_col_property(this, this.col_data, new_cols, old_cols)
108+
let old_cols = self.columns
109+
let new_columns = Object.keys(new_col_data)
110+
this.__update_frame_in_place(null, null, new_col_data, null, new_dtype)
111+
this.__set_col_property(self, self.col_data, new_columns, old_cols)
112+
112113
}
113114

114115
} else {
@@ -695,7 +696,8 @@ export class DataFrame extends Ndframe {
695696
let df = new DataFrame([...this.values],
696697
{
697698
columns: [...this.column_names],
698-
index: this.index, dtypes: this.dtypes
699+
index: this.index,
700+
dtypes: this.dtypes
699701
})
700702
return df
701703
}
@@ -716,7 +718,6 @@ export class DataFrame extends Ndframe {
716718
}
717719

718720
/**
719-
* Generate a new DataFrame with the specified index.
720721
* Set the DataFrame index (row labels) using an array of the same length.
721722
* @param {kwargs} {index: Array of new index values}
722723
*/
@@ -872,6 +873,22 @@ export class DataFrame extends Ndframe {
872873
// throw Error("Value Error: must specify the column to sort by")
873874
// }
874875

876+
// sorted_index.map(idx => {
877+
// new_row_data.push(this.values[idx])
878+
// })
879+
880+
// if (utils.__key_in_object(kwargs, "inplace") && kwargs['inplace'] == true) {
881+
// this.__update_frame_in_place(new_row_data, null, null, sorted_index, null)
882+
883+
// } else {
884+
// let df = new DataFrame(new_row_data, { columns: this.column_names, index: sorted_index, dtype: this.dtypes })
885+
// return df
886+
// }
887+
888+
// } else {
889+
// throw Error("Value Error: must specify the column to sort by")
890+
// }
891+
875892
// }
876893

877894

@@ -1093,17 +1110,14 @@ export class DataFrame extends Ndframe {
10931110
groupby(col) {
10941111

10951112
let len = this.shape[0]
1096-
10971113
let column_names = this.column_names
10981114
let col_dict = {};
10991115
let key_column = null;
11001116

11011117
if (col.length == 2) {
1102-
11031118
if (column_names.includes(col[0])) {
11041119
// eslint-disable-next-line no-unused-vars
11051120
var [data1, col_name1] = indexLoc(this, { "rows": [`0:${len}`], "columns": [`${col[0]}`], "type": "loc" });
1106-
11071121
}
11081122
else {
11091123
throw new Error(`column ${col[0]} does not exist`);
@@ -1259,8 +1273,7 @@ export class DataFrame extends Ndframe {
12591273
let row_value = values[i]
12601274
for (let j = 0; j < row_value.length; j++) {
12611275

1262-
let val = row_value[j] == 0 ? 0 : !!row_value[j]
1263-
if (!val) {
1276+
if (isNaN(row_value[j]) && typeof row_value[j] != "string" ) {
12641277
temp_data.push(nan_val)
12651278
} else {
12661279
temp_data.push(row_value[j])
@@ -1269,8 +1282,12 @@ export class DataFrame extends Ndframe {
12691282
}
12701283
data.push(temp_data);
12711284
}
1285+
if (kwargs['inplace']) {
1286+
this.__update_frame_in_place(data, null, null, null, null)
1287+
} else {
1288+
return new DataFrame(data, { columns: columns, index: this.index })
12721289

1273-
return new DataFrame(data, { columns: columns, index: this.index })
1290+
}
12741291

12751292
}
12761293

@@ -1306,37 +1323,6 @@ export class DataFrame extends Ndframe {
13061323
}
13071324

13081325

1309-
1310-
// let new_row_data = []
1311-
// let row_data = this.values;
1312-
// let columns = this.column_names;
1313-
1314-
// row_data.map(arr=>{
1315-
// let temp_arr = []
1316-
// arr.map(val=>{
1317-
// if (isNaN(val) && typeof val != "string" ){
1318-
// temp_arr.push(true)
1319-
// }else{
1320-
// temp_arr.push(false)
1321-
// }
1322-
// })
1323-
// new_row_data.push(temp_arr)
1324-
// })
1325-
1326-
// // for (let i = 0; i < values.length; i++) {
1327-
// // let temp_data = []
1328-
// // let row_value = values[i]
1329-
// // for (let j = 0; j < row_value.length; j++) {
1330-
1331-
// // let val = row_value[j] == 0 ? true : !row_value[j]
1332-
// // temp_data.push(val)
1333-
// // }
1334-
// // data.push(temp_data);
1335-
// // }
1336-
1337-
// return new DataFrame(new_row_data, { columns: columns, index: this.index })
1338-
1339-
13401326
/**
13411327
* Obtain index containing nan values
13421328
* @return Array list (int)

danfojs/src/plotting/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//perform plotting
2-
// import { newPlot } from 'plotly.js' //comment out when building for Node Version
2+
import { newPlot } from 'plotly.js' //comment out when building for Node Version
33
import { Utils } from "../core/utils"
44
import { Series } from "../core/series"
55

danfojs/tests/core/frame.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ describe("DataFrame", function () {
3333
df.drop({ columns: ["C"], axis: 1, inplace: true });
3434
let new_data = [[1, 2], [4, 5]]
3535
assert.deepEqual(df.values, new_data);
36+
assert.deepEqual(df.dtypes.length, 2);
37+
3638
})
3739

3840
it("check if data is updated after row is dropped", function () {
@@ -77,6 +79,7 @@ describe("DataFrame", function () {
7779
df.drop({ index: ["a", "b"], axis: 0, inplace: true });
7880
let new_data = [[20, 34, 5]]
7981
assert.deepEqual(df.values, new_data);
82+
8083
})
8184
})
8285

@@ -1397,8 +1400,8 @@ describe("DataFrame", function () {
13971400
let df = new DataFrame(data, { columns: column })
13981401

13991402
let df_val = [[-999, 1, 2, 3], [3, 4, -999, 9], [5, 6, 7, 8]]
1400-
1401-
assert.deepEqual(df.fillna({ values: -999 }).values, df_val)
1403+
df.fillna({ values: -999, inplace:true})
1404+
assert.deepEqual(df.values, df_val)
14021405
});
14031406
it("replace all NaN value", function () {
14041407
let data = [[NaN, 1, 2, 3], [3, 4, NaN, 9], [5, 6, 7, 8]]

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "danfojs",
3-
"version": "0.0.15",
3+
"version": "0.1.0",
44
"description": "JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.",
55
"main": "dist/index.js",
66
"contributors": [

0 commit comments

Comments
 (0)