Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
steveoni committed Aug 15, 2020
2 parents 7121812 + a2817eb commit 6d21a47
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 115 deletions.
107 changes: 54 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,60 @@ easy and intuitive. It is heavily inspired by [Pandas](https://pandas.pydata.org
- 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



To use danfo.js via script tags, copy and paste the CDN below to your HTML file

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js"></script>
```

### Example Usage in the Browser

```html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js"></script>
<title>Document</title>
</head>

<body>

<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>

<script>
dfd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
.then(df => {
df['AAPL.Open'].plot("div1").box() //makes a box plot
df.plot("div2").table() //display csv as table
new_df = df.set_index({ key: "Date" }) //resets the index to Date column
new_df.plot("div3").line({ columns: ["AAPL.Open", "AAPL.High"] }) //makes a timeseries plot
}).catch(err => {
console.log(err);
})
</script>

</body>

</html>
```

Output in Browser:

![](assets/browser-out.gif)


## How to install
danfo.js is hosted on NPM, and can installed via package managers like npm and yarn

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


To use danfo.js via script tags, copy and paste the CDN below to your HTML file

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js"></script>
```

### Example Usage in the Browser

```html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js"></script>
<title>Document</title>
</head>

<body>

<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>

<script>
dfd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
.then(df => {
df['AAPL.Open'].plot("div1").box() //makes a box plot
df.plot("div2").table() //display csv as table
new_df = df.set_index({ key: "Date" }) //resets the index to Date column
new_df.plot("div3").line({ columns: ["AAPL.Open", "AAPL.High"] }) //makes a timeseries plot
}).catch(err => {
console.log(err);
})
</script>

</body>

</html>
```

Output in Browser:

![](assets/browser-out.gif)


#### [See the Official Getting Started Guide](https://jsdata.gitbook.io/danfojs/getting-started)

## Documentation
Expand Down
100 changes: 43 additions & 57 deletions danfojs/src/core/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,37 @@ export class DataFrame extends Ndframe {
throw Error("No column found. Axis of 1 must be accompanied by an array of column(s) names")
}
let self = this;
let new_col_data = {}
let new_dtype = []

const index = data.map((x) => {
let col_idx = self.columns.indexOf(x)
if (col_idx == -1) {
throw new Error(`column "${x}" does not exist`)
}
return col_idx
});
const values = this.values
let new_dtype = []
let new_data = values.map(function (element) {
let new_arr = utils.__remove_arr(element, index);
new_dtype = utils.__remove_arr(self.dtypes, index);
return new_arr;
});

this.col_data.forEach((col, idx) => {
if (!index.includes(idx)) {
new_col_data[self.column_names[idx]] = col
new_dtype.push(self.dtypes[idx])
}
})

if (!kwargs['inplace']) {
let old_cols = this.columns
let columns = utils.__remove_arr(this.columns, index);
let df = new DataFrame(new_data, { columns: columns, index: self.index, dtypes: new_dtype })
df.__set_col_property(df, df.col_data, columns, old_cols)
let old_cols = self.columns
let new_columns = Object.keys(new_col_data)
let df = new DataFrame(new_col_data, { index: self.index, dtypes: new_dtype })
df.__set_col_property(df, df.col_data, new_columns, old_cols)
return df

} else {
let new_cols = utils.__remove_arr(this.columns, index);
let old_cols = this.columns
this.columns = new_cols
this.row_data_tensor = tf.tensor(new_data);
this.data = new_data
this.__set_col_types(new_dtype, false)
this.__set_col_property(this, this.col_data, new_cols, old_cols)
let old_cols = self.columns
let new_columns = Object.keys(new_col_data)
this.__update_frame_in_place(null, null, new_col_data, null, new_dtype)
this.__set_col_property(self, self.col_data, new_columns, old_cols)

}

} else {
Expand Down Expand Up @@ -695,7 +696,8 @@ export class DataFrame extends Ndframe {
let df = new DataFrame([...this.values],
{
columns: [...this.column_names],
index: this.index, dtypes: this.dtypes
index: this.index,
dtypes: this.dtypes
})
return df
}
Expand All @@ -716,7 +718,6 @@ export class DataFrame extends Ndframe {
}

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

// sorted_index.map(idx => {
// new_row_data.push(this.values[idx])
// })

// if (utils.__key_in_object(kwargs, "inplace") && kwargs['inplace'] == true) {
// this.__update_frame_in_place(new_row_data, null, null, sorted_index, null)

// } else {
// let df = new DataFrame(new_row_data, { columns: this.column_names, index: sorted_index, dtype: this.dtypes })
// return df
// }

// } else {
// throw Error("Value Error: must specify the column to sort by")
// }

// }


Expand Down Expand Up @@ -1093,17 +1110,14 @@ export class DataFrame extends Ndframe {
groupby(col) {

let len = this.shape[0]

let column_names = this.column_names
let col_dict = {};
let key_column = null;

if (col.length == 2) {

if (column_names.includes(col[0])) {
// eslint-disable-next-line no-unused-vars
var [data1, col_name1] = indexLoc(this, { "rows": [`0:${len}`], "columns": [`${col[0]}`], "type": "loc" });

}
else {
throw new Error(`column ${col[0]} does not exist`);
Expand Down Expand Up @@ -1259,8 +1273,7 @@ export class DataFrame extends Ndframe {
let row_value = values[i]
for (let j = 0; j < row_value.length; j++) {

let val = row_value[j] == 0 ? 0 : !!row_value[j]
if (!val) {
if (isNaN(row_value[j]) && typeof row_value[j] != "string" ) {
temp_data.push(nan_val)
} else {
temp_data.push(row_value[j])
Expand All @@ -1269,8 +1282,12 @@ export class DataFrame extends Ndframe {
}
data.push(temp_data);
}
if (kwargs['inplace']) {
this.__update_frame_in_place(data, null, null, null, null)
} else {
return new DataFrame(data, { columns: columns, index: this.index })

return new DataFrame(data, { columns: columns, index: this.index })
}

}

Expand Down Expand Up @@ -1306,37 +1323,6 @@ export class DataFrame extends Ndframe {
}



// let new_row_data = []
// let row_data = this.values;
// let columns = this.column_names;

// row_data.map(arr=>{
// let temp_arr = []
// arr.map(val=>{
// if (isNaN(val) && typeof val != "string" ){
// temp_arr.push(true)
// }else{
// temp_arr.push(false)
// }
// })
// new_row_data.push(temp_arr)
// })

// // for (let i = 0; i < values.length; i++) {
// // let temp_data = []
// // let row_value = values[i]
// // for (let j = 0; j < row_value.length; j++) {

// // let val = row_value[j] == 0 ? true : !row_value[j]
// // temp_data.push(val)
// // }
// // data.push(temp_data);
// // }

// return new DataFrame(new_row_data, { columns: columns, index: this.index })


/**
* Obtain index containing nan values
* @return Array list (int)
Expand Down
2 changes: 1 addition & 1 deletion danfojs/src/plotting/plot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//perform plotting
// import { newPlot } from 'plotly.js' //comment out when building for Node Version
import { newPlot } from 'plotly.js' //comment out when building for Node Version
import { Utils } from "../core/utils"
import { Series } from "../core/series"

Expand Down
7 changes: 5 additions & 2 deletions danfojs/tests/core/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ describe("DataFrame", function () {
df.drop({ columns: ["C"], axis: 1, inplace: true });
let new_data = [[1, 2], [4, 5]]
assert.deepEqual(df.values, new_data);
assert.deepEqual(df.dtypes.length, 2);

})

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

})
})

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

let df_val = [[-999, 1, 2, 3], [3, 4, -999, 9], [5, 6, 7, 8]]

assert.deepEqual(df.fillna({ values: -999 }).values, df_val)
df.fillna({ values: -999, inplace:true})
assert.deepEqual(df.values, df_val)
});
it("replace all NaN value", function () {
let data = [[NaN, 1, 2, 3], [3, 4, NaN, 9], [5, 6, 7, 8]]
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "danfojs",
"version": "0.0.15",
"version": "0.1.0",
"description": "JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.",
"main": "dist/index.js",
"contributors": [
Expand Down

0 comments on commit 6d21a47

Please sign in to comment.