diff --git a/.gitbook/assets/419Nr0T2ZmL.jpeg b/.gitbook/assets/419Nr0T2ZmL.jpeg new file mode 100644 index 0000000..971413a Binary files /dev/null and b/.gitbook/assets/419Nr0T2ZmL.jpeg differ diff --git a/.gitbook/assets/B17076_Cover.jpg b/.gitbook/assets/B17076_Cover.jpg new file mode 100644 index 0000000..726b939 Binary files /dev/null and b/.gitbook/assets/B17076_Cover.jpg differ diff --git a/.gitbook/assets/screen-shot-2020-08-11-at-12.34.08-am.png b/.gitbook/assets/Screen Shot 2020-08-11 at 12.34.08 AM.png similarity index 100% rename from .gitbook/assets/screen-shot-2020-08-11-at-12.34.08-am.png rename to .gitbook/assets/Screen Shot 2020-08-11 at 12.34.08 AM.png diff --git a/.gitbook/assets/screen-shot-2020-08-11-at-12.38.30-am.png b/.gitbook/assets/Screen Shot 2020-08-11 at 12.38.30 AM.png similarity index 100% rename from .gitbook/assets/screen-shot-2020-08-11-at-12.38.30-am.png rename to .gitbook/assets/Screen Shot 2020-08-11 at 12.38.30 AM.png diff --git a/.gitbook/assets/screen-shot-2021-02-14-at-7.22.16-pm.png b/.gitbook/assets/Screen Shot 2021-02-14 at 7.22.16 PM.png similarity index 100% rename from .gitbook/assets/screen-shot-2021-02-14-at-7.22.16-pm.png rename to .gitbook/assets/Screen Shot 2021-02-14 at 7.22.16 PM.png diff --git a/.gitbook/assets/image (4).png b/.gitbook/assets/image (2).png similarity index 100% rename from .gitbook/assets/image (4).png rename to .gitbook/assets/image (2).png diff --git a/.gitbook/assets/newplot-1-.png b/.gitbook/assets/newplot (1) (1).png similarity index 100% rename from .gitbook/assets/newplot-1-.png rename to .gitbook/assets/newplot (1) (1).png diff --git a/.gitbook/assets/newplot (10).png b/.gitbook/assets/newplot (10).png new file mode 100644 index 0000000..5622cb3 Binary files /dev/null and b/.gitbook/assets/newplot (10).png differ diff --git a/.gitbook/assets/newplot-11-.png b/.gitbook/assets/newplot (11).png similarity index 100% rename from .gitbook/assets/newplot-11-.png rename to .gitbook/assets/newplot (11).png diff --git a/.gitbook/assets/newplot (12).png b/.gitbook/assets/newplot (12).png new file mode 100644 index 0000000..6f09ebc Binary files /dev/null and b/.gitbook/assets/newplot (12).png differ diff --git a/.gitbook/assets/newplot-13-.png b/.gitbook/assets/newplot (13).png similarity index 100% rename from .gitbook/assets/newplot-13-.png rename to .gitbook/assets/newplot (13).png diff --git a/.gitbook/assets/newplot-14-.png b/.gitbook/assets/newplot (14).png similarity index 100% rename from .gitbook/assets/newplot-14-.png rename to .gitbook/assets/newplot (14).png diff --git a/.gitbook/assets/newplot-15-.png b/.gitbook/assets/newplot (15).png similarity index 100% rename from .gitbook/assets/newplot-15-.png rename to .gitbook/assets/newplot (15).png diff --git a/.gitbook/assets/newplot (19).png b/.gitbook/assets/newplot (19).png new file mode 100644 index 0000000..8e257da Binary files /dev/null and b/.gitbook/assets/newplot (19).png differ diff --git a/.gitbook/assets/newplot-2- (1).png b/.gitbook/assets/newplot (2) (1) (1).png similarity index 100% rename from .gitbook/assets/newplot-2- (1).png rename to .gitbook/assets/newplot (2) (1) (1).png diff --git a/.gitbook/assets/newplot-2-.png b/.gitbook/assets/newplot (2) (1) (2).png similarity index 100% rename from .gitbook/assets/newplot-2-.png rename to .gitbook/assets/newplot (2) (1) (2).png diff --git a/.gitbook/assets/newplot (2) (1) (3).png b/.gitbook/assets/newplot (2) (1) (3).png new file mode 100644 index 0000000..9f34611 Binary files /dev/null and b/.gitbook/assets/newplot (2) (1) (3).png differ diff --git a/.gitbook/assets/newplot (2) (1).png b/.gitbook/assets/newplot (2) (1).png new file mode 100644 index 0000000..9f34611 Binary files /dev/null and b/.gitbook/assets/newplot (2) (1).png differ diff --git a/.gitbook/assets/newplot (2) (2) (1).png b/.gitbook/assets/newplot (2) (2) (1).png new file mode 100644 index 0000000..9f34611 Binary files /dev/null and b/.gitbook/assets/newplot (2) (2) (1).png differ diff --git a/.gitbook/assets/newplot (2) (2).png b/.gitbook/assets/newplot (2) (2).png new file mode 100644 index 0000000..9f34611 Binary files /dev/null and b/.gitbook/assets/newplot (2) (2).png differ diff --git a/.gitbook/assets/newplot (2).png b/.gitbook/assets/newplot (2).png new file mode 100644 index 0000000..9f34611 Binary files /dev/null and b/.gitbook/assets/newplot (2).png differ diff --git a/.gitbook/assets/newplot (20).png b/.gitbook/assets/newplot (20).png new file mode 100644 index 0000000..4f2ac2e Binary files /dev/null and b/.gitbook/assets/newplot (20).png differ diff --git a/.gitbook/assets/newplot (21).png b/.gitbook/assets/newplot (21).png new file mode 100644 index 0000000..caf3da7 Binary files /dev/null and b/.gitbook/assets/newplot (21).png differ diff --git a/.gitbook/assets/newplot (22).png b/.gitbook/assets/newplot (22).png new file mode 100644 index 0000000..b6aa9f1 Binary files /dev/null and b/.gitbook/assets/newplot (22).png differ diff --git a/.gitbook/assets/newplot-23-.png b/.gitbook/assets/newplot (23).png similarity index 100% rename from .gitbook/assets/newplot-23-.png rename to .gitbook/assets/newplot (23).png diff --git a/.gitbook/assets/newplot (24).png b/.gitbook/assets/newplot (24).png new file mode 100644 index 0000000..cd8f8b0 Binary files /dev/null and b/.gitbook/assets/newplot (24).png differ diff --git a/.gitbook/assets/newplot (25).png b/.gitbook/assets/newplot (25).png new file mode 100644 index 0000000..6921110 Binary files /dev/null and b/.gitbook/assets/newplot (25).png differ diff --git a/.gitbook/assets/newplot (26).png b/.gitbook/assets/newplot (26).png new file mode 100644 index 0000000..df735b0 Binary files /dev/null and b/.gitbook/assets/newplot (26).png differ diff --git a/.gitbook/assets/newplot (27).png b/.gitbook/assets/newplot (27).png new file mode 100644 index 0000000..9d7daa6 Binary files /dev/null and b/.gitbook/assets/newplot (27).png differ diff --git a/.gitbook/assets/newplot (3).png b/.gitbook/assets/newplot (3).png new file mode 100644 index 0000000..d63d265 Binary files /dev/null and b/.gitbook/assets/newplot (3).png differ diff --git a/.gitbook/assets/newplot-32-.png b/.gitbook/assets/newplot (32).png similarity index 100% rename from .gitbook/assets/newplot-32-.png rename to .gitbook/assets/newplot (32).png diff --git a/.gitbook/assets/newplot (4).png b/.gitbook/assets/newplot (4).png new file mode 100644 index 0000000..6d5d7f7 Binary files /dev/null and b/.gitbook/assets/newplot (4).png differ diff --git a/.gitbook/assets/newplot-5-.png b/.gitbook/assets/newplot (5).png similarity index 100% rename from .gitbook/assets/newplot-5-.png rename to .gitbook/assets/newplot (5).png diff --git a/.gitbook/assets/newplot (6).png b/.gitbook/assets/newplot (6).png new file mode 100644 index 0000000..3840faa Binary files /dev/null and b/.gitbook/assets/newplot (6).png differ diff --git a/.gitbook/assets/newplot (7).png b/.gitbook/assets/newplot (7).png new file mode 100644 index 0000000..1c17ee4 Binary files /dev/null and b/.gitbook/assets/newplot (7).png differ diff --git a/.gitbook/assets/newplot-9-.png b/.gitbook/assets/newplot (9).png similarity index 100% rename from .gitbook/assets/newplot-9-.png rename to .gitbook/assets/newplot (9).png diff --git a/.gitbook/assets/newplot-2- (1) (1) (1).png b/.gitbook/assets/newplot-2- (1) (1) (1).png new file mode 100644 index 0000000..9f34611 Binary files /dev/null and b/.gitbook/assets/newplot-2- (1) (1) (1).png differ diff --git a/.gitbook/assets/newplot-2- (1) (1) (2) (1).png b/.gitbook/assets/newplot-2- (1) (1) (2) (1).png new file mode 100644 index 0000000..9f34611 Binary files /dev/null and b/.gitbook/assets/newplot-2- (1) (1) (2) (1).png differ diff --git a/.gitbook/assets/newplot-2- (1) (1) (2) (2).png b/.gitbook/assets/newplot-2- (1) (1) (2) (2).png new file mode 100644 index 0000000..9f34611 Binary files /dev/null and b/.gitbook/assets/newplot-2- (1) (1) (2) (2).png differ diff --git a/.gitbook/assets/newplot-2- (1) (1) (2).png b/.gitbook/assets/newplot-2- (1) (1) (2).png new file mode 100644 index 0000000..9f34611 Binary files /dev/null and b/.gitbook/assets/newplot-2- (1) (1) (2).png differ diff --git a/.gitbook/assets/newplot-29- (1).png b/.gitbook/assets/newplot-29- (2) (1) (1) (1).png similarity index 100% rename from .gitbook/assets/newplot-29- (1).png rename to .gitbook/assets/newplot-29- (2) (1) (1) (1).png diff --git a/.gitbook/assets/newplot-29- (2) (1) (1) (2).png b/.gitbook/assets/newplot-29- (2) (1) (1) (2).png new file mode 100644 index 0000000..a884a20 Binary files /dev/null and b/.gitbook/assets/newplot-29- (2) (1) (1) (2).png differ diff --git a/.gitbook/assets/newplot-29- (2) (1) (1) (3).png b/.gitbook/assets/newplot-29- (2) (1) (1) (3).png new file mode 100644 index 0000000..a884a20 Binary files /dev/null and b/.gitbook/assets/newplot-29- (2) (1) (1) (3).png differ diff --git a/.gitbook/assets/newplot-29- (2) (1) (1) (4).png b/.gitbook/assets/newplot-29- (2) (1) (1) (4).png new file mode 100644 index 0000000..a884a20 Binary files /dev/null and b/.gitbook/assets/newplot-29- (2) (1) (1) (4).png differ diff --git a/.gitbook/assets/newplot-29- (2) (1) (1).png b/.gitbook/assets/newplot-29- (2) (1) (1).png new file mode 100644 index 0000000..a884a20 Binary files /dev/null and b/.gitbook/assets/newplot-29- (2) (1) (1).png differ diff --git a/.gitbook/assets/newplot-29- (2) (1) (2).png b/.gitbook/assets/newplot-29- (2) (1) (2).png new file mode 100644 index 0000000..a884a20 Binary files /dev/null and b/.gitbook/assets/newplot-29- (2) (1) (2).png differ diff --git a/.gitbook/assets/newplot-29- (2) (1) (3).png b/.gitbook/assets/newplot-29- (2) (1) (3).png new file mode 100644 index 0000000..a884a20 Binary files /dev/null and b/.gitbook/assets/newplot-29- (2) (1) (3).png differ diff --git a/.gitbook/assets/newplot-29- (2) (1).png b/.gitbook/assets/newplot-29- (2) (1).png new file mode 100644 index 0000000..a884a20 Binary files /dev/null and b/.gitbook/assets/newplot-29- (2) (1).png differ diff --git a/.gitbook/assets/newplot-29- (2) (2) (1).png b/.gitbook/assets/newplot-29- (2) (2) (1).png new file mode 100644 index 0000000..a884a20 Binary files /dev/null and b/.gitbook/assets/newplot-29- (2) (2) (1).png differ diff --git a/.gitbook/assets/newplot-29- (2) (2) (2).png b/.gitbook/assets/newplot-29- (2) (2) (2).png new file mode 100644 index 0000000..a884a20 Binary files /dev/null and b/.gitbook/assets/newplot-29- (2) (2) (2).png differ diff --git a/.gitbook/assets/newplot-29- (2) (2).png b/.gitbook/assets/newplot-29- (2) (2).png new file mode 100644 index 0000000..a884a20 Binary files /dev/null and b/.gitbook/assets/newplot-29- (2) (2).png differ diff --git a/README.md b/README.md index a0875e2..92a7bb7 100644 --- a/README.md +++ b/README.md @@ -7,38 +7,61 @@ description: >- # Danfo.js Documentation -D**anfo.js** is heavily inspired by the [Pandas](https://pandas.pydata.org/pandas-docs/stable/index.html) library and provides a similar interface and API. This means users familiar with the [Pandas ](https://pandas.pydata.org/pandas-docs/stable/index.html)API can easily use D**anfo.js.** +D**anfo.js** is heavily inspired by the [Pandas](https://pandas.pydata.org/pandas-docs/stable/index.html) library and provides a similar interface and API. This means users familiar with the [Pandas ](https://pandas.pydata.org/pandas-docs/stable/index.html)API can easily use D**anfo.js.** ## Main Features -* Danfo.js is fast. It is built on[ Tensorflow.js](https://js.tensorflow.org/), and supports tensors out of the box. This means you can [convert danfo data structure](api-reference/dataframe/) to Tensors. -* Easy handling of missing ****data \(represented as `NaN`\) in floating point as well as non-floating point data -* Size mutability: columns can be inserted/deleted from DataFrame +* Danfo.js is fast and supports[ Tensorflow.js](https://js.tensorflow.org)'s tensors out of the box. This means you can [convert Danfo.js ](api-reference/dataframe/)DataFrames to Tensors, and vice versa. +* Easy handling of missing data (represented as `NaN, undefined, or null`) in data +* Size mutability: columns can be inserted/deleted from DataFrames * Automatic and explicit alignment: objects can be explicitly aligned to a set of labels, or the user can simply ignore the labels and let [`Series`](api-reference/series/), [`DataFrame`](api-reference/dataframe/), etc. automatically align the data for you in computations -* Powerful, flexible [groupby](api-reference/groupby/) functionality to perform split-apply-combine operations on data sets, for both aggregating and transforming data -* Make it easy to convert Arrays, JSONs, List or Objects, Tensors and differently-indexed data structures into DataFrame objects +* Powerful, flexible, [groupby](api-reference/groupby/) functionality to perform split-apply-combine operations on data sets, for both aggregating and transforming data +* Make it easy to convert Arrays, JSONs, List or Objects, Tensors, and differently-indexed data structures into DataFrame objects * Intelligent label-based slicing, fancy indexing, and querying of large data sets * Intuitive [merging](api-reference/general-functions/danfo.merge.md) and [joining](api-reference/general-functions/danfo.concat.md) data sets -* Robust IO tools for loading data from [flat-files](api-reference/input-output/danfo.read_csv.md) \(CSV and delimited\) and JSON data format. -* Powerful, flexible and intutive API for [plotting](https://app.gitbook.com/@jsdata/s/danfojs/~/drafts/-MESZnq3_VBU0EW71MxS/api-reference/plotting) DataFrames and Series interactively. +* Robust IO tools for loading data from [flat-files](api-reference/input-output/danfo.read\_csv.md) (CSV and delimited), Excel, and JSON data format. +* Powerful, flexible, and intiutive API for [plotting](https://app.gitbook.com/@jsdata/s/danfojs/\~/drafts/-MESZnq3\_VBU0EW71MxS/api-reference/plotting) DataFrames and Series interactively. * Timeseries-specific functionality: date range generation and date and time properties. * Robust data preprocessing functions like [OneHotEncoders](api-reference/general-functions/danfo.onehotencoder.md), [LabelEncoders](api-reference/general-functions/danfo.labelencoder.md), and scalers like [StandardScaler](api-reference/general-functions/danfo.standardscaler.md) and [MinMaxScaler](api-reference/general-functions/danfo.minmaxscaler.md) are supported on DataFrame and Series ## Getting Started -New to danfo? Check out the getting started guides. They contain an introduction to _danfo's_ main concepts and links to additional contents. +New to Danfo? Check out the getting started guides. It contains a quick introduction to D\_anfo's\_ main concepts and links to additional content. -{% page-ref page="getting-started.md" %} +{% content-ref url="getting-started.md" %} +[getting-started.md](getting-started.md) +{% endcontent-ref %} ## **API Reference** -The reference guide contains a detailed description of the **danfo** API. The reference describes how each function works and which parameters can be used. +The reference guide contains a detailed description of the **danfo** API. The reference describes how each function works and which parameters can be used. -{% page-ref page="api-reference/" %} +{% content-ref url="api-reference/" %} +[api-reference](api-reference/) +{% endcontent-ref %} + +## User Guides/Tutorials + +{% content-ref url="examples/" %} +[examples](examples/) +{% endcontent-ref %} + +## Building Data Driven Applications with Danfo.js - Book + +{% content-ref url="building-data-driven-applications-with-danfo.js-book.md" %} +[building-data-driven-applications-with-danfo.js-book.md](building-data-driven-applications-with-danfo.js-book.md) +{% endcontent-ref %} ## Contributing Guide -Want to help improve our documentation and existing functionalities? The contributing guidelines will guide you through the process. +Want to help improve our documentation and existing functionalities? The contributing guidelines will guide you through the process. + +{% content-ref url="contributing-guide.md" %} +[contributing-guide.md](contributing-guide.md) +{% endcontent-ref %} -{% page-ref page="contributing-guide.md" %} +## Release Notes +{% content-ref url="release-notes.md" %} +[release-notes.md](release-notes.md) +{% endcontent-ref %} diff --git a/SUMMARY.md b/SUMMARY.md index 8c3c302..3288ce0 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -4,26 +4,37 @@ * [Getting Started](getting-started.md) * [API reference](api-reference/README.md) * [General Functions](api-reference/general-functions/README.md) - * [danfo.date\_range](api-reference/general-functions/danfo.date_range.md) + * [danfo.tensorflow](api-reference/general-functions/danfo.tensorflow.md) + * [danfo. convertFunctionTotransformer](api-reference/general-functions/danfo.-convertfunctiontotransformer.md) + * [danfo.streamCsvTransformer](api-reference/general-functions/danfo.streamcsvtransformer.md) + * [danfo.streamJSON](api-reference/general-functions/danfo.streamjson.md) + * [danfo.streamCSV](api-reference/general-functions/danfo.streamcsv.md) + * [danfo.Utils](api-reference/general-functions/danfo.utils.md) + * [danfo.Str](api-reference/general-functions/danfo.str.md) + * [danfo.Dt](api-reference/general-functions/danfo.dt.md) + * [danfo.dateRange](api-reference/general-functions/danfo.date\_range.md) * [danfo.OneHotEncoder](api-reference/general-functions/danfo.onehotencoder.md) * [danfo.StandardScaler](api-reference/general-functions/danfo.standardscaler.md) * [danfo.MinMaxScaler](api-reference/general-functions/danfo.minmaxscaler.md) * [danfo.LabelEncoder](api-reference/general-functions/danfo.labelencoder.md) - * [danfo.to\_datetime](api-reference/general-functions/danfo.to_datetime.md) - * [danfo.get\_dummies](api-reference/general-functions/danfo.get_dummies.md) + * [danfo.toDateTime](api-reference/general-functions/danfo.to\_datetime.md) + * [danfo.getDummies](api-reference/general-functions/danfo.get\_dummies.md) * [danfo.concat](api-reference/general-functions/danfo.concat.md) * [danfo.merge](api-reference/general-functions/danfo.merge.md) * [Input/Output](api-reference/input-output/README.md) - * [read](api-reference/input-output/read.md) - * [danfo.read\_excel](api-reference/input-output/danfo.read_excel.md) - * [danfo.read\_json](api-reference/input-output/danfo.read_json.md) - * [danfo.read\_csv](api-reference/input-output/danfo.read_csv.md) + * [danfo.readExcel](api-reference/input-output/danfo.read\_excel.md) + * [danfo.toExcel](api-reference/input-output/danfo.to\_excel.md) + * [danfo.readJSON](api-reference/input-output/danfo.read\_json.md) + * [danfo.toJSON](api-reference/input-output/danfo.to\_json.md) + * [danfo.readCSV](api-reference/input-output/danfo.read\_csv.md) + * [danfo.toCSV](api-reference/input-output/danfo.to\_csv.md) * [Series](api-reference/series/README.md) + * [Creating a Series](api-reference/series/creating-a-series.md) * [Series.append](api-reference/series/series.append.md) - * [Series.cumsum](api-reference/series/series.cumsum.md) - * [Series.cummax](api-reference/series/series.cummax.md) - * [Series.cumprod](api-reference/series/series.cumprod.md) - * [Series.cummin](api-reference/series/series.cummin.md) + * [Series.cumSum](api-reference/series/series.cumsum.md) + * [Series.cumMax](api-reference/series/series.cummax.md) + * [Series.cumProd](api-reference/series/series.cumprod.md) + * [Series.cumMin](api-reference/series/series.cummin.md) * [Series.str.split](api-reference/series/series.str.split.md) * [Series.str.len](api-reference/series/series.str.len.md) * [Series.str.join](api-reference/series/series.str.join.md) @@ -46,27 +57,25 @@ * [Series.str.capitalize](api-reference/series/series.str.capitalize.md) * [Series.dt.seconds](api-reference/series/series.dt.second.md) * [Series.dt.minutes](api-reference/series/series.dt.minute.md) - * [Series.dt.monthday](api-reference/series/series.dt.monthday.md) - * [Series.dt.month\_name](api-reference/series/series.dt.month_name.md) - * [Series.dt.hour](api-reference/series/series.dt.hour.md) - * [Series.dt.weekdays](api-reference/series/series.dt.weekdays.md) - * [Series.dt.day](api-reference/series/series.dt.day.md) + * [Series.dt.dayOfMonth](api-reference/series/series.dt.monthday.md) + * [Series.dt.monthName](api-reference/series/series.dt.month\_name.md) + * [Series.dt.hours](api-reference/series/series.dt.hour.md) + * [Series.dt.dayOfWeek](api-reference/series/series.dt.weekdays.md) + * [Series.dt.dayOfWeek](api-reference/series/series.dt.day.md) * [Series.dt.month](api-reference/series/series.dt.month.md) * [Series.dt.year](api-reference/series/series.dt.year.md) - * [Series.argmax](api-reference/series/series.argmax.md) - * [Series.argmin](api-reference/series/series.argmin.md) - * [Series.argsort](api-reference/series/series.argsort.md) + * [Series.argMax](api-reference/series/series.argmax.md) + * [Series.argMin](api-reference/series/series.argmin.md) + * [Series.argSort](api-reference/series/series.argsort.md) * [Series.replace](api-reference/series/series.replace.md) - * [Series.isna](api-reference/series/series.isna.md) - * [Series.fillna](api-reference/series/series.fillna.md) - * [Series.dropna](api-reference/series/series.dropna.md) - * [Series.drop\_duplicates](api-reference/series/series.drop_duplicates.md) - * [Series.value\_counts](api-reference/series/series.value_counts.md) - * [Series.nunique](api-reference/series/series.nunique.md) + * [Series.isNa](api-reference/series/series.isna.md) + * [Series.fillNa](api-reference/series/series.fillna.md) + * [Series.dropNa](api-reference/series/series.dropna.md) + * [Series.dropDuplicates](api-reference/series/series.drop\_duplicates.md) + * [Series.valueCounts](api-reference/series/series.value\_counts.md) + * [Series.nUnique](api-reference/series/series.nunique.md) * [Series.unique](api-reference/series/series.unique.md) - * [Series.corr](api-reference/series/series.corr.md) * [Series.abs](api-reference/series/series.abs.md) - * [Series.dot](api-reference/series/series.dot.md) * [Series.ne](api-reference/series/series.ne.md) * [Series.eq](api-reference/series/series.eq.md) * [Series.ge](api-reference/series/series.ge.md) @@ -74,7 +83,9 @@ * [Series.gt](api-reference/series/series.gt.md) * [Series.lt](api-reference/series/series.lt.md) * [Series.iloc](api-reference/series/series.iloc.md) - * [Series.size](api-reference/series/series.size.md) + * [Series.loc](api-reference/series/series.loc.md) + * [Series.at](api-reference/series/series.at.md) + * [Series.iat](api-reference/series/series.iat.md) * [Series.ndim](api-reference/series/series.ndim.md) * [Series.shape](api-reference/series/series.shape.md) * [Series.dtype](api-reference/series/series.dtype.md) @@ -83,11 +94,11 @@ * [Series.index](api-reference/series/series.index.md) * [Series.apply](api-reference/series/series.apply.md) * [Series.map](api-reference/series/series.map.md) - * [Series.set\_index](api-reference/series/series.set_index.md) - * [Series.reset\_index](api-reference/series/series.reset_index.md) + * [Series.setIndex](api-reference/series/series.set\_index.md) + * [Series.resetIndex](api-reference/series/series.reset\_index.md) * [Series.describe](api-reference/series/series.describe.md) * [Series.copy](api-reference/series/series.copy.md) - * [Series.sort\_values](api-reference/series/series.sort_values.md) + * [Series.sortValues](api-reference/series/series.sort\_values.md) * [Series.var](api-reference/series/series.var.md) * [Series.std](api-reference/series/series.std.md) * [Series.round](api-reference/series/series.round.md) @@ -109,31 +120,35 @@ * [Series.sample](api-reference/series/series.sample.md) * [Series.tail](api-reference/series/series.tail.md) * [Series.head](api-reference/series/series.head.md) + * [Series.and](api-reference/series/series.and.md) + * [Series.or](api-reference/series/series.or.md) * [Dataframe](api-reference/dataframe/README.md) - * [DataFrame.sort\_index](api-reference/dataframe/dataframe.sort_index.md) + * [Creating a DataFrame](api-reference/dataframe/creating-a-dataframe.md) + * [DataFrame.sortIndex](api-reference/dataframe/dataframe.sort\_index.md) * [DataFrame.append](api-reference/dataframe/dataframe.append.md) - * [DataFrame.nunique](api-reference/dataframe/dataframe.nunique-1.md) + * [DataFrame.nUnique](api-reference/dataframe/dataframe.nunique-1.md) * [DataFrame.tensor](api-reference/dataframe/dataframe.tensor.md) * [DataFrame.print](api-reference/dataframe/dataframe.print.md) - * [DataFrame.to\_csv](api-reference/dataframe/dataframe.to_csv.md) - * [DataFrame.to\_json](api-reference/dataframe/dataframe.to_json.md) - * [DataFrame.sort\_values](api-reference/dataframe/dataframe.sort_values.md) - * [DataFrame.set\_index](api-reference/dataframe/dataframe.set_index.md) - * [DataFrame.reset\_index](api-reference/dataframe/dataframe.reset_index.md) + * [DataFrame.toCSV](api-reference/dataframe/dataframe.to\_csv.md) + * [DataFrame.toJSON](api-reference/dataframe/dataframe.to\_json.md) + * [DataFrame.toExcel](api-reference/dataframe/dataframe.to\_excel.md) + * [DataFrame.sortValues](api-reference/dataframe/dataframe.sort\_values.md) + * [DataFrame.setIndex](api-reference/dataframe/dataframe.set\_index.md) + * [DataFrame.resetIndex](api-reference/dataframe/dataframe.reset\_index.md) * [DataFrame.rename](api-reference/dataframe/dataframe.rename.md) * [DataFrame.drop](api-reference/dataframe/dataframe.drop.md) - * [DataFrame.unique](api-reference/dataframe/dataframe.nunique.md) - * [DataFrame.astype](api-reference/dataframe/dataframe.astype.md) + * [DataFrame.asType](api-reference/dataframe/dataframe.astype.md) * [DataFrame.shape](api-reference/dataframe/dataframe.shape.md) - * [DataFrame.size](api-reference/dataframe/dataframe.size.md) - * [DataFrame.axes](api-reference/dataframe/dataframe.axes.md) + * [DataFrame.axis](api-reference/dataframe/dataframe.axes.md) * [DataFrame.ndim](api-reference/dataframe/dataframe.ndim.md) * [DataFrame.values](api-reference/dataframe/dataframe.values.md) - * [DataFrame.select\_dtypes](api-reference/dataframe/dataframe.select_dtypes.md) + * [DataFrame.selectDtypes](api-reference/dataframe/dataframe.select\_dtypes.md) * [DataFrame.ctypes](api-reference/dataframe/dataframe.dtypes.md) * [DataFrame.index](api-reference/dataframe/dataframe.index.md) * [DataFrame.loc](api-reference/dataframe/danfo.dataframe.loc.md) * [DataFrame.iloc](api-reference/dataframe/danfo.dataframe.iloc.md) + * [DataFrame.at](api-reference/dataframe/dataframe.at.md) + * [DataFrame.iat](api-reference/dataframe/dataframe.iat.md) * [DataFrame.head](api-reference/dataframe/danfo.dataframe.head.md) * [DataFrame.tail](api-reference/dataframe/danfo.dataframe.tail.md) * [DataFrame.sample](api-reference/dataframe/danfo.dataframe.sample.md) @@ -151,10 +166,10 @@ * [DataFrame.var](api-reference/dataframe/danfo.dataframe.var.md) * [DataFrame.count](api-reference/dataframe/danfo.dataframe.count.md) * [DataFrame.round](api-reference/dataframe/danfo.dataframe.round.md) - * [DataFrame.cumsum](api-reference/dataframe/danfo.dataframe.cumsum.md) - * [DataFrame.cummin](api-reference/dataframe/danfo.dataframe.cummin.md) - * [DataFrame.cummax](api-reference/dataframe/danfo.dataframe.cummax.md) - * [DataFrame.cumprod](api-reference/dataframe/danfo.dataframe.cumprod.md) + * [DataFrame.cumSum](api-reference/dataframe/danfo.dataframe.cumsum.md) + * [DataFrame.cumMin](api-reference/dataframe/danfo.dataframe.cummin.md) + * [DataFrame.cumMax](api-reference/dataframe/danfo.dataframe.cummax.md) + * [DataFrame.cumProd](api-reference/dataframe/danfo.dataframe.cumprod.md) * [DataFrame.copy](api-reference/dataframe/danfo.dataframe.copy.md) * [DataFrame.describe](api-reference/dataframe/danfo.dataframe.describe.md) * [DataFrame.sum](api-reference/dataframe/danfo.dataframe.sum.md) @@ -163,11 +178,11 @@ * [DataFrame.addColumn](api-reference/dataframe/danfo.dataframe.addcolumn.md) * [DataFrame.groupby](api-reference/dataframe/danfo.dataframe.groupby.md) * [DataFrame.column](api-reference/dataframe/danfo.dataframe.column.md) - * [DataFrame.fillna](api-reference/dataframe/danfo.dataframe.fillna.md) - * [DataFrame.isna](api-reference/dataframe/danfo.dataframe.isna.md) - * [DataFrame.nanindex](api-reference/dataframe/danfo.dataframe.nanindex.md) - * [DataFrame.dropna](api-reference/dataframe/danfo.dataframe.dropna.md) + * [DataFrame.fillNa](api-reference/dataframe/danfo.dataframe.fillna.md) + * [DataFrame.isNa](api-reference/dataframe/danfo.dataframe.isna.md) + * [DataFrame.dropNa](api-reference/dataframe/danfo.dataframe.dropna.md) * [DataFrame.apply](api-reference/dataframe/danfo.dataframe.apply.md) + * [DataFrame.applyMap](api-reference/dataframe/dataframe.apply\_map.md) * [DataFrame.It](api-reference/dataframe/danfo.dataframe.it.md) * [DataFrame.gt](api-reference/dataframe/danfo.dataframe.gt.md) * [DataFrame.le](api-reference/dataframe/danfo.dataframe.le.md) @@ -175,6 +190,7 @@ * [DataFrame.ne](api-reference/dataframe/danfo.dataframe.ne.md) * [DataFrame.eq](api-reference/dataframe/danfo.dataframe.eq.md) * [DataFrame.replace](api-reference/dataframe/danfo.dataframe.replace.md) + * [Configuration Options](api-reference/configuration-options.md) * [Plotting](api-reference/plotting/README.md) * [Timeseries Plots](api-reference/plotting/timeseries-plots.md) * [Violin Plots](api-reference/plotting/violin-plots.md) @@ -185,10 +201,9 @@ * [Scatter Plots](api-reference/plotting/scatter-plots.md) * [Bar Charts](api-reference/plotting/bar-charts.md) * [Line Charts](api-reference/plotting/line-charts.md) - * [Configuring your plots](api-reference/plotting/configuring-your-plots.md) - * [Untitled](api-reference/untitled.md) + * [Customizing your plots](api-reference/plotting/configuring-your-plots.md) * [Groupby](api-reference/groupby/README.md) - * [Groupby.get\_groups](api-reference/groupby/groupby.get_groups.md) + * [Groupby.getGroups](api-reference/groupby/groupby.getGroups.md) * [Groupby.col](api-reference/groupby/groupby.col.md) * [Groupby.max](api-reference/groupby/groupby.max.md) * [Groupby.min](api-reference/groupby/groupby.min.md) @@ -197,14 +212,15 @@ * [Groupby.std](api-reference/groupby/groupby.std.md) * [Groupby.var](api-reference/groupby/groupby.var.md) * [Groupby.count](api-reference/groupby/groupby.count.md) - * [Groupby.cumsum](api-reference/groupby/groupby.cumsum.md) - * [Groupby.cummax](api-reference/groupby/groupby.cummax.md) - * [Groupby.cummin](api-reference/groupby/groupby.cummin.md) - * [Groupby.cumprod](api-reference/groupby/groupby.cumprod.md) + * [Groupby.cumSum](api-reference/groupby/groupby.cumsum.md) + * [Groupby.cumMax](api-reference/groupby/groupby.cummax.md) + * [Groupby.cumMin](api-reference/groupby/groupby.cummin.md) + * [Groupby.cumProd](api-reference/groupby/groupby.cumprod.md) * [Groupby.agg](api-reference/groupby/groupby.agg.md) * [User Guides](examples/README.md) + * [Migrating to the stable version of Danfo.js](examples/migrating-to-the-stable-version-of-danfo.js.md) * [Using Danfojs in React](examples/using-danfojs-in-react.md) * [Titanic Survival Prediction using Danfo.js and Tensorflow.js](examples/titanic-survival-prediction-using-danfo.js-and-tensorflow.js.md) +* [Building Data Driven Applications with Danfo.js - Book](building-data-driven-applications-with-danfo.js-book.md) * [Contributing Guide](contributing-guide.md) * [Release Notes](release-notes.md) - diff --git a/api-reference/README.md b/api-reference/README.md index 70dff34..9e79ca8 100644 --- a/api-reference/README.md +++ b/api-reference/README.md @@ -1,15 +1,21 @@ --- description: >- - This page gives an overview of all public danfo objects, functions and - methods. All classes and functions exposed in danfo.* namespace are public. + List of all public Danfo objects, functions and methods. All classes and + functions exposed in danfo.* namespace is public. --- # API reference +{% hint style="info" %} +A stable version of Danfojs (v1), has been released, and it comes with full Typescript support, new features, and many bug fixes. See release note [here](../release-notes.md#latest-release-node-v1.0.0-browser-v1.0.0). + +There are a couple of breaking changes, so we have prepared a short migration [guide](../examples/migrating-to-the-stable-version-of-danfo.js.md) for pre-v1 users. +{% endhint %} + * [General Functions](general-functions/) * [Data manipulations](general-functions/#data-manipulations) * [Data Processing/Normalization](general-functions/#data-processing-normalization) - * [Top-level dealing with datetimelike](general-functions/#top-level-dealing-with-datetime) + * [Top-level dealing with datetime like](general-functions/#top-level-dealing-with-datetime) * [Input/output](input-output/) * [CSV](input-output/#csv) * [JSON](input-output/#json) @@ -26,7 +32,7 @@ description: >- * [Accessors](series/#accessors) * [Serialization / IO / conversion](series/#serialization-io-conversion) * [DataFrame](dataframe/) - * [Attributes ](dataframe/#attributes) + * [Attributes](dataframe/#attributes) * [Conversion](dataframe/#conversion) * [Indexing, iteration](dataframe/#indexing-iteration) * [Binary operator functions](dataframe/#binary-operator-functions) @@ -51,6 +57,3 @@ description: >- * [Indexing, iteration](groupby/#indexing-iteration) * [Function application](groupby/#function-application) * [Computations / descriptive stats](groupby/#computations-descriptive-stats) - - - diff --git a/api-reference/configuration-options.md b/api-reference/configuration-options.md new file mode 100644 index 0000000..d2fa5d7 --- /dev/null +++ b/api-reference/configuration-options.md @@ -0,0 +1,128 @@ +--- +description: >- + This section describes all user configurable options available on + DataFrame/Series creation. +--- + +# Configuration Options + +On DataFrame/Series creation, a config object can be passed along to configure some internal properties of the created object. The following list shows what options are available and what they do. + +| Parameter | Description | +| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| tableDisplayConfig | **Object**, General table display options. Because we use the table package under the hood to display a table in the console, all [table display configurations](https://www.npmjs.com/package/table) are supported. | +| tableMaxRow | **Number**, the total number of rows to display in the console when the **print** function is called. Defaults to 10 | +| dtypeTestLim | **Number**, the total number of values to test when inferring data type. Defaults to 20 | +| lowMemoryMode |

Boolean, whether to use minimal memory space or not. Defaults to false.
Note: There's a slight decrease in speed when low memory mode is set to true.

| + +> See an example of creating DataFrame [in low memory mode](dataframe/creating-a-dataframe.md#creating-a-dataframe-and-specifying-memory-mode) + +## Examples of setting configs + +### Add a DataFrame header + +```javascript + const data = { + "Name": ["Apples", "Mango", "Banana", "Pear"], + "Count": [21, 5, 30, 10], + "Price": [200, 300, 40, 250] + }; +const df = new DataFrame(data, { + config: { + tableDisplayConfig: { + header: { + alignment: 'center', + content: 'THE HEADER\nThis is the table about something', + }, + }, + } +}); +df.print() +``` + +```javascript +╔════════════════════════════════════════════════════════════════════════╗ +║ THE HEADER ║ +║ This is the table about something ║ +╟────────────┬───────────────────┬───────────────────┬───────────────────╢ +║ │ Name │ Count │ Price ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Apples │ 21 │ 200 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ Mango │ 5 │ 300 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ Banana │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ Pear │ 10 │ 250 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +### Configure column size and display format of DataFrame + +```javascript +const data = { + "Name": ["Apples", "Mango", "Banana", "Pear"], + "Count": [21, 5, 30, 10], + "Price": [200, 300, 40, 250] +}; +const df = new DataFrame(data, { + config: { + tableDisplayConfig: { + header: { + alignment: 'center', + content: 'THE HEADER\nThis is the table about something', + }, + columns: [ + { alignment: 'left' }, + { alignment: 'center', width: 20 }, + { alignment: 'right' }, + { alignment: 'justify' } + ], + }, + } +}); +df.print() +``` + +```javascript +╔══════════════════════════════════════════╗ +║ THE HEADER ║ +║ This is the table about something ║ +╟───┬──────────────────────┬───────┬───────╢ +║ │ Name │ Count │ Price ║ +╟───┼──────────────────────┼───────┼───────╢ +║ 0 │ Apples │ 21 │ 200 ║ +╟───┼──────────────────────┼───────┼───────╢ +║ 1 │ Mango │ 5 │ 300 ║ +╟───┼──────────────────────┼───────┼───────╢ +║ 2 │ Banana │ 30 │ 40 ║ +╟───┼──────────────────────┼───────┼───────╢ +║ 3 │ Pear │ 10 │ 250 ║ +╚═══╧══════════════════════╧═══════╧═══════╝ +``` + +### Configure the number of rows displayed when **print** is called + +```javascript +const data = { + "Name": ["Apples", "Mango", "Banana", "Pear"], + "Count": [21, 5, 30, 10], + "Price": [200, 300, 40, 250], + +}; +const df = new DataFrame(data, { + config: { + tableMaxColInConsole: 6, + tableMaxRow: 1 + } +}); +df.print() +``` + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Count │ Price ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Apples │ 21 │ 200 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` diff --git a/api-reference/dataframe/README.md b/api-reference/dataframe/README.md index 4b14800..f1f7322 100644 --- a/api-reference/dataframe/README.md +++ b/api-reference/dataframe/README.md @@ -1,142 +1,139 @@ --- -description: 'Two-dimensional, size-mutable, potentially heterogeneous tabular data.' +description: Two-dimensional, size-mutable, potentially heterogeneous tabular data. --- # Dataframe -> [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame)\(data, {**columns:** \[ Array \], **dtypes:** \[ Array \], **index:** \[Array\]}\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L20)\] - ### Attributes -| [`DataFrame.index`](dataframe.index.md) | The index \(row labels\) of the DataFrame. | -| :--- | :--- | -| [`DataFrame.columns`](danfo.dataframe.column.md) | The column labels of the DataFrame. | +| [`DataFrame.index`](dataframe.index.md) | The index (row labels) of the DataFrame. | +| ------------------------------------------------ | ---------------------------------------- | +| [`DataFrame.columns`](danfo.dataframe.column.md) | The column labels of the DataFrame. | -| [`DataFrame.ctypes`](dataframe.dtypes.md) | Return the data types in the DataFrame. | -| :--- | :--- | -| [`DataFrame.select_dtypes`](dataframe.select_dtypes.md) | Return a subset of the DataFrame’s columns based on the column dtypes. | -| [`DataFrame.values`](dataframe.values.md) | Return a Numpy representation of the DataFrame. | -| [`DataFrame.axes`](dataframe.axes.md) | Return a Object representing the axes of the DataFrame. | -| [`DataFrame.ndim`](dataframe.ndim.md) | Return an int representing the number of axes / array dimensions. | -| [`DataFrame.size`](dataframe.size.md) | Return an int representing the number of elements in this object. | -| [`DataFrame.shape`](dataframe.shape.md) | Return a tuple representing the dimensionality of the DataFrame. | +| [`DataFrame.ctypes`](dataframe.dtypes.md) | | +| ----------------------------------------- | - | +| [`DataFrame.values`](dataframe.values.md) | | +| [`DataFrame.axis`](dataframe.axes.md) | | +| [`DataFrame.ndim`](dataframe.ndim.md) | | +| [`DataFrame.size`](broken-reference/) | | +| [`DataFrame.shape`](dataframe.shape.md) | | ### Conversion -| [`DataFrame.astype`](dataframe.astype.md) | Cast a pandas object to a specified dtype `dtype`. | -| :--- | :--- | -| [`DataFrame.copy`](danfo.dataframe.copy.md) | Make a copy of this object’s indices and data. | +| [`DataFrame.asType`](dataframe.astype.md) | Cast a pandas object to a specified dtype `dtype`. | +| ------------------------------------------- | -------------------------------------------------- | +| [`DataFrame.copy`](danfo.dataframe.copy.md) | Make a copy of this object’s indices and data. | ### Indexing, iteration -| [`DataFrame.head`](danfo.dataframe.head.md) | Return the first n rows | -| :--- | :--- | -| [`DataFrame.loc`](danfo.dataframe.loc.md) | Access a group of rows and columns by label\(s\) or a boolean array. | -| [`DataFrame.iloc`](danfo.dataframe.iloc.md) | Purely integer-location based indexing for selection by position. | -| [`DataFrame.tail`](danfo.dataframe.tail.md) | Return the last n rows. | -| [`DataFrame.query`](danfo.dataframe.query.md) | Query the columns of a DataFrame with a boolean expression. | +| [`DataFrame.head`](danfo.dataframe.head.md) | Return the first n rows | +| --------------------------------------------- | ------------------------------------------------------------------ | +| [`DataFrame.loc`](danfo.dataframe.loc.md) | Access a group of rows and columns by label(s) or a boolean array. | +| [`DataFrame.iloc`](danfo.dataframe.iloc.md) | Purely integer-location based indexing for selection by position. | +| [`DataFrame.tail`](danfo.dataframe.tail.md) | Return the last n rows. | +| [`DataFrame.query`](danfo.dataframe.query.md) | Query the columns of a DataFrame with a boolean expression. | ### Binary operator functions -| [`DataFrame.add`](danfo.dataframe.add.md) | Get Addition of dataframe and other, element-wise \(binary operator add\). | -| :--- | :--- | -| [`DataFrame.sub`](danfo.dataframe.sub.md) | Get Subtraction of dataframe and other, element-wise \(binary operator sub\). | -| [`DataFrame.mul`](danfo.dataframe.mul.md) | Get Multiplication of dataframe and other, element-wise \(binary operator mul\). | -| [`DataFrame.div`](danfo.dataframe.div.md) | Get Floating division of dataframe and other, element-wise \(binary operator truediv\). | -| [`DataFrame.mod`](danfo.dataframe.mod.md) | Get Modulo of dataframe and other, element-wise \(binary operator mod\). | -| [`DataFrame.pow`](danfo.dataframe.pow.md) | Get Exponential power of dataframe and other, element-wise \(binary operator pow\). | -| [`DataFrame.lt`]() | Get Less than of dataframe and other, element-wise \(binary operator lt\). | -| [`DataFrame.gt`](danfo.dataframe.gt.md) | Get Greater than of dataframe and other, element-wise \(binary operator gt\). | -| [`DataFrame.le`](danfo.dataframe.le.md) | Get Less than or equal to of dataframe and other, element-wise \(binary operator le\). | -| [`DataFrame.ge`]() | Get Greater than or equal to of dataframe and other, element-wise \(binary operator ge\). | -| [`DataFrame.ne`](danfo.dataframe.ne.md) | Get Not equal to of dataframe and other, element-wise \(binary operator ne\). | -| [`DataFrame.eq`](danfo.dataframe.eq.md) | Get Equal to of dataframe and other, element-wise \(binary operator eq\). | +| [`DataFrame.add`](danfo.dataframe.add.md) | Get Addition of dataframe and other, element-wise (binary operator add). | +| ----------------------------------------- | --------------------------------------------------------------------------------------- | +| [`DataFrame.sub`](danfo.dataframe.sub.md) | Get Subtraction of dataframe and other, element-wise (binary operator sub). | +| [`DataFrame.mul`](danfo.dataframe.mul.md) | Get Multiplication of dataframe and other, element-wise (binary operator mul). | +| [`DataFrame.div`](danfo.dataframe.div.md) | Get Floating division of dataframe and other, element-wise (binary operator truediv). | +| [`DataFrame.mod`](danfo.dataframe.mod.md) | Get Modulo of dataframe and other, element-wise (binary operator mod). | +| [`DataFrame.pow`](danfo.dataframe.pow.md) | Get Exponential power of dataframe and other, element-wise (binary operator pow). | +| [`DataFrame.lt`](broken-reference/) | Get Less than of dataframe and other, element-wise (binary operator lt). | +| [`DataFrame.gt`](danfo.dataframe.gt.md) | Get Greater than of dataframe and other, element-wise (binary operator gt). | +| [`DataFrame.le`](danfo.dataframe.le.md) | Get Less than or equal to of dataframe and other, element-wise (binary operator le). | +| [`DataFrame.ge`](broken-reference/) | Get Greater than or equal to of dataframe and other, element-wise (binary operator ge). | +| [`DataFrame.ne`](danfo.dataframe.ne.md) | Get Not equal to of dataframe and other, element-wise (binary operator ne). | +| [`DataFrame.eq`](danfo.dataframe.eq.md) | Get Equal to of dataframe and other, element-wise (binary operator eq). | ### Function application & GroupBy -| [`DataFrame.apply`](danfo.dataframe.apply.md) | Apply a function along an axis of the DataFrame. | -| :--- | :--- | -| [`DataFrame.groupby`](../groupby/) | Group DataFrame using a mapper or by a Series of columns. | -| [`DataFrame.map`](../series/series.map.md) | Map a function on Object along an axis to DataFrame | +| [`DataFrame.apply`](danfo.dataframe.apply.md) | Apply a function along an axis of the DataFrame. | +| --------------------------------------------- | --------------------------------------------------------- | +| [`DataFrame.groupby`](../groupby/) | Group DataFrame using a mapper or by a Series of columns. | +| [`DataFrame.map`](../series/series.map.md) | Map a function on Object along an axis to DataFrame | ### Computations / descriptive stats -| [`DataFrame.abs`](danfo.dataframe.abs.md) | Return a Series/DataFrame with absolute numeric value of each element. | -| :--- | :--- | -| [`DataFrame.corr`]() | Compute pairwise correlation of columns, excluding NA/null values. | -| [`DataFrame.count`](danfo.dataframe.count.md) | Count non-NAN cells for each column or row. | -| [`DataFrame.cummax`](danfo.dataframe.cummax.md) | Return cumulative maximum over a DataFrame or Series axis. | -| [`DataFrame.cummin`](danfo.dataframe.cummin.md) | Return cumulative minimum over a DataFrame or Series axis. | -| [`DataFrame.cumprod`](danfo.dataframe.cumprod.md) | Return cumulative product over a DataFrame or Series axis. | -| [`DataFrame.cumsum`](danfo.dataframe.cumsum.md) | Return cumulative sum over a DataFrame or Series axis. | -| [`DataFrame.describe`](danfo.dataframe.describe.md) | Generate descriptive statistics. | -| [`DataFrame.max`](danfo.dataframe.max.md) | Return the maximum of the values for the requested axis. | -| [`DataFrame.mean`](danfo.dataframe.mean.md) | Return the mean of the values for the requested axis. | -| [`DataFrame.median`](danfo.dataframe.median.md) | Return the median of the values for the requested axis. | -| [`DataFrame.min`](danfo.dataframe.min.md) | Return the minimum of the values for the requested axis. | -| [`DataFrame.mode`](../series/series.mode.md) | Get the mode\(s\) of each element along the selected axis. | -| [`DataFrame.round`](danfo.dataframe.round.md) | Round a DataFrame to a variable number of decimal places. | -| [`DataFrame.sum`](danfo.dataframe.sum.md) | Return the sum of the values for the requested axis. | -| [`DataFrame.std`](danfo.dataframe.std.md) | Return sample standard deviation over requested axis. | -| [`DataFrame.var`](danfo.dataframe.var.md) | Return unbiased variance over requested axis. | -| [`DataFrame.nunique`](dataframe.nunique.md) | Count distinct observations over requested axis. | +| [`DataFrame.abs`](danfo.dataframe.abs.md) | Return a Series/DataFrame with absolute numeric value of each element. | +| --------------------------------------------------- | ---------------------------------------------------------------------- | +| [`DataFrame.corr`](broken-reference/) | Compute pairwise correlation of columns, excluding NA/null values. | +| [`DataFrame.count`](danfo.dataframe.count.md) | Count non-NAN cells for each column or row. | +| [`DataFrame.cumMax`](danfo.dataframe.cummax.md) | Return cumulative maximum over a DataFrame or Series axis. | +| [`DataFrame.cumMin`](danfo.dataframe.cummin.md) | Return cumulative minimum over a DataFrame or Series axis. | +| [`DataFrame.cumProd`](danfo.dataframe.cumprod.md) | Return cumulative product over a DataFrame or Series axis. | +| [`DataFrame.cumSum`](danfo.dataframe.cumsum.md) | Return cumulative sum over a DataFrame or Series axis. | +| [`DataFrame.describe`](danfo.dataframe.describe.md) | Generate descriptive statistics. | +| [`DataFrame.max`](danfo.dataframe.max.md) | Return the maximum of the values for the requested axis. | +| [`DataFrame.mean`](danfo.dataframe.mean.md) | Return the mean of the values for the requested axis. | +| [`DataFrame.median`](danfo.dataframe.median.md) | Return the median of the values for the requested axis. | +| [`DataFrame.min`](danfo.dataframe.min.md) | Return the minimum of the values for the requested axis. | +| [`DataFrame.mode`](../series/series.mode.md) | Get the mode(s) of each element along the selected axis. | +| [`DataFrame.round`](danfo.dataframe.round.md) | Round a DataFrame to a variable number of decimal places. | +| [`DataFrame.sum`](danfo.dataframe.sum.md) | Return the sum of the values for the requested axis. | +| [`DataFrame.std`](danfo.dataframe.std.md) | Return sample standard deviation over requested axis. | +| [`DataFrame.var`](danfo.dataframe.var.md) | Return unbiased variance over requested axis. | +| [`DataFrame.nUnique`](broken-reference/) | Count distinct observations over requested axis. | ### Reindexing / selection / label manipulation -| | | -| :--- | :--- | -| [`DataFrame.drop`](dataframe.drop.md) | Drop specified labels from rows or columns. | -| [`DataFrame.head`](danfo.dataframe.head.md) | Return the first n rows. | -| [`DataFrame.rename`](dataframe.rename.md) | Alter axes labels. | -| [`DataFrame.reset_index`](dataframe.reset_index.md) | Reset the index of a DataFrame | -| [`DataFrame.sample`](danfo.dataframe.sample.md) | Return a random sample of items from an axis of object. | -| [`DataFrame.set_index`](dataframe.set_index.md) | Set the DataFrame index using existing columns. | -| [`DataFrame.tail`](danfo.dataframe.tail.md) | Return the last n rows. | +| | | +| --------------------------------------------------- | ------------------------------------------------------- | +| [`DataFrame.drop`](dataframe.drop.md) | Drop specified labels from rows or columns. | +| [`DataFrame.head`](danfo.dataframe.head.md) | Return the first n rows. | +| [`DataFrame.rename`](dataframe.rename.md) | Alter axes labels. | +| [`DataFrame.resetIndex`](dataframe.reset\_index.md) | Reset the index of a DataFrame | +| [`DataFrame.sample`](danfo.dataframe.sample.md) | Return a random sample of items from an axis of object. | +| [`DataFrame.setIndex`](dataframe.set\_index.md) | Set the DataFrame index using existing columns. | +| [`DataFrame.tail`](danfo.dataframe.tail.md) | Return the last n rows. | ### Missing data handling -| | | -| :--- | :--- | -| [`DataFrame.dropna`](danfo.dataframe.dropna.md) | Remove missing values. | -| [`DataFrame.fillna`](danfo.dataframe.fillna.md) | Fill NaN values with specified values | -| [`DataFrame.isna`](danfo.dataframe.isna.md) | Detect missing values. | +| | | +| ------------------------------------------------- | ------------------------------------------- | +| [`DataFrame.dropNa`](danfo.dataframe.dropna.md) | Remove missing values. | +| [`DataFrame.fillNa`](danfo.dataframe.fillna.md) | Fill NaN values with specified values | +| [`DataFrame.isNa`](danfo.dataframe.isna.md) | Detect missing values. | | [`DataFrame.replace`](danfo.dataframe.replace.md) | Replace values given in replace with value. | ### Sorting & transposing -| | | -| :--- | :--- | -| [`DataFrame.sort_values`](dataframe.sort_values.md) | Sort by the values along either axis. | -| [`DataFrame.T`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.T.html#pandas.DataFrame.T) | Return transpose of DataFrame | +| | | +| ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | +| [`DataFrame.sortVlues`](dataframe.sort\_values.md) | Sort by the values along either axis. | +| [`DataFrame.T`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.T.html#pandas.DataFrame.T) | Return transpose of DataFrame | ### Combining / comparing / joining / merging -| | | -| :--- | :--- | -| [`DataFrame.addColumn`](danfo.dataframe.addcolumn.md) | Add new columns to a DataFrame. | -| [`DataFrame.concat`](../general-functions/danfo.concat.md) | Concatenate DataFrames together. | -| [`DataFrame.merge`](../general-functions/danfo.merge.md) | Merge DataFrame or named Series objects with a database-style join. | +| | | +| ---------------------------------------------------------- | ------------------------------------------------------------------- | +| [`DataFrame.addColumn`](danfo.dataframe.addcolumn.md) | Add new columns to a DataFrame. | +| [`DataFrame.concat`](../general-functions/danfo.concat.md) | Concatenate DataFrames together. | +| [`DataFrame.merge`](../general-functions/danfo.merge.md) | Merge DataFrame or named Series objects with a database-style join. | ### Plotting `Series.plot` is both a callable method and a namespace attribute for specific plotting methods of the form `Series.plot.`. -| | | -| :--- | :--- | -| [DataFrame.plot.bar](../plotting/bar-charts.md) | Vertical bar plot. | -| [`DataFrame.plot.box`](../plotting/box-plots.md) | Make a box plot of the DataFrame columns. | -| [`DataFrame.plot.violin`](../plotting/box-plots.md) | Make a violin plot of the DataFrame columns. | -| [`DataFrame.plot.hist`](../plotting/histograms.md) | Draw one histogram of the DataFrame’s columns. | +| | | +| -------------------------------------------------------- | ------------------------------------------------------------- | +| [DataFrame.plot.bar](../plotting/bar-charts.md) | Vertical bar plot. | +| [`DataFrame.plot.box`](../plotting/box-plots.md) | Make a box plot of the DataFrame columns. | +| [`DataFrame.plot.violin`](../plotting/box-plots.md) | Make a violin plot of the DataFrame columns. | +| [`DataFrame.plot.hist`](../plotting/histograms.md) | Draw one histogram of the DataFrame’s columns. | | [`DataFrame.plot.scatter`](../plotting/scatter-plots.md) | Generate Kernel Density Estimate plot using Gaussian kernels. | -| [`DataFrame.plot.line`](../plotting/line-charts.md) | Plot Series or DataFrame as lines. | -| [`DataFrame.plot.pie`](../plotting/pie-charts.md) | Generate a pie plot. | -| [`Timeseries Plots`](../plotting/timeseries-plots.md) | Time series plots | -| [`Table`](../plotting/tables.md) | Display Series as Interactive table in Div | +| [`DataFrame.plot.line`](../plotting/line-charts.md) | Plot Series or DataFrame as lines. | +| [`DataFrame.plot.pie`](../plotting/pie-charts.md) | Generate a pie plot. | +| [`Timeseries Plots`](../plotting/timeseries-plots.md) | Time series plots | +| [`Table`](../plotting/tables.md) | Display Series as Interactive table in Div | ### Serialization / IO / conversion -| | | -| :--- | :--- | -| [`DataFrame.to_csv`](dataframe.to_csv.md) | Write object to a comma-separated values \(csv\) file. | -| [`DataFrame.to_json`](dataframe.to_json.md) | Convert the object to a JSON string. | - +| | | +| ------------------------------------------------------------- | -------------------------------- | +| [`DataFrame.toCSV`](dataframe.to\_csv.md) | Convert DataFrame to a CSV file. | +| [`DataFrame.toJSON`](dataframe.to\_json.md) | Convert the object to a JSON. | +| ``[`DataFrame.toExcel`](../input-output/danfo.to\_excel.md)`` | Convert DataFrame to Excel file | diff --git a/api-reference/dataframe/creating-a-dataframe.md b/api-reference/dataframe/creating-a-dataframe.md new file mode 100644 index 0000000..b19e5f9 --- /dev/null +++ b/api-reference/dataframe/creating-a-dataframe.md @@ -0,0 +1,318 @@ +--- +description: Creates a DataFrame object from flat structure +--- + +# Creating a DataFrame + +danfo.**DataFrame**(data, options) + +| Parameters | Type | Description | +| ---------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| data | 2D Array, 2D Tensor, JSON object. | Flat data structure to load into DataFrame | +| options | Object |

Optional configuration object. Supported properties are:

index: Array of numeric or string names for subseting array. If not specified, indexes are auto-generated.

columns: Array of column names. If not specified, column names are auto generated.

dtypes: Array of data types for each the column. If not specified, dtypes are/is inferred.

config: General configuration object for extending or setting NDframe behavior. See full options here

| + +In order to create a DataFrame, you need to call the new Keyword and pass in a flat data structure. In the following examples, we show you how to create DataFrames by specifying different config options. + +### Creating a `DataFrame` from a JSON object: + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + + +json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 }, + { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 }, + { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 }, + { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }] + +df = new dfd.DataFrame(json_data) +df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +```markup + + + + + + + + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} + +### Creating a `DataFrame` from an array of array + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let arr = [[12, 34, 2.2, 2], [30, 30, 2.1, 7]] +let df = new dfd.DataFrame(arr, {columns: ["A", "B", "C", "D"]}) +df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +```markup + + + + + + + + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C │ D ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 12 │ 34 │ 2.2 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 30 │ 30 │ 2.1 │ 7 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +### Creating a `DataFrame` from a 2D tensor + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") +const tf = dfd.tensorflow + +let tensor_arr = tf.tensor2d([[12, 34, 2.2, 2], [30, 30, 2.1, 7]]) +let df = new dfd.DataFrame(tensor_arr, {columns: ["A", "B", "C", "D"]}) +df.print() +df.ctypes.print() +``` +{% endtab %} + +{% tab title="Browser" %} +```markup + + + + + + + + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} + +``` +╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C │ D ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 12 │ 34 │ 2.20000004768... │ 2 ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 30 │ 30 │ 2.09999990463... │ 7 ║ +╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔═══╤══════════════════════╗ +║ │ 0 ║ +╟───┼──────────────────────╢ +║ A │ int32 ║ +╟───┼──────────────────────╢ +║ B │ int32 ║ +╟───┼──────────────────────╢ +║ C │ float32 ║ +╟───┼──────────────────────╢ +║ D │ int32 ║ +╚═══╧══════════════════════╝ +``` + +### Creating a `DataFrame` from an object + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + + +dates = new dfd.dateRange({ start: '2017-01-01', end: "2020-01-01", period: 4, freq: "Y" }) + +console.log(dates); + +obj_data = {'A': dates, + 'B': ["bval1", "bval2", "bval3", "bval4"], + 'C': [10, 20, 30, 40], + 'D': [1.2, 3.45, 60.1, 45], + 'E': ["test", "train", "test", "train"] + } + +df = new dfd.DataFrame(obj_data) +df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +```markup + + + + + + + + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} + +``` +//output in console +╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C │ D │ E ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1/1/2017, 1:0... │ bval1 │ 10 │ 1.2 │ test ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1/1/2018, 1:0... │ bval2 │ 20 │ 3.45 │ train ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 1/1/2019, 1:0... │ bval3 │ 30 │ 60.1 │ test ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 1/1/2020, 1:0... │ bval4 │ 40 │ 45 │ train ║ +╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +### Creating a `DataFrame` and specifying index, dtypes, columns + +You can create a DataFrame and specify options like index, column names, dtypes as well as configuration options like display, memory mode etc. + +> Note: Specifing dtypes, column names and index on DataFrame creation makes the process slightly faster. + +{% tabs %} +{% tab title="Node" %} +```javascript +import { DataFrame } from "danfojs" + +let data1 = [[1, 2.3, 3, 4, 5, "girl"], [30, 40.1, 39, 89, 78, "boy"]]; +let index = ["a", "b"]; +let columns = ["col1", "col2", "col3", "col4", "col5", "col6"] +let dtypes = ["int32", "float32", "int32", "int32", "int32", "string"] + +let df = new DataFrame(data1, { index, columns, dtypes }); +df.print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ col1 │ col2 │ col3 │ col4 │ col5 │ col6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ a │ 1 │ 2.3 │ 3 │ 4 │ 5 │ girl ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ b │ 30 │ 40.1 │ 39 │ 89 │ 78 │ boy ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +### Creating a `DataFrame` and specifying memory mode + +To use less space on DataFrame creation, you can set the low memory mode as demonstrated below: + +```javascript +import { DataFrame } from "danfojs" + +let data1 = [[1, 2.3, 3, 4, 5, "girl"], [30, 40.1, 39, 89, 78, "boy"]]; + +let df = new DataFrame(data1, { + config: { lowMemoryMode: true } +}); +df.print() +``` + +{% hint style="info" %} +**Note**: In low memory mode, less space is used by the DataFrame. The drawback is that some operations especially the ones involving column data become slightly slower. +{% endhint %} + +For loading flat files like CSV, EXCEL and, JSON into DataFrames, see this [page](../input-output/) diff --git a/api-reference/dataframe/danfo.dataframe.abs.md b/api-reference/dataframe/danfo.dataframe.abs.md index 291487e..bac894a 100644 --- a/api-reference/dataframe/danfo.dataframe.abs.md +++ b/api-reference/dataframe/danfo.dataframe.abs.md @@ -4,11 +4,11 @@ description: Return a DataFrame with the absolute numeric value of each element. # DataFrame.abs -danfo.DataFrame.**abs**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L973)\] +danfo.DataFrame.**sum**(options) -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ------ | -------------------------------------------------------------------------------------------------- | ------------------ | +| options | Object | **inplace:** Boolean indicating whether to perform the operation inplace or not. Defaults to false | { inplace: false } | ## **Examples** @@ -33,14 +33,13 @@ df_abs.abs().print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -69,4 +68,3 @@ df_abs.abs().print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.add.md b/api-reference/dataframe/danfo.dataframe.add.md index 3277882..3ee1719 100644 --- a/api-reference/dataframe/danfo.dataframe.add.md +++ b/api-reference/dataframe/danfo.dataframe.add.md @@ -1,31 +1,29 @@ --- -description: 'Get Addition of DataFrame and other, element-wise (binary operator add).' +description: Get Addition of DataFrame and other, element-wise (binary operator add). --- # DataFrame.add -danfo.DataFrame.**add**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L347)\] +danfo.DataFrame.**add**(other, option) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array or Scalar | Object to modulo with | | -| axis | Int | 0 for row, 1 for column | 0 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | | +| ---------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | - | +| other | DataFrame, Series, Array or Scalar | Object to add with | | | +| option | Object |

{

axis: 0 for row, 1 for column.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

|

{

axis: 1,

inplace: false

}

| | ## **Examples** -### Addition of **scalar to** DataFrame: +### Addition of **scalar to** DataFrame along default axis 1 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - {"Col2": [23, 20, 10, 24]} +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} let df = new dfd.DataFrame(data) let df_new = df.add(2) @@ -36,14 +34,13 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -59,21 +56,22 @@ df_new.print() {% endtab %} {% endtabs %} -### Addition of **Series to** DataFrame along the column axis: +### Addition of **Series to** DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") +let data = { + "Col1": [1, 4, 5, 1], + "Col2": [3, 2, 0, 4] +} -let data = { "Col1": [1, 4, 5, 1], - "Col2": [3, 2, 0, 4] } - let df = new dfd.DataFrame(data) let sf = new dfd.Series([4, 5]) -let df_new = df.add(sf, axis = 1) +let df_new = df.add(sf, { axis: 1 }) df_new.print() ``` @@ -81,14 +79,13 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -104,7 +101,7 @@ df_new.print() {% endtab %} {% endtabs %} -### Addition of ****DataFrame to a DataFrame +### Addition of DataFrame to a DataFrame {% tabs %} {% tab title="Node" %} @@ -123,20 +120,18 @@ let df2 = new dfd.DataFrame(data2) let df_new = df.add(df2) df_new.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -152,20 +147,22 @@ df_new.print() {% endtab %} {% endtabs %} -### Addition of ****JavaScript Array to DataFrame +### Addition of Array to DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} - +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} + let df = new dfd.DataFrame(data) -let val = [2,2] +let val = [2, 2, 2, 2] -let df_new = df.add(val, axis=1) +let df_new = df.add(val, { axis: 0 }) df_new.print() ``` @@ -173,28 +170,69 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 12 │ 25 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 47 │ 22 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 58 │ 12 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 12 │ 26 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 12 │ 25 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 47 │ 22 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 58 │ 12 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 12 │ 26 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} +### Addition works inplace +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} + +let df = new dfd.DataFrame(data) +let val = [2, 2, 2, 2] + +df.add(val, { axis: 0, inplace: true }) + +df.print() +``` +{% endtab %} +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 12 │ 25 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 47 │ 22 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 58 │ 12 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 12 │ 26 ║ +╚════════════╧═══════════════════╧═══════════════════╝ +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/danfo.dataframe.addcolumn.md b/api-reference/dataframe/danfo.dataframe.addcolumn.md index 3bf3252..422cd9c 100644 --- a/api-reference/dataframe/danfo.dataframe.addcolumn.md +++ b/api-reference/dataframe/danfo.dataframe.addcolumn.md @@ -4,69 +4,52 @@ description: Add new column to a DataFrame # DataFrame.addColumn -danfo.DataFrame.**addColumn**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1083)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{column : str, name of the column to add

-

value: Series, Array. New values to add }

-
+danfo.DataFrame.**addColumn**(column**,** values**,** options) -**Returns:** +| Parameters | Type | Description | Default | +| ----------- | ------------------ | ------------------------------------------------------------- | ----------------- | +| **column** | String | Name of the column to add. | | +| **values** | Series**,** Array | New values to add | | +| **options** | Object | **inplace**: Whether to perform the operation inplace or not. | Default to false. | - ****return **Null** +**Returns:** ## **Examples** ## **Add Array as a new column to DataFrame** -New columns get added at the end of the DataFrame, and this happens so returns nothing, +New columns get added at the end of the DataFrame. {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"A": [30, 1, 2, 3], - "B": [34, 4, 5, 6], - "C": [20, 20, 30, 40]} + +let data = { + "A": [30, 1, 2, 3], + "B": [34, 4, 5, 6], + "C": [20, 20, 30, 40] +} let df = new dfd.DataFrame(data) df.print() let new_col = [1, 2, 3, 4] -df.addColumn({ "column": "D", "value": new_col }); +df.addColumn("D", new_col, { inplace: true }); df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -79,9 +62,6 @@ df.print() ║ 3 │ 3 │ 6 │ 40 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - - Shape: (4,3) - ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -103,30 +83,32 @@ df.print() {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"A": [30, 1, 2, 3], - "B": [34, 4, 5, 6], - "C": [20, 20, 30, 40]} + +let data = { + "A": [30, 1, 2, 3], + "B": [34, 4, 5, 6], + "C": [20, 20, 30, 40] +} let df = new dfd.DataFrame(data) +df.print() + let s = new dfd.Series([1, 2, 3, 4]) -df.addColumn({ "column": "D", "value": s }); +df.addColumn("D", s, { inplace: true }); df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -141,4 +123,3 @@ df.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.apply.md b/api-reference/dataframe/danfo.dataframe.apply.md index 2812b5c..15ab9fc 100644 --- a/api-reference/dataframe/danfo.dataframe.apply.md +++ b/api-reference/dataframe/danfo.dataframe.apply.md @@ -1,49 +1,23 @@ --- -description: >- - Apply a function to each element or along a specified axis of a DataFrame. - Supports JavaScipt functions when axis is not specified, and accepts - Tensorflow functions when axis is specified. +description: Apply a function to each element or along a specified axis of a DataFrame. --- # DataFrame.apply -danfo.DataFrame.**apply**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1566)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{callable: Function to call on each element,

-

axis: undefined: if undefined, then any JavaScript function

-

is accepted and will be applied element-wise.

-

0: Apply along row/index axis

-

1: Apply across columns axis

-

}

-
undefined
- -**Returns:** - - ****return **DataFrame** +danfo.DataFrame.**apply**(callable, options) + +| Parameters | Type | Description | Default | +| ---------- | -------- | --------------------------------------------------------------------- | --------- | +| callable | Function | Function to apply to each column or row | | +| options | Object | **axis**: 0 or 1. If 0, compute the power column-wise, if 1, row-wise | {axis: 1} | ## **Examples** -### Apply a JavaScript function to all elements in DataFrame +### Apply a function along default axis 1 (columns) -The **apply** function calls a JavaScript function on every element of the DataFrame when the axis is not specified. +{% hint style="info" %} +Note that the specified function passed to `apply` will be called with an array of the values across the specified axis. +{% endhint %} {% tabs %} {% tab title="Node" %} @@ -54,88 +28,38 @@ let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]] let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -function sum_vals(x) { - return x + 20 +function sum_vals(col) { + return col.reduce((a, b) => a + b, 0); } -let df_new = df.apply({callable: sum_vals }) +let df_new = df.apply(sum_vals, { axis: 1 }) df_new.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 21 │ 22 │ 23 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 24 │ 25 │ 26 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 40 │ 50 │ 60 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 59 │ 109 │ 98 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` -{% endtab %} -{% endtabs %} - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - -let data = [{ short_name: ["NG", "GH", "EGY", "SA"] }, - { long_name: ["Nigeria", "Ghana", "Eqypt", "South Africa"] }] -let df = new dfd.DataFrame(data) - -function lower(x) { - return `${x}`.toLowerCase() -} - -let df_new = df.apply({ callable: lower }) -df_new.print() - - -``` -{% endtab %} - -{% tab title="Browser" %} ``` - +╔═══╤═════╗ +║ 0 │ 6 ║ +╟───┼─────╢ +║ 1 │ 15 ║ +╟───┼─────╢ +║ 2 │ 90 ║ +╟───┼─────╢ +║ 3 │ 206 ║ +╚═══╧═════╝ ``` {% endtab %} {% endtabs %} -{% tabs %} -{% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ short_name │ long_name ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ ng │ nigeria ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ gh │ ghana ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ egy │ eqypt ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ sa │ south africa ║ -╚═══╧═══════════════════╧═══════════════════╝ -``` -{% endtab %} -{% endtabs %} - -### Apply [Tensorflow](https://js.tensorflow.org/api/latest/) function element-wise - -You can call any compatible [Tensorflow](https://js.tensorflow.org/api/latest/) function on a DataFrame across a specified axis. For functions that operate _**element-wise**_ and returns the same shape as the original DataFrame, you must specify an axis of 0. +### Apply a function along axis 0 (row) {% tabs %} {% tab title="Node" %} @@ -146,81 +70,31 @@ let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]] let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -function sum_vals(x) { - return x.logSigmoid() +function sum_vals(col) { + return col.reduce((a, b) => a + b, 0); } -let df_new = df.apply({axis: 0, callable: sum_vals }) +let df_new = df.apply(sum_vals, { axis: 0 }) df_new.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ -0.3132616579... │ -0.1269280463... │ -0.0485873296... ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ -0.0181499607... │ -0.0067153489... │ -0.0024756519... ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ -2.0611536921... │ -9.3576229122... │ -4.2483541311... ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ -1.1548223864... │ -2.2273639090... │ -1.3336148713... ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` -{% endtab %} -{% endtabs %} - -### Apply [Tensorflow](https://js.tensorflow.org/api/latest/) function along column axis - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - -let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]] -let cols = ["A", "B", "C"] -let df = new dfd.DataFrame(data, { columns: cols }) - -function sum_vals(x) { - return x.sum() -} - -let df_new = df.apply({axis: 1, callable: sum_vals }) -df_new.print() -``` -{% endtab %} - -{% tab title="Browser" %} ``` - +╔═══╤═════╗ +║ A │ 64 ║ +╟───┼─────╢ +║ B │ 126 ║ +╟───┼─────╢ +║ C │ 127 ║ +╚═══╧═════╝ ``` {% endtab %} {% endtabs %} - -{% tabs %} -{% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ A │ 64 ║ -╟───┼──────────────────────╢ -║ B │ 126 ║ -╟───┼──────────────────────╢ -║ C │ 127 ║ -╚═══╧══════════════════════╝ -``` -{% endtab %} -{% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.column.md b/api-reference/dataframe/danfo.dataframe.column.md index a937fc6..61eccba 100644 --- a/api-reference/dataframe/danfo.dataframe.column.md +++ b/api-reference/dataframe/danfo.dataframe.column.md @@ -1,18 +1,14 @@ --- -description: Return the elements of the specified column in the DataFrame +description: Return the elements of the specified column as a Series --- # DataFrame.column -danfo.DataFrame.**column**\(col\_name\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1217)\] +danfo.DataFrame.**column**(column) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| col\_name | Str | The name of a column in the DataFrame | | - -**Returns:** - - ****return **Series** +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------------------------------- | ------- | +| column | String | The name of a column in the DataFrame | | ## **Examples** @@ -32,46 +28,39 @@ df.column("Name").print() //Alternatively, you can retrieve columns by using the object property df['Name'].print() //produces the same result as above - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ Name ║ -╟───┼──────────────────────╢ -║ 0 │ Apples ║ -╟───┼──────────────────────╢ -║ 1 │ Mango ║ -╟───┼──────────────────────╢ -║ 2 │ Banana ║ -╟───┼──────────────────────╢ -║ 3 │ NaN ║ -╚═══╧══════════════════════╝ - -╔═══╤══════════════════════╗ -║ │ Name ║ -╟───┼──────────────────────╢ -║ 0 │ Apples ║ -╟───┼──────────────────────╢ -║ 1 │ Mango ║ -╟───┼──────────────────────╢ -║ 2 │ Banana ║ -╟───┼──────────────────────╢ -║ 3 │ NaN ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════════╗ +║ 0 │ Apples ║ +╟───┼───────────╢ +║ 1 │ App ║ +╟───┼───────────╢ +║ 2 │ Banana ║ +╟───┼───────────╢ +║ 3 │ undefined ║ +╚═══╧═══════════╝ + +╔═══╤═══════════╗ +║ 0 │ Apples ║ +╟───┼───────────╢ +║ 1 │ App ║ +╟───┼───────────╢ +║ 2 │ Banana ║ +╟───┼───────────╢ +║ 3 │ undefined ║ +╚═══╧═══════════╝ ``` {% endtab %} {% endtabs %} To select more than one column with specific rows, you can use any of the following: [DataFrame.loc](danfo.dataframe.loc.md), [DataFrame.iloc](danfo.dataframe.iloc.md) or [DataFrame.query](danfo.dataframe.query.md) - diff --git a/api-reference/dataframe/danfo.dataframe.copy.md b/api-reference/dataframe/danfo.dataframe.copy.md index d149d12..1920e8d 100644 --- a/api-reference/dataframe/danfo.dataframe.copy.md +++ b/api-reference/dataframe/danfo.dataframe.copy.md @@ -1,14 +1,10 @@ --- -description: Makes a new copy of the DataFrame +description: Makes a deep copy of the DataFrame --- # DataFrame.copy -danfo.DataFrame.**copy**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L940)\] - -**Returns:** - - ****return **new DataFrame** +danfo.DataFrame.**copy**() ## **Examples** @@ -27,15 +23,13 @@ new_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -47,10 +41,6 @@ new_df.print() ╟───┼───────────────────┼───────────────────┼───────────────────╢ ║ 3 │ -20 │ 6 │ -40 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - ``` {% endtab %} {% endtabs %} - - - diff --git a/api-reference/dataframe/danfo.dataframe.count.md b/api-reference/dataframe/danfo.dataframe.count.md index 23c6948..6bd35e2 100644 --- a/api-reference/dataframe/danfo.dataframe.count.md +++ b/api-reference/dataframe/danfo.dataframe.count.md @@ -6,19 +6,15 @@ description: >- # DataFrame.count -danfo.DataFrame.**count**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L587)\] +danfo.DataFrame.**count**(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| axis | Int | 0 for row and 1 for columns | 1 | - -**Returns:** - - ****return **Series** +| Parameters | Type | Description | Default | +| ---------- | ------ | ----------------------------------------------------------------------------------- | ----------- | +| options | Object | **axis:** 0 or 1. If 0, compute the mean column-wise, if 1, row-wise. Defaults to 1 | { axis: 1 } | ## **Examples** -## Count Non-NaN values along default axis 1 \(column\) +## Count Non-NaN values along default axis 1 (column) {% tabs %} {% tab title="Node" %} @@ -36,28 +32,27 @@ df.count().print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══════╤══════════════════════╗ -║ │ 0 ║ -╟───────┼──────────────────────╢ -║ Name │ 3 ║ -╟───────┼──────────────────────╢ -║ Count │ 2 ║ -╟───────┼──────────────────────╢ -║ Price │ 4 ║ -╚═══════╧══════════════════════╝ +``` +╔═══╤═══╗ +║ 0 │ 2 ║ +╟───┼───╢ +║ 1 │ 3 ║ +╟───┼───╢ +║ 2 │ 2 ║ +╟───┼───╢ +║ 3 │ 2 ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} -## Count Non-NaN values along row axis \(0\) +## Count Non-NaN values along row axis (0) {% tabs %} {% tab title="Node" %} @@ -66,39 +61,31 @@ const dfd = require("danfojs-node") let data = { "Name": ["Apples", "Mango", "Banana", undefined], "Count": [NaN, 5, NaN, 10], - "Price": [200, 300, 40, 250] }] + "Price": [200, 300, 40, 250] } let df = new dfd.DataFrame(data) -df.count({axis: 0).print() +df.count({axis: 0}).print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 2 ║ -╟───┼──────────────────────╢ -║ 1 │ 3 ║ -╟───┼──────────────────────╢ -║ 2 │ 2 ║ -╟───┼──────────────────────╢ -║ 3 │ 2 ║ -╚═══╧══════════════════════╝ +``` +╔═══════╤═══╗ +║ Name │ 3 ║ +╟───────┼───╢ +║ Count │ 2 ║ +╟───────┼───╢ +║ Price │ 4 ║ +╚═══════╧═══╝ ``` {% endtab %} {% endtabs %} -## - - - +## diff --git a/api-reference/dataframe/danfo.dataframe.cummax.md b/api-reference/dataframe/danfo.dataframe.cummax.md index 561b794..a04bb20 100644 --- a/api-reference/dataframe/danfo.dataframe.cummax.md +++ b/api-reference/dataframe/danfo.dataframe.cummax.md @@ -2,32 +2,32 @@ description: Return cumulative maximum over a DataFrame or Series axis. --- -# DataFrame.cummax +# DataFrame.cumMax -danfo.DataFrame.**cummax**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L739)\] +danfo.DataFrame.cumMax(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs | Object | {**axis**: 0 for row and 1 for column} | {axis: 1} | +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------- | +| options | Object |

axis: 0 for row and 1 for column

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

| {axis: 1, inplace: false} | **Returns:** - ****return **DataFrame** +\*\*\*\* return **DataFrame** ## **Examples** -## Cumulative maximum of elements along default axis \(row\) +## Cumulative maximum of elements along axis (row) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -let new_df = df.cummax({ axis: 0 }) +let new_df = df.cumMax({ axis: 0 }) new_df.print() ``` @@ -35,14 +35,13 @@ new_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -58,18 +57,18 @@ new_df.print() {% endtab %} {% endtabs %} -## Cumulative maximum of elements along column axis \(1\) +## Cumulative maximum of elements along column axis (1) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -let new_df = df.cummax({ axis: 1 }) +let new_df = df.cumMax({ axis: 1 }) new_df.print() ``` @@ -77,14 +76,13 @@ new_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -99,4 +97,3 @@ new_df.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.cummin.md b/api-reference/dataframe/danfo.dataframe.cummin.md index 69b6dea..4cd3d05 100644 --- a/api-reference/dataframe/danfo.dataframe.cummin.md +++ b/api-reference/dataframe/danfo.dataframe.cummin.md @@ -2,32 +2,28 @@ description: Return cumulative minimum over a DataFrame or Series axis. --- -# DataFrame.cummin +# DataFrame.cumMin -danfo.DataFrame.**cummin**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L717)\] +danfo.DataFrame.**cumMin**(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs | Object | {**axis**: 0 for row and 1 for column} | {axis: 1} | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------- | +| options | Object |

axis: 0 for row and 1 for column

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

| {axis: 1, inplace: false} | ## **Examples** -## Cumulative minimum of elements along default axis \(row\) +## Cumulative minimum of elements along axis 0 (row) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -let new_df = df.cummin({ axis: 0 }) +let new_df = df.cumMin({ axis: 0 }) new_df.print() ``` @@ -35,14 +31,13 @@ new_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -58,18 +53,18 @@ new_df.print() {% endtab %} {% endtabs %} -## Cumulative minimum of elements along column axis \(1\) +## Cumulative minimum of elements along column axis (1) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -let new_df = df.cummin({ axis: 1 }) +let new_df = df.cumMin({ axis: 1 }) new_df.print() ``` @@ -77,14 +72,13 @@ new_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -99,4 +93,3 @@ new_df.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.cumprod.md b/api-reference/dataframe/danfo.dataframe.cumprod.md index 60fab0d..5dba3cf 100644 --- a/api-reference/dataframe/danfo.dataframe.cumprod.md +++ b/api-reference/dataframe/danfo.dataframe.cumprod.md @@ -2,32 +2,28 @@ description: Return cumulative product over a DataFrame or Series axis. --- -# DataFrame.cumprod +# DataFrame.cumProd -danfo.DataFrame.**cumprod**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L739)\] +danfo.DataFrame.**cumProd**(options) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L706)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs | Object | {**axis**: 0 for row and 1 for column} | {axis: 1} | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------- | +| options | Object |

axis: 0 for row and 1 for column

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

| {axis: 1, inplace: false} | ## **Examples** -## Cumulative product of elements along default axis \(row\) +## Cumulative product of elements along default axis 1 (column) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[1, 2, 3], [1, 5, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -let new_df = df.cumprod() +let new_df = df.cumProd() new_df.print() ``` @@ -35,41 +31,40 @@ new_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 2 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 1 │ 10 │ 18 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 2 │ 300 │ 720 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 4 │ 26700 │ 56160 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 11 │ 220 │ 660 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 15 │ 90 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 2 │ 60 │ 2400 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 2 │ 178 │ 13884 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -## Cumulative product of elements along column axis \(1\) +## Cumulative product of elements along column axis (1) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[1, 2, 3], [1, 5, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -let new_df = df.cumprod({axis: 1}) +let new_df = df.cumProd({ axis: 1 }) new_df.print() ``` @@ -77,26 +72,24 @@ new_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 2 │ 6 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 1 │ 5 │ 30 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 2 │ 60 │ 2400 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 2 │ 178 │ 13884 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 11 │ 220 │ 660 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 15 │ 90 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 2 │ 60 │ 2400 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 2 │ 178 │ 13884 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.cumsum.md b/api-reference/dataframe/danfo.dataframe.cumsum.md index b1e91f1..ce997aa 100644 --- a/api-reference/dataframe/danfo.dataframe.cumsum.md +++ b/api-reference/dataframe/danfo.dataframe.cumsum.md @@ -2,32 +2,28 @@ description: Return cumulative sum over a DataFrame or Series axis. --- -# DataFrame.cumsum +# DataFrame.cumSum -danfo.DataFrame.**cumsum**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L706)\] +danfo.DataFrame.cumSum(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs | Object | {**axis**: 0 for row and 1 for column} | {axis: 1} | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------- | +| options | Object |

axis: 0 for row and 1 for column

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

| {axis: 1, inplace: false} | ## **Examples** -## Cumulative sum of elements along default axis \(row\) +## Cumulative sum of elements along default axis (row) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -let new_df = df.cumsum({ axis: 0 }) +let new_df = df.cumSum({ axis: 0 }) new_df.print() ``` @@ -35,14 +31,13 @@ new_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -58,7 +53,7 @@ new_df.print() {% endtab %} {% endtabs %} -## Cumulative sum of elements along column axis \(1\) +## Cumulative sum of elements along column axis (1) {% tabs %} {% tab title="Node" %} @@ -69,7 +64,7 @@ data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -let new_df = df.cumsum({ axis: 1 }) +let new_df = df.cumSum({ axis: 1 }) new_df.print() ``` @@ -77,14 +72,13 @@ new_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -99,4 +93,3 @@ new_df.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.describe.md b/api-reference/dataframe/danfo.dataframe.describe.md index 7c5b2c1..2bff123 100644 --- a/api-reference/dataframe/danfo.dataframe.describe.md +++ b/api-reference/dataframe/danfo.dataframe.describe.md @@ -6,20 +6,17 @@ description: >- # DataFrame.describe -danfo.DataFrame.**describe**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L821)\] - -**Returns:** - - ****return **DataFrame** +danfo.DataFrame.**describe**() ## **Examples** -Descriptive statistics include those that summarize the central tendency, dispersion and shape of a dataset’s distribution, excluding `NaN` values. +Descriptive statistics include those that summarize the central tendency, dispersion and shape of a dataset’s distribution, excluding `NaN` values. {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") + let data = [[0, 2, 4, "a"], [360, 180, 360, "b"], [2, 4, 6, "c"]] let col_names = ["col1", "col2", "col3", "col4"] let df = new dfd.DataFrame(data, {columns: col_names}) @@ -30,34 +27,32 @@ df.describe().print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔══════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ col1 │ col2 │ col3 ║ -╟──────────┼───────────────────┼───────────────────┼───────────────────╢ -║ count │ 3 │ 3 │ 3 ║ -╟──────────┼───────────────────┼───────────────────┼───────────────────╢ -║ mean │ 120.666664 │ 62 │ 123.333336 ║ -╟──────────┼───────────────────┼───────────────────┼───────────────────╢ -║ std │ 207.271159 │ 102.19589 │ 204.961785 ║ -╟──────────┼───────────────────┼───────────────────┼───────────────────╢ -║ min │ 0 │ 2 │ 4 ║ -╟──────────┼───────────────────┼───────────────────┼───────────────────╢ -║ median │ 2 │ 4 │ 6 ║ -╟──────────┼───────────────────┼───────────────────┼───────────────────╢ -║ max │ 360 │ 180 │ 360 ║ -╟──────────┼───────────────────┼───────────────────┼───────────────────╢ -║ variance │ 42961.333333 │ 10444 │ 42009.333333 ║ -╚══════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ col1 │ col2 │ col3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ count │ 3 │ 3 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ mean │ 120.66666666666… │ 62 │ 123.33333333333… ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ std │ 207.27115895206… │ 102.19589032832… │ 204.961785055979 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ min │ 0 │ 2 │ 4 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ median │ 2 │ 4 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ max │ 360 │ 180 │ 360 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ variance │ 42961.333333333… │ 10444 │ 42009.333333333… ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -## - +## diff --git a/api-reference/dataframe/danfo.dataframe.diff.md b/api-reference/dataframe/danfo.dataframe.diff.md new file mode 100644 index 0000000..3b15c8a --- /dev/null +++ b/api-reference/dataframe/danfo.dataframe.diff.md @@ -0,0 +1,313 @@ +--- +description: >- + Get difference between a dataframe and other. Accepts DataFrame, Series, number[] and number. +--- + +# DataFrame.diff + +danfo.DataFrame.diff(other, option) + +| Parameters | Type | Description | Default | +| ---------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------- | +| other | DataFrame, Series, Array or Scalar | Object to calculate difference with | | +| option | Object |

{

axis: 0 for column, 1 for row (default).

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| { axis: 1, inplace: false } | + +## **Examples** + +### Difference with **previous row** of current DataFrame along default axis 1 + +{% tabs %} +{% tab title="Node" %} + +```javascript +import * as dfd from "danfojs"; + +const data = [ + [0, 2, 4], + [10, 10, 10], + [1, 2, 3], +]; + +const df = new dfd.DataFrame(data); + +const df_new = df.diff(1); + +df_new.print(); +``` + +{% endtab %} + +{% tab title="Browser" %} + +```html + + + + + + + + + + + + +``` + +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 │ Col3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ NaN │ NaN │ NaN ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 10 │ 8 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ -9 │ -8 │ -7 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` + +{% endtab %} +{% endtabs %} + +### Difference with **following row** of current DataFrame along default axis 1 + +{% tabs %} +{% tab title="Node" %} + +```javascript +import * as dfd from "danfojs"; + +const data = [ + [0, 2, 4], + [10, 10, 10], + [1, 2, 3], +]; + +const df = new dfd.DataFrame(data); + +const df_new = df.diff(-1); + +df_new.print(); +``` + +{% endtab %} + +{% tab title="Browser" %} + +```html + + + + + + + + + + + + +``` + +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 │ Col3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ -10 │ -8 │ -6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 10 │ 8 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ NaN │ NaN │ NaN ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` + +{% endtab %} +{% endtabs %} + +### Difference with **Series** and DataFrame along axis 1 + +{% tabs %} +{% tab title="Node" %} + +```javascript +import * as dfd from "danfojs"; + +const data = [ + [0, 2, 4], + [10, 10, 10], + [1, 2, 3], +]; + +const df = new dfd.DataFrame(data); + +const sf = new dfd.Series([1, 2, 1]); + +const df_new = df.diff(sf); + +df_new.print(); +``` + +{% endtab %} + +{% tab title="Browser" %} + +```html + + + + + + + + + + + + +``` + +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 │ Col3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ -1 │ 0 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 9 │ 8 │ 9 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 0 │ 0 │ 2 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` + +{% endtab %} +{% endtabs %} + +### Difference between DataFrame and **another** DataFrame + +{% tabs %} +{% tab title="Node" %} + +```javascript +import * as dfd from "danfojs"; + +const data = [ + [0, 2, 4], + [3, 10, 4], +]; + +const original_df = new dfd.DataFrame(data); + +const comparison_df = new dfd.DataFrame([ + [-1, -2, 4], + [10, 5, 0], +]); + +const df_new = original_df.diff(comparison_df); + +df_new.print(); +``` + +{% endtab %} + +{% tab title="Browser" %} + +```html + + + + + + + + + + + + +``` + +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 │ Col3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 4 │ 0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ -7 │ 5 │ 4 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` + +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/danfo.dataframe.div.md b/api-reference/dataframe/danfo.dataframe.div.md index e6977b7..64929e0 100644 --- a/api-reference/dataframe/danfo.dataframe.div.md +++ b/api-reference/dataframe/danfo.dataframe.div.md @@ -1,34 +1,29 @@ --- -description: >- - Get Float division of DataFrame and other, element-wise (binary operator - truediv). +description: Get division of DataFrame and other, element-wise --- # DataFrame.div -danfo.DataFrame.**div**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L401)\] +danfo.DataFrame.div(other, option) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array or Scalar | Object to modulo with | | -| axis | Int | 0 for row, 1 for column | 0 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- | +| other | DataFrame, Series, Array or Scalar | Object to divide with | | +| option | Object |

{

axis: 0 for row, 1 for column.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| { axis: 1, inplace: false } | ## **Examples** -### Division of ****DataFrame with a scalar value: +### Division of **scalar with** DataFrame along default axis 1 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} - +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} let df = new dfd.DataFrame(data) let df_new = df.div(2) @@ -39,44 +34,44 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 5 │ 11.5 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 22.5 │ 10 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 28 │ 5 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 5 │ 12 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 5 │ 11.5 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 22.5 │ 10 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 28 │ 5 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 5 │ 12 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -### Division of ****DataFrame with a Series along the column axis: +### Division of **Series with** DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") +let data = { + "Col1": [1, 4, 5, 1], + "Col2": [3, 2, 0, 4] +} -let data = { "Col1": [1, 4, 5, 1], - "Col2": [3, 2, 0, 4] } - let df = new dfd.DataFrame(data) let sf = new dfd.Series([4, 5]) -let df_new = df.div(sf, axis = 1) +let df_new = df.div(sf, { axis: 1 }) df_new.print() ``` @@ -84,38 +79,37 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 0.25 │ 0.60000002384... ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 1 │ 0.40000000596... ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 1.25 │ 0 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 0.25 │ 0.80000001192... ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 0.25 │ 0.6000000238418… ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 0.4000000059604… ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 1.25 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 0.25 │ 0.8000000119209… ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -### Division of ****DataFrame with a DataFrame +### Division of DataFrame **with** another DataFrame {% tabs %} {% tab title="Node" %} ```javascript -const dfd = require("danfojs-node") +const dfd = require("danfojs") -let data = {"Col1": [1, 4, 5, 0], +let data = {"Col1": [1, 4, 5, 0], "Col2": [2, 0, 1, 4]} let data2 = {"new_col1": [1, 5, 20, 10], @@ -127,49 +121,50 @@ let df2 = new dfd.DataFrame(data2) let df_new = df.div(df2) df_new.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 0.10000000149... ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 0.80000001192... │ 0 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 0.25 │ 1 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 0 │ 2 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 0.1000000014901… ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 0.8000000119209… │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 0.25 │ 1 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 0 │ 2 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + ``` {% endtab %} {% endtabs %} -### Division of ****DataFrame with a JavaScript Array +### Division of Array **with** DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} - +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} + let df = new dfd.DataFrame(data) -let val = [2,2] +let val = [2, 2, 2, 2] -let df_new = df.div(val, axis=1) +let df_new = df.div(val, { axis: 0 }) df_new.print() ``` @@ -177,28 +172,70 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 5 │ 11.5 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 22.5 │ 10 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 28 │ 5 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 5 │ 12 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 5 │ 11.5 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 22.5 │ 10 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 28 │ 5 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 5 │ 12 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} +### Division works inplace +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} + +let df = new dfd.DataFrame(data) +let val = [2, 2, 2, 2] + +df.div(val, { axis: 0, inplace: true }) + +df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 5 │ 11.5 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 22.5 │ 10 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 28 │ 5 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 5 │ 12 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/danfo.dataframe.dropna.md b/api-reference/dataframe/danfo.dataframe.dropna.md index 08bc41e..85a3c42 100644 --- a/api-reference/dataframe/danfo.dataframe.dropna.md +++ b/api-reference/dataframe/danfo.dataframe.dropna.md @@ -1,122 +1,116 @@ --- -description: 'Remove missing values (NaNs, undefined) for DataFrame' +description: Remove missing values (NaNs, undefined, null) for DataFrame --- -# DataFrame.dropna - -danfo.DataFrame.**dropna**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1430)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{axis: 0: Apply along row/index axis

-

1: Apply across columns axis

-

inplace:If true, perform operation inplace

-

and return None.

-

}

-
-

{axis: 0,

-

inplace: false}

-
- -**Returns:** - - ****return **DataFrame** +# DataFrame.dropNa + +danfo.DataFrame.**dropNa**(axis, options) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1430)] + +| Parameters | Type | Description | Default | +| ---------- | ------ | -------------------------------------------------------------------------------------------------- | -------------------- | +| axis | Int | 0 or 1. If 0, drop columns with NaNs, if 1, drop rows with NaNs | 1 | +| options | Object | **inplace**: Boolean indicating whether to perform the operation inplace or not. Defaults to false | {**inplace:** false} | ## **Examples** -### Drop rows \(axis=0\) with missing values +### Drop rows (axis=0) with missing values {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, undefined, 78]] +let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, NaN, 78]] let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) df.print() -let df_drop = df.dropna({axis: 0}) +let df_drop = df.dropNa({ axis: 0 }) df_drop.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 2 │ 3 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 2 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ NaN │ 5 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ NaN │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 39 │ NaN │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╗ +║ │ C ║ +╟────────────┼───────────────────╢ +║ 0 │ 3 ║ +╟────────────┼───────────────────╢ +║ 1 │ 6 ║ +╟────────────┼───────────────────╢ +║ 2 │ 40 ║ +╟────────────┼───────────────────╢ +║ 3 │ 78 ║ +╚════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -### Drop columns \(axis=1\) with missing values +### Drop columns (axis=1) with missing values {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, undefined, 78]] +let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, NaN, 78]] let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) df.print() -df.dropna({axis: 1, inplace: true}) +df.dropNa({ axis: 1, inplace: true }) df.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╗ -║ │ C ║ -╟───┼───────────────────╢ -║ 0 │ 3 ║ -╟───┼───────────────────╢ -║ 1 │ 6 ║ -╟───┼───────────────────╢ -║ 2 │ 40 ║ -╟───┼───────────────────╢ -║ 3 │ 78 ║ -╚═══╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 2 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ NaN │ 5 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ NaN │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 39 │ NaN │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 2 │ 3 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.eq.md b/api-reference/dataframe/danfo.dataframe.eq.md index 957c7a5..4fdbc19 100644 --- a/api-reference/dataframe/danfo.dataframe.eq.md +++ b/api-reference/dataframe/danfo.dataframe.eq.md @@ -1,23 +1,23 @@ --- -description: 'Get Equal to of DataFrame and other, element-wise (binary operator eq).' +description: Get Equal to of DataFrame and other, element-wise (binary operator eq). --- # DataFrame.eq -danfo.DataFrame.**eq**\(other, axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L718)\] +danfo.DataFrame.eq(other, option) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | -| axis | Int | Whether to compare by the index \(0\) or columns \(1\). | 0 | +| Parameters | Type | Description | Default | +| ---------- | -------------------------------- | ----------------------------------------------------------- | --------- | +| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | +| option | Object | **axis**: 0 or 1. If 0, add column-wise, if 1, add row-wise | {axis: 1} | **Returns:** - ****return **DataFrame** +*** ## **Examples** -### Comparing ****DataFrame with a scalar value: +### Comparing a DataFrame with a scalar value: {% tabs %} {% tab title="Node" %} @@ -36,14 +36,13 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -59,7 +58,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a Series along the column axis: +### Comparing a DataFrame with a Series along the column axis: {% tabs %} {% tab title="Node" %} @@ -71,17 +70,15 @@ let data = {"Col1": [10, 45, 56, 10], let df = new dfd.DataFrame(data) let sf = new dfd.Series([10,40]) -let df_rep = df.eq(sf, axis=1) +let df_rep = df.eq(sf, {axis:1}) df_rep.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} @@ -104,7 +101,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a DataFrame +### Comparing a DataFrame with a DataFrame {% tabs %} {% tab title="Node" %} @@ -127,7 +124,6 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} @@ -150,7 +146,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a JavaScript Array +### Comparing a DataFrame with a JavaScript Array {% tabs %} {% tab title="Node" %} @@ -162,7 +158,7 @@ let data = {"Col1": [10, 45, 56, 10], let df = new dfd.DataFrame(data) let val = [10,40] -let df_rep = df.eq(val, axis=1) +let df_rep = df.eq(val, {axis:1}) df_rep.print() ``` @@ -170,7 +166,6 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} @@ -192,4 +187,3 @@ df_rep.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.fillna.md b/api-reference/dataframe/danfo.dataframe.fillna.md index f019e6e..8279d2e 100644 --- a/api-reference/dataframe/danfo.dataframe.fillna.md +++ b/api-reference/dataframe/danfo.dataframe.fillna.md @@ -4,133 +4,106 @@ description: >- for an array-like object. --- -# DataFrame.fillna - -danfo.DataFrame.**fillna**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1235)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{columns:Array of column name(s) to fill. If undefined fill all - columns

-

values: Array | Scalar of value(s) to fill with.

-

inplace: boolean. true | false. Whether to perform operation to - the original Object or create a new one.

-

}

-
- -**Returns:** - - ****return **DataFrame** +# DataFrame.fillNa + +danfo.DataFrame.fillNa(values, options) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1235)] + +| Parameters | Type | Description | Default | +| ---------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | +| values | Array \| Scalar | The list of value(s) to use for replacement. | | +| options | Object |

{columns:Array of column name(s) to fill. If undefined fill all columns

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| {inplace: false} | ## **Examples** -### Fill NaNs in specified columns with specified values +### Fill missing values in specified columns with specified values + +Missing values are NaN, undefined or null values {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Name":["Apples", "Mango", "Banana", undefined], - "Count": [NaN, 5, NaN, 10], - "Price": [200, 300, 40, 250]} - +let data = { + "Name": ["Apples", "Mango", "Banana", undefined], + "Count": [NaN, 5, NaN, 10], + "Price": [200, 300, 40, 250] +} + let df = new dfd.DataFrame(data) df.print() -let df_filled = df.fillna({columns: ["Name", "Count"], values: ["Apples", df["Count"].mean()]}) +let values = ["Apples", df["Count"].mean()] +let df_filled = df.fillNa(values, { columns: ["Name", "Count"] }) df_filled.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -//Before filling -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ Name │ Count │ Price ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ Apples │ NaN │ 200 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ Mango │ 5 │ 300 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ Banana │ NaN │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ NaN │ 10 │ 250 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - //After filling - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ Name │ Count │ Price ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ Apples │ 7.5 │ 200 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ Mango │ 5 │ 300 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ Banana │ 7.5 │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ Apples │ 10 │ 250 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝═╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Count │ Price ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Apples │ NaN │ 200 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ Mango │ 5 │ 300 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ Banana │ NaN │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ undefined │ 10 │ 250 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Count │ Price ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Apples │ 7.5 │ 200 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ Mango │ 5 │ 300 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ Banana │ 7.5 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ Apples │ 10 │ 250 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -### Fill all columns with NaNs with a specified value +### Fill all columns with NaNs with a specified value {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Name":["Apples", "Mango", "Banana", undefined], - "Count": [NaN, 5, NaN, 10], - "Price": [200, 300, 40, 250]} +let data = { + "Name": ["Apples", "Mango", "Banana", undefined], + "Count": [NaN, 5, NaN, 10], + "Price": [200, 300, 40, 250] +} let df = new dfd.DataFrame(data) -let df_filled = df.fillna({ values: ["Apples"] }) +let df_filled = df.fillNa("Apples") df_filled.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -146,13 +119,12 @@ df_filled.print() {% endtab %} {% endtabs %} -### Fill NaNs inplace +### Fill NaNs inplace {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") - let data = { "Name": ["Apples", "Mango", "Banana", undefined], "Count": [NaN, 5, NaN, 10], @@ -160,9 +132,9 @@ let data = { } let df = new dfd.DataFrame(data) -df.fillna({ +let values = ["Apples", df["Count"].mean()] +df.fillNa(values, { columns: ["Name", "Count"], - values: ["Apples", df["Count"].mean()], inplace: true }) df.print() @@ -171,15 +143,13 @@ df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -194,4 +164,3 @@ df.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.ge.md b/api-reference/dataframe/danfo.dataframe.ge.md index bc1efbc..40a4316 100644 --- a/api-reference/dataframe/danfo.dataframe.ge.md +++ b/api-reference/dataframe/danfo.dataframe.ge.md @@ -6,20 +6,16 @@ description: >- # DataFrame.ge -danfo.DataFrame.**ge**\(other, axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1616)\] +danfo.DataFrame.ge(other, option) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | -| axis | Int | Whether to compare by the index \(0\) or columns \(1\). | 0 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | -------------------------------- | ----------------------------------------------------------- | --------- | +| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | +| option | Object | **axis**: 0 or 1. If 0, add column-wise, if 1, add row-wise | {axis: 1} | ## **Examples** -### Comparing ****DataFrame with a scalar value: +### Comparing a DataFrame with a scalar value: {% tabs %} {% tab title="Node" %} @@ -39,14 +35,13 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -62,7 +57,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a Series along the column axis: +### Comparing a DataFrame with a Series along the column axis: {% tabs %} {% tab title="Node" %} @@ -75,17 +70,15 @@ let data = {"Col1": [10, 45, 56, 10], let df = new dfd.DataFrame(data) let sf = new dfd.Series([10,40]) -let df_rep = df.ge(sf, axis=1) +let df_rep = df.ge(sf, {axis:1}) df_rep.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} @@ -108,7 +101,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a DataFrame +### Comparing a DataFrame with a DataFrame {% tabs %} {% tab title="Node" %} @@ -126,13 +119,11 @@ let df2 = new dfd.DataFrame(data2) let df_rep = df.ge(df2) df_rep.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} @@ -155,7 +146,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a JavaScript Array +### Comparing a DataFrame with a JavaScript Array {% tabs %} {% tab title="Node" %} @@ -167,7 +158,7 @@ let data = {"Col1": [10, 45, 56, 10], let df = new dfd.DataFrame(data) let val = [10,40] -let df_rep = df.ge(val, axis=1) +let df_rep = df.ge(val, {axis:1}) df_rep.print() ``` @@ -175,7 +166,6 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} @@ -197,4 +187,3 @@ df_rep.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.groupby.md b/api-reference/dataframe/danfo.dataframe.groupby.md index 5f187bd..30f4721 100644 --- a/api-reference/dataframe/danfo.dataframe.groupby.md +++ b/api-reference/dataframe/danfo.dataframe.groupby.md @@ -4,69 +4,128 @@ description: Group DataFrame using a mapper or by a Series of columns. # DataFrame.groupby -danfo.DataFrame.**groupby**\(columns\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1142)\] +danfo.DataFrame.**groupby**(columns) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| columns | Array | The names of a column\(s\) in the DataFrame to group by | | - -**Returns:** - - ****return **DataFrame.groups** +| Parameters | Type | Description | Default | +| ---------- | ----- | ----------------------------------------------------- | ------- | +| columns | Array | The names of a column(s) in the DataFrame to group by | | ## **Examples** -## **Select a single column from a DataFrame** +## **Groupby a single column from a DataFrame** {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]] + +let data = [["Pear", 2, 3], ["Pear", 5, 6], ["Apple", 30, 40], ["Apple", 89, 78]] let cols = ["A", "B", "C"] -let df = new DataFrame(data, { columns: cols }) -let group_df = df.groupby(["A"]); -group_df.col_dict +let df = new dfd.DataFrame(data, { columns: cols }) +let group_df = df.groupby(["A"]) +console.log(group_df) +``` + +``` +// ouput +Groupby { + colDict: { + Pear: { A: [Array], B: [Array], C: [Array] }, + Apple: { A: [Array], B: [Array], C: [Array] } + }, + keyToValue: { Pear: [ 'Pear' ], Apple: [ 'Apple' ] }, + keyCol: [ 'A' ], + data: [ + [ 'Pear', 2, 3 ], + [ 'Pear', 5, 6 ], + [ 'Apple', 30, 40 ], + [ 'Apple', 89, 78 ] + ], + columnName: [ 'A', 'B', 'C' ], + colDtype: [ 'string' ], + colIndex: [ 0 ] +} ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} +A groupby operation will return a GroupBy class object. You can apply any of the following operation on the groupby result: + +1. [count](danfo.dataframe.count.md) +2. [sum](danfo.dataframe.sum.md) +3. [std](danfo.dataframe.std.md) +4. [var](danfo.dataframe.var.md) +5. [mean](danfo.dataframe.mean.md) +6. [cumSum](danfo.dataframe.cumsum.md) +7. [cumMax](danfo.dataframe.cummax.md) +8. [cumProd](danfo.dataframe.cumprod.md) +9. [cumMin](danfo.dataframe.cummin.md) +10. [max](danfo.dataframe.max.md) +11. [min](danfo.dataframe.min.md) + +## Example of Groupby and apply a sum function + {% tabs %} -{% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ Name ║ -╟───┼──────────────────────╢ -║ 0 │ Apples ║ -╟───┼──────────────────────╢ -║ 1 │ Mango ║ -╟───┼──────────────────────╢ -║ 2 │ Banana ║ -╟───┼──────────────────────╢ -║ 3 │ NaN ║ -╚═══╧══════════════════════╝ - -╔═══╤══════════════════════╗ -║ │ Name ║ -╟───┼──────────────────────╢ -║ 0 │ Apples ║ -╟───┼──────────────────────╢ -║ 1 │ Mango ║ -╟───┼──────────────────────╢ -║ 2 │ Banana ║ -╟───┼──────────────────────╢ -║ 3 │ NaN ║ -╚═══╧══════════════════════╝ +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = [["Pear", 2, 3], ["Pear", 5, 6], ["Apple", 30, 40], ["Apple", 89, 78]] +let cols = ["A", "B", "C"] +let df = new dfd.DataFrame(data, { columns: cols }) +let group_df = df.groupby(["A"]).sum() + +group_df.print() ``` {% endtab %} {% endtabs %} -To select more than one column with specific rows, you can use any of the following: [DataFrame.loc](danfo.dataframe.loc.md), [DataFrame.iloc](danfo.dataframe.iloc.md) or [DataFrame.query](danfo.dataframe.query.md) +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B_sum │ C_sum ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Pear │ 7 │ 9 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ Apple │ 119 │ 118 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +## **Groupby a two columns from a DataFrame** +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = [["Pear", 2, 3], ["Pear", 2, 6], ["Apple", 30, 40], ["Apple", 89, 78]] +let cols = ["A", "B", "C"] +let df = new dfd.DataFrame(data, { columns: cols }) +let group_df = df.groupby(["A", "B"]).sum() + +group_df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C_sum ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Pear │ 2 │ 9 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ Apple │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ Apple │ 89 │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` diff --git a/api-reference/dataframe/danfo.dataframe.gt.md b/api-reference/dataframe/danfo.dataframe.gt.md index 7243088..f27ae72 100644 --- a/api-reference/dataframe/danfo.dataframe.gt.md +++ b/api-reference/dataframe/danfo.dataframe.gt.md @@ -1,23 +1,19 @@ --- -description: 'Get Greater than of DataFrame and other, element-wise (binary operator eq).' +description: Get Greater than of DataFrame and other, element-wise (binary operator eq). --- # DataFrame.gt -danfo.DataFrame.**gt**\(other, axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1583)\] +danfo.DataFrame.g**t**(other, option) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | -| axis | Int | Whether to compare by the index \(0\) or columns \(1\). | 0 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | -------------------------------- | ----------------------------------------------------------- | --------- | +| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | +| option | Object | **axis**: 0 or 1. If 0, add column-wise, if 1, add row-wise | {axis: 1} | ## **Examples** -### Comparing ****DataFrame with a scalar value: +### Comparing a DataFrame with a scalar value {% tabs %} {% tab title="Node" %} @@ -36,14 +32,13 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -59,7 +54,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a Series along the column axis: +### Comparing a DataFrame with a Series along the column axis: {% tabs %} {% tab title="Node" %} @@ -71,24 +66,22 @@ let data = {"Col1": [10, 45, 56, 10], let df = new dfd.DataFrame(data) let sf = new dfd.Series([10,40]) -let df_rep = df.gt(sf, axis=1) +let df_rep = df.gt(sf, {axis:1}) df_rep.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -104,7 +97,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a DataFrame +### Comparing a DataFrame with another DataFrame {% tabs %} {% tab title="Node" %} @@ -122,20 +115,18 @@ let df2 = new dfd.DataFrame(data2) let df_rep = df.gt(df2) df_rep.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -151,19 +142,21 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a JavaScript Array +### Comparing a DataFrame with a JavaScript Array {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} -let df = new dfd.DataFrame(data) -let val = [10,40] -let df_rep = df.gt(val, axis=1) +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} +let df = new dfd.DataFrame(data) +let val = [10, 40] +let df_rep = df.gt(val, { axis: 1 }) df_rep.print() ``` @@ -171,14 +164,13 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -193,4 +185,3 @@ df_rep.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.head.md b/api-reference/dataframe/danfo.dataframe.head.md index 3fec50c..31c72c0 100644 --- a/api-reference/dataframe/danfo.dataframe.head.md +++ b/api-reference/dataframe/danfo.dataframe.head.md @@ -4,15 +4,11 @@ description: Returns the first n rows of the DataFrame based on position. # DataFrame.head -danfo.DataFrame.**head**\(rows\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L292)\] +danfo.DataFrame.**head**(rows) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| rows | Int | The number of rows to return | 5 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ---- | ---------------------------- | ------- | +| rows | Int | The number of rows to return | 5 | ## **Examples** @@ -28,20 +24,18 @@ let data = { "Name": ["Apples", "Mango", "Banana", "Pear"], let df = new dfd.DataFrame(data) let s_df = df.head(2) s_df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -52,4 +46,3 @@ s_df.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.iloc.md b/api-reference/dataframe/danfo.dataframe.iloc.md index 714537a..9cd794c 100644 --- a/api-reference/dataframe/danfo.dataframe.iloc.md +++ b/api-reference/dataframe/danfo.dataframe.iloc.md @@ -4,45 +4,22 @@ description: Purely integer-location based indexing for selection by position. # DataFrame.iloc -danfo.DataFrame.**iloc**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L254)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{

-

rows: Array, index of row position

-

columns: Array, index of position along columns

-

}

-
- -**Returns:** - - ****return **DataFrame** +danfo.DataFrame.**iloc**(args) + +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | +| args | Object |

{

rows: Array, index of row position

columns: Array, index of position along columns

}

| | ## **Examples** -`.iloc()` is primarily integer position based \(from `0` to `length-1` of the axis\). +`.iloc()` is primarily integer position based (from `0` to `length-1` of the axis). Allowed inputs are: * An integer, e.g. `5`. * A list or array of integers, e.g. `[4, 3, 0]`. * A string slice object with ints, e.g. `"1:7"` +* A boolean array. _**Note:** only the start index is included._ @@ -69,14 +46,13 @@ sub_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -92,7 +68,7 @@ sub_df.print() ### **Index by a slice of row and return all columns** -The [**iloc**](danfo.dataframe.iloc.md) function also accepts string slices of the form \[start: end\], e.g "\[1: 4\]". This will return all values between index position 1 and 3. The end index is not included. +The [**iloc**](danfo.dataframe.iloc.md) function also accepts string slices of the form \[start: end], e.g "\[1: 3]". This will return all values between index position 1 and 3. The end index is not included. {% tabs %} {% tab title="Node" %} @@ -111,14 +87,13 @@ sub_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -146,20 +121,18 @@ df.print() let sub_df = df.iloc({columns: ["1:"]}) sub_df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -190,7 +163,7 @@ sub_df.print() {% endtab %} {% endtabs %} -### Indexing both axes by the specified index +### Indexing both axis by the specified index {% tabs %} {% tab title="Node" %} @@ -209,15 +182,13 @@ sub_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -231,7 +202,7 @@ sub_df.print() ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - //after slice + //after indexing ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Count │ Price ║ @@ -244,7 +215,7 @@ sub_df.print() {% endtab %} {% endtabs %} -### Indexing both axes by slices +### Indexing both axis by slices {% tabs %} {% tab title="Node" %} @@ -260,20 +231,18 @@ df.print() let sub_df = df.iloc({rows: ["2:3"], columns: ["1:2"]}) sub_df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -287,8 +256,6 @@ sub_df.print() ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - Shape: (1,1) - ╔═══╤═══════════════════╗ ║ │ Count ║ ╟───┼───────────────────╢ @@ -298,7 +265,7 @@ sub_df.print() {% endtab %} {% endtabs %} -### More default slicing behaviour +### More default slicing behavior If you specify a slice start position, **iloc** automatically returns all values after that position. For instance: @@ -316,20 +283,18 @@ df.print() let sub_df = df.iloc({rows: ["2:"], columns: ["1:"]}) sub_df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -355,6 +320,3 @@ sub_df.print() ``` {% endtab %} {% endtabs %} - - - diff --git a/api-reference/dataframe/danfo.dataframe.isna.md b/api-reference/dataframe/danfo.dataframe.isna.md index 5e8e811..34b3f8c 100644 --- a/api-reference/dataframe/danfo.dataframe.isna.md +++ b/api-reference/dataframe/danfo.dataframe.isna.md @@ -1,17 +1,13 @@ --- description: >- - Return a boolean same-sized object indicating if the values are NaN. - NaN/undefined values gets mapped to true values, and everything else gets - mapped to false values. + Return a boolean same-sized object indicating if the values are missing. NaN. + null and undefined values get mapped to true, and everything else gets mapped + to false. --- -# DataFrame.isna +# DataFrame.isNa -danfo.DataFrame.**isna**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1350)\] - -**Returns:** - - ****return **DataFrame** +danfo.DataFrame.**isNa**(kwargs) ## **Examples** @@ -24,21 +20,19 @@ let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, undefined, 78]] let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -df.isna().print() - +df.isNa().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -53,4 +47,3 @@ df.isna().print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.it.md b/api-reference/dataframe/danfo.dataframe.it.md index 7dbc6eb..86ba58a 100644 --- a/api-reference/dataframe/danfo.dataframe.it.md +++ b/api-reference/dataframe/danfo.dataframe.it.md @@ -1,23 +1,19 @@ --- -description: 'Get Less than of DataFrame and other, element-wise (binary operator eq).' +description: Get Less than of DataFrame and other, element-wise (binary operator eq). --- # DataFrame.It -danfo.DataFrame.l**t**\(other, axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1566)\] +danfo.DataFrame.l**t**(other, option) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | -| axis | Int | Whether to compare by the index \(0\) or columns \(1\). | 0 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | -------------------------------- | ----------------------------------------------------------- | --------- | +| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | +| option | Object | **axis**: 0 or 1. If 0, add column-wise, if 1, add row-wise | {axis: 1} | ## **Examples** -### Comparing ****DataFrame with a scalar value: +### Comparing a DataFrame with a scalar value: {% tabs %} {% tab title="Node" %} @@ -36,14 +32,13 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -59,36 +54,36 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a Series along the column axis: +### Comparing a DataFrame with a Series along the column axis: {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} let df = new dfd.DataFrame(data) -let sf = new dfd.Series([10,40]) +let sf = new dfd.Series([10, 40]) -let df_rep = df.lt(sf, axis=1) +let df_rep = df.lt(sf, { axis: 1 }) df_rep.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -104,7 +99,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a DataFrame +### Comparing a DataFrame with another DataFrame {% tabs %} {% tab title="Node" %} @@ -122,20 +117,18 @@ let df2 = new dfd.DataFrame(data2) let df_rep = df.lt(df2) df_rep.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -151,20 +144,21 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a JavaScript Array +### Comparing a DataFrame with an Array {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} - +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} let df = new dfd.DataFrame(data) -let val = [10,40] +let val = [10, 40] -let df_rep = df.lt(val, axis=1) +let df_rep = df.lt(val, { axis: 1 }) df_rep.print() ``` @@ -172,14 +166,13 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -194,4 +187,3 @@ df_rep.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.le.md b/api-reference/dataframe/danfo.dataframe.le.md index b6e33b9..559fecd 100644 --- a/api-reference/dataframe/danfo.dataframe.le.md +++ b/api-reference/dataframe/danfo.dataframe.le.md @@ -6,20 +6,16 @@ description: >- # DataFrame.le -danfo.DataFrame.le\(other, axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L718)\] +danfo.DataFrame.le(other, option) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | -| axis | Int | Whether to compare by the index \(0\) or columns \(1\). | 0 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | -------------------------------- | ----------------------------------------------------------- | --------- | +| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | +| option | Object | **axis**: 0 or 1. If 0, add column-wise, if 1, add row-wise | {axis: 1} | ## **Examples** -### Comparing ****DataFrame with a scalar value: +### Comparing a DataFrame with a scalar value: {% tabs %} {% tab title="Node" %} @@ -39,14 +35,13 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -62,7 +57,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a Series along the column axis: +### Comparing a DataFrame with a Series along the column axis: {% tabs %} {% tab title="Node" %} @@ -75,24 +70,22 @@ let data = {"Col1": [10, 45, 56, 10], let df = new dfd.DataFrame(data) let sf = new dfd.Series([10,40]) -let df_rep = df.le(sf, axis=1) +let df_rep = df.le(sf, {axis:1}) df_rep.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -108,7 +101,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a DataFrame +### Comparing a DataFrame with another DataFrame {% tabs %} {% tab title="Node" %} @@ -131,7 +124,6 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} @@ -154,7 +146,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a JavaScript Array +### Comparing a DataFrame with an Array {% tabs %} {% tab title="Node" %} @@ -166,7 +158,7 @@ let data = {"Col1": [10, 45, 56, 10], let df = new dfd.DataFrame(data) let val = [10,40] -let df_rep = df.le(val, axis=1) +let df_rep = df.le(val, {axis:1}) df_rep.print() ``` @@ -174,7 +166,6 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} @@ -196,4 +187,3 @@ df_rep.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.loc.md b/api-reference/dataframe/danfo.dataframe.loc.md index f5fd6bf..5fa3188 100644 --- a/api-reference/dataframe/danfo.dataframe.loc.md +++ b/api-reference/dataframe/danfo.dataframe.loc.md @@ -4,44 +4,26 @@ description: Access a group of rows and columns by label(s) # DataFrame.loc -danfo.DataFrame.**loc**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{

-

rows: Array, labels of row index

-

columns: Array, labels of column names

-

}

-
- -**Returns:** - - ****return **DataFrame** +danfo.DataFrame.**loc**(args) + +| Parameters | Type | Description | Default | +| ---------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | +| args | Object |

{

rows: Array, labels, Boolean mask of row index

columns: Array, labels of column names

}

| | ## **Examples** -`.loc()` is primarily label based, but row index also accepts numeric slices +`.loc()` is label position based-from `0` to `length-1` of the row axis. + +Allowed inputs for are: + +* An integer, e.g. `"r1"`. +* A list or array of integers, e.g. `["a", "b", "d"]`. +* A boolean mask. E.g \[ true, false, false ] +* A string slice object with ints, e.g. `[`'`"a":"d"'], ["1:4"]` -Allowed inputs are: +_**Note:** only \*\*\*\* the start label is included, and the end label is ignored._ -* A single label, e.g. `5` or `'a'`, \(note that `5` is interpreted as a _label_ of the index, and **not** as an integer position along the index\). -* A list or array of labels, e.g. `['a', 'b', 'c']`. +`.loc` will raise a `ValueEror` if a requested label is not found. ### **Index by specific rows and return all columns** @@ -65,15 +47,13 @@ sub_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -120,14 +100,13 @@ sub_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -141,7 +120,7 @@ sub_df.print() ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - //after slicing + //after indexing ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Count │ Price ║ @@ -178,15 +157,13 @@ sub_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -213,5 +190,169 @@ sub_df.print() {% endtab %} {% endtabs %} +## **Index by a slice of row** + +The **loc** function also accepts string slices of the form \[start: end], e.g **\[\`"a":"c"\`]**. This will return all values from label positions `a` to c. + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = { "Name": ["Apples", "Mango", "Banana", "Pear"], + "Count": [21, 5, 30, 10], + "Price": [200, 300, 40, 250] } + +let df = new dfd.DataFrame(data, { index: ["a", "b", "c", "d"] }) +df.print() +let sub_df = df.loc({ rows: [`"a":"c"`], columns: ["Name", "Price"] }) +sub_df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Count │ Price ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ a │ Apples │ 21 │ 200 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ b │ Mango │ 5 │ 300 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ c │ Banana │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ d │ Pear │ 10 │ 250 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Price ║ +╟────────────┼───────────────────┼───────────────────╢ +║ a │ Apples │ 200 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ b │ Mango │ 300 ║ +╚════════════╧═══════════════════╧═══════════════════╝ +``` +{% endtab %} +{% endtabs %} + +{% hint style="info" %} +Note that when using loc with alphabetic slices. We expect you to pass labels in the correct format. That is, string labels must be explicitly quoted. For example, the following loc slice will throw an error:\ +df`.loc({ row: ["a:e"]}).print()`\ +For the slice above to work, you must quote each slice, e.g:\ +df``.loc({ row: [`"a":"e"`]}).print()``\ +\ +_**Inner**_ _**quotes are not needed for numeric indices!**_ +{% endhint %} + +### Slice DataFrame rows by boolean condition + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + "Name": ["Apples", "Mango", "Banana", "Pear"], + "Count": [21, 5, 30, 10], + "Price": [200, 300, 40, 250] +} + +let df = new dfd.DataFrame(data, { index: ["a", "b", "c", "d"] }) +let sub_df = df.loc({ rows: df["Count"].gt(6) }) +sub_df.print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Count │ Price ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ a │ Apples │ 21 │ 200 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ c │ Banana │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ d │ Pear │ 10 │ 250 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` + +### Slice DataFrame rows by multiple boolean conditions + +{% hint style="info" %} +_By design, you can chain as many boolean logic as required, as long as they resolve to a Boolean array of the same length as the DataFrame._ +{% endhint %} + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + "Name": ["Apples", "Mango", "Banana", "Pear"], + "Count": [21, 5, 30, 10], + "Price": [200, 300, 40, 250] +} + +let df = new dfd.DataFrame(data, { index: ["a", "b", "c", "d"] }) +let condition = df["Count"].gt(6).and(df["Price"].lt(250)) +let sub_df = df.loc({ rows: condition }) +sub_df.print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Count │ Price ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ a │ Apples │ 21 │ 200 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ c │ Banana │ 30 │ 40 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +### Slice DataFrame with boolean mask + +{% hint style="info" %} +_You can index a DataFrame with an array of boolean values as long as they resolve to an array of the same length as the DataFrame._ +{% endhint %} +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") +let data = { + "Name": ["Apples", "Mango", "Banana", "Pear"], + "Count": [21, 5, 30, 10], + "Price": [200, 300, 40, 250] +} + +let df = new dfd.DataFrame(data, { index: ["a", "b", "c", "d"] }) + +let sub_df = df.loc({ rows: [false, true, true, true] }) +sub_df.print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Count │ Price ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ b │ Mango │ 5 │ 300 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ c │ Banana │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ d │ Pear │ 10 │ 250 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` diff --git a/api-reference/dataframe/danfo.dataframe.max.md b/api-reference/dataframe/danfo.dataframe.max.md index bb8b088..abb2b0a 100644 --- a/api-reference/dataframe/danfo.dataframe.max.md +++ b/api-reference/dataframe/danfo.dataframe.max.md @@ -4,44 +4,39 @@ description: Return the maximum of the values for the requested axis. # DataFrame.max -danfo.DataFrame.**max**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L519)\] +danfo.DataFrame.**max**(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| axis | Int | 0 for row and 1 for columns | 1 | - -**Returns:** - - ****return **Series** +| Parameters | Type | Description | Default | +| ---------- | ------ | ----------------------------------------------------------------------------------- | ----------- | +| options | Object | **axis:** 0 or 1. If 0, compute the mean column-wise, if 1, row-wise. Defaults to 1 | { axis: 1 } | ## **Examples** -## Return the maximum value along default axis 1 \(column\) +## Return the maximum value along default axis 1 (column) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] -df.print() +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] -let df = new dfd.DataFrame(data) +let df = new dfd.DataFrame(data, { columns: cols }) +df.print() df.max().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -54,44 +49,44 @@ df.max().print() ║ 3 │ 2 │ 89 │ 78 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ A │ 11 ║ -╟───┼──────────────────────╢ -║ B │ 89 ║ -╟───┼──────────────────────╢ -║ C │ 78 ║ -╚═══╧══════════════════════╝ +╔═══╤════╗ +║ 0 │ 20 ║ +╟───┼────╢ +║ 1 │ 15 ║ +╟───┼────╢ +║ 2 │ 40 ║ +╟───┼────╢ +║ 3 │ 89 ║ +╚═══╧════╝ + ``` {% endtab %} {% endtabs %} -## Return the maximum value along row axis \(0\) +## Return the maximum value along row axis (0) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] +let df = new dfd.DataFrame(data, { columns: cols }) df.print() -let df = new dfd.DataFrame(data) -df.max(axis=0).print() +df.max({ axis: 0 }).print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -104,18 +99,13 @@ df.max(axis=0).print() ║ 3 │ 2 │ 89 │ 78 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 20 ║ -╟───┼──────────────────────╢ -║ 1 │ 15 ║ -╟───┼──────────────────────╢ -║ 2 │ 40 ║ -╟───┼──────────────────────╢ -║ 3 │ 89 ║ -╚═══╧══════════════════════╝ +╔═══╤════╗ +║ A │ 11 ║ +╟───┼────╢ +║ B │ 89 ║ +╟───┼────╢ +║ C │ 78 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.mean.md b/api-reference/dataframe/danfo.dataframe.mean.md index 754ed57..7cff35a 100644 --- a/api-reference/dataframe/danfo.dataframe.mean.md +++ b/api-reference/dataframe/danfo.dataframe.mean.md @@ -1,22 +1,22 @@ --- -description: Return the mean of the values for the requested axis. +description: Returns the mean of the values for the requested axis. --- # DataFrame.mean -danfo.DataFrame.**mean**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L454)\] +danfo.DataFrame.**mean**(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| axis | Int | 0 for row and 1 for columns | 1 | +| Parameters | Type | Description | Default | +| ---------- | ------ | ----------------------------------------------------------------------------------- | ----------- | +| options | Object | **axis:** 0 or 1. If 0, compute the mean column-wise, if 1, row-wise. Defaults to 1 | { axis: 1 } | **Returns:** - ****return **Series** +\*\*\*\* return **Series** ## **Examples** -## Calculates the mean of values along default axis 1 \(column\) +## Computes the mean of values along default axis 1 (column) {% tabs %} {% tab title="Node" %} @@ -26,23 +26,21 @@ const dfd = require("danfojs-node") data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] cols = ["A", "B", "C"] -df.print() - let df = new dfd.DataFrame(data) +df.print() df.mean().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -55,69 +53,63 @@ df.mean().print() ║ 3 │ 2 │ 89 │ 78 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ A │ 4 ║ -╟───┼──────────────────────╢ -║ B │ 38.5 ║ -╟───┼──────────────────────╢ -║ C │ 31.75 ║ -╚═══╧══════════════════════╝ +╔═══╤════════════════════╗ +║ 0 │ 11.333333333333334 ║ +╟───┼────────────────────╢ +║ 1 │ 7.333333333333333 ║ +╟───┼────────────────────╢ +║ 2 │ 24 ║ +╟───┼────────────────────╢ +║ 3 │ 56.333333333333336 ║ +╚═══╧════════════════════╝ ``` {% endtab %} {% endtabs %} -## Calculates the mean of values along row axis \(0\) +## Computes the mean of values along row axis (0) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] -df.print() let df = new dfd.DataFrame(data) -df.mean(axis=0).print() +df.print() +df.mean({ axis: 0 }).print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 11 │ 20 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 1 │ 15 │ 6 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 2 │ 30 │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 2 │ 89 │ 78 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 11.333333015441895 ║ -╟───┼──────────────────────╢ -║ 1 │ 7.333333492279053 ║ -╟───┼──────────────────────╢ -║ 2 │ 24 ║ -╟───┼──────────────────────╢ -║ 3 │ 56.33333206176758 ║ -╚═══╧══════════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 11 │ 20 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 15 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 2 │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 2 │ 89 │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔═══╤═══════╗ +║ A │ 4 ║ +╟───┼───────╢ +║ B │ 38.5 ║ +╟───┼───────╢ +║ C │ 31.75 ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.median.md b/api-reference/dataframe/danfo.dataframe.median.md index 7b5e45e..f94fd72 100644 --- a/api-reference/dataframe/danfo.dataframe.median.md +++ b/api-reference/dataframe/danfo.dataframe.median.md @@ -4,19 +4,15 @@ description: Return the median of the values for the requested axis. # DataFrame.median -danfo.DataFrame.**median**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L474)\] +danfo.DataFrame.**median**(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| axis | Int | 0 for row and 1 for columns | 1 | - -**Returns:** - - ****return **Series** +| Parameters | Type | Description | Default | +| ---------- | ------ | ----------------------------------------------------------------------------------- | ----------- | +| options | Object | **axis:** 0 or 1. If 0, compute the mean column-wise, if 1, row-wise. Defaults to 1 | { axis: 1 } | ## **Examples** -## Calculates the median of values along default axis 1 \(column\) +## Computes the median of values along default axis 1 (column) {% tabs %} {% tab title="Node" %} @@ -26,98 +22,91 @@ const dfd = require("danfojs-node") data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] cols = ["A", "B", "C"] -df.print() - let df = new dfd.DataFrame(data) +df.print() df.median().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 11 │ 20 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 1 │ 15 │ 6 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 2 │ 30 │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 2 │ 89 │ 78 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ A │ 2 ║ -╟───┼──────────────────────╢ -║ B │ 25 ║ -╟───┼──────────────────────╢ -║ C │ 23 ║ -╚═══╧══════════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 11 │ 20 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 15 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 2 │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 2 │ 89 │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔═══╤════╗ +║ 0 │ 11 ║ +╟───┼────╢ +║ 1 │ 6 ║ +╟───┼────╢ +║ 2 │ 30 ║ +╟───┼────╢ +║ 3 │ 78 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} -## Calculates the median of values along row axis \(0\) +## Computes the median of values along row axis (0) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] + +let df = new dfd.DataFrame(data, { columns: cols }) df.print() -let df = new dfd.DataFrame(data) -df.median(axis=0).print() +df.median({ axis: 0 }).print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 11 │ 20 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 1 │ 15 │ 6 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 2 │ 30 │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 2 │ 89 │ 78 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 11 ║ -╟───┼──────────────────────╢ -║ 1 │ 6 ║ -╟───┼──────────────────────╢ -║ 2 │ 30 ║ -╟───┼──────────────────────╢ -║ 3 │ 78 ║ -╚═══╧══════════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 11 │ 20 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 15 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 2 │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 2 │ 89 │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔═══╤════╗ +║ A │ 2 ║ +╟───┼────╢ +║ B │ 25 ║ +╟───┼────╢ +║ C │ 23 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.min.md b/api-reference/dataframe/danfo.dataframe.min.md index 3a65ec4..668c2af 100644 --- a/api-reference/dataframe/danfo.dataframe.min.md +++ b/api-reference/dataframe/danfo.dataframe.min.md @@ -4,45 +4,39 @@ description: Return the minimum of the values for the requested axis. # DataFrame.min -danfo.DataFrame.**min**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L499)\] +danfo.DataFrame.**min**(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| axis | Int | 0 for row and 1 for columns | 1 | - -**Returns:** - - ****return **Series** +| Parameters | Type | Description | Default | +| ---------- | ------ | ----------------------------------------------------------------------------------- | ----------- | +| options | Object | **axis:** 0 or 1. If 0, compute the mean column-wise, if 1, row-wise. Defaults to 1 | { axis: 1 } | ## **Examples** -## Returns the minimum value along default axis 1 \(column\) +## Returns the minimum value along default axis 1 (column) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] +let df = new dfd.DataFrame(data, { columns: cols }) df.print() - -let df = new dfd.DataFrame(data) df.min().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -55,45 +49,44 @@ df.min().print() ║ 3 │ 2 │ 89 │ 78 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ A │ 1 ║ -╟───┼──────────────────────╢ -║ B │ 15 ║ -╟───┼──────────────────────╢ -║ C │ 3 ║ -╚═══╧══════════════════════╝ +╔═══╤═══╗ +║ 0 │ 3 ║ +╟───┼───╢ +║ 1 │ 1 ║ +╟───┼───╢ +║ 2 │ 2 ║ +╟───┼───╢ +║ 3 │ 2 ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} -## Return the minimum value along row axis \(0\) +## Return the minimum value along row axis (0) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] +let df = new dfd.DataFrame(data, { columns: cols }) df.print() -let df = new dfd.DataFrame(data) -df.min(axis=0).print() +df.min({ axis: 0 }).print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -106,18 +99,13 @@ df.min(axis=0).print() ║ 3 │ 2 │ 89 │ 78 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 3 ║ -╟───┼──────────────────────╢ -║ 1 │ 1 ║ -╟───┼──────────────────────╢ -║ 2 │ 2 ║ -╟───┼──────────────────────╢ -║ 3 │ 2 ║ -╚═══╧══════════════════════╝ +╔═══╤════╗ +║ A │ 1 ║ +╟───┼────╢ +║ B │ 15 ║ +╟───┼────╢ +║ C │ 3 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.mod.md b/api-reference/dataframe/danfo.dataframe.mod.md index 1f66ce1..7979969 100644 --- a/api-reference/dataframe/danfo.dataframe.mod.md +++ b/api-reference/dataframe/danfo.dataframe.mod.md @@ -1,32 +1,29 @@ --- -description: 'Get Modulo of DataFrame and other, element-wise (binary operator mod).' +description: Get Modulo of DataFrame and other, element-wise (binary operator mod). --- # DataFrame.mod -danfo.DataFrame.**mod**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L436)\] +danfo.DataFrame.mod(other, option) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array or Scalar | Object to modulo with | | -| axis | Int | 0 for row, 1 for column | 0 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- | +| other | DataFrame, Series, Array or Scalar | Object to modulo with | | +| option | Object |

{

axis: 0 for row, 1 for column.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| { axis: 1, inplace: false } | ## **Examples** -### Modulo of ****DataFrame with a scalar value: +### Modulo of **scalar with** DataFrame along default axis 1 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} - +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} let df = new dfd.DataFrame(data) let df_new = df.mod(2) @@ -37,44 +34,45 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 0 │ 1 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 1 │ 0 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 0 │ 0 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 0 │ 1 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 0 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 0 │ 0 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + ``` {% endtab %} {% endtabs %} -### Modulo of ****DataFrame with a Series along the column axis: +### Modulo of **Series with** DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript -const dfd = require("danfojs") +const dfd = require("danfojs-node") +let data = { + "Col1": [1, 4, 5, 1], + "Col2": [3, 2, 0, 4] +} -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]}] - let df = new dfd.DataFrame(data) -let sf = new dfd.Series([10,40]) +let sf = new dfd.Series([4, 5]) -let df_new = df.mod(sf, axis=1) +let df_new = df.mod(sf, { axis: 1 }) df_new.print() ``` @@ -82,41 +80,41 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 0 │ 23 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 5 │ 20 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 6 │ 10 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 0 │ 24 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 3 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 0 │ 2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 1 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 1 │ 4 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + ``` {% endtab %} {% endtabs %} -### Modulo of ****DataFrame with a DataFrame +### Modulo of DataFrame with a DataFrame {% tabs %} {% tab title="Node" %} ```javascript -const dfd = require("danfojs-node") +const dfd = require("danfojs") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} +let data = {"Col1": [1, 4, 5, 0], + "Col2": [2, 0, 1, 4]} -let data2 = {"new_col1": [10, 45, 200, 10], - "new_Col2": [230, 200, 110, 24]} +let data2 = {"new_col1": [1, 5, 20, 10], + "new_Col2": [20, 2, 1, 2]} let df = new dfd.DataFrame(data) let df2 = new dfd.DataFrame(data2) @@ -124,49 +122,50 @@ let df2 = new dfd.DataFrame(data2) let df_new = df.mod(df2) df_new.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```javascript -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 0 │ 23 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 0 │ 20 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 56 │ 10 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 0 │ 0 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 0 │ 2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 4 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 5 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 0 │ 0 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + ``` {% endtab %} {% endtabs %} -### Modulo of ****DataFrame with a JavaScript Array +### Modulo of Array with DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} - +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} + let df = new dfd.DataFrame(data) -let val = [10,40] +let val = [2, 2, 2, 2] -let df_new = df.mod(val, axis=1) +let df_new = df.mod(val, { axis: 0 }) df_new.print() ``` @@ -174,26 +173,70 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 0 │ 1 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 0 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 0 │ 0 ║ +╚════════════╧═══════════════════╧═══════════════════╝ +``` +{% endtab %} +{% endtabs %} + +### Modulo works inplace + +{% tabs %} +{% tab title="Node" %} ```javascript -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 0 │ 23 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 5 │ 20 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 6 │ 10 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 0 │ 24 ║ -╚═══╧═══════════════════╧═══════════════════╝ +const dfd = require("danfojs-node") + +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} + +let df = new dfd.DataFrame(data) +let val = [2, 2, 2, 2] + +df.mod(val, { axis: 0, inplace: true }) + +df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +``` ``` {% endtab %} {% endtabs %} +{% tabs %} +{% tab title="Output" %} +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 0 │ 1 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 0 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 0 │ 0 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/danfo.dataframe.mul.md b/api-reference/dataframe/danfo.dataframe.mul.md index 6f042d0..a2e0071 100644 --- a/api-reference/dataframe/danfo.dataframe.mul.md +++ b/api-reference/dataframe/danfo.dataframe.mul.md @@ -1,31 +1,29 @@ --- -description: 'Get Multiplication of dataframe and other, element-wise (binary operator mul).' +description: Get Multiplication of dataframe and other, element-wise (binary operator mul). --- # DataFrame.mul -danfo.DataFrame.**mul**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L383)\] +danfo.DataFrame.mul(other, option) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array or Scalar | Object to modulo with | | -| axis | Int | 0 for row, 1 for column | 0 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- | +| other | DataFrame, Series, Array or Scalar | Object to multiply with | | +| option | Object |

{

axis: 0 for row, 1 for column.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| { axis: 1, inplace: false } | ## **Examples** -### Multiplication of ****DataFrame with a scalar value: +### Multiplication of **scalar with** DataFrame along default axis 1 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} let df = new dfd.DataFrame(data) let df_new = df.mul(2) @@ -36,44 +34,44 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 20 │ 46 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 90 │ 40 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 112 │ 20 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 20 │ 48 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 20 │ 46 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 90 │ 40 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 112 │ 20 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 20 │ 48 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -### Multiplication of ****DataFrame with a Series along the column axis: +### Multiplication of **Series with** DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") +let data = { + "Col1": [1, 4, 5, 1], + "Col2": [3, 2, 0, 4] +} -let data = { "Col1": [1, 4, 5, 1], - "Col2": [3, 2, 0, 4] } - let df = new dfd.DataFrame(data) let sf = new dfd.Series([4, 5]) -let df_new = df.mul(sf, axis = 1) +let df_new = df.mul(sf, { axis: 1 }) df_new.print() ``` @@ -81,36 +79,36 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 4 │ 15 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 16 │ 10 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 20 │ 0 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 4 │ 20 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 4 │ 15 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 16 │ 10 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 20 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 4 │ 20 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -### Multiplication of ****DataFrame with a DataFrame +### Multiplication of DataFrame **with** another DataFrame {% tabs %} {% tab title="Node" %} ```javascript -const dfd = require("danfojs-node") -let data = {"Col1": [1, 4, 5, 0], +const dfd = require("danfojs") + +let data = {"Col1": [1, 4, 5, 0], "Col2": [2, 0, 1, 4]} let data2 = {"new_col1": [1, 5, 20, 10], @@ -122,49 +120,49 @@ let df2 = new dfd.DataFrame(data2) let df_new = df.mul(df2) df_new.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 40 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 20 │ 0 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 100 │ 1 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 0 │ 8 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 40 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 20 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 100 │ 1 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 0 │ 8 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -### Multiplication of ****DataFrame with a JavaScript Array +### Multiplication of Array **with** DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} - +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} + let df = new dfd.DataFrame(data) -let val = [2,2] +let val = [2, 2, 2, 2] -let df_new = df.mul(val, axis=1) +let df_new = df.mul(val, { axis: 0 }) df_new.print() ``` @@ -172,28 +170,70 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 20 │ 46 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 90 │ 40 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 112 │ 20 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 20 │ 48 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 20 │ 46 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 90 │ 40 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 112 │ 20 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 20 │ 48 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + ``` {% endtab %} {% endtabs %} +### Multiplication works inplace +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} + +let df = new dfd.DataFrame(data) +let val = [2, 2, 2, 2] + +df.mul(val, { axis: 0, inplace: true }) + +df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 20 │ 46 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 90 │ 40 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 112 │ 20 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 20 │ 48 ║ +╚════════════╧═══════════════════╧═══════════════════╝ +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/danfo.dataframe.nanindex.md b/api-reference/dataframe/danfo.dataframe.nanindex.md deleted file mode 100644 index 31db040..0000000 --- a/api-reference/dataframe/danfo.dataframe.nanindex.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -description: Returns array of index with missing values ---- - -# DataFrame.nanindex - -danfo.DataFrame.**nanIndex**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1410)\] - -**Returns:** - -```text - ****return **Array** -``` - -## **Examples** - -### Drop rows \(axis=0\) with missing values - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - -let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, undefined, 78]] -let cols = ["A", "B", "C"] -let df = new dfd.DataFrame(data, { columns: cols }) - -df.print() - -console.log(df.nanIndex()); -``` -{% endtab %} - -{% tab title="Browser" %} -```text - -``` -{% endtab %} -{% endtabs %} - -{% tabs %} -{% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 2 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ NaN │ 5 │ 6 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ NaN │ 30 │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 39 │ NaN │ 78 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - -[ 1, 2, 3 ] -``` -{% endtab %} -{% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.ne.md b/api-reference/dataframe/danfo.dataframe.ne.md index 4a807f7..36ab6e2 100644 --- a/api-reference/dataframe/danfo.dataframe.ne.md +++ b/api-reference/dataframe/danfo.dataframe.ne.md @@ -1,23 +1,23 @@ --- -description: 'Get Not Equal to of DataFrame and other, element-wise (binary operator eq).' +description: Get Not Equal to of DataFrame and other, element-wise (binary operator eq). --- # DataFrame.ne -danfo.DataFrame.ne\(other, axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1633)\] +danfo.DataFrame.ne(other, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | -| axis | Int | Whether to compare by the index \(0\) or columns \(1\). | 0 | +| Parameters | Type | Description | Default | +| ---------- | -------------------------------- | ----------------------------------------------------------- | --------- | +| other | DataFrame, Series, Array, Scalar | Data structure, or array-like object to compare against | | +| options | Object | **axis**: 0 or 1. If 0, add column-wise, if 1, add row-wise | {axis: 1} | **Returns:** - ****return **DataFrame** +*** ## **Examples** -### Comparing ****DataFrame with a scalar value: +### Comparing a DataFrame with a scalar value: {% tabs %} {% tab title="Node" %} @@ -36,14 +36,13 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -59,7 +58,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a Series along the column axis: +### Comparing a DataFrame with a Series along the column axis: {% tabs %} {% tab title="Node" %} @@ -71,24 +70,22 @@ let data = {"Col1": [10, 45, 56, 10], let df = new dfd.DataFrame(data) let sf = new dfd.Series([10,40]) -let df_rep = df.ne(sf, axis=1) +let df_rep = df.ne(sf, {axis:1}) df_rep.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -104,7 +101,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a DataFrame +### Comparing a DataFrame with a DataFrame {% tabs %} {% tab title="Node" %} @@ -122,20 +119,18 @@ let df2 = new dfd.DataFrame(data2) let df_rep = df.ne(df2) df_rep.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -151,7 +146,7 @@ df_rep.print() {% endtab %} {% endtabs %} -### Comparing ****DataFrame with a JavaScript Array +### Comparing a DataFrame with a JavaScript Array {% tabs %} {% tab title="Node" %} @@ -171,14 +166,13 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ 0 │ 1 │ 2 │ 3 ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -189,4 +183,3 @@ df_rep.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.pctChange.md b/api-reference/dataframe/danfo.dataframe.pctChange.md new file mode 100644 index 0000000..542029f --- /dev/null +++ b/api-reference/dataframe/danfo.dataframe.pctChange.md @@ -0,0 +1,305 @@ +--- +description: >- + Get percent difference between a dataframe and other. Accepts DataFrame, Series, number[] and number. +--- + +# DataFrame.pctChange + +danfo.DataFrame.pctChange(other, option) + +| Parameters | Type | Description | Default | +| ---------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------- | +| other | DataFrame, Series, Array or Scalar | Object to calculate difference with | | +| option | Object |

{

axis: 0 for column, 1 for row (default).

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| { axis: 1, inplace: false } | + +## **Examples** + +### Percent difference with **previous row** of current DataFrame along default axis 1 + +{% tabs %} +{% tab title="Node" %} + +```javascript +import * as dfd from "danfojs"; + +const data = [[90], [900], [900]]; + +const df = new dfd.DataFrame(data); + +const df_new = df.pctChange(1); + +df_new.print(); +``` + +{% endtab %} + +{% tab title="Browser" %} + +```html + + + + + + + + + + + + +``` + +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} + +``` +╔════════════╤═══════════════════╗ +║ │ Col1 ║ +╟────────────┼───────────────────╢ +║ 0 │ NaN ║ +╟────────────┼───────────────────╢ +║ 1 │ 9 ║ +╟────────────┼───────────────────╢ +║ 2 │ 0 ║ +╚════════════╧═══════════════════╝ + +``` + +{% endtab %} +{% endtabs %} + +### Percentage difference with **following row** of current DataFrame along default axis 1 + +{% tabs %} +{% tab title="Node" %} + +```javascript +import * as dfd from "danfojs"; + +const data = [ + [0, 5, 15], + [10, 10, 10], + [1, 2, 5], +]; + +const df = new dfd.DataFrame(data); + +const df_new = df.pctChange(-1); + +df_new.print(); +``` + +{% endtab %} + +{% tab title="Browser" %} + +```html + + + + + + + + + + + + +``` + +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 │ Col3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ -1 │ -0.5 │ 0.5 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 9 │ 4 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ NaN │ NaN │ NaN ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` + +{% endtab %} +{% endtabs %} + +### Percentage difference with **Series** and DataFrame along axis 1 + +{% tabs %} +{% tab title="Node" %} + +```javascript +import * as dfd from "danfojs"; + +const data = [ + [0, 2, 4], + [10, 10, 10], + [1, 2, 3], +]; + +const df = new dfd.DataFrame(data); + +const sf = new dfd.Series([1, 2, 1]); + +const df_new = df.pctChange(sf); + +df_new.print(); +``` + +{% endtab %} + +{% tab title="Browser" %} + +```html + + + + + + + + + + + + +``` + +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 │ Col3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ -1 │ 0 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 9 │ 4 │ 9 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 0 │ 0 │ 2 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` + +{% endtab %} +{% endtabs %} + +### Percentage difference between DataFrame and **another** DataFrame + +{% tabs %} +{% tab title="Node" %} + +```javascript +import * as dfd from "danfojs"; + +const data = [ + [0, 2, 4], + [3, 10, 4], +]; + +const original_df = new dfd.DataFrame(data); + +const comparison_df = new dfd.DataFrame([ + [-1, -2, 4], + [6, 5, 0], +]); + +const df_new = original_df.pctChange(comparison_df); + +df_new.print(); +``` + +{% endtab %} + +{% tab title="Browser" %} + +```html + + + + + + + + + + + + +``` + +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 │ Col3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ -1 │ -2 │ 0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ -0.5 │ 1 │ -1 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` + +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/danfo.dataframe.pow.md b/api-reference/dataframe/danfo.dataframe.pow.md index aa7a15e..1f2926d 100644 --- a/api-reference/dataframe/danfo.dataframe.pow.md +++ b/api-reference/dataframe/danfo.dataframe.pow.md @@ -6,29 +6,26 @@ description: >- # DataFrame.pow -danfo.DataFrame.**pow**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L418)\] +danfo.DataFrame.pow(other, option) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array or Scalar | Object to modulo with | | -| axis | Int | 0 for row, 1 for column | 0 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- | +| other | DataFrame, Series, Array or Scalar | Object to raised to power with | | +| option | Object |

{

axis: 0 for row, 1 for column.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| { axis: 1, inplace: false } | ## **Examples** -### Exponent of ****DataFrame with a scalar value: +### Exponential of **scalar with** DataFrame along default axis 1 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} - +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} let df = new dfd.DataFrame(data) let df_new = df.pow(2) @@ -39,43 +36,45 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 100 │ 529 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 2025 │ 400 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 3136 │ 100 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 100 │ 576 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 100 │ 529 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 2025 │ 400 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 3136 │ 100 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 100 │ 576 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + ``` {% endtab %} {% endtabs %} -### Exponent of ****DataFrame with a Series along the column axis: +### Exponential of **Series with** DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") +let data = { + "Col1": [1, 4, 5, 1], + "Col2": [3, 2, 0, 4] +} -let data = { "Col1": [1, 4, 5, 1], - "Col2": [3, 2, 0, 4] } let df = new dfd.DataFrame(data) let sf = new dfd.Series([4, 5]) -let df_new = df.pow(sf, axis = 1) +let df_new = df.pow(sf, { axis: 1 }) df_new.print() ``` @@ -83,37 +82,39 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 243 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 256 │ 32 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 625 │ 0 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 1 │ 1024 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 243 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 256 │ 32 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 625 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 1 │ 1024 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + ``` {% endtab %} {% endtabs %} -### Exponent of ****DataFrame with a DataFrame +### Exponential of DataFrame with another DataFrame {% tabs %} {% tab title="Node" %} ```javascript -let data = { "Col1": [1, 4, 5, 1], - "Col2": [3, 2, 0, 4] } - +const dfd = require("danfojs") + +let data = {"Col1": [1, 4, 5, 0], + "Col2": [2, 0, 1, 4]} + let data2 = {"new_col1": [1, 5, 20, 10], "new_Col2": [20, 2, 1, 2]} @@ -123,49 +124,50 @@ let df2 = new dfd.DataFrame(data2) let df_new = df.pow(df2) df_new.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 1048576 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 1024 │ 0 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 95367433551872 │ 1 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 0 │ 16 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 1048576 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1024 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 95367433551872 │ 1 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 0 │ 16 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + ``` {% endtab %} {% endtabs %} -### Exponent of ****DataFrame with a JavaScript Array +### Exponential of Array with DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} - +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} + let df = new dfd.DataFrame(data) -let val = [2,2] +let val = [2, 2, 2, 2] -let df_new = df.pow(val, axis=1) +let df_new = df.pow(val, { axis: 0 }) df_new.print() ``` @@ -173,26 +175,70 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 100 │ 12167 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 2025 │ 8000 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 3136 │ 1000 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 100 │ 13824 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 100 │ 529 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 2025 │ 400 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 3136 │ 100 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 100 │ 576 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} +### Exponential works inplace + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} + +let df = new dfd.DataFrame(data) +let val = [2, 2, 2, 2] + +df.pow(val, { axis: 0, inplace: true }) + +df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 100 │ 529 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 2025 │ 400 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 3136 │ 100 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 100 │ 576 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/danfo.dataframe.query.md b/api-reference/dataframe/danfo.dataframe.query.md index 902230c..2d43b1e 100644 --- a/api-reference/dataframe/danfo.dataframe.query.md +++ b/api-reference/dataframe/danfo.dataframe.query.md @@ -1,49 +1,104 @@ --- -description: >- - Query the DataFrame by the result of a logical comparison. Supports logical - operations like (">", "<", ">=", "<=", and. "==") +description: Query the DataFrame by the result of a logical comparison or boolean mask. --- # DataFrame.query -danfo.DataFrame.**query**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1011)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{column : str, name of the column

-

is: Logical operator, one of ">", "<", - ">=", "<=", and. "=="

-

to: Int, Float, Str. Value to compare against,

-

inplace: boolean. true | false. Whether to perform operation to - the original Object or create a new one.

-

}

-
{inplace: false}
- -**Returns:** - - ****return **new DataFrame** +danfo.DataFrame.**query**(kwargs) + +| Parameters | Type | Description | Default | +| ---------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | +| kwargs | Object |

{

condition: A logical boolean mask,

column : str, name of the column

is: Logical operator, one of ">", "<", ">=", "<=", and. "=="

to: Int, Float, Str. Value to compare against,

inplace: boolean. true

|

false. Whether to perform operation to the original Object or create a new one.

}

| ## **Examples** +## **Query a DataFrame using a boolean mask** + +{% hint style="info" %} +Querying by a boolean condition is supported from v0.3.0 and above. +{% endhint %} + +```javascript +const dfd = require("danfojs-node") + +let data = { + "A": ["Ng", "Yu", "Mo", "Ng"], + "B": [34, 4, 5, 6], + "C": [20, 20, 30, 40] +} +let df = new dfd.DataFrame(data) +df.print() +let query_df = df.query(df["B"].gt(5)) +query_df.print() //after query +``` + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Ng │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ Yu │ 4 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ Mo │ 5 │ 30 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ Ng │ 6 │ 40 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Ng │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ Ng │ 6 │ 40 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +It also supports condition chaining as long as the final boolean mask is the same length as the DataFrame rows. For example in the following code, we use multiple chaining conditions: + +```javascript +const dfd = require("danfojs-node") + +let data = { + "A": ["Ng", "Yu", "Mo", "Ng"], + "B": [34, 4, 5, 6], + "C": [20, 20, 30, 40] +} +let df = new dfd.DataFrame(data) +df.print() + +let query_df = df.query(df["B"].gt(5).and(df["C"].lt(40))) +query_df.print() //after query +``` + +``` +// output +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Ng │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ Yu │ 4 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ Mo │ 5 │ 30 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ Ng │ 6 │ 40 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Ng │ 34 │ 20 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + ## **Query a DataFrame using logical operators** -To query a DataFrame, you can specify the column to use, the logical operator \(">", "<", ">=", "<=", and. "=="\), and the value to compare against. +{% hint style="info" %} +This is only supported in older versions. That is versions lower than v1.0.0 +{% endhint %} + +To query a DataFrame, you can specify the column to use, the logical operator (">", "<", ">=", "<=", and. "=="), and the value to compare against. {% tabs %} {% tab title="Node" %} @@ -65,14 +120,13 @@ query_df.print() //after query {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` //before query ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ @@ -98,60 +152,13 @@ query_df.print() //after query {% endtab %} {% endtabs %} -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") -let data = {"A": [30, 1, 2, 3], - "B": [34, 4, 5, 6], - "C": [20, 20, 30, 40]} - -let df = new dfd.DataFrame(data) - -df.print() - -let query_df = df.query({ "column": "A", "is": ">", "to": 9 }) -query_df.print() //after query - -``` -{% endtab %} - -{% tab title="Browser" %} -``` - -``` -{% endtab %} -{% endtabs %} - -{% tabs %} -{% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 30 │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 1 │ 4 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 2 │ 5 │ 30 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 3 │ 6 │ 40 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - -//after query - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 30 │ 34 │ 20 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` -{% endtab %} -{% endtabs %} - ## **Query by a string column in a DataFrame** -The query method also works on string columns. +{% hint style="info" %} +This is only supported in older versions. That is versions lower than v1.0.0 +{% endhint %} + +The query method also works on string columns. {% tabs %} {% tab title="Node" %} @@ -167,21 +174,18 @@ df.print() let query_df = df.query({ column: "A", is: "==", to: "Ng"}) query_df.print() //after query - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -206,50 +210,3 @@ query_df.print() //after query ``` {% endtab %} {% endtabs %} - -## **Query a DataFrame inplace** - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - -let data = {"A": [30, 1, 2, 3], - "B": [34, 4, 5, 6], - "C": [20, 20, 30, 40]} - -let cols = ["A", "B", "C"] -let df = new dfd.DataFrame(data, { columns: cols }) - -df.query({ - column: "B", - is: ">", - to: 5, - inplace: true -}) -df.print() - -``` -{% endtab %} - -{% tab title="Browser" %} -``` - -``` -{% endtab %} -{% endtabs %} - -{% tabs %} -{% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 30 │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 3 │ 6 │ 40 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` -{% endtab %} -{% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.replace.md b/api-reference/dataframe/danfo.dataframe.replace.md index 91e21f1..ff4b3db 100644 --- a/api-reference/dataframe/danfo.dataframe.replace.md +++ b/api-reference/dataframe/danfo.dataframe.replace.md @@ -4,38 +4,13 @@ description: Replaces values in a DataFrame with specified values # DataFrame.replace -> danfo.DataFrame.**replace**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L1670)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{replace: int, float, str. The value to replace.

-

with: Int, float, str. The new value to replace with.

-

in: Array. An array of column names to replace, If not specified, - replace all columns.

-

}

-
- -**Returns:** - - ****return **DataFrame** - -\*\*\*\* +> danfo.DataFrame.**replace**(oldValue, newValue, options) + +| Parameters | Type | Description | Default | +| ---------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | +| oldValue | String, boolean, Number | The value you want to replace | | +| newValue | String, boolean, Number | The new value you want to replace the old value with | | +| options | Object |

columns: Array. An array of column names to replace, If not specified, replace all columns.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

| {inplace: false} | ## **Examples** @@ -44,11 +19,13 @@ description: Replaces values in a DataFrame with specified values ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} let df = new dfd.DataFrame(data) -let df_rep = df.replace({ "replace": 10, "with": -999, "in": ["Col1"] }) +let df_rep = df.replace(10, -999, { columns: ["Col1"] }) df_rep.print() @@ -58,14 +35,13 @@ df_rep.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -81,27 +57,24 @@ df_rep.print() {% endtab %} {% endtabs %} -By not specifying a ****column**,** the ****replace works on all columns **** +If a column name is not specified, **replace** works on all columns: {% tabs %} {% tab title="Node" %} ```javascript -const dfd = require("danfojs-js") - +const dfd = require("danfojs-node") let data = [["A", "A", "A", "B"], ["B", "C", "C", "D"]] let df = new dfd.DataFrame(data) //replace value in all column -let df_rep = df.replace({ "replace": "A", "with": "boy" }) +let df_rep = df.replace("A", "BOY") df_rep.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} @@ -109,15 +82,13 @@ df_rep.print() {% tabs %} {% tab title="Output" %} ```javascript - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ 0 │ 1 │ 2 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ boy │ boy │ boy │ B ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ B │ C │ C │ D ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ 0 │ 1 │ 2 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ BOY │ BOY │ BOY │ B ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ B │ C │ C │ D ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.round.md b/api-reference/dataframe/danfo.dataframe.round.md index b85c27e..43a0222 100644 --- a/api-reference/dataframe/danfo.dataframe.round.md +++ b/api-reference/dataframe/danfo.dataframe.round.md @@ -4,27 +4,24 @@ description: Round elements in a DataFrame to a specified number of decimal plac # DataFrame.round -danfo.DataFrame.**round**\(dp\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L706)\] +danfo.DataFrame.**round**(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| dp | Int | Number of decimal places to round to | 1 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ------ | -------------------------------------------------------------------------------------------------- | ------------------ | +| dp | Int | Number of decimal places to round to. Defaults to 1 | 1 | +| options | Object | **inplace:** Boolean indicating whether to perform the operation inplace or not. Defaults to false | { inplace: false } | ## **Examples** -## Round elements to 1dp \(Default\) +## Round elements to 1dp (Default) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11.20, 20.1234, 3.567], [1, 15.1, 6.0], [2, 3.09, 40.234]] -cols = ["A", "B", "C"] +let data = [[11.20, 20.1234, 3.567], [1, 15.1, 6.0], [2, 3.09, 40.234]] +let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) df.print() @@ -37,14 +34,13 @@ new_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -92,14 +88,13 @@ new_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -126,5 +121,4 @@ new_df.print() {% endtab %} {% endtabs %} -## - +## diff --git a/api-reference/dataframe/danfo.dataframe.sample.md b/api-reference/dataframe/danfo.dataframe.sample.md index 0a0f76e..a7e8869 100644 --- a/api-reference/dataframe/danfo.dataframe.sample.md +++ b/api-reference/dataframe/danfo.dataframe.sample.md @@ -4,51 +4,46 @@ description: Return a random sample of rows from DataFrame. # DataFrame.sample -danfo.DataFrame.**sample**\(num, seed\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L314)\] +danfo.DataFrame.**sample**(num, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| num | Int | The number of rows to return. Defaults to -1, which shuffles and return all rows. | -1 | -| seed | int | An integer specifying the random seed that will be used to create the distribution. Ensures reproducibility of generated samples. | 1 | +| Parameters | Type | Description | Default | +| ---------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | +| num | Integer | The number of rows to return. Defaults to 5, which shuffles and return all rows. | 5 | +| options | Object | **seed**: An integer specifying the random seed that will be used to create the distribution. Ensures reproducibility of generated samples. | { seed: 1 } | -**Returns:** - - ****return **{Promies} resolves to DataFrame** - -## **Examples** +## Sample a DataFrame randomly {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -async function load_data() { - let data = { - Name: ["Apples", "Mango", "Banana", "Pear"], - Count: [21, 5, 30, 10], - Price: [200, 300, 40, 250], - }; - - let df = new dfd.DataFrame(data); - let s_df = await df.sample(2); - s_df.print(); - +async function sample_data() { + let data = { + Name: ["Apples", "Mango", "Banana", "Pear"], + Count: [21, 5, 30, 10], + Price: [200, 300, 40, 250], + }; + + let df = new dfd.DataFrame(data); + let s_df = await df.sample(2); + s_df.print(); + } -load_data() +sample_data() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -60,3 +55,51 @@ load_data() {% endtab %} {% endtabs %} +## Sample a DataFrame randomly with seed + +By setting `seed` when using `sample`, you can ensure that the random sampling is reproducible. + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +async function load_data() { + let data = { + Name: ["Apples", "Mango", "Banana", "Pear"], + Count: [21, 5, 30, 10], + Price: [200, 300, 40, 250], + }; + + let df = new dfd.DataFrame(data); + let s_df = await df.sample(3, { seed: 2 }); + s_df.print(); + +} + +load_data() +``` +{% endtab %} + +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Count │ Price ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ Mango │ 5 │ 300 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ Banana │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Apples │ 21 │ 200 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/danfo.dataframe.std.md b/api-reference/dataframe/danfo.dataframe.std.md index 0a93231..47169a5 100644 --- a/api-reference/dataframe/danfo.dataframe.std.md +++ b/api-reference/dataframe/danfo.dataframe.std.md @@ -4,56 +4,51 @@ description: Return sample standard deviation over requested axis. # DataFrame.std -danfo.DataFrame.**var**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L563)\] +danfo.DataFrame.**std**(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| axis | Int | 0 for row and 1 for columns | 1 | - -**Returns:** - - ****return **Series** +| Parameters | Type | Description | Default | +| ---------- | ------ | ----------------------------------------------------------------------------------- | ----------- | +| options | Object | **axis:** 0 or 1. If 0, compute the mean column-wise, if 1, row-wise. Defaults to 1 | { axis: 1 } | ## **Examples** -## Calculates the standard deviation of values along default axis 1 \(column\) +## Calculates the standard deviation of values along default axis 1 (column) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] -let df = new dfd.DataFrame(data) +let df = new dfd.DataFrame(data, { columns: cols }) df.std().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 4.69041575982343 ║ -╟───┼──────────────────────╢ -║ 1 │ 34.23935357645254 ║ -╟───┼──────────────────────╢ -║ 2 │ 35.103418636936205 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════════════════════╗ +║ 0 │ 8.504900548115383 ║ +╟───┼────────────────────╢ +║ 1 │ 7.094598884597588 ║ +╟───┼────────────────────╢ +║ 2 │ 19.697715603592208 ║ +╟───┼────────────────────╢ +║ 3 │ 47.37439533475159 ║ +╚═══╧════════════════════╝ ``` {% endtab %} {% endtabs %} -## Calculates the standard deviation of values along row axis \(0\) +## Calculates the standard deviation of values along row axis (0) {% tabs %} {% tab title="Node" %} @@ -63,20 +58,19 @@ data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] cols = ["A", "B", "C"] let df = new dfd.DataFrame(data) -df.std(axis=0).print() +df.std({axis:0}).print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -92,7 +86,4 @@ df.std(axis=0).print() {% endtab %} {% endtabs %} -## - - - +## diff --git a/api-reference/dataframe/danfo.dataframe.sub.md b/api-reference/dataframe/danfo.dataframe.sub.md index 439c9cb..9f53957 100644 --- a/api-reference/dataframe/danfo.dataframe.sub.md +++ b/api-reference/dataframe/danfo.dataframe.sub.md @@ -1,31 +1,29 @@ --- -description: 'Get Subtraction of dataframe and other, element-wise (binary operator sub).' +description: Get Subtraction of dataframe and other, element-wise (binary operator sub). --- # DataFrame.sub -danfo.DataFrame.**sub**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L365)\] +danfo.DataFrame.sub(other, option) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | DataFrame, Series, Array or Scalar | Object to modulo with | | -| axis | Int | 0 for row, 1 for column | 0 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- | +| other | DataFrame, Series, Array or Scalar | Object to subtract | | +| option | Object |

{

axis: 0 for row, 1 for column.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| { axis: 1, inplace: false } | ## **Examples** -### Subtraction of **scalar from** DataFrame: +### Subtraction of **scalar from** DataFrame along default axis 1 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} let df = new dfd.DataFrame(data) let df_new = df.sub(2) @@ -36,44 +34,44 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 8 │ 21 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 43 │ 18 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 54 │ 8 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 8 │ 22 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 8 │ 21 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 43 │ 18 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 54 │ 8 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 8 │ 22 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -### Subtraction of **Series from** DataFrame along the column axis: +### Subtraction of **Series from** DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") +let data = { + "Col1": [1, 4, 5, 1], + "Col2": [3, 2, 0, 4] +} -let data = { "Col1": [1, 4, 5, 1], - "Col2": [3, 2, 0, 4] } - let df = new dfd.DataFrame(data) let sf = new dfd.Series([4, 5]) -let df_new = df.sub(sf, axis = 1) +let df_new = df.sub(sf, { axis: 1 }) df_new.print() ``` @@ -81,37 +79,36 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ -3 │ -2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 0 │ -3 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 1 │ -5 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ -3 │ -1 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ -3 │ -2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 0 │ -3 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 1 │ -5 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ -3 │ -1 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -### Subtraction of ****DataFrame from a DataFrame +### Subtraction of DataFrame from another DataFrame {% tabs %} {% tab title="Node" %} ```javascript -const dfd = require("danfojs-node") +const dfd = require("danfojs") -let data = {"Col1": [1, 4, 5, 0], +let data = {"Col1": [1, 4, 5, 0], "Col2": [2, 0, 1, 4]} let data2 = {"new_col1": [1, 5, 20, 10], @@ -123,49 +120,49 @@ let df2 = new dfd.DataFrame(data2) let df_new = df.sub(df2) df_new.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 0 │ -18 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ -1 │ -2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ -15 │ 0 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ -10 │ 2 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 0 │ -18 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ -1 │ -2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ -15 │ 0 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ -10 │ 2 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -### Subtraction of ****JavaScript Array from Array +### Subtraction of Array from DataFrame along axis 0 {% tabs %} {% tab title="Node" %} ```javascript -const dfd = require("danfojs") +const dfd = require("danfojs-node") + +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} -let data = {"Col1": [10, 45, 56, 10], - "Col2": [23, 20, 10, 24]} - let df = new dfd.DataFrame(data) -let val = [2,2] +let val = [2, 2, 2, 2] -let df_new = df.sub(val, axis=1) +let df_new = df.sub(val, { axis: 0 }) df_new.print() ``` @@ -173,28 +170,71 @@ df_new.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Col1 │ Col2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 8 │ 21 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 43 │ 18 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 54 │ 8 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 8 │ 22 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 8 │ 21 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 43 │ 18 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 54 │ 8 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 8 │ 22 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + ``` {% endtab %} {% endtabs %} +### Subtraction works inplace + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + "Col1": [10, 45, 56, 10], + "Col2": [23, 20, 10, 24] +} +let df = new dfd.DataFrame(data) +let val = [2, 2, 2, 2] + +df.sub(val, { axis: 0, inplace: true }) +df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Col1 │ Col2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 8 │ 21 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 43 │ 18 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 54 │ 8 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 8 │ 22 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/danfo.dataframe.sum.md b/api-reference/dataframe/danfo.dataframe.sum.md index d8d1e96..46ac59f 100644 --- a/api-reference/dataframe/danfo.dataframe.sum.md +++ b/api-reference/dataframe/danfo.dataframe.sum.md @@ -4,19 +4,15 @@ description: Return the sum of the values for the requested axis. # DataFrame.sum -danfo.DataFrame.**sum**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L940)\] +danfo.DataFrame.**sum**(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs | Object | {**axis**: 0 for row and 1 for column} | {axis: 1} | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ------ | ----------------------------------------------------------------------------------- | ----------- | +| options | Object | **axis:** 0 or 1. If 0, compute the mean column-wise, if 1, row-wise. Defaults to 1 | { axis: 1 } | ## **Examples** -## Sum elements along default axis \(column\) +## Sum elements along default axis 1 (column) {% tabs %} {% tab title="Node" %} @@ -36,40 +32,39 @@ df_sum.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ -20.1 │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 30 │ -4 │ -20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 47.3 │ 5 │ 30 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ -20 │ 6 │ -40 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - -╔═══╤══════════════════════╗ -║ │ sum ║ -╟───┼──────────────────────╢ -║ A │ 37.2 ║ -╟───┼──────────────────────╢ -║ B │ 41 ║ -╟───┼──────────────────────╢ -║ C │ -10 ║ -╚═══╧══════════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ -20.1 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 30 │ -4 │ -20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 47.3 │ 5 │ 30 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ -20 │ 6 │ -40 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔═══╤══════╗ +║ 0 │ 33.9 ║ +╟───┼──────╢ +║ 1 │ 6 ║ +╟───┼──────╢ +║ 2 │ 82.3 ║ +╟───┼──────╢ +║ 3 │ -54 ║ +╚═══╧══════╝ ``` {% endtab %} {% endtabs %} -## Sum elements along row axis \(0\) +## Sum elements along row axis (0) {% tabs %} {% tab title="Node" %} @@ -89,14 +84,13 @@ df_sum.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -109,18 +103,13 @@ df_sum.print() ║ 3 │ -20 │ 6 │ -40 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -╔═══╤══════════════════════╗ -║ │ sum ║ -╟───┼──────────────────────╢ -║ 0 │ 33.9 ║ -╟───┼──────────────────────╢ -║ 1 │ 6 ║ -╟───┼──────────────────────╢ -║ 2 │ 82.3 ║ -╟───┼──────────────────────╢ -║ 3 │ -54 ║ -╚═══╧══════════════════════╝ +╔═══╤════════════════════╗ +║ A │ 37.199999999999996 ║ +╟───┼────────────────────╢ +║ B │ 41 ║ +╟───┼────────────────────╢ +║ C │ -10 ║ +╚═══╧════════════════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.tail.md b/api-reference/dataframe/danfo.dataframe.tail.md index a69fa3e..0913390 100644 --- a/api-reference/dataframe/danfo.dataframe.tail.md +++ b/api-reference/dataframe/danfo.dataframe.tail.md @@ -4,15 +4,11 @@ description: Returns the last n rows from the DataFrame based on position. # DataFrame.tail -danfo.DataFrame.**tail**\(rows\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L292)\] +danfo.DataFrame.**tail**(rows) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| rows | Int | The number of rows to return | 5 | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ---- | ---------------------------- | ------- | +| rows | Int | The number of rows to return | 5 | ## **Examples** @@ -28,20 +24,18 @@ let data = { "Name": ["Apples", "Mango", "Banana", "Pear"], let df = new dfd.DataFrame(data) let s_df = df.tail(3) s_df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -52,4 +46,3 @@ s_df.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/danfo.dataframe.var.md b/api-reference/dataframe/danfo.dataframe.var.md index 6b88002..e84331b 100644 --- a/api-reference/dataframe/danfo.dataframe.var.md +++ b/api-reference/dataframe/danfo.dataframe.var.md @@ -4,95 +4,108 @@ description: Return unbiased variance over requested axis. # DataFrame.var -danfo.DataFrame.**var**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L563)\] +danfo.DataFrame.**var**(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| axis | Int | 0 for row and 1 for columns | 1 | - -**Returns:** - - ****return **Series** +| Parameters | Type | Description | Default | +| ---------- | ------ | ----------------------------------------------------------------------------------- | ----------- | +| options | Object | **axis:** 0 or 1. If 0, compute the mean column-wise, if 1, row-wise. Defaults to 1 | { axis: 1 } | ## **Examples** -## Calculate variance of values along default axis 1 \(column\) +## Computes the variance of values along default axis 1 (column) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] -let df = new dfd.DataFrame(data) +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] + +let df = new dfd.DataFrame(data, { columns: cols }) +df.print() df.var().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 22 ║ -╟───┼──────────────────────╢ -║ 1 │ 1172.3333333333333 ║ -╟───┼──────────────────────╢ -║ 2 │ 1232.25 ║ -╚═══╧══════════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 11 │ 20 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 15 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 2 │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 2 │ 89 │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔═══╤═══════════════════╗ +║ 0 │ 72.33333333333334 ║ +╟───┼───────────────────╢ +║ 1 │ 50.33333333333333 ║ +╟───┼───────────────────╢ +║ 2 │ 388 ║ +╟───┼───────────────────╢ +║ 3 │ 2244.333333333333 ║ +╚═══╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -## Calculate variance of values along row axis \(0\) +## Computes the variance of values along row axis (0) {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] -cols = ["A", "B", "C"] -let df = new dfd.DataFrame(data) -df.var(axis=0).print() +let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] +let cols = ["A", "B", "C"] + +let df = new dfd.DataFrame(data, { columns: cols }) +df.print() +df.var({ axis: 0 }).print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 72.33333333333334 ║ -╟───┼──────────────────────╢ -║ 1 │ 50.33333333333333 ║ -╟───┼──────────────────────╢ -║ 2 │ 388 ║ -╟───┼──────────────────────╢ -║ 3 │ 2244.333333333333 ║ -╚═══╧══════════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 11 │ 20 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 15 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 2 │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 2 │ 89 │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔═══╤════════════════════╗ +║ A │ 22 ║ +╟───┼────────────────────╢ +║ B │ 1172.3333333333333 ║ +╟───┼────────────────────╢ +║ C │ 1232.25 ║ +╚═══╧════════════════════╝ ``` {% endtab %} {% endtabs %} - - - - - diff --git a/api-reference/dataframe/dataframe.append.md b/api-reference/dataframe/dataframe.append.md index d13e0a0..b8bc62e 100644 --- a/api-reference/dataframe/dataframe.append.md +++ b/api-reference/dataframe/dataframe.append.md @@ -4,19 +4,17 @@ description: Adds new row to the end of a DataFrame # DataFrame.append -danfo.DataFrame.**append**\(val\) \[[source](https://github.com/opensource9ja/danfojs/blob/2696f1d8420dd364464aae7c5c175c6cd0ef4c93/danfojs/src/core/frame.js#L2059)\] +danfo.DataFrame.**append**(values, index, options) \[[source](https://github.com/opensource9ja/danfojs/blob/2696f1d8420dd364464aae7c5c175c6cd0ef4c93/danfojs/src/core/frame.js#L2059)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| val | Array \| Series | Object to append | | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------- | +| values | Array, Series or DataFrame | Value to append to the DataFrame | | +| index | Array | The new index value(s) to append to the Series. Must contain the same number of values as`newValues` as they map `1 - 1`. | | +| options | Object |

Optional parameters

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

|

{

inplace : false

}

| ## **Examples** -### **Sort DataFrame by a column in ascending order** +### **Appends a new row to the end of a DataFrame** {% tabs %} {% tab title="Node" %} @@ -28,22 +26,20 @@ let data = [[0, 2, 4, "b"], let df = new dfd.DataFrame(data) df.print() -let new_df = df.append([[20, 40, 60, "d"]]) +let new_df = df.append([[20, 40, 60, "d"]], [3]) new_df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ 0 │ 1 │ 2 │ 3 ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -55,8 +51,6 @@ new_df.print() ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - Shape: (4,4) - ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ 0 │ 1 │ 2 │ 3 ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -72,5 +66,4 @@ new_df.print() {% endtab %} {% endtabs %} -\*\*\*\* - +*** diff --git a/api-reference/dataframe/dataframe.apply_map.md b/api-reference/dataframe/dataframe.apply_map.md new file mode 100644 index 0000000..55a622c --- /dev/null +++ b/api-reference/dataframe/dataframe.apply_map.md @@ -0,0 +1,64 @@ +--- +description: Apply a function to a Dataframe values element-wise. +--- + +# DataFrame.applyMap + +danfo.DataFrame.applyMap(callable, options) + +| Parameters | Type | Description | Default | +| ---------- | -------- | --------------------------------------------------------------------- | --------- | +| callable | Function | Function to apply to each column or row | | +| options | Object | **axis**: 0 or 1. If 0, compute the power column-wise, if 1, row-wise | {axis: 1} | + +## **Examples** + +### Apply a function to each element in a DataFrame + +{% hint style="info" %} +Note that the specified function passed to **applyMap** will be called with each element in the DataFrame. If you need to apply a function across an axis, then use the [apply](danfo.dataframe.apply.md) function. +{% endhint %} + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + short_name: ["NG", "GH", "EGY", "SA"], + long_name: ["Nigeria", "Ghana", "Eqypt", "South Africa"] +} +let df = new dfd.DataFrame(data) + +function lower(x) { + return `${x}`.toLowerCase() +} + +let df_new = df.apply_map(lower) +df_new.print() +``` +{% endtab %} + +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ short_name │ long_name ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ ng │ nigeria ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ gh │ ghana ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ egy │ eqypt ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ sa │ south africa ║ +╚════════════╧═══════════════════╧═══════════════════╝ +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/dataframe.astype.md b/api-reference/dataframe/dataframe.astype.md index af73978..5e0d9cd 100644 --- a/api-reference/dataframe/dataframe.astype.md +++ b/api-reference/dataframe/dataframe.astype.md @@ -2,37 +2,13 @@ description: Cast column of a DataFrame to a specified dtype. --- -# DataFrame.astype - -danfo.DataFrame.**astype**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{

-

column: Array, label/column name of column to cast

-

dtype: dtype to cast to. One of [string, float32, int32]

-

}

-
- -**Returns:** - - ****return **DataFrame** +# DataFrame.asType + +danfo.DataFrame.asType(options) + +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | +| options | Object |

{

column: String, label/column name of column to cast

dtype: dtype to cast to. One of [string, float32, int32, boolean]

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| { inplace: false } | ## **Examples** @@ -52,7 +28,7 @@ let df = new dfd.DataFrame(data) df.print() df.ctypes.print() -let df_new = df.astype({column: "A", dtype: "int32"}) +let df_new = df.asType("A", "int32") df_new.print() df.ctypes.print() @@ -61,14 +37,13 @@ df.ctypes.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` //before casting ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C │ D ║ @@ -137,25 +112,23 @@ let data = { "A": [-20.1, 30, 47.3, -20] , "D": ["20", "13", "45", "90"] } let df = new dfd.DataFrame(data) -let df_new = df.astype({column: "D", dtype: "int32"}) +let df_new = df.asType("D", "int32") df_new.print() -df.ctypes.print() - +df_new.ctypes.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -168,18 +141,15 @@ df.ctypes.print() ║ 3 │ -20 │ 6 │ 40.11 │ 90 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ A │ float32 ║ -╟───┼──────────────────────╢ -║ B │ int32 ║ -╟───┼──────────────────────╢ -║ C │ float32 ║ -╟───┼──────────────────────╢ -║ D │ int32 ║ -╚═══╧══════════════════════╝ - +╔═══╤═════════╗ +║ A │ float32 ║ +╟───┼─────────╢ +║ B │ int32 ║ +╟───┼─────────╢ +║ C │ float32 ║ +╟───┼─────────╢ +║ D │ int32 ║ +╚═══╧═════════╝ ``` {% endtab %} {% endtabs %} @@ -197,26 +167,23 @@ let data = { "A": [-20.1, 30, 47.3, -20] , "D": ["a", "b", "c", "c"] } let df = new dfd.DataFrame(data) -let df_new = df.astype({column: "D", dtype: "int32"}) +let df_new = df.asType("D","int32") df_new.print() -df.ctypes.print() - +df_new.ctypes.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -229,18 +196,15 @@ df.ctypes.print() ║ 3 │ -20 │ 6 │ 40.11 │ NaN ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ A │ float32 ║ -╟───┼──────────────────────╢ -║ B │ int32 ║ -╟───┼──────────────────────╢ -║ C │ float32 ║ -╟───┼──────────────────────╢ -║ D │ int32 ║ -╚═══╧══════════════════════╝ +╔═══╤═════════╗ +║ A │ float32 ║ +╟───┼─────────╢ +║ B │ int32 ║ +╟───┼─────────╢ +║ C │ float32 ║ +╟───┼─────────╢ +║ D │ int32 ║ +╚═══╧═════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.at.md b/api-reference/dataframe/dataframe.at.md new file mode 100644 index 0000000..180413d --- /dev/null +++ b/api-reference/dataframe/dataframe.at.md @@ -0,0 +1,36 @@ +--- +description: Access a single value for a row/column label pair. +--- + +# DataFrame.at + +> danfo.DataFrame.at(row, column) + +| Parameters | Type | Description | Default | +| ---------- | -------------- | ------------------------- | ------- | +| row | Number, String | row position in the index | | +| column | String | Column position | | + +**Return:** Scalar + + + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + "Name": ["Apples", "Mango", "Banana", "Pear"], + "Count": [21, 5, 30, 10], + "Price": [200, 300, 40, 250] +} + +let df = new dfd.DataFrame(data, { index: [1, "b", "c", "d"] }) +df.at(1, "Count") + +//output +21 +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/dataframe.axes.md b/api-reference/dataframe/dataframe.axes.md index fbccf92..388d0cb 100644 --- a/api-reference/dataframe/dataframe.axes.md +++ b/api-reference/dataframe/dataframe.axes.md @@ -1,17 +1,12 @@ --- description: >- - Return an Object containing the axes of the DataFrame. It has the row axis - labels and column axis labels as the only members. They are returned in that - order. + Return an Object containing the axis of the DataFrame. It has the row axis + labels and column axis labels as the only members. --- -# DataFrame.axes +# DataFrame.axis -danfo.DataFrame.**axes** \[[source](https://github.com/opensource9ja/danfojs/blob/eb5919d2cac34271fc3b725fa24aa3ad4eacde37/danfojs/src/core/generic.js#L290)\] - -**Returns:** - - ****return **Object** +danfo.DataFrame.**axis** ## **Examples** @@ -26,24 +21,21 @@ let data = {"A": [-20.1, 30, 47.3, -20], let df = new dfd.DataFrame(data, {index: ["a", "b", "c", "d"]}) -console.log(df.axes) - +console.log(df.axis) ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` { index: [ 'a', 'b', 'c', 'd' ], columns: [ 'A', 'B', 'C' ] } ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.drop.md b/api-reference/dataframe/dataframe.drop.md index 039a74b..3ea14a2 100644 --- a/api-reference/dataframe/dataframe.drop.md +++ b/api-reference/dataframe/dataframe.drop.md @@ -6,44 +6,21 @@ description: >- # DataFrame.drop -danfo.DataFrame.**drop**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{

-

columns: [Array(Columns| Index)] array of column names to drop

-

index: [Array(Columns| Index)] index labels to drop

-

axis: row=0, columns=1

-

inplace: specify whether to drop the row/column with/without creating - a new DataFrame

-

}

-
{axis: 1, inplace:false}
+danfo.DataFrame.**drop**(options) + +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- | +| options | Object |

{

columns: Array of column names to drop.

index: Array of index labels to drop.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| {\*\*inplace:\*\*false} | **Returns:** - ****return **DataFrame** +\*\*\*\* return **DataFrame** ## **Examples** ### Drop columns by specifying the names -By setting **inplace** to _true_, the original DataFrame is modified and nothing is returned. To not modify the original DataFrame and return a new one, set **inplace** to false or leave it as default. +By setting **inplace** to _true_, the original DataFrame is modified and nothing is returned. To not modify the original DataFrame and return a new one, set **inplace** to false or leave it as default. {% tabs %} {% tab title="Node" %} @@ -56,21 +33,20 @@ let data = { "A": [-20, 30, 47.3, -20], "D": ["a", "b", "c", "c"] } let df = new dfd.DataFrame(data) -df.drop({ columns: ["C", "B"], axis: 1, inplace: true }); +df.drop({ columns: ["C", "B"], inplace: true }); df.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ A │ D ║ ╟───┼───────────────────┼───────────────────╢ @@ -93,28 +69,28 @@ df.print() ```javascript const dfd = require("danfojs-node") -let data = { "A": [-20, 30, 47.3, -20], - "B": [34, -4, 5, 6] , - "C": [20, 20, 30, 30], - "D": ["a", "b", "c", "c"] } +let data = { + "A": [-20, 30, 47.3, -20], + "B": [34, -4, 5, 6], + "C": [20, 20, 30, 30], + "D": ["a", "b", "c", "c"] +} let df = new dfd.DataFrame(data) -df.drop({ index: [0, 2], axis: 0, inplace: true }); +df.drop({ index: [0, 2], inplace: true }); df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -139,22 +115,20 @@ let data = { "A": [-20, 30, 47.3, -20], "D": ["a", "b", "c", "c"] } let df = new dfd.DataFrame(data, {index: ["a", "b", "c", "d"]}) -df.drop({ index: ["a", "c"], axis: 0, inplace: true }); +df.drop({ index: ["a", "c"], inplace: true }); df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -165,4 +139,3 @@ df.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.dtypes.md b/api-reference/dataframe/dataframe.dtypes.md index b59af75..489e570 100644 --- a/api-reference/dataframe/dataframe.dtypes.md +++ b/api-reference/dataframe/dataframe.dtypes.md @@ -7,15 +7,11 @@ description: >- # DataFrame.ctypes -danfo.DataFrame.**dtypes** \[[source](https://github.com/opensource9ja/danfojs/blob/eb5919d2cac34271fc3b725fa24aa3ad4eacde37/danfojs/src/core/frame.js#L1848)\] - -**Returns:** - - ****return **Series** +danfo.DataFrame.**dtypes** ## **Examples** -Returns auto-generated ****index of a ****DataFrame +Returns auto-generated index of a DataFrame {% tabs %} {% tab title="Node" %} @@ -34,14 +30,13 @@ df.ctypes.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -60,7 +55,6 @@ Columns with mixed types are represented as **string.** {% tabs %} {% tab title="Node" %} ```javascript - const dfd = require("danfojs-node") let data = {"A": [-20.1, 30, 47.3, -20], @@ -76,14 +70,13 @@ df.ctypes.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -99,5 +92,4 @@ df.ctypes.print() {% endtab %} {% endtabs %} -**Note**: To cast a type, use the [astype](dataframe.astype.md) method. - +**Note**: To cast a type, use the [asType](dataframe.astype.md) method. diff --git a/api-reference/dataframe/dataframe.iat.md b/api-reference/dataframe/dataframe.iat.md new file mode 100644 index 0000000..c50f4f3 --- /dev/null +++ b/api-reference/dataframe/dataframe.iat.md @@ -0,0 +1,36 @@ +--- +description: Access a single value for a row/column pair by integer position. +--- + +# DataFrame.iat + +> danfo.DataFrame.iat(row, column) + +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------- | ------- | +| row | Number | row index position | | +| column | Number | Column index position | | + +**Return:** Scalar + + + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + "Name": ["Apples", "Mango", "Banana", "Pear"], + "Count": [21, 5, 30, 10], + "Price": [200, 300, 40, 250] +} + +let df = new dfd.DataFrame(data, { index: [1, "b", "c", "d"] }) +df.iat(1, 2) + +//output +300 +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/dataframe/dataframe.index.md b/api-reference/dataframe/dataframe.index.md index cf14245..d38c7b5 100644 --- a/api-reference/dataframe/dataframe.index.md +++ b/api-reference/dataframe/dataframe.index.md @@ -4,15 +4,11 @@ description: The index (row labels) of the DataFrame. # DataFrame.index -danfo.DataFrame.**index** \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/frame.js#L940)\] - -**Returns:** - - ****return **new DataFrame** +danfo.DataFrame.**index** ## **Examples** -Returns auto-generated ****index of a ****DataFrame +Returns auto-generated index of a DataFrame {% tabs %} {% tab title="Node" %} @@ -30,21 +26,18 @@ console.log(df.index); {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` [0, 1, 2, 3] ``` {% endtab %} {% endtabs %} -Returns set ****index of a ****DataFrame - {% tabs %} {% tab title="Node" %} ```javascript @@ -61,16 +54,14 @@ console.log(df.index); {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` [ 'r1', 'r2', 'r3', 'r4' ] ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.ndim.md b/api-reference/dataframe/dataframe.ndim.md index a163ac4..d35bfb9 100644 --- a/api-reference/dataframe/dataframe.ndim.md +++ b/api-reference/dataframe/dataframe.ndim.md @@ -1,16 +1,12 @@ --- description: >- - Return an int representing the number of axes / array dimensions. Returns 1 if - Series. Otherwise return 2 for DataFrame. + Return an integer representing the number of dimensions. Returns 1 if Series. + Otherwise return 2 for DataFrame. --- # DataFrame.ndim -danfo.DataFrame.**ndim** \[[source](https://github.com/opensource9ja/danfojs/blob/eb5919d2cac34271fc3b725fa24aa3ad4eacde37/danfojs/src/core/generic.js#L290)\] - -**Returns:** - - ****return **Int** +danfo.DataFrame.**ndim** **Note:** To get the **shape** of the DataFrame use the .[shape](dataframe.shape.md) property. @@ -27,22 +23,19 @@ let data = {"A": [-20.1, 30, 47.3, -20], let df = new dfd.DataFrame(data) console.log(df.ndim) - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` 2 ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.nunique-1.md b/api-reference/dataframe/dataframe.nunique-1.md index 4cf2a14..177b0ec 100644 --- a/api-reference/dataframe/dataframe.nunique-1.md +++ b/api-reference/dataframe/dataframe.nunique-1.md @@ -1,18 +1,18 @@ -# DataFrame.nunique +--- +description: Returns the number of unique elements in a column, across the specified axis. +--- -danfo.DataFrame.**nunique**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/f84d7f53f2b0639e464f9483fb5cea969ad913d6/danfojs/src/core/frame.js#L1975)\] +# DataFrame.nUnique -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| axis | Int | 0 for row axis, and 1 for column axis | 1 | +danfo.DataFrame.nUnique(axis) \[[source](https://github.com/opensource9ja/danfojs/blob/f84d7f53f2b0639e464f9483fb5cea969ad913d6/danfojs/src/core/frame.js#L1975)] -**Returns:** - - ****return **Series** +| Parameters | Type | Description | Default | +| ---------- | ---- | ------------------------------------- | ------- | +| axis | Int | 0 for row axis, and 1 for column axis | 1 | ## **Examples** -### Return number of unique values along column axis \(axis=1\) +### Return number of unique values along default axis (axis=1) {% tabs %} {% tab title="Node" %} @@ -26,36 +26,32 @@ let data = { "A": [-20, 30, 47.3, -20] , let df = new dfd.DataFrame(data) df.nunique().print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ A │ 3 ║ -╟───┼──────────────────────╢ -║ B │ 4 ║ -╟───┼──────────────────────╢ -║ C │ 2 ║ -╟───┼──────────────────────╢ -║ D │ 3 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══╗ +║ 0 │ 4 ║ +╟───┼───╢ +║ 1 │ 4 ║ +╟───┼───╢ +║ 2 │ 4 ║ +╟───┼───╢ +║ 3 │ 4 ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} -### Return number of unique values in row axis \(axis=0\) +### Return number of unique values in row axis (axis=0) {% tabs %} {% tab title="Node" %} @@ -68,35 +64,30 @@ let data = { "A": [-20, 30, 47.3, -20] , "D": ["a", "b", "c", "c"] } let df = new dfd.DataFrame(data) -df.nunique(axis=0).print() - +df.nUnique(axis=0).print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 4 ║ -╟───┼──────────────────────╢ -║ 1 │ 4 ║ -╟───┼──────────────────────╢ -║ 2 │ 4 ║ -╟───┼──────────────────────╢ -║ 3 │ 4 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══╗ +║ A │ 3 ║ +╟───┼───╢ +║ B │ 4 ║ +╟───┼───╢ +║ C │ 2 ║ +╟───┼───╢ +║ D │ 3 ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} -**Note:** To get the unique elements along an axis, use ****[DataFrame.unique.](dataframe.nunique-1.md) - +**Note:** To get the unique elements along an axis, see [DataFrame.unique.](dataframe.nunique-1.md) diff --git a/api-reference/dataframe/dataframe.nunique.md b/api-reference/dataframe/dataframe.nunique.md deleted file mode 100644 index 53b88fd..0000000 --- a/api-reference/dataframe/dataframe.nunique.md +++ /dev/null @@ -1,96 +0,0 @@ ---- -description: >- - Return unique values of DataFrame along an axis. Uniques are returned in order - of appearance. Set-based unique, therefore does NOT sort. ---- - -# DataFrame.unique - -danfo.DataFrame.**unique**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/f84d7f53f2b0639e464f9483fb5cea969ad913d6/danfojs/src/core/frame.js#L1945)\] - -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| axis | Int | 0 for row axis, and 1 for column axis | 1 | - -**Returns:** - - ****return **Object** - -## **Examples** - -### Return unique values along column axis \(axis=1\) - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - -let data = { "A": [-20, 30, 47.3, -20], - "B": [34, -4, 5, 6] , - "C": [20, 20, 30, 30], - "D": ["a", "b", "c", "c"] } - -let df = new dfd.DataFrame(data) -console.log(df.unique()) //defaults to axis 1 -``` -{% endtab %} - -{% tab title="Browser" %} -``` - -``` -{% endtab %} -{% endtabs %} - -{% tabs %} -{% tab title="Output" %} -```text -{ - A: [ -20, 30, 47.3 ], - B: [ 34, -4, 5, 6 ], - C: [ 20, 30 ], - D: [ 'a', 'b', 'c' ] -} -``` -{% endtab %} -{% endtabs %} - -### Return unique values in row axis \(axis=0\) - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - -let data = { "A": [-20, 30, 47.3, -20], - "B": [34, -4, 5, 6] , - "C": [20, 20, 30, 30], - "D": ["a", "b", "c", "c"] } - -let df = new dfd.DataFrame(data) -console.log(df.unique(axis=0)); -``` -{% endtab %} - -{% tab title="Browser" %} -``` - -``` -{% endtab %} -{% endtabs %} - -{% tabs %} -{% tab title="Output" %} -```text -{ - '0': [ -20, 34, 20, 'a' ], - '1': [ 30, -4, 20, 'b' ], - '2': [ 47.3, 5, 30, 'c' ], - '3': [ -20, 6, 30, 'c' ] -} -``` -{% endtab %} -{% endtabs %} - -**Note:** To get the number of unique elements along an axis, use ****[DataFrame.nunique.](dataframe.nunique-1.md) - diff --git a/api-reference/dataframe/dataframe.print.md b/api-reference/dataframe/dataframe.print.md index de4ea91..be750a9 100644 --- a/api-reference/dataframe/dataframe.print.md +++ b/api-reference/dataframe/dataframe.print.md @@ -1,14 +1,12 @@ --- -description: Pretty prints n number of rows in a DataFrame or Series to the console +description: >- + Pretty prints default (10) number of rows in a DataFrame or Series to the + console --- # DataFrame.print -danfo.DataFrame.**print\(**rows**\)** \[[source](https://github.com/opensource9ja/danfojs/blob/eb5919d2cac34271fc3b725fa24aa3ad4eacde37/danfojs/src/core/generic.js#L290)\] - -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| **rows** | Int | Number of rows to display. | 5 | +danfo.DataFrame.**print()** ## **Examples** @@ -29,15 +27,13 @@ df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Abs │ Count │ country code ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -72,61 +68,38 @@ console.log(String(df)); {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` DataFrame { - kwargs: { columns: [ 'Abs', 'Count', 'country code' ] }, - series: false, - data: [ [ 20.2, 34, 'NG' ], [ 30, 4, 'FR' ], [ 47.3, 5, 'GH' ] ], - row_data_tensor: Tensor { - kept: false, - isDisposedInternal: false, - shape: [ 3, 3 ], - dtype: 'float32', - size: 9, - strides: [ 3 ], - dataId: {}, - id: 0, - rankType: '2' - }, - index_arr: [ 0, 1, 2 ], - columns: [ 'Abs', 'Count', 'country code' ], - col_data: [ [ 20.2, 30, 47.3 ], [ 34, 4, 5 ], [ 'NG', 'FR', 'GH' ] ], - col_data_tensor: Tensor { - kept: false, - isDisposedInternal: false, - shape: [ 3, 3 ], - dtype: 'float32', - size: 9, - strides: [ 3 ], - dataId: {}, - id: 1, - rankType: '2' + '$dataIncolumnFormat': [ [ 20.2, 30, 47.3 ], [ 34, 4, 5 ], [ 'NG', 'FR', 'GH' ] ], + '$index': [ 0, 1, 2 ], + '$columns': [ 'Abs', 'Count', 'country code' ], + '$dtypes': [ 'float32', 'int32', 'string' ], + '$isSeries': false, + '$config': Configs { + tableDisplayConfig: {}, + tableMaxRow: 10, + tableMaxColInConsole: 10, + dtypeTestLim: 20, + lowMemoryMode: false }, - col_types: [ 'float32', 'int32', 'string' ], - Abs: [Getter/Setter], - Count: [Getter/Setter], - 'country code': [Getter/Setter] + '$data': [ [ 20.2, 34, 'NG' ], [ 30, 4, 'FR' ], [ 47.3, 5, 'GH' ] ] } - //after casting to string - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ Abs │ Count │ country code ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 20.2 │ 34 │ NG ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 30 │ 4 │ FR ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 47.3 │ 5 │ GH ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Abs │ Count │ country code ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 20.2 │ 34 │ NG ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 30 │ 4 │ FR ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 47.3 │ 5 │ GH ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.rename.md b/api-reference/dataframe/dataframe.rename.md index 2a26f85..fae6861 100644 --- a/api-reference/dataframe/dataframe.rename.md +++ b/api-reference/dataframe/dataframe.rename.md @@ -1,86 +1,61 @@ --- description: >- - Change axes labels. Object values must be unique (1-to-1). Labels not + Change axis labels. Object values must be unique (1-to-1). Labels not contained in a dict / Series will be left as-is. Extra labels listed don’t throw an error. --- # DataFrame.rename -danfo.DataFrame.**rename**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{

-

mapper: Object of labels and transformations to apply to that axis’ - values.

-

axis: row=0, columns=1.

-

inplace: specify whether to perform the operation to the row/column - with/without creating a new DataFrame

-

}

-
{axis: 1, inplace:false}
- -**Returns:** - - ****return **DataFrame** +danfo.DataFrame.**rename**(mapper, options) + +| Parameters | Type | Description | Default | +| ----------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | +| **mapper** | Object | **L**abels and transformations to apply to that axis’ values. | | +| **options** | Object |

axis: row=0, columns=1.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

|

{

axis : 1,

inplace : false

}

| ## **Examples** -### Rename columns +### Rename columns -By setting **inplace** to _true_, the original DataFrame is modified and nothing is returned. To not modify the original DataFrame and return a new one, set **inplace** to false or leave it as default. +By setting **inplace** to _true_, the original DataFrame is modified and nothing is returned. To not modify the original DataFrame and return a new one, set **inplace** to false or leave it as default. {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = { "A": [-20, 30, 47.3], - "B": [34, -4, 5], - "C": [20, 2, 3, 30] } +let data = { + "A": [-20, 30, 47.3], + "B": [34, -4, 5], + "C": [20, 2, 30] +} let df = new dfd.DataFrame(data) -df.rename({ mapper: {"A": "new_name"},inplace: true }) +df.rename({ "A": "new_name" }, { inplace: true }) df.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ new_name │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ -20 │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 30 │ -4 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 47.3 │ 5 │ 30 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ new_name │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 30 │ -4 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 47.3 │ 5 │ 30 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} @@ -93,28 +68,26 @@ df.print() const dfd = require("danfojs-node") let data = { "A": [-20, 30, 47.3], - "B": [34, -4, 5, 6], - "C": [20, 2, 3, 30] } + "B": [34, -4, 6], + "C": [20, 2, 30] } let df = new dfd.DataFrame(data) -df = df.rename({ mapper: {"A": "new_name", "C": "new_c"}}) -df.print() +df = df.rename({ A: "new_name", C: "new_c" }) +df.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ new_name │ B │ new_c ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -135,29 +108,28 @@ df.print() ```javascript const dfd = require("danfojs-node") -let data = { "A": [-20, 30, 47.3], - "B": [34, -4, 5, 6], - "C": [20, 2, 3, 30] } +let data = { + "A": [-20, 30, 47.3], + "B": [34, -4, 6], + "C": [20, 2, 30] +} -let df = new dfd.DataFrame(data, {index: ["a", "b", "a"]}) -df = df.rename({ mapper: {"a": 0}, axis: 0}) +let df = new dfd.DataFrame(data, { index: ["a", "b", "c"] }) +df = df.rename({ "a": 0 }, { axis: 0 }) df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -170,4 +142,3 @@ df.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.reset_index.md b/api-reference/dataframe/dataframe.reset_index.md index 7d5ff53..410842c 100644 --- a/api-reference/dataframe/dataframe.reset_index.md +++ b/api-reference/dataframe/dataframe.reset_index.md @@ -1,18 +1,18 @@ --- -description: 'Reset the index of the DataFrame, and use the default one instead.' +description: Resets the index of the DataFrame, and use the default one instead. --- -# DataFrame.reset\_index +# DataFrame.resetIndex -danfo.DataFrame.**reset\_index**\(inplace\) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)\] +danfo.DataFrame.resetIndex(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| inplace | Boolean | **inplace**: specify whether to perform the operation to the row/column with/without creating a new DataFrame | false | +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------- | +| options | Object |

{

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| { **inplace**: false} | **Returns:** - ****return **DataFrame** +\*\*\*\* return **DataFrame** ## **Examples** @@ -21,56 +21,51 @@ danfo.DataFrame.**reset\_index**\(inplace\) \[[source](https://github.com/openso ```javascript const dfd = require("danfojs-node") -let data = { "A": [-20, 30, 47.3], - "B": [34, -4, 5, 6], - "C": [20, 2, 3, 30] } +let data = { + "A": [-20, 30, 47.3], + "B": [34, 5, 6], + "C": [20, 3, 30] +} -let df = new dfd.DataFrame(data, {index: ["a", "b", "a"]}) +let df = new dfd.DataFrame(data, { index: ["a", "b", "c"] }) df.print() -df.reset_index(true) //inplace -//df = df.reset_index() //not in inplace +df.resetIndex({ inplace: true }) //inplace +//df = df.resetIndex() //not in inplace df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ a │ -20 │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ b │ 30 │ -4 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ a │ 47.3 │ 5 │ 30 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - //after reseting index - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ -20 │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 30 │ -4 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 47.3 │ 5 │ 30 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ a │ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ b │ 30 │ 5 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ c │ 47.3 │ 6 │ 30 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 30 │ 5 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 47.3 │ 6 │ 30 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.select_dtypes.md b/api-reference/dataframe/dataframe.select_dtypes.md index f145e92..0623ca7 100644 --- a/api-reference/dataframe/dataframe.select_dtypes.md +++ b/api-reference/dataframe/dataframe.select_dtypes.md @@ -2,17 +2,13 @@ description: Return a subset of the DataFrame’s columns based on the column dtypes. --- -# DataFrame.select\_dtypes +# DataFrame.selectDtypes -danfo.DataFrame.**select\_dtypes** \[[source](https://github.com/opensource9ja/danfojs/blob/db48bf9701e1c3205811ba2699b42ce56ef7e63b/danfojs/src/core/frame.js#L778)\] +danfo.DataFrame.selectDtypes() -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| include | Array | List of column dtypes to return | | - -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ----- | ------------------------------- | ------- | +| include | Array | List of column dtypes to return | | ## **Examples** @@ -28,28 +24,27 @@ let data = {"A": [-20.1, 30, 47.3, -20], let df = new dfd.DataFrame(data) -float_df = df.select_dtypes(['float32']) + +float_df = df.selectDtypes(['float32']) float_df.print() -mix_df = df.select_dtypes(include=['float32', "int32"]) +mix_df = df.selectDtypes(['float32', "int32"]) mix_df.print() -str_df = df.select_dtypes(include=['string']) +str_df = df.selectDtypes(['string']) str_df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` //select float column(s) ╔═══╤══════════════════════╗ ║ │ A ║ @@ -93,4 +88,3 @@ str_df.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.set_index.md b/api-reference/dataframe/dataframe.set_index.md index a601c0b..4ff9b50 100644 --- a/api-reference/dataframe/dataframe.set_index.md +++ b/api-reference/dataframe/dataframe.set_index.md @@ -4,40 +4,13 @@ description: >- length). --- -# DataFrame.set\_index - -danfo.DataFrame.**set\_index**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{

-

key: This key can be either a single column name or a single array - of the same length as the calling DataFrame,

-

drop: Delete columns to be used as the new index.

-

inplace: specify whether to perform the operation to the row/column - with/without creating a new DataFrame

-

}

-
{drop: true, inplace:false}
- -**Returns:** - - ****return **DataFrame** +# DataFrame.setIndex + +danfo.DataFrame.setIndex(options) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)] + +| Parameters | Type | Description | Default | +| ---------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | +| options | Object |

{

index: An array of index values to set.

column: A column name to set the index to.

drop: Whether to drop the column whose index was set. Defaults to false.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| {**drop**: false, \*\*inplace:\*\*false} | ## **Examples** @@ -46,56 +19,101 @@ danfo.DataFrame.**set\_index**\(kwargs\) \[[source](https://github.com/opensourc {% tabs %} {% tab title="Node" %} ```javascript - const dfd = require("danfojs-node") let data = { "A": [-20, 30, 47.3], - "B": [34, -4, 5, 6], - "C": [20, 2, 3, 30] } + "B": [34, 5, 6], + "C": [20, 3, 30] } -let df = new dfd.DataFrame(data, {index: ["a", "b", "a"]}) +let df = new dfd.DataFrame(data, {index: ["a", "b", "c"]}) df.print() -df.set_index({key: "A", inplace: true}) +df.setIndex({column: "A", inplace: true}) df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ a │ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ b │ 30 │ 5 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ c │ 47.3 │ 6 │ 30 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ -20 │ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 30 │ 30 │ 5 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 47.3 │ 47.3 │ 6 │ 30 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +{% endtab %} +{% endtabs %} + +### **Setting index to a column in the DataFrame and dropping the column** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data = { "A": [-20, 30, 47.3], + "B": [34, 5, 6], + "C": [20, 3, 30] } + + +let df = new dfd.DataFrame(data, {index: ["a", "b", "c"]}) +df.print() + +df.setIndex({column: "A", drop: true, inplace: true}) +df.print() +``` +{% endtab %} +{% tab title="Browser" %} +``` ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ a │ -20 │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ b │ 30 │ -4 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ a │ 47.3 │ 5 │ 30 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - - -//after setting index - -╔══════╤═══════════════════╤═══════════════════╗ -║ │ B │ C ║ -╟──────┼───────────────────┼───────────────────╢ -║ -20 │ 34 │ 20 ║ -╟──────┼───────────────────┼───────────────────╢ -║ 30 │ -4 │ 20 ║ -╟──────┼───────────────────┼───────────────────╢ -║ 47.3 │ 5 │ 30 ║ -╚══════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ a │ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ b │ 30 │ 5 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ c │ 47.3 │ 6 │ 30 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ B │ C ║ +╟────────────┼───────────────────┼───────────────────╢ +║ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 30 │ 5 │ 3 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 47.3 │ 6 │ 30 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} @@ -108,56 +126,49 @@ df.print() const dfd = require("danfojs-node") let data = { "A": [-20, 30, 47.3], - "B": [34, -4, 5, 6], - "C": [20, 2, 3, 30] } + "B": [34, -5, 6], + "C": [20, 3, 30] } let df = new dfd.DataFrame(data) df.print() -let new_index = ["a", "b", "a"] -df.set_index({key: new_index, inplace: true}) +let new_index = ["a", "b", "c"] +df.setIndex({index: new_index, inplace: true}) df.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ -20 │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 30 │ -4 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 47.3 │ 5 │ 30 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - //after setting the index - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ a │ -20 │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ b │ 30 │ -4 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ a │ 47.3 │ 5 │ 30 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 30 │ -5 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 47.3 │ 6 │ 30 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ a │ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ b │ 30 │ -5 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ c │ 47.3 │ 6 │ 30 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} -**Note:** To reset an index to the default values, use the [DataFrame.reset\_index](dataframe.reset_index.md). - +**Note:** To reset an index to the default values, use the [DataFrame.resetIndex](dataframe.reset\_index.md). diff --git a/api-reference/dataframe/dataframe.shape.md b/api-reference/dataframe/dataframe.shape.md index ef0b4ca..e773461 100644 --- a/api-reference/dataframe/dataframe.shape.md +++ b/api-reference/dataframe/dataframe.shape.md @@ -4,11 +4,7 @@ description: Returns an Array representing the dimensionality of the DataFrame. # DataFrame.shape -danfo.DataFrame.**shape** \[[source](https://github.com/opensource9ja/danfojs/blob/eb5919d2cac34271fc3b725fa24aa3ad4eacde37/danfojs/src/core/generic.js#L290)\] - -**Returns:** - - ****return **Int** +danfo.DataFrame.**shape** ## **Examples** @@ -24,22 +20,19 @@ let df = new dfd.DataFrame(data, {index: ["a", "b", "c", "d"]}) console.log(df.shape) - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` [4,3] ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.size.md b/api-reference/dataframe/dataframe.size.md deleted file mode 100644 index a1cece6..0000000 --- a/api-reference/dataframe/dataframe.size.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -description: >- - Return an int representing the number of elements in this object. Return the - number of rows if Series. Otherwise return the number of rows times number of - columns if DataFrame. ---- - -# DataFrame.size - -danfo.DataFrame.**size** \[[source](https://github.com/opensource9ja/danfojs/blob/eb5919d2cac34271fc3b725fa24aa3ad4eacde37/danfojs/src/core/generic.js#L290)\] - -**Returns:** - - ****return **Int** - -## **Examples** - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - -let data = {"A": [-20.1, 30, 47.3, -20], - "B": [34, -4, 5, 6], - "C": [20, -20, 30, -40]} -let df = new dfd.DataFrame(data, {index: ["a", "b", "c", "d"]}) - -console.log(df.size) - - -``` -{% endtab %} - -{% tab title="Browser" %} -``` - -``` -{% endtab %} -{% endtabs %} - -{% tabs %} -{% tab title="Output" %} -```text -12 -``` -{% endtab %} -{% endtabs %} - diff --git a/api-reference/dataframe/dataframe.sort_index.md b/api-reference/dataframe/dataframe.sort_index.md index e95017b..9d867c0 100644 --- a/api-reference/dataframe/dataframe.sort_index.md +++ b/api-reference/dataframe/dataframe.sort_index.md @@ -2,38 +2,17 @@ description: Sort DataFrame by index --- -# DataFrame.sort\_index - -danfo.DataFrame.**sort\_index**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/2696f1d8420dd364464aae7c5c175c6cd0ef4c93/danfojs/src/core/frame.js#L2059)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{

-

ascending: Order of sorting

-

inplace: specify whether to perform the operation to the row/column - with/without creating a new DataFrame

-

}

-
{ascending: true, inplace:false}
+# DataFrame.sortIndex + +DataFrame.sortIndex(options) \[[source](https://github.com/opensource9ja/danfojs/blob/e25010c26d9c423412613d820015a48ad03d5c6d/danfojs-node/src/core/frame.js#L2094)] + +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | +| options | Object |

{

ascending: Sorting order.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

| {**ascending**: true, \*\*inplace:\*\*false} | **Returns:** - ****return **DataFrame** +\*\*\*\* return **DataFrame** ## **Examples** @@ -52,21 +31,20 @@ let df = new dfd.DataFrame(data, { "columns": ["col1", "col2", "col3", "col4"], index: ["b", "a", "c"] }) df.print() -let df2 = df.sort_index({ ascending: false }) +let df2 = df.sortIndex({ ascending: false }) df2.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ col1 │ col2 │ col3 │ col4 ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -93,5 +71,4 @@ df2.print() {% endtab %} {% endtabs %} -\*\*\*\* - +*** diff --git a/api-reference/dataframe/dataframe.sort_values.md b/api-reference/dataframe/dataframe.sort_values.md index 829c6c5..03b8981 100644 --- a/api-reference/dataframe/dataframe.sort_values.md +++ b/api-reference/dataframe/dataframe.sort_values.md @@ -2,40 +2,14 @@ description: Sort a Dataframe in ascending or descending order by a specified column name. --- -# DataFrame.sort\_values - -danfo.DataFrame.**sort\_values**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargsObject -

{

-

by: This key can be either a single column name or a single array - of the same length as the calling DataFrame,

-

ascending: Order of sorting

-

inplace: specify whether to perform the operation to the row/column - with/without creating a new DataFrame

-

}

-
{ascending: true, inplace:false}
- -**Returns:** - - ****return **DataFrame** +# DataFrame.sortValues + +danfo.DataFrame.**sortValues**(by, options) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)] + +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- | +| **by** | Object | This key can be either a single column name or a single array of the same length as the calling DataFrame. | | +| options | Object |

Optional configuration:

ascending: Order of sorting

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

|

{

ascending: true, inplace: false

}

| ## **Examples** @@ -46,37 +20,37 @@ danfo.DataFrame.**sort\_values**\(kwargs\) \[[source](https://github.com/opensou ```javascript const dfd = require("danfojs-node") -let data = { "A": [-20, 30, 47.3], - "B": [34, -4, 5, 6], - "C": [20, 2, 3, 30] } +let data = { + "A": [-20, 30, 47.3], + "B": [34, 5, 6], + "C": [20, 3, 30] +} let df = new dfd.DataFrame(data) -df.sort_values({by: "C", inplace: true}) +df.sortValues("C", { inplace: true }) df.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 30 │ -4 │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 47.3 │ 5 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ -20 │ 34 │ 20 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 30 │ 5 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 47.3 │ 6 │ 30 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} @@ -86,40 +60,38 @@ df.print() {% tabs %} {% tab title="Node" %} ```javascript - const dfd = require("danfojs-node") let data = { "A": [-20, 30, 47.3], - "B": [34, -4, 5, 6], - "C": [20, 2, 3, 30] } + "B": [34, 5, 6], + "C": [20, 3, 30] } + let df = new dfd.DataFrame(data) -df.sort_values({by: "B", inplace: true, ascending: false}) +df.sortValues("C", { ascending: false, inplace: true }) df.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ -20 │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 47.3 │ 5 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 30 │ -4 │ 2 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 47.3 │ 6 │ 30 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 30 │ 5 │ 3 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.tensor.md b/api-reference/dataframe/dataframe.tensor.md index 5f001fa..3a3eea6 100644 --- a/api-reference/dataframe/dataframe.tensor.md +++ b/api-reference/dataframe/dataframe.tensor.md @@ -1,18 +1,14 @@ --- description: >- - Return a Tensorflow tensor representation of the DataFrame. Only the values in - the DataFrame will be returned, the axes labels will be removed. + Return a Tensorflow tensor of the DataFrame. Only the values in the DataFrame + will be returned, the axis labels will be removed. --- # DataFrame.tensor -danfo.DataFrame.**tensor** \[[source](https://github.com/opensource9ja/danfojs/blob/eb5919d2cac34271fc3b725fa24aa3ad4eacde37/danfojs/src/core/generic.js#L290)\] +danfo.DataFrame.**tensor** -**Returns:** - - ****return **tf.tensor** - -> **Note:** [Tensorflow](https://js.tensorflow.org/api/latest/#tensor) tensors have single dtype \(mainly float32\), and will replace any string value with NaN. Use with care. +> **Note:** [Tensorflow](https://js.tensorflow.org/api/latest/#tensor) tensors have single dtype, and will replace any string value with NaN. Use with care. ## **Examples** @@ -38,22 +34,21 @@ tf_tensor.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` float32 Tensor { kept: false, isDisposedInternal: false, - shape: [ 3, 3 ], + shape: [ 4, 3 ], dtype: 'float32', - size: 9, + size: 12, strides: [ 3 ], dataId: {}, id: 0, @@ -62,13 +57,14 @@ Tensor { Tensor [[-20 , 34, 20], - [30 , -4, 2 ], - [47.2999992, 5 , 30]] + [30 , -4, 20], + [47.2999992, 5 , 30], + [-20 , 6 , 30]] ``` {% endtab %} {% endtabs %} -String values in a Tensor are represented as NaN, so ensure to transform them before working with tensor representations. +String values in a Tensor are represented as NaN, so ensure to transform them before working with tensor representations. {% tabs %} {% tab title="Node" %} @@ -76,7 +72,7 @@ String values in a Tensor are represented as NaN, so ensure to transform them be const dfd = require("danfojs-node") let data = { "Abs": [20.2, 30, 47.3] , - "Count": [34, 4, 5, 6] , + "Count": [34, 5, 6] , "country code": ["NG", "FR", "GH"] } @@ -93,14 +89,13 @@ tf_tensor.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` float32 Tensor { @@ -122,4 +117,3 @@ Tensor ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/dataframe/dataframe.to_csv.md b/api-reference/dataframe/dataframe.to_csv.md index 858cfa9..101cb4b 100644 --- a/api-reference/dataframe/dataframe.to_csv.md +++ b/api-reference/dataframe/dataframe.to_csv.md @@ -1,54 +1,117 @@ --- -description: Convert DataFrame data to a comma-separated values (csv) +description: Convert DataFrame to a comma-separated values (CSV) --- -# DataFrame.to\_csv +# DataFrame.toCSV -danfo.DataFrame.**to\_csv**\(path\) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)\] +{% hint style="danger" %} +Deprecated in v1.1.0: Use the [`dfd.toCSV`](../input-output/danfo.to\_csv.md) function directly instead +{% endhint %} + +DataFrame.toCSV(options) -**Returns:** +| | | | | +| -------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | +| **Parameters** | Type | Description | Default | +| **options** | object, optional |

Configuration object:

filePath: Local file path to write the CSV file to. If not specified, the CSV will be returned as a string. Only needed in Nodejs version


fileName: The name of the file to download as. Only needed in browser environment.


download: Boolean indicating whether to automatically download the CSV file in the browser. Only needed in the browser environment.

header: Boolean indicating whether to include a header row in the CSV file.

sep: Character to be used as a separator in the CSV file.

|

{
sep: ","
}

| - ****returns **Promise** +The **toCSV** function can be used to write out a DataFrame or Series to CSV file. The output is configurable and will depend on the environment. In the following examples, we show you how to write/download a CSV file from Node and Browser environments. -## **Examples** +*** -### Convert DataFrame to CSV format +### Convert DataFrame to CSV string and return value {% tabs %} -{% tab title="Node" %} +{% tab title="Node.js" %} ```javascript const dfd = require("danfojs-node") -let data = { "Abs": [20.2, 30, 47.3] , - "Count": [34, 4, 5, 6] , - "country code": ["NG", "FR", "GH"] } +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; +let df = new dfd.DataFrame(data); -let df = new dfd.DataFrame(data) +const csv = df.toCSV(); +console.log(csv); -df.to_csv("/home/link/to/path.csv").then((csv) => { - console.log(csv); - -}).catch((err) => { +//output +Abs,Count,country code +20.2,34,NG +30,4,FR +47.3,5,GH +``` +{% endtab %} - console.log(err); -}) +{% tab title="Browser" %} +```markup + + + + + + + + Document + + + + + + + + ``` {% endtab %} {% endtabs %} +### Convert DataFrame to CSV and write to local file path + +Writing a CSV file to a local file path is only supported in the Nodejs environment + {% tabs %} -{% tab title="Output" %} -```text -Abs,Count,country code -20.2,34,NG -30,4,FR -47.3,5,GH +{% tab title="Node.js" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + df.toCSV({ filePath: "testOut.csv"}); ``` {% endtab %} {% endtabs %} -{% hint style="info" %} -To export DataFrame as Json, use [DataFrame.to\_json](dataframe.to_json.md) -{% endhint %} +### Convert DataFrame to CSV and download file in browser + +You can automatically convert and download a CSV file in a browser environment, by specifying a `fileName` and setting `download` to **true**. + +```javascript +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); +df.toCSV({ fileName: "testOut.csv", download: true}); +``` diff --git a/api-reference/dataframe/dataframe.to_excel.md b/api-reference/dataframe/dataframe.to_excel.md new file mode 100644 index 0000000..7157518 --- /dev/null +++ b/api-reference/dataframe/dataframe.to_excel.md @@ -0,0 +1,57 @@ +--- +description: >- + Converts a DataFrame or Series to Excel file and write file to disk or + download in browser. +--- + +# DataFrame.toExcel + +{% hint style="danger" %} +Deprecated in v1.1.0: Use the [`dfd.toExcel`](../input-output/danfo.to\_excel.md) function directly instead +{% endhint %} + +> DataFrame.toExcel(options) + +| **Parameters** | Type | Description | Default | +| -------------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | +| **options** | object, optional |

Configuration object:

filePath: Local file path to write the CSV file to. If not specified, the CSV will be returned as a string. Only needed in Nodejs version


fileName: The name of the file to download as. Only needed in the browser environment.


sheetName: Name to call the excel sheet.

|

{
filePath: "./output.xlsx",
sheetName: "Sheet1"

}

| + +The **toExcel** function can be used to write out a DataFrame or Series to Excel (**.xlsx**) file. The output format will depend on the environment. In the following examples, we show you how to write/download an Excel file from Node and Browser environments. + +### Convert DataFrame to Excel and write to file path + +Writing an Excel file to a local file path is only supported in the Nodejs environment + +{% tabs %} +{% tab title="Node.js" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + +df.toExcel({ filePath: "testOut.xlsx"}); +``` +{% endtab %} +{% endtabs %} + +### Convert DataFrame to Excel and download the file in a browser + +You can automatically convert and download an Excel file in a browser environment, by specifying a `fileName`. + +```javascript +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + +df.toExcel({ fileName: "testOut.xlsx", download: true }); +``` diff --git a/api-reference/dataframe/dataframe.to_json.md b/api-reference/dataframe/dataframe.to_json.md index 968ca81..3a6f4db 100644 --- a/api-reference/dataframe/dataframe.to_json.md +++ b/api-reference/dataframe/dataframe.to_json.md @@ -2,50 +2,130 @@ description: Convert DataFrame to JSON format --- -# DataFrame.to\_json +# DataFrame.toJSON -danfo.DataFrame.**to\_json**\(path\) \[[source](https://github.com/opensource9ja/danfojs/blob/cf5c7ae3a009458e61eedd18d9c9b5b6b10d5276/danfojs/src/core/frame.js#L125)\] +{% hint style="danger" %} +Deprecated in v1.1.0: Use the [dfd.toJSON](../input-output/danfo.to\_json.md) function directly instead +{% endhint %} -**Returns:** +> DataFrame.toJSON(options) - ****returns **Promise** +| | | | | +| -------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------- | +| **Parameters** | Type | Description | Default | +| **options** | object, optional |

Configuration object:

filePath: Local file path to write the CSV file to. If not specified, the CSV will be returned as a string. Only needed in Nodejs version


fileName: The name of the file to download as. Only needed in browser environment.


format: The format of the JSON. Can be one of row or column.

|

{
format: "column"
}

| -## **Examples** +The **toJSON** function can be used to write out a DataFrame or Series to JSON format/file. The output is configurable and will depend on the environment. In the following examples, we show you how to write/download a JSON file from Node and Browser environments. -### Convert DataFrame to JSON format +### Convert DataFrame/Series to JSON and return value {% tabs %} -{% tab title="Node" %} +{% tab title="Node.js" %} ```javascript const dfd = require("danfojs-node") -let data = { "Abs": [20.2, 30, 47.3] , - "Count": [34, 4, 5, 6] , - "country code": ["NG", "FR", "GH"] } +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + +const jsonObj = df.toJSON(); //defaults to column format +console.log(jsonObj); + +//output +[ + { Abs: 20.2, Count: 34, 'country code': 'NG' }, + { Abs: 30, Count: 4, 'country code': 'FR' }, + { Abs: 47.3, Count: 5, 'country code': 'GH' } +] + +//row format +const jsonObjRow = df.toJSON({ + format: "row" +}); + + +console.log(jsonObjRow); +//output +{ + Abs: [ 20.2, 30, 47.3 ], + Count: [ 34, 4, 5 ], + 'country code': [ 'NG', 'FR', 'GH' ] +} +``` +{% endtab %} + +{% tab title="Browser" %} +```markup + + + + + + + Document + -let df = new dfd.DataFrame(data) + -df.to_json("/home/link/to/path.csv").then((json) => { - console.log(json); -}).catch((err) => { - console.log(err); -}) + + + + ``` {% endtab %} {% endtabs %} +### Convert DataFrame/Series to JSON and write to local file path + +Writing a DataFrame/Series as JSON, to a local file path is only supported in the Nodejs environment + {% tabs %} -{% tab title="Output" %} -```text -[{"Abs":20.2,"Count":34,"country code":"NG"}, -{"Abs":30,"Count":4,"country code":"FR"}, -{"Abs":47.3,"Count":5,"country code":"GH"}] +{% tab title="Node.js" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + +df.toJSON({ filePath: "./testOutput.json" }); ``` {% endtab %} {% endtabs %} -{% hint style="info" %} -To export DataFrame as CSV, use [DataFrame.to\_csv](dataframe.to_json.md) -{% endhint %} +### Convert DataFrame/Series to JSON and download file in browser + +You can automatically convert and download a DataFrame/Series as a JSON file in a browser environment, by specifying a `fileName` and setting `download` to **true**. + +```javascript +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); +df.toJSON({ fileName: "test_out.json", download: true }); +``` diff --git a/api-reference/dataframe/dataframe.values.md b/api-reference/dataframe/dataframe.values.md index 0f87f7f..99c6d6b 100644 --- a/api-reference/dataframe/dataframe.values.md +++ b/api-reference/dataframe/dataframe.values.md @@ -4,13 +4,9 @@ description: Return a the JavaScript array representation of the DataFrame. # DataFrame.values -danfo.DataFrame.**values** \[[source](https://github.com/opensource9ja/danfojs/blob/eb5919d2cac34271fc3b725fa24aa3ad4eacde37/danfojs/src/core/generic.js#L290)\] +danfo.DataFrame.**values** -**Returns:** - - ****return **Array** - -**Note:** To get the [Tensorflow](https://js.tensorflow.org/) tensor backing the DataFrame, you can call the **.**[**tensor**](dataframe.tensor.md) property on the DataFrame. +**Note:** To get the [Tensorflow](https://js.tensorflow.org) tensor of the DataFrame, you can call the **.**[**tensor**](dataframe.tensor.md) property on the DataFrame. ## **Examples** @@ -26,20 +22,18 @@ let data = {"A": [-20.1, 30, 47.3, -20], let df = new dfd.DataFrame(data) console.log(df.values) - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` [ [ -20.1, 34, 20 ], [ 30, -4, -20 ], @@ -49,4 +43,3 @@ console.log(df.values) ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/general-functions/README.md b/api-reference/general-functions/README.md index b74b5da..52a0787 100644 --- a/api-reference/general-functions/README.md +++ b/api-reference/general-functions/README.md @@ -4,25 +4,52 @@ description: Top level functions that can be called from the Danfo namespace # General Functions -### Data manipulations +### Data transformation -| | | -| :--- | :--- | -| [`merge`](danfo.merge.md) | Merge DataFrame or named Series objects with a database-style join. | -| [`concat`](danfo.concat.md) | Concatenate danfo objects along a particular axis with optional set logic along the other axes. | -| [`get_dummies`](danfo.get_dummies.md) | Convert categorical variable into dummy/indicator variables. Similar to OneHotEncoding | +| | | +| ------------------------------------- | ----------------------------------------------------------------------------------------------- | +| [`merge`](danfo.merge.md) | Merge DataFrame or named Series objects with a database-style join. | +| [`concat`](danfo.concat.md) | Concatenate danfo objects along a particular axis with optional set logic along the other axes. | +| [`getDummies`](danfo.get\_dummies.md) | Convert categorical variable into dummy/indicator variables. Similar to OneHotEncoding | -### Data Processing/Normalization +### Data Normalization -| [LabelEncoder](danfo.labelencoder.md) | Encode target labels with value between 0 and n\_classes-1. | -| :--- | :--- | -| [OneHotEncoder](danfo.onehotencoder.md) | Encode categorical features as a one-hot numeric array. | +| [LabelEncoder](danfo.labelencoder.md) | Encode target labels with value between 0 and n\_classes-1. | +| ----------------------------------------- | ---------------------------------------------------------------------- | +| [OneHotEncoder](danfo.onehotencoder.md) | Encode categorical features as a one-hot numeric array. | | [StandardScaler](danfo.standardscaler.md) | Standardize features by removing the mean and scaling to unit variance | -| [`MinMaxScaler`](danfo.minmaxscaler.md) | Transform features by scaling each feature to a given range | +| [`MinMaxScaler`](danfo.minmaxscaler.md) | Transform features by scaling each feature to a given range | -### Top-level dealing with datetime +### Working with DateTime -| [`to_datetime`](danfo.to_datetime.md) | Convert argument to datetime. | -| :--- | :--- | -| [`date_range`](danfo.date_range.md) | Return a fixed frequency DatetimeIndex. | +| [`toDateTime`](danfo.to\_datetime.md) | Convert argument to datetime. | +| ------------------------------------- | ----------------------------------------------------------------------------------------------------- | +| [`dateRange`](danfo.date\_range.md) | Return a fixed frequency Datetime Index. | +| [Dt](danfo.dt.md) | A class that converts strings of Date Time into a usable format, by exposing various helper methods. | + +### Streaming Functions + +| [streamCSV](danfo.streamcsv.md) | A function that loads a CSV object as a stream, returning intermediate rows as a DataFrame. | +| ---------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | +| [streamJSON](danfo.streamjson.md) | A function that loads a JSON object as a stream, returning intermediate rows as a DataFrame. | +| [streamCSVTransformer](danfo.streamcsvtransformer.md) | A function that loads a CSV object as a stream, and applies a map-reduce function to intermediate rows. | +| [convertFunctionTotransformer](danfo.-convertfunctiontotransformer.md) | A function to convert any JS function into a Stream transformer. | + + + +### Utility and Configurations + +| [Utils](danfo.utils.md) | A utility class with helper methods mostly used internally. | +| -------------------------- | ------------------------------------------------------------ | +| [Config](broken-reference) | Base configuration class for NDframe objects | + +### Strings + +| [Str](danfo.str.md) | A class that converts strings into a usable format, by exposing various helper methods. | +| ------------------- | --------------------------------------------------------------------------------------- | + +### Internal Libs + +| [tensoflow](danfo.tensorflow.md) | Exported Tensorflow.js library. This helps to avoid duplicated Tensorflow.js library use. | +| -------------------------------- | ------------------------------------------------------------------------------------------ | diff --git a/api-reference/general-functions/danfo.-convertfunctiontotransformer.md b/api-reference/general-functions/danfo.-convertfunctiontotransformer.md new file mode 100644 index 0000000..08be24f --- /dev/null +++ b/api-reference/general-functions/danfo.-convertfunctiontotransformer.md @@ -0,0 +1,103 @@ +--- +description: Converts a function to a pipe transformer. Only available in Nodejs version. +--- + +# danfo. convertFunctionTotransformer + +danfo.**convertFunctionTotransformer**(func) + +| Parameters | Type | Description | Default | +| ---------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------- | +| **func** | Function | A valid JavaScript function to convert to a [pipe transformer.](https://nodejs.org/api/stream.html#implementing-a-transform-stream) | | + +**Returns:** + +> return A [pipe transformer](https://nodejs.org/api/stream.html#implementing-a-transform-stream) that applies the function to each row of object. + +The **convertFunctionTotransformer** takes a function and converts it to a Nodejs stream transformer function which can be used in combination with streamCsvTransformer to incrementally transform large files. + +## **Converting a function to a transformer** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +/* + * A simple function that takes each row of a DataFrame and splits the + * name field. +*/ +const renamer = (dfRow: DataFrame) => { + const dfModified = dfRow["Names"].map((name) => name.split(",")[0]) + return dfModified +} + +const transformer = dfd.convertFunctionTotransformer(renamer) +console.log(transformer) +``` +{% endtab %} + +{% tab title="Browser" %} +```markup + + + + + + + + + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +Transform { + _readableState: ReadableState { + objectMode: true, + highWaterMark: 16, + buffer: BufferList { head: null, tail: null, length: 0 }, + length: 0, + pipes: [], + flowing: null, + ended: false, + endEmitted: false, + reading: false, + sync: false, + needReadable: false, + emittedReadable: false, + readableListening: false, + resumeScheduled: false, + errorEmitted: false, + emitClose: true, + autoDestroy: true, + destroyed: false, + errored: null, + closed: false, + closeEmitted: false, + defaultEncoding: 'utf8', + awaitDrainWriters: null, + writecb: null, + writechunk: null, + writeencoding: null + } +} +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/general-functions/danfo.concat.md b/api-reference/general-functions/danfo.concat.md index 3422f83..cb0cde1 100644 --- a/api-reference/general-functions/danfo.concat.md +++ b/api-reference/general-functions/danfo.concat.md @@ -4,41 +4,15 @@ description: Concatenate DataFrames and Series along an axis # danfo.concat -danfo.**concat**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L254)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargs - Object -

{

-

df_list: List of DataFrames or Series to concatenate together.

-

axis: One of 0 or 1. The axis on which to perform concatenation. - Specified axis must align in both Objects

-

}

-
{axis: 1}
- -**Returns:** - - ****return **DataFrame** +danfo.**concat**(options) + +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | +| options | Object |

{

dfList: List of DataFrames or Series to concatenate together.

axis: One of 0 or 1. The axis on which to perform concatenation. Specified axis must align in both Objects

}

| {**axis**: 1} | ## **Examples** -### **Concatenate two DataFrames along column axis \(1\)** +### **Concatenate two DataFrames along column axis (1)** {% tabs %} {% tab title="Node" %} @@ -59,21 +33,20 @@ let df1 = new dfd.DataFrame(data, { columns: colum1 }) let df2 = new dfd.DataFrame(data2, { columns: colum2 }) -let com_df = dfd.concat({ df_list: [df1, df2], axis: 1 }) +let com_df = dfd.concat({ dfList: [df1, df2], axis: 1 }) com_df.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Key1 │ Key2 │ A │ ... │ Key1_2 │ Key2_2 │ A_2 │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -89,7 +62,7 @@ com_df.print() {% endtab %} {% endtabs %} -### **Concatenate two DataFrames along row axis \(0\)** +### **Concatenate two DataFrames along row axis (0)** {% tabs %} {% tab title="Node" %} @@ -110,22 +83,20 @@ let df1 = new dfd.DataFrame(data, { columns: colum1 }) let df2 = new dfd.DataFrame(data2, { columns: colum2 }) -let com_df = dfd.concat({ df_list: [df1, df2], axis: 0 }) +let com_df = dfd.concat({ dfList: [df1, df2], axis: 0 }) com_df.print(10) ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Key1 │ Key2 │ A │ B │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -149,7 +120,7 @@ com_df.print(10) {% endtab %} {% endtabs %} -### **Concatenate two Series along row axis \(0\)** +### **Concatenate two Series along row axis (0)** {% tabs %} {% tab title="Node" %} @@ -170,22 +141,20 @@ let df1 = new dfd.DataFrame(data, { columns: colum1 }) let df2 = new dfd.DataFrame(data2, { columns: colum2 }) -let com_df = dfd.concat({ df_list: [df1, df2], axis: 0 }) +let com_df = dfd.concat({ dfList: [df1, df2], axis: 0 }) com_df.print(10) ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Key1 │ Key2 │ A │ B │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -209,5 +178,4 @@ com_df.print(10) {% endtab %} {% endtabs %} -See also [danfo.concat ](danfo.concat.md)for joining objects based on axis. - +See also [danfo.merge ](danfo.merge.md)for joining objects based SQL-like joins. diff --git a/api-reference/general-functions/danfo.date_range.md b/api-reference/general-functions/danfo.date_range.md index c172783..efcfb4c 100644 --- a/api-reference/general-functions/danfo.date_range.md +++ b/api-reference/general-functions/danfo.date_range.md @@ -2,40 +2,13 @@ description: Return a fixed frequency Dates spread between start and end parameters. --- -# danfo.date\_range - -danfo.**date\_range**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L254)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargs - Object -

{

-

start: str or datetime-like. Left bound for generating dates.

-

end: str or datetime-like. Right bound for generating dates.

-

period : int. Number of periods to generate.

-

freq: str or DateOffset, one of ["M","D","s","H","m","Y"].

-

}

-
{freq: 'D'}
- -**Returns:** - - ****return **DataFrame** +# danfo.dateRange + +danfo.**dateRange**(options) + +| Parameters | Type | Description | +| ----------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **options** | Object |

Includes any of the following:

start: Left bound for generating dates.

end: Right bound for generating dates.

period : Number of periods to generate.

offSet: Date range offset

freq: Date range frequency. One of ["M","D","s","H","m","Y"]

| ## **Examples** @@ -44,7 +17,7 @@ danfo.**date\_range**\(kwargs\) \[[source](https://github.com/opensource9ja/danf ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":'1/1/2018',period:5, freq:'M'}) +let data = new dfd.dateRange({"start":'1/1/2018', period:5, freq:'M'}) console.log(data); ``` {% endtab %} @@ -73,14 +46,13 @@ console.log(data); - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` [ '1/1/2018, 12:00:00 AM', '2/1/2018, 12:00:00 AM', @@ -97,21 +69,20 @@ console.log(data); ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":'1/1/2018',period:12, freq:'Y'}) +let data = new dfd.dateRange({ "start": '1/1/2018', period: 12, freq: 'Y' }) console.log(data); ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` [ '1/1/2018, 12:00:00 AM', '1/1/2019, 12:00:00 AM', @@ -131,6 +102,5 @@ console.log(data); {% endtabs %} {% hint style="info" %} -datetime properties of Series or datetime-like columns in DataFrame can be accessed via accessors in the **dt** name space. See [Accessors](https://app.gitbook.com/@jsdata/s/danfojs/~/drafts/-MEMaWwva1cjt8CxnG-b/api-reference/series#accessors) +Datetime properties of Series or datetime-like columns in DataFrame can be accessed via accessors in the **dt** name space. See [Accessors](https://app.gitbook.com/@jsdata/s/danfojs/\~/drafts/-MEMaWwva1cjt8CxnG-b/api-reference/series#accessors) {% endhint %} - diff --git a/api-reference/general-functions/danfo.dt.md b/api-reference/general-functions/danfo.dt.md new file mode 100644 index 0000000..1e5b59b --- /dev/null +++ b/api-reference/general-functions/danfo.dt.md @@ -0,0 +1,48 @@ +--- +description: Accessor object for date time properties of the Series values. +--- + +# danfo.Dt + +For example, in the following example, we convert a Series to an `Dt` instance and apply a couple of **DateTime** methods. + +{% tabs %} +{% tab title="Node" %} +```javascript +import { Dt, Series } from "danfojs-node" + +const sf = new Series(["1/1/2000", "1/2/2000", "2/3/2000", "1/4/2000", "4/5/2000"]) +const dtS = new Dt(sf) + +dtS.dayOfWeekName().print() +dtS.monthName().print() +``` +{% endtab %} +{% endtabs %} + +``` +// output +╔═══╤═══════════╗ +║ 0 │ Saturday ║ +╟───┼───────────╢ +║ 1 │ Sunday ║ +╟───┼───────────╢ +║ 2 │ Thursday ║ +╟───┼───────────╢ +║ 3 │ Tuesday ║ +╟───┼───────────╢ +║ 4 │ Wednesday ║ +╚═══╧═══════════╝ + +╔═══╤══════════╗ +║ 0 │ January ║ +╟───┼──────────╢ +║ 1 │ January ║ +╟───┼──────────╢ +║ 2 │ February ║ +╟───┼──────────╢ +║ 3 │ January ║ +╟───┼──────────╢ +║ 4 │ April ║ +╚═══╧══════════╝ +``` diff --git a/api-reference/general-functions/danfo.get_dummies.md b/api-reference/general-functions/danfo.get_dummies.md index 1cb3b8f..9af101a 100644 --- a/api-reference/general-functions/danfo.get_dummies.md +++ b/api-reference/general-functions/danfo.get_dummies.md @@ -2,40 +2,14 @@ description: Convert categorical variable into dummy/indicator variables. --- -# danfo.get\_dummies - -danfo.**get\_dummies**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L254)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargs - Object -

{

-

data: Array | Series | DataFrame

-

prefix_sep: String separator for created columns e.g "_",

-

prefix: String | Array of String, of column names

-

columns: [Array] columns to be encoded in DataFrame.

-

}

-
{prefix_sep: "_"}
- -**Returns:** - - ****return **DataFrame** +# danfo.getDummies + +danfo.**getDummies**(kwargs) + +| Parameters | Type | Description | Default | +| ----------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | +| data | Series or Dataframe | The data to dummify | | +| **options** | Object |

These includes:

columns: Array of column names to dummify. If not specified, all categorical columns are encoded.

prefixSeparator: String separator for created columns e.g "_",

prefix: Prefix for the new columns

|

{

prefixSeparator: "-"

}

| ## **Examples** @@ -49,35 +23,33 @@ const dfd = require("danfojs-node") let datasf = ['pear', 'mango', "pawpaw", "mango", "bean"] let sf1 = new dfd.Series(datasf) -let dum_df = dfd.get_dummies({data: sf1, prefix:"fruit"}) +let dum_df = dfd.getDummies(sf1, { prefix: "fruit" }) dum_df.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ fruit_pear │ fruit_mango │ fruit_pawpaw │ fruit_bean ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 0 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 0 │ 1 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 0 │ 0 │ 1 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 0 │ 1 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ 0 │ 0 │ 0 │ 1 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ fruit_pear │ fruit_mango │ fruit_pawpaw │ fruit_bean ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 0 │ 0 │ 0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 0 │ 1 │ 0 │ 0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 0 │ 0 │ 1 │ 0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 0 │ 1 │ 0 │ 0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ 0 │ 0 │ 0 │ 1 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} @@ -96,21 +68,20 @@ let data = { fruits: ['pear', 'mango', "pawpaw", "mango", "bean"], let df = new dfd.DataFrame(data) df.print() -let dum_df = dfd.get_dummies({ data: df }) +let dum_df = dfd.getDummies(df) dum_df.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ fruits │ Count │ Country ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -159,21 +130,20 @@ let data = { fruits: ['pear', 'mango', "pawpaw", "mango", "bean"], let df = new dfd.DataFrame(data) df.print() -let dum_df = dfd.get_dummies({ data: df, columns: ['fruits']}) +let dum_df = dfd.getDummies(df, { columns: ['fruits']}) dum_df.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ fruits │ Count │ Country ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -211,4 +181,3 @@ dum_df.print() {% hint style="info" %} See also [LabelEncoder](danfo.labelencoder.md) and [OneHotEncoder](danfo.onehotencoder.md) {% endhint %} - diff --git a/api-reference/general-functions/danfo.labelencoder.md b/api-reference/general-functions/danfo.labelencoder.md index 1951475..9944f53 100644 --- a/api-reference/general-functions/danfo.labelencoder.md +++ b/api-reference/general-functions/danfo.labelencoder.md @@ -4,11 +4,11 @@ description: Encode target labels with value between 0 and n_classes-1. # danfo.LabelEncoder -class danfo.**LabelEncoder** \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L254)\] +class danfo.**LabelEncoder** -danfo.js provides the LabelEncoder class for encoding Series and Arrays to integer between 0 and n\_classes -1. This is mostly used as a preprocessing step before most machine learning tasks. +danfo.js provides the LabelEncoder class for encoding Series and Arrays to integer between 0 and n\_classes -1. This is mostly used as a preprocessing step before most machine learning tasks. -The API is similar to sklearn's [LabelEncoder](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html?highlight=labelencoder#sklearn.preprocessing.LabelEncoder), and provides a fit and transform method. +The API is similar to sklearn's [LabelEncoder](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html?highlight=labelencoder#sklearn.preprocessing.LabelEncoder), and provides a fit and transform method. ## **Examples** @@ -17,6 +17,8 @@ The API is similar to sklearn's [LabelEncoder](https://scikit-learn.org/stable/m {% tabs %} {% tab title="Node" %} ```javascript +const dfd = require('danfojs-node') + let data = ["dog","cat","man","dog","cat","man","man","cat"] let series = new dfd.Series(data) @@ -26,51 +28,23 @@ encode.fit(series) console.log(encode); let sf_enc = encode.transform(series.values) -sf_enc.print() +console.log(sf_enc) let new_sf = encode.transform(["dog","man"]) -new_sf.print() -``` -{% endtab %} - -{% tab title="Browser" %} -``` - +console.log(new_sf) ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -LabelEncoder { label: [ 'dog', 'cat', 'man' ] } -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 0 ║ -╟───┼──────────────────────╢ -║ 1 │ 1 ║ -╟───┼──────────────────────╢ -║ 2 │ 2 ║ -╟───┼──────────────────────╢ -║ 3 │ 0 ║ -╟───┼──────────────────────╢ -║ 4 │ 1 ║ -╟───┼──────────────────────╢ -║ 5 │ 2 ║ -╟───┼──────────────────────╢ -║ 6 │ 2 ║ -╟───┼──────────────────────╢ -║ 7 │ 1 ║ -╚═══╧══════════════════════╝ - -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 0 ║ -╟───┼──────────────────────╢ -║ 1 │ 2 ║ -╚═══╧══════════════════════╝ +``` +LabelEncoder { '$labels': { dog: 0, cat: 1, man: 2 } } +[ + 0, 1, 2, 0, + 1, 2, 2, 1 +] +[ 0, 2 ] ``` {% endtab %} {% endtabs %} @@ -96,48 +70,27 @@ encode.fit(df['fruits']) console.log(encode); let sf_enc = encode.transform(df['fruits'].values) -sf_enc.print() +console.log(sf_enc); -let new_sf = encode.transform(["mango","man"]) -new_sf.print() +let new_sf = encode.transform(["mango","mane"]) +console.log(new_sf); ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -LabelEncoder { label: [ 'pear', 'mango', 'pawpaw', 'bean' ] } -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 0 ║ -╟───┼──────────────────────╢ -║ 1 │ 1 ║ -╟───┼──────────────────────╢ -║ 2 │ 2 ║ -╟───┼──────────────────────╢ -║ 3 │ 1 ║ -╟───┼──────────────────────╢ -║ 4 │ 3 ║ -╚═══╧══════════════════════╝ - -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 1 ║ -╟───┼──────────────────────╢ -║ 1 │ -1 ║ -╚═══╧══════════════════════╝ +``` +LabelEncoder { '$labels': { pear: 0, mango: 1, pawpaw: 2, bean: 3 } } +[ 0, 1, 2, 1, 3 ] +[ 1, -1 ] ``` {% endtab %} {% endtabs %} -See also [OneHotEncoder](danfo.onehotencoder.md) and[ danfo.get\_dummies](danfo.get_dummies.md) - +See also [OneHotEncoder](danfo.onehotencoder.md) and[ danfo.getDummies](danfo.get\_dummies.md) diff --git a/api-reference/general-functions/danfo.merge.md b/api-reference/general-functions/danfo.merge.md index 54b3330..63252a3 100644 --- a/api-reference/general-functions/danfo.merge.md +++ b/api-reference/general-functions/danfo.merge.md @@ -6,52 +6,23 @@ description: >- # danfo.merge -danfo.**merge**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L254)\] - - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargs - Object -

{

-

left: A DataFrame or named Series object.

-

right: Another DataFrame or named Series object.

-

on: Column names to join on. Must be found in both the left and - right DataFrame and/or Series objects.

-

how: One of 'left','right','outer', 'inner'. - Defaults to 'inner'

-

}

-
{how: inner}
- -**Returns:** - - ****return **DataFrame** +danfo.**merge**(options) + +| Parameters | Type | Description | +| ---------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | Object |

left: A DataFrame or named Series object.

right: Another DataFrame or named Series object.

on: Column names to join on. Must be found in both the left and right DataFrame and/or Series objects.

how: One of 'left','right','outer', 'inner'. Defaults to 'inner'

| ## **Examples** -**danfo.js** merge function is similar to Pandas merge and performs in-memory join operations idiomatically very similar to relational databases like SQL. +**danfo.js** merge function is similar to Pandas merge and performs in-memory join operations idiomatically very similar to relational databases like SQL. danfo.js provides a single function, [`merge()`](danfo.merge.md), as the entry point for all standard database join operations between `DataFrame` or named `Series` objects. -For a more intuitive understanding, this [guide](https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#brief-primer-on-merge-methods-relational-algebra) on the [Pandas](https://pandas.pydata.org/pandas-docs/stable) doc is worth reading. +For a more intuitive understanding, this [guide](https://pandas.pydata.org/pandas-docs/stable/user\_guide/merging.html#brief-primer-on-merge-methods-relational-algebra) on the [Pandas](https://pandas.pydata.org/pandas-docs/stable) doc is worth reading. ### **Merging by a single key found in both axis** -By default, danfo performs _**inner**_ join. An inner join requires each row in the two joined DataFrames to have matching column values. This is similar to the **intersection** of two sets. It returns a DataFrame with only those rows that have common characteristics. +In the following example, we perform an inner join. An inner join requires each row in the two joined DataFrames to have matching column values. This is similar to the **intersection** of two sets. It returns a DataFrame with only those rows that have common characteristics. {% tabs %} {% tab title="Node" %} @@ -73,22 +44,20 @@ let df2 = new dfd.DataFrame(data2, { columns: colum2 }) df1.print() df2.print() -let merge_df = dfd.merge({ "left": df1, "right": df2, "on": ["Key1"]}) +let merge_df = dfd.merge({ "left": df1, "right": df2, "on": ["Key1"], how: "inner"}) merge_df.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` //first DataFrame ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Key1 │ Key2 │ A │ B ║ @@ -131,7 +100,6 @@ merge_df.print() ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ ║ 3 │ K2 │ K2 │ A3 │ B3 │ K0 │ C3 │ D3 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - ``` {% endtab %} {% endtabs %} @@ -143,7 +111,6 @@ Merging by two keys takes into consideration the keys appearing in both`left` an {% tabs %} {% tab title="Node" %} ```javascript - const dfd = require("danfojs-node") @@ -169,14 +136,13 @@ merge_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` //first DataFrame ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Key1 │ Key2 │ A │ B ║ @@ -217,12 +183,11 @@ merge_df.print() ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ ║ 2 │ K1 │ K0 │ A2 │ B2 │ C2 │ D2 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - ``` {% endtab %} {% endtabs %} -The how parameter takes other types of joins like left, right and outer join and these are similar to their SQL equivalent +The how parameter takes other types of joins like left, right and outer join and these are similar to their SQL equivalent ### Outer join/merge on DataFrame @@ -254,14 +219,13 @@ merge_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` //First DataFrame ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Key1 │ Key2 │ A │ B ║ @@ -339,14 +303,13 @@ merge_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` //first DataFrame ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Key1 │ Key2 │ A │ B ║ @@ -424,14 +387,13 @@ merge_df.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` //first DataFrame ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Key1 │ Key2 │ A │ B ║ @@ -481,4 +443,3 @@ merge_df.print() {% hint style="info" %} See also [danfo.concat ](danfo.concat.md)for joining objects based on axis. {% endhint %} - diff --git a/api-reference/general-functions/danfo.minmaxscaler.md b/api-reference/general-functions/danfo.minmaxscaler.md index b0c4310..a607336 100644 --- a/api-reference/general-functions/danfo.minmaxscaler.md +++ b/api-reference/general-functions/danfo.minmaxscaler.md @@ -4,13 +4,13 @@ description: Transform features by scaling each feature to a range of max and mi # danfo.MinMaxScaler -class danfo.**MinMaxScaler** \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L254)\] +class danfo.**MinMaxScaler** danfo.js provides the MinMaxScaler class for standardization of DataFrame and Series. This estimator scales and translates each feature individually such that it is in the given range on the training set, e.g. between zero and one. This transformation is often used as an alternative to zero mean, unit variance scaling like [Standardscaler](danfo.standardscaler.md). -The API is similar to sklearn's [MinMaxScaler](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html?highlight=minmaxscaler#sklearn.preprocessing.MinMaxScaler), and provides a fit and transform method. +The API is similar to sklearn's [MinMaxScaler](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html?highlight=minmaxscaler#sklearn.preprocessing.MinMaxScaler), and provides a fit and transform method. ## **Examples** @@ -34,21 +34,18 @@ scaler.fit(df) let df_enc = scaler.transform(df) df_enc.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ 0 │ 1 │ 2 │ 3 ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -88,27 +85,24 @@ let data = [[100,1000,2000, 3000] , [1, 1, 1, 0]] let df = new dfd.DataFrame(data) -let sf = df.iloc({columns: ["0"]}) +let sf = df.iloc({columns: [0]}) scaler.fit(sf) let df_enc = scaler.transform(sf) df_enc.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` Shape: (3,1) ╔═══╤═══════════════════╗ @@ -125,4 +119,3 @@ df_enc.print() {% endtabs %} See also [MinMaxScaler](danfo.minmaxscaler.md) - diff --git a/api-reference/general-functions/danfo.onehotencoder.md b/api-reference/general-functions/danfo.onehotencoder.md index 752a196..8d7c979 100644 --- a/api-reference/general-functions/danfo.onehotencoder.md +++ b/api-reference/general-functions/danfo.onehotencoder.md @@ -4,11 +4,11 @@ description: Encode categorical features as a one-hot numeric array. # danfo.OneHotEncoder -class danfo.**OneHotEncoder** \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L254)\] +class danfo.**OneHotEncoder** -danfo.js provides the OneHotEncoder class for encoding values in Series and Arrays to one-hot numeric arrays. This is mostly used as a preprocessing step before most machine learning tasks. +danfo.js provides the OneHotEncoder class for encoding values in Series and Arrays to one-hot numeric arrays. This is mostly used as a preprocessing step before most machine learning tasks. -The API is similar to sklearn's [OneHotEncoder](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html?highlight=onehotencoder#sklearn.preprocessing.OneHotEncoder), and provides a fit and transform method. +The API is similar to scikit-learn's [OneHotEncoder](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html?highlight=onehotencoder#sklearn.preprocessing.OneHotEncoder), and provides a fit and transform method. ## **Examples** @@ -19,9 +19,11 @@ The API is similar to sklearn's [OneHotEncoder](https://scikit-learn.org/stable/ ```javascript const dfd = require("danfojs-node") -let data = { fruits: ['pear', 'mango', "pawpaw", "mango", "bean"], - Count: [20, 30, 89, 12, 30], - Country: ["NG", "NG", "GH", "RU", "RU"]} +let data = { + fruits: ['pear', 'mango', "pawpaw", "mango", "bean"], + Count: [20, 30, 89, 12, 30], + Country: ["NG", "NG", "GH", "RU", "RU"] +} let df = new dfd.DataFrame(data) @@ -31,49 +33,26 @@ encode.fit(df['fruits']) console.log(encode); let sf_enc = encode.transform(df['fruits'].values) -sf_enc.print() - -let new_sf = encode.transform(["mango","bean"]) -new_sf.print() -``` -{% endtab %} - -{% tab title="Browser" %} -``` +console.log(sf_enc) +let new_sf = encode.transform(["mango", "bean"]) +console.log(new_sf) ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ pear │ mango │ pawpaw │ bean ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 0 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 0 │ 1 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 0 │ 0 │ 1 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 0 │ 1 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ 0 │ 0 │ 0 │ 1 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - Shape: (2,4) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ pear │ mango │ pawpaw │ bean ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 0 │ 1 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 0 │ 0 │ 0 │ 1 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - +``` +OneHotEncoder { '$labels': [ 'pear', 'mango', 'pawpaw', 'bean' ] } +[ + [ 1, 0, 0, 0 ], + [ 0, 1, 0, 0 ], + [ 0, 0, 1, 0 ], + [ 0, 1, 0, 0 ], + [ 0, 0, 0, 1 ] +] +[ [ 0, 1, 0, 0 ], [ 0, 0, 0, 1 ] ] ``` {% endtab %} {% endtabs %} @@ -82,70 +61,4 @@ new_sf.print() **Labels not found in the original data used for fitting are represented with 0s all through** {% endhint %} -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - -let data = { fruits: ['pear', 'mango', "pawpaw", "mango", "bean"] , - Count: [20, 30, 89, 12, 30], - Country: ["NG", "NG", "GH", "RU", "RU"]} - - -let df = new dfd.DataFrame(data) -let encode = new dfd.OneHotEncoder() - -encode.fit(df['fruits']) -console.log(encode); - -let sf_enc = encode.transform(df['fruits'].values) -sf_enc.print() - -let new_sf = encode.transform(["mango","woman", "cup"]) -new_sf.print() -``` -{% endtab %} - -{% tab title="Browser" %} -``` - -``` -{% endtab %} -{% endtabs %} - -{% tabs %} -{% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ pear │ mango │ pawpaw │ bean ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 0 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 0 │ 1 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 0 │ 0 │ 1 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 0 │ 1 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ 0 │ 0 │ 0 │ 1 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - Shape: (3,4) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ pear │ mango │ pawpaw │ bean ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 0 │ 1 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 0 │ 0 │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 0 │ 0 │ 0 │ 0 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - -``` -{% endtab %} -{% endtabs %} - -See also [LabelEncoder](danfo.labelencoder.md) and[ danfo.get\_dummies](danfo.get_dummies.md) - +See also [LabelEncoder](danfo.labelencoder.md) and[ danfo.getDummies](danfo.get\_dummies.md) diff --git a/api-reference/general-functions/danfo.standardscaler.md b/api-reference/general-functions/danfo.standardscaler.md index 5e66567..323f53d 100644 --- a/api-reference/general-functions/danfo.standardscaler.md +++ b/api-reference/general-functions/danfo.standardscaler.md @@ -4,15 +4,15 @@ description: Standardize features by removing the mean and scaling to unit varia # danfo.StandardScaler -class danfo.**StandScaler** \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L254)\] +class danfo.**StandScaler** -danfo.js provides the StandardScaler class for standardization of DataFrame and Series. The standard score of a sample `x` is calculated as: +danfo.js provides the StandardScaler class for the standardization of DataFrame and Series. The standard score of a sample `x` is calculated as: -> z = \(x - u\) / s +> z = (x - u) / s where `u` is the mean of the training samples or zero if `with_mean=False`, and `s` is the standard deviation of the training samples or one if `with_std=False`. -The API is similar to sklearn's [StandardScaler](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html?highlight=standardscaler#sklearn.preprocessing.StandardScaler), and provides a fit and transform method. +The API is similar to sklearn's [StandardScaler](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html?highlight=standardscaler#sklearn.preprocessing.StandardScaler), and provides a fit and transform method. ## **Examples** @@ -37,37 +37,32 @@ sf_enc.print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 100 ║ -╟───┼──────────────────────╢ -║ 1 │ 1000 ║ -╟───┼──────────────────────╢ -║ 2 │ 2000 ║ -╟───┼──────────────────────╢ -║ 3 │ 3000 ║ -╚═══╧══════════════════════╝ - -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ -1.1375757455825806 ║ -╟───┼──────────────────────╢ -║ 1 │ -0.4191068708896637 ║ -╟───┼──────────────────────╢ -║ 2 │ 0.37919193506240845 ║ -╟───┼──────────────────────╢ -║ 3 │ 1.1774907112121582 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤══════╗ +║ 0 │ 100 ║ +╟───┼──────╢ +║ 1 │ 1000 ║ +╟───┼──────╢ +║ 2 │ 2000 ║ +╟───┼──────╢ +║ 3 │ 3000 ║ +╚═══╧══════╝ + +╔═══╤═════════════════════╗ +║ 0 │ -1.3135592937469482 ║ +╟───┼─────────────────────╢ +║ 1 │ -0.4839428961277008 ║ +╟───┼─────────────────────╢ +║ 2 │ 0.4378530979156494 ║ +╟───┼─────────────────────╢ +║ 3 │ 1.3596490621566772 ║ +╚═══╧═════════════════════╝ ``` {% endtab %} {% endtabs %} @@ -78,58 +73,53 @@ sf_enc.print() {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let scaler = new dfd.StandardScaler() -let data = [[100,1000,2000, 3000] , - [20, 30, 89, 12], - [1, 1, 1, 0]] -let df = new dfd.DataFrame(data) +let data = [[100, 1000, 2000, 3000], + [20, 30, 89, 12], + [1, 1, 1, 0]] + +let df = new dfd.DataFrame(data, { columns: ['a', 'b', 'c', 'd'] }) df.print() +let scaler = new dfd.StandardScaler() scaler.fit(df) let df_enc = scaler.transform(df) df_enc.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ 0 │ 1 │ 2 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 100 │ 1000 │ 2000 │ 3000 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 20 │ 30 │ 20 │ 10 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 1 │ 1 │ 1 │ 0 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - Shape: (3,4) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ 0 │ 1 │ 2 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ -0.4185734987... │ 0.48862975835... │ 1.49663341045... │ 2.50463700294... ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ -0.4992137849... │ -0.4891337454319 │ -0.4992137849... │ -0.5092938542... ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ -0.5183658599... │ -0.5183658599... │ -0.5183658599... │ -0.5193738341... ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ a │ b │ c │ d ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 100 │ 1000 │ 2000 │ 3000 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 20 │ 30 │ 89 │ 12 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 1 │ 1 │ 1 │ 0 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ a │ b │ c │ d ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1.3909024000167… │ 1.4137537479400… │ 1.4131401777267… │ 1.4142049551010… ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ -0.473994612693… │ -0.675643563270… │ -0.658863127231… │ -0.702851355075… ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ -0.916907668113… │ -0.738110065460… │ -0.754277229309… │ -0.711353600025… ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} See also [MinMaxScaler](danfo.minmaxscaler.md) - diff --git a/api-reference/general-functions/danfo.str.md b/api-reference/general-functions/danfo.str.md new file mode 100644 index 0000000..f12c428 --- /dev/null +++ b/api-reference/general-functions/danfo.str.md @@ -0,0 +1,67 @@ +--- +description: Accessor object for String-like properties of Series values. +--- + +# danfo.Str + +For example, in the following example, we convert a Series to an `Str` instance and apply a couple of **String** methods. + +{% tabs %} +{% tab title="Node" %} +```javascript +import { Str, Series } from "danfojs-node" + +const sf = new Series(["Dog", "Cat", "Bird", "Fish", "ShArk", "tiGer"]) +const sfStr = new Str(sf) + +sfStr.toLowerCase().print() +sfStr.toUpperCase().print() +sfStr.join("Added", "-").print() +``` +{% endtab %} +{% endtabs %} + +``` +// output +╔═══╤═══════╗ +║ 0 │ dog ║ +╟───┼───────╢ +║ 1 │ cat ║ +╟───┼───────╢ +║ 2 │ bird ║ +╟───┼───────╢ +║ 3 │ fish ║ +╟───┼───────╢ +║ 4 │ shark ║ +╟───┼───────╢ +║ 5 │ tiger ║ +╚═══╧═══════╝ + +╔═══╤═══════╗ +║ 0 │ DOG ║ +╟───┼───────╢ +║ 1 │ CAT ║ +╟───┼───────╢ +║ 2 │ BIRD ║ +╟───┼───────╢ +║ 3 │ FISH ║ +╟───┼───────╢ +║ 4 │ SHARK ║ +╟───┼───────╢ +║ 5 │ TIGER ║ +╚═══╧═══════╝ +╔═══╤═════════════╗ +║ 0 │ Dog-Added ║ +╟───┼─────────────╢ +║ 1 │ Cat-Added ║ +╟───┼─────────────╢ +║ 2 │ Bird-Added ║ +╟───┼─────────────╢ +║ 3 │ Fish-Added ║ +╟───┼─────────────╢ +║ 4 │ ShArk-Added ║ +╟───┼─────────────╢ +║ 5 │ tiGer-Added ║ +╚═══╧═════════════╝ + +``` diff --git a/api-reference/general-functions/danfo.streamcsv.md b/api-reference/general-functions/danfo.streamcsv.md new file mode 100644 index 0000000..f70b704 --- /dev/null +++ b/api-reference/general-functions/danfo.streamcsv.md @@ -0,0 +1,104 @@ +--- +description: >- + Streams a CSV file from a local or remote location in chunks. Each + intermediate chunk is passed as a DataFrame to the callback function. +--- + +# danfo.streamCSV + +danfo.**streamCSV**(filePath, callback, options) + +| Parameters | Type | Description | +| ---------- | -------- | -------------------------------------------------------------------------------------------------------------- | +| filePath | string | URL or local file path to CSV file. | +| callback | Function | Callback function to be called once the specifed rows are parsed into DataFrame. | +| options | object | Optional configuration object. Supports all [Papaparse](https://www.papaparse.com/docs#config) config options. | + +The **streamCSV** function streams a CSV file from a local or remote location in chunks. Each intermediate chunk is passed as a DataFrame to the callback function. + +## **Stream CSV file from local path** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") +const path = require("path") + +const filePath = path.join(process.cwd(), "raw_data", "titanic.csv"); + +dfd.streamCSV(filePath, (df) => { + if (df) { + // Do any processing here + df.print(); + } +}); +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +//Showing few rows +... + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ PassengerId │ Survived │ Pclass │ Name │ ... │ Fare │ Cabin │ Embarked ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 676 │ 687 │ 0 │ 3 │ Panula, Mr. Jaa… │ ... │ 39.6875 │ │ S ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ PassengerId │ Survived │ Pclass │ Name │ ... │ Fare │ Cabin │ Embarked ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 677 │ 688 │ 0 │ 3 │ Dakic, Mr. Bran… │ ... │ 10.1708 │ │ S ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +... +``` +{% endtab %} +{% endtabs %} + +## **Stream CSV file from remote path** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +const remoteFile = "https://raw.githubusercontent.com/opensource9ja/danfojs/dev/danfojs-node/tests/samples/titanic.csv" + +const callback = (df) => { + //Perform any processing here + if (df) { + df.print(); + } +} + +dfd.streamCSV(remoteFile, callback, { header: true }) +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +//Showing a few rows +... + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Survived │ Pclass │ Name │ Sex │ Age │ Siblings/Spouse… │ Parents/Childre… │ Fare ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 523 │ 0 │ 1 │ Mr. John Farthi… │ male │ 49 │ 0 │ 0 │ 221.7792 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Survived │ Pclass │ Name │ Sex │ Age │ Siblings/Spouse… │ Parents/Childre… │ Fare ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 524 │ 0 │ 3 │ Mr. Johan Werne… │ male │ 39 │ 0 │ 0 │ 7.925 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +... +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/general-functions/danfo.streamcsvtransformer.md b/api-reference/general-functions/danfo.streamcsvtransformer.md new file mode 100644 index 0000000..30363fc --- /dev/null +++ b/api-reference/general-functions/danfo.streamcsvtransformer.md @@ -0,0 +1,179 @@ +--- +description: >- + A pipeline transformer to stream a CSV file from local storage, transform it + with a custom transformer, and write to the output stream. Only available in + Node.js +--- + +# danfo.streamCsvTransformer + +danfo.**streamCsvTransformer**(func) + +| Parameters | Type | Description | +| ------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| inputFilePath | Function | The path to the CSV file to stream from. | +| transformer | Function |

The transformer function to apply to each row.

Note that each row of the CSV file is passed as a DataFrame with a single row to the transformer function, and the transformer function is expected to return a transformed DataFrame.

| +| options | object |

Configuration options for the pipeline. These include:

| + +**Returns:** + +> A promise that resolves when the pipeline transformation is complete. + +The streamCsvTransformer can be used to [incrementally transform](https://en.wikipedia.org/wiki/Stream\_processing) a CSV file. This is done by: + +* Streaming a CSV file from a local or **remote** path. +* Passing each corresponding row as a DataFrame to the specified transformer function. +* Writing the result to an output stream. + +## **Stream processing a local file** + +In the example below, we stream a local CSV file (titanic.csv), apply a transformer function, and write the output to **`titanicOutLocal.csv`**. + +The transformer takes each `Name` column, splits the person's title, and creates a new column from it. + +{% tabs %} +{% tab title="Node" %} +```javascript +import { DataFrame, Series, streamCsvTransformer } from "danfojs-node"; +import path from "path" + +const inputFilePath = path.join(process.cwd(), "raw_data", "titanic.csv"); +const outputFilePath = path.join(process.cwd(), "raw_data", "titanicOutLocal.csv"); + +/** + * A simple function that takes a DataFrame, and transforms the Name column. +* */ +const transformer = (df) => { + const titles = df["Name"].map((name) => name.split(".")[0]); + const names = df["Name"].map((name) => name.split(".")[1]); + df["Name"] = names + df.addColumn("titles", titles, { inplace: true }) + return df +} + +dfd.streamCsvTransformer(inputFilePath, transformer, { + outputFilePath, + inputStreamOptions: { header: false } +}) +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +//initial head of titanic.csv before transforming + +PassengerId,Survived,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked +1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S +2,1,1,"Cumings, Mrs. John Bradley (Florence Briggs Thayer)",female,38,1,0,PC 17599,71.2833,C85,C +3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,STON/O2. 3101282,7.925,,S + + +//Head of titanicOutLocal.csv after transforming + +PassengerId,Survived,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked,titles +1,0,3, Owen Harris,male,22,1,0,A/5 21171,7.25,,S,Braund, Mr +2,1,1, John Bradley (Florence Briggs Thayer),female,38,1,0,PC 17599,71.2833,C85,C,Cumings, Mrs +3,1,3, Laina,female,26,0,0,STON/O2. 3101282,7.925,,S,Heikkinen, Miss +``` +{% endtab %} +{% endtabs %} + +## **Stream processing of remote file** + +In the example below, we stream a remote CSV file (titanic.csv), applies a transformer function, and write the output to the `titanicOutLocal` file. + +The transformer takes each `Name` column, splits the person's title, and creates a new column from it. + +{% tabs %} +{% tab title="Node" %} +```javascript +import { DataFrame, Series, streamCsvTransformer } from "danfojs-node"; +import path from "path" + +const inputFilePath = "https://raw.githubusercontent.com/opensource9ja/danfojs/dev/danfojs-node/tests/samples/titanic.csv" +const outputFilePath = path.join(process.cwd(), "raw_data", "titanicOutRemote.csv"); + + +/** + * A simple function that takes a DataFrame, and transforms the Name column. +* */ +const transformer = (df) => { + const titles = df["Name"].map((name) => name.split(".")[0]); + const names = df["Name"].map((name) => name.split(".")[1]); + df["Name"] = names + df.addColumn("titles", titles, { inplace: true }) + return df +} + +dfd.streamCsvTransformer(inputFilePath, transformer, { + outputFilePath, + inputStreamOptions: { header: false } +}) +``` +{% endtab %} +{% endtabs %} + +## **Stream processing with a custom writer** + +If you need custom control of the output writer, then you can provide a pipe-able custom writer. See [https://www.freecodecamp.org/news/node-js-streams-everything-you-need-to-know-c9141306be93/](https://www.freecodecamp.org/news/node-js-streams-everything-you-need-to-know-c9141306be93/) + +In the example below, we add a custom writer that logs each row. You can extend this to upload each chunk to a database, or any other function you need. + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require('danfojs-node-nightly') +const path = require("path") +const stream = require("stream") + +const inputFilePath = "https://raw.githubusercontent.com/opensource9ja/danfojs/dev/danfojs-node/tests/samples/titanic.csv" + +const transformer = (df) => { + const titles = df["Name"].map((name) => name.split(".")[0]); + const names = df["Name"].map((name) => name.split(".")[1]); + df["Name"] = names + df.addColumn("titles", titles, { inplace: true }) + return df +} +let count = 0 + +const customWriter = function () { + const csvOutputStream = new stream.Writable({ objectMode: true }) + csvOutputStream._write = (chunk, encoding, callback) => { + //Do anything here. For example you can write to online storage DB + console.log("Chunk written: " + chunk) // Eah chunk is a row DataFrame + count += 1 + callback() + + } + return csvOutputStream +} + +dfd.streamCsvTransformer( + inputFilePath, + transformer, + { + customCSVStreamWriter: customWriter, + inputStreamOptions: { header: true } + }) +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +//Showing the last log +... + +Chunk written: +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Survived │ Pclass │ Name │ Sex │ Age │ Siblings/Spouse… │ Parents/Childre… │ Fare │ titles ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 884 │ 0 │ 3 │ Patrick Dooley │ male │ 32 │ 0 │ 0 │ 7.75 │ Mr ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/general-functions/danfo.streamjson.md b/api-reference/general-functions/danfo.streamjson.md new file mode 100644 index 0000000..c834210 --- /dev/null +++ b/api-reference/general-functions/danfo.streamjson.md @@ -0,0 +1,101 @@ +--- +description: >- + Streams a JSON file from a local or remote location in chunks. Each + intermediate chunk is passed as a DataFrame to the callback function. +--- + +# danfo.streamJSON + +danfo.**streamJSON**(filePath, callback, options) + +| Parameters | Type | Description | +| ---------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| filePath | string | URL or local file path to CSV file. | +| callback | Function | Callback function to be called once the specifed rows are parsed into DataFrame. | +| options | object | Optional configuration object. We use the `request` library for reading remote json files, Hence all `request` parameters such as `method`, `headers`, are supported. | + +The **streamJSON** function streams a JSON file from a local or remote location in chunks. Each intermediate chunk is passed as a DataFrame to the callback function. + +## **Stream JSON file from local path** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") +const path = require("path") + +const filePath = path.join(process.cwd(), "raw_data", "book_small.json"); + +dfd.streamJSON(filePath, (df) => { + if (df) { + // Do any processing here + df.print(); + } +}); +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +//Showing the last rows +... + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ book_id │ title │ image_url │ authors ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 10 │ 32848471 │ Egomaniac │ https://images.… │ Vi Keeland ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ book_id │ title │ image_url │ authors ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 11 │ 33288638 │ Wait for It │ https://s.gr-as… │ Mariana Zapata ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +{% endtab %} +{% endtabs %} + +## **Stream JSON file from remote path** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") +const path = require("path") + +const remoteFile = "https://raw.githubusercontent.com/opensource9ja/danfojs/dev/danfojs-node/tests/samples/book.json" + +const callback = (df) => { + //Perform any processing here + if (df) { + df.print(); + } +} + +dfd.streamJSON(remoteFile, callback, { header: true }) +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +//Showing a few rows +... + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ book_id │ title │ image_url │ authors ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 10 │ 32848471 │ Egomaniac │ https://images.… │ Vi Keeland ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ book_id │ title │ image_url │ authors ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 11 │ 33288638 │ Wait for It │ https://s.gr-as… │ Mariana Zapata ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/general-functions/danfo.tensorflow.md b/api-reference/general-functions/danfo.tensorflow.md new file mode 100644 index 0000000..727f08c --- /dev/null +++ b/api-reference/general-functions/danfo.tensorflow.md @@ -0,0 +1,70 @@ +--- +description: Exported internal Tensoflow.js library +--- + +# danfo.tensorflow + +danfo.**tensorflow** + +**Returns:** + +> return [Tensorflow.js](https://www.npmjs.com/package/@tensorflow/tfjs) library + +## **Examples** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") +const tf = dfd.tensorflow + +let tensor_arr = tf.tensor2d([[12, 34, 2.2, 2], [30, 30, 2.1, 7]]) +console.log(tensor_arr) +``` +{% endtab %} + +{% tab title="Browser" %} +```markup + + + + + + + + + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +Tensor { + kept: false, + isDisposedInternal: false, + shape: [ 2, 4 ], + dtype: 'float32', + size: 8, + strides: [ 4 ], + dataId: {}, + id: 4, + rankType: '2' +} +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/general-functions/danfo.to_datetime.md b/api-reference/general-functions/danfo.to_datetime.md index 2e7c0a3..2adb884 100644 --- a/api-reference/general-functions/danfo.to_datetime.md +++ b/api-reference/general-functions/danfo.to_datetime.md @@ -1,149 +1,136 @@ --- -description: Convert Object to datetime format +description: Converts an array of Date strings to Date object. --- -# danfo.to\_datetime +# danfo.toDateTime -danfo.**to\_datetime**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L254)\] +danfo.**toDateTime**(data) - - - - - - - - - - - - - - - - - -
ParametersTypeDescriptionDefault
kwargs - Object -

{

-

data: Array | Series, the object to convert.

-

format: The strftime to parse time, eg "%Y-m-d%", "%m-d-Y%", - and "%m-d-Y H%M%S%"

-

}

-
- -**Returns:** - - ****return **DataFrame** +| Parameters | Type | Description | Default | +| ---------- | ------------- | --------------- | ------------------------------------------------- | +| **data** | Array, Series | **data**: Array | Series with Date strings to convert to Date time. | ## **Examples** -### **Convert Series to Dummy codes** +In the following example, we convert a **Series** of Date strings to DateTime objects, so we can call various Date methods on them. {% tabs %} {% tab title="Node" %} ```javascript -let data = new dfd.date_range({"start":'1/1/2018',period:12, freq:'M'}) -let sf = new dfd.Series(data) -let dt = dfd.to_datetime({data:sf}) +const dfd = require('danfojs-node') + +let data = new dateRange({ "start": '1/1/2018', period: 12, freq: 'M' }) +let sf = new Series(data) +sf.print() -dt.month().print() -dt.month_name().print() -dt.weekdays().print() -dt.day().print() -dt.seconds().print() +let dt = toDateTime(data) +dt.dayOfMonth().print() +dt.dayOfWeekName().print() +dt.hours().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -//Int representation for month -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 0 ║ -╟───┼──────────────────────╢ -║ 1 │ 1 ║ -╟───┼──────────────────────╢ -║ 2 │ 2 ║ -╟───┼──────────────────────╢ -║ 3 │ 3 ║ -╟───┼──────────────────────╢ -║ 4 │ 4 ║ -╚═══╧══════════════════════╝ - -//string representation for month -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ Jan ║ -╟───┼──────────────────────╢ -║ 1 │ Feb ║ -╟───┼──────────────────────╢ -║ 2 │ Mar ║ -╟───┼──────────────────────╢ -║ 3 │ Apr ║ -╟───┼──────────────────────╢ -║ 4 │ May ║ -╚═══╧══════════════════════╝ - -//string representation for day of the week -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ Mon ║ -╟───┼──────────────────────╢ -║ 1 │ Thu ║ -╟───┼──────────────────────╢ -║ 2 │ Thu ║ -╟───┼──────────────────────╢ -║ 3 │ Sun ║ -╟───┼──────────────────────╢ -║ 4 │ Tue ║ -╚═══╧══════════════════════╝ - -//Int representation for day of the week -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 1 ║ -╟───┼──────────────────────╢ -║ 1 │ 4 ║ -╟───┼──────────────────────╢ -║ 2 │ 4 ║ -╟───┼──────────────────────╢ -║ 3 │ 0 ║ -╟───┼──────────────────────╢ -║ 4 │ 2 ║ -╚═══╧══════════════════════╝ -//Hour of the day +``` +╔═══╤════════════════════════╗ +║ 0 │ 1/1/2018, 12:00:00 AM ║ +╟───┼────────────────────────╢ +║ 1 │ 2/1/2018, 12:00:00 AM ║ +╟───┼────────────────────────╢ +║ 2 │ 3/1/2018, 12:00:00 AM ║ +╟───┼────────────────────────╢ +║ 3 │ 4/1/2018, 12:00:00 AM ║ +╟───┼────────────────────────╢ +║ 4 │ 5/1/2018, 12:00:00 AM ║ +╟───┼────────────────────────╢ +║ 5 │ 6/1/2018, 12:00:00 AM ║ +╟───┼────────────────────────╢ +║ 6 │ 7/1/2018, 12:00:00 AM ║ +╟───┼────────────────────────╢ +║ 7 │ 8/1/2018, 12:00:00 AM ║ +╟───┼────────────────────────╢ +║ 8 │ 9/1/2018, 12:00:00 AM ║ +╟───┼────────────────────────╢ +║ 9 │ 10/1/2018, 12:00:00 AM ║ +╚═══╧════════════════════════╝ + +╔═══╤═══╗ +║ 0 │ 1 ║ +╟───┼───╢ +║ 1 │ 1 ║ +╟───┼───╢ +║ 2 │ 1 ║ +╟───┼───╢ +║ 3 │ 1 ║ +╟───┼───╢ +║ 4 │ 1 ║ +╟───┼───╢ +║ 5 │ 1 ║ +╟───┼───╢ +║ 6 │ 1 ║ +╟───┼───╢ +║ 7 │ 1 ║ +╟───┼───╢ +║ 8 │ 1 ║ +╟───┼───╢ +║ 9 │ 1 ║ +╚═══╧═══╝ + +╔═══╤═══════════╗ +║ 0 │ Monday ║ +╟───┼───────────╢ +║ 1 │ Thursday ║ +╟───┼───────────╢ +║ 2 │ Thursday ║ +╟───┼───────────╢ +║ 3 │ Sunday ║ +╟───┼───────────╢ +║ 4 │ Tuesday ║ +╟───┼───────────╢ +║ 5 │ Friday ║ +╟───┼───────────╢ +║ 6 │ Sunday ║ +╟───┼───────────╢ +║ 7 │ Wednesday ║ +╟───┼───────────╢ +║ 8 │ Saturday ║ +╟───┼───────────╢ +║ 9 │ Monday ║ +╚═══╧═══════════╝ + +╔═══╤═══╗ +║ 0 │ 0 ║ +╟───┼───╢ +║ 1 │ 0 ║ +╟───┼───╢ +║ 2 │ 0 ║ +╟───┼───╢ +║ 3 │ 0 ║ +╟───┼───╢ +║ 4 │ 0 ║ +╟───┼───╢ +║ 5 │ 0 ║ +╟───┼───╢ +║ 6 │ 0 ║ +╟───┼───╢ +║ 7 │ 0 ║ +╟───┼───╢ +║ 8 │ 0 ║ +╟───┼───╢ +║ 9 │ 0 ║ +╚═══╧═══╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 0 ║ -╟───┼──────────────────────╢ -║ 1 │ 0 ║ -╟───┼──────────────────────╢ -║ 2 │ 0 ║ -╟───┼──────────────────────╢ -║ 3 │ 0 ║ -╟───┼──────────────────────╢ -║ 4 │ 0 ║ -╚═══╧══════════════════════╝ ``` {% endtab %} {% endtabs %} {% hint style="info" %} -datetime properties of Series or datetime-like columns in DataFrame can be accessed via accessors in the **dt** name space. See [Accessors](https://app.gitbook.com/@jsdata/s/danfojs/~/drafts/-MEMaWwva1cjt8CxnG-b/api-reference/series#accessors) +Date time properties of Series or datetime-like columns in DataFrame can be accessed via accessors in the **dt** name-space. See [Accessors](https://app.gitbook.com/@jsdata/s/danfojs/\~/drafts/-MEMaWwva1cjt8CxnG-b/api-reference/series#accessors) {% endhint %} - diff --git a/api-reference/general-functions/danfo.utils.md b/api-reference/general-functions/danfo.utils.md new file mode 100644 index 0000000..c673a1b --- /dev/null +++ b/api-reference/general-functions/danfo.utils.md @@ -0,0 +1,25 @@ +--- +description: Utility class with useful methods +--- + +# danfo.Utils + +The Utils class holds useful utility methods, mostly used internally in the Danfojs library. + +For example, in the following example, we use the `inferDtype` function from the utils class. + +{% tabs %} +{% tab title="Node" %} +```javascript +import { Utils } from "danfojs-node" + +const utils = new Utils() + +const arr = [NaN, 2.1, 3.3, 2.09] +console.log(utils.inferDtype(arr)) + +//output +[ 'float32' ] +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/groupby.md b/api-reference/groupby.md index 1db2e52..50a8170 100644 --- a/api-reference/groupby.md +++ b/api-reference/groupby.md @@ -37,11 +37,11 @@ description: >- | [`GroupBy.bfill`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.bfill.html#pandas.core.groupby.GroupBy.bfill)\(\[limit\]\) | Backward fill the values. | | [`GroupBy.backfill`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.backfill.html#pandas.core.groupby.GroupBy.backfill)\(\[limit\]\) | Backward fill the values. | | [`GroupBy.count`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.count.html#pandas.core.groupby.GroupBy.count)\(\) | Compute count of group, excluding missing values. | -| [`GroupBy.cumcount`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cumcount.html#pandas.core.groupby.GroupBy.cumcount)\(\[ascending\]\) | Number each item in each group from 0 to the length of that group - 1. | -| [`GroupBy.cummax`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cummax.html#pandas.core.groupby.GroupBy.cummax)\(\[axis\]\) | Cumulative max for each group. | -| [`GroupBy.cummin`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cummin.html#pandas.core.groupby.GroupBy.cummin)\(\[axis\]\) | Cumulative min for each group. | -| [`GroupBy.cumprod`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cumprod.html#pandas.core.groupby.GroupBy.cumprod)\(\[axis\]\) | Cumulative product for each group. | -| [`GroupBy.cumsum`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cumsum.html#pandas.core.groupby.GroupBy.cumsum)\(\[axis\]\) | Cumulative sum for each group. | +| [`GroupBy.cumCount`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cumcount.html#pandas.core.groupby.GroupBy.cumcount)\(\[ascending\]\) | Number each item in each group from 0 to the length of that group - 1. | +| [`GroupBy.cumMax`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cummax.html#pandas.core.groupby.GroupBy.cummax)\(\[axis\]\) | Cumulative max for each group. | +| [`GroupBy.cumMin`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cummin.html#pandas.core.groupby.GroupBy.cummin)\(\[axis\]\) | Cumulative min for each group. | +| [`GroupBy.cumProd`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cumprod.html#pandas.core.groupby.GroupBy.cumprod)\(\[axis\]\) | Cumulative product for each group. | +| [`GroupBy.cumSum`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cumsum.html#pandas.core.groupby.GroupBy.cumsum)\(\[axis\]\) | Cumulative sum for each group. | | [`GroupBy.ffill`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.ffill.html#pandas.core.groupby.GroupBy.ffill)\(\[limit\]\) | Forward fill the values. | | [`GroupBy.first`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.first.html#pandas.core.groupby.GroupBy.first)\(\[numeric\_only, min\_count\]\) | Compute first of group values. | | [`GroupBy.head`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.head.html#pandas.core.groupby.GroupBy.head)\(\[n\]\) | Return first n rows of each group. | @@ -74,11 +74,11 @@ The following methods are available in both `SeriesGroupBy` and `DataFrameGroupB | [`DataFrameGroupBy.corr`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.corr.html#pandas.core.groupby.DataFrameGroupBy.corr) | Compute pairwise correlation of columns, excluding NA/null values. | | [`DataFrameGroupBy.count`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.count.html#pandas.core.groupby.DataFrameGroupBy.count)\(\) | Compute count of group, excluding missing values. | | [`DataFrameGroupBy.cov`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.cov.html#pandas.core.groupby.DataFrameGroupBy.cov) | Compute pairwise covariance of columns, excluding NA/null values. | -| [`DataFrameGroupBy.cumcount`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.cumcount.html#pandas.core.groupby.DataFrameGroupBy.cumcount)\(\[ascending\]\) | Number each item in each group from 0 to the length of that group - 1. | -| [`DataFrameGroupBy.cummax`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.cummax.html#pandas.core.groupby.DataFrameGroupBy.cummax)\(\[axis\]\) | Cumulative max for each group. | -| [`DataFrameGroupBy.cummin`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.cummin.html#pandas.core.groupby.DataFrameGroupBy.cummin)\(\[axis\]\) | Cumulative min for each group. | -| [`DataFrameGroupBy.cumprod`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.cumprod.html#pandas.core.groupby.DataFrameGroupBy.cumprod)\(\[axis\]\) | Cumulative product for each group. | -| [`DataFrameGroupBy.cumsum`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.cumsum.html#pandas.core.groupby.DataFrameGroupBy.cumsum)\(\[axis\]\) | Cumulative sum for each group. | +| [`DataFrameGroupBy.cumCount`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.cumcount.html#pandas.core.groupby.DataFrameGroupBy.cumcount)\(\[ascending\]\) | Number each item in each group from 0 to the length of that group - 1. | +| [`DataFrameGroupBy.cumMax`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.cummax.html#pandas.core.groupby.DataFrameGroupBy.cummax)\(\[axis\]\) | Cumulative max for each group. | +| [`DataFrameGroupBy.cumMin`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.cummin.html#pandas.core.groupby.DataFrameGroupBy.cummin)\(\[axis\]\) | Cumulative min for each group. | +| [`DataFrameGroupBy.cumProd`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.cumprod.html#pandas.core.groupby.DataFrameGroupBy.cumprod)\(\[axis\]\) | Cumulative product for each group. | +| [`DataFrameGroupBy.cumSum`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.cumsum.html#pandas.core.groupby.DataFrameGroupBy.cumsum)\(\[axis\]\) | Cumulative sum for each group. | | [`DataFrameGroupBy.describe`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.describe.html#pandas.core.groupby.DataFrameGroupBy.describe)\(\*\*kwargs\) | Generate descriptive statistics. | | [`DataFrameGroupBy.diff`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.diff.html#pandas.core.groupby.DataFrameGroupBy.diff) | First discrete difference of element. | | [`DataFrameGroupBy.ffill`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.ffill.html#pandas.core.groupby.DataFrameGroupBy.ffill)\(\[limit\]\) | Forward fill the values. | diff --git a/api-reference/groupby/README.md b/api-reference/groupby/README.md index 9a1db65..7e37891 100644 --- a/api-reference/groupby/README.md +++ b/api-reference/groupby/README.md @@ -8,7 +8,7 @@ description: 'GroupBy objects are returned by groupby calls: danfo.DataFrame.gro | | | | :--- | :--- | -| [`GroupBy.get_group`](groupby.get_groups.md) | Construct DataFrame from group with provided name. | +| [`GroupBy.get_group`](groupby.getGroup.md) | Construct DataFrame from group with provided name. | ### Function application @@ -21,10 +21,10 @@ description: 'GroupBy objects are returned by groupby calls: danfo.DataFrame.gro | | | | :--- | :--- | | [`GroupBy.count`](groupby.count.md) | Compute count of group, excluding missing values. | -| [`GroupBy.cummax`](groupby.cummax.md) | Cumulative max for each group. | -| [`GroupBy.cummin`](groupby.cummin.md) | Cumulative min for each group. | -| [`GroupBy.cumprod`](groupby.cumprod.md) | Cumulative product for each group. | -| [`GroupBy.cumsum`](groupby.cumsum.md) | Cumulative sum for each group. | +| [`GroupBy.cumMax`](groupby.cummax.md) | Cumulative max for each group. | +| [`GroupBy.cumMin`](groupby.cummin.md) | Cumulative min for each group. | +| [`GroupBy.cumProd`](groupby.cumprod.md) | Cumulative product for each group. | +| [`GroupBy.cumSum`](groupby.cumsum.md) | Cumulative sum for each group. | | [`GroupBy.max`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.max.html#pandas.core.groupby.GroupBy.max) | Compute max of group values. | | [`GroupBy.mean`](groupby.mean.md) | Compute mean of groups, excluding missing values. | | [`GroupBy.min`](groupby.min.md) | Compute min of group values. | diff --git a/api-reference/groupby/groupby.agg.md b/api-reference/groupby/groupby.agg.md index 45c844a..fca7d03 100644 --- a/api-reference/groupby/groupby.agg.md +++ b/api-reference/groupby/groupby.agg.md @@ -4,17 +4,19 @@ description: Obtain data aggregate per groups for each column # Groupby.agg -> danfo.Groupby.**agg**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L349)\] +> danfo.Groupby.**agg**(kwargs) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L349)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs | Object | kwargs contain keys which are column names in the dataframe, and the values are operation to be performed | | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------------------------------------------------- | ------- | +| ops | Object | keys are column names and `values` are aggregation operator | {} | **Return:** DataFrame **Examples** -Using mean and sum aggregate +**Aggregation using one aggregate operator per column** + +1) Assigning `mean` and `sum` aggregate to different column {% tabs %} {% tab title="Node" %} @@ -33,24 +35,24 @@ let data ={'A': ['foo', 'bar', 'foo', 'bar', let df = new dfd.DataFrame(data) let grp = df.groupby(["A"]) -grp.agg({"C":"mean","D":"sum"}).print() +grp.agg({C:"mean",D:"sum"}).print() ``` {% endtab %} {% endtabs %} -```text +``` Shape: (2,3) -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ C_mean │ D_sum ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ 4.19999980926... │ 27 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ bar │ 3 │ 9 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ C_mean │ D_sum ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ 4.2 │ 27 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ bar │ 3 │ 9 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -Mean and Sum aggregate on dataframe groupby two column +2) Mean and Sum aggregate on dataframe grouped by two column {% tabs %} {% tab title="Node" %} @@ -69,26 +71,62 @@ let data ={'A': ['foo', 'bar', 'foo', 'bar', let df = new dfd.DataFrame(data) let grp = df.groupby(["A","B"]) -grp.agg({"C":"mean","D":"sum"}).print() +grp.agg({C:"mean",D:"sum"}).print() ``` {% endtab %} {% endtabs %} -```text - Shape: (5,4) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_mean │ D_sum ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ one │ 3.5 │ 10 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ two │ 3.5 │ 9 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ three │ 7 │ 8 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ bar │ one │ 3 │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ bar │ two │ 2 │ 6 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C_mean │ D_sum ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 3.5 │ 10 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ two │ 3.5 │ 9 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ three │ 7 │ 8 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ bar │ one │ 3 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ bar │ three │ 4 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ two │ 2 │ 6 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +**Aggregation using two or more aggregate operator per column** + +Assigning `mean` and `sum`, `min`, `std`, `count` aggregate to different column + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={'A': ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + 'B': ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + 'C': [1,3,2,4,5,2,6,7], + 'D': [3,2,4,1,5,6,7,8] + } + +let df = new dfd.DataFrame(data) + +let grp = df.groupby(["A"]) +grp.agg({C:["mean", "sum", "min"], + D:["sum", "count", "std"]}).print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ C_mean │ C_sum │ C_min │ D_sum │ D_count │ D_std ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ 4.2 │ 21 │ 1 │ 27 │ 5 │ 2.0736441353327… ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ bar │ 3 │ 9 │ 2 │ 9 │ 3 │ 2.6457513110645… ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` \ No newline at end of file diff --git a/api-reference/groupby/groupby.apply.md b/api-reference/groupby/groupby.apply.md index 2150a21..9e01b0e 100644 --- a/api-reference/groupby/groupby.apply.md +++ b/api-reference/groupby/groupby.apply.md @@ -4,11 +4,11 @@ description: Apply custom aggregate function to grouped data # Groupby.apply -danfo.Groupby.**apply**\(callable\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs-node/src/core/groupby.js#L297)\] +danfo.Groupby.**apply**\(callable\) \[[source](https://github.com/javascriptdata/danfojs/blob/9bfda6dcb6b2b620591ec7b3340d35e3f801c8ab/src/danfojs-base/aggregators/groupby.ts#L552)\] | Parameters | Type | Description | Default | | :--- | :--- | :--- | :--- | -| callable | Function \| function to be applied to grouped data | Undefined | | +| callable | Function \| function to be applied to grouped data. the callable functons takes in DataFrame as argument adn returns DataFrame or Series | Undefined | | **Returns:** @@ -24,26 +24,28 @@ Using apply to create a custom function that subtract the minimum value of each const dfd = require("danfojs-node") let data = { - 'A': ['foo', 'bar', 'foo', 'bar', + A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1, 3, 2, 4, 5, 2, 6, 7], + C: [1, 3, 2, 4, 5, 2, 6, 7], - 'D': [3, 2, 4, 1, 5, 6, 7, 8] + D: [3, 2, 4, 1, 5, 6, 7, 8] }; + let df = new dfd.DataFrame(data); -let group_df = df.groupby(["A", "B"]); +let groupDf = df.groupby(["A", "B"]).col(['C', 'D']); const subMin = (x) => { - return x.sub(x.min()); + //find the min across column + return x.sub(x.min({axis:0})); }; -group_df.apply(subMin).print(); +groupDf.apply(subMin).print(); ``` {% endtab %} @@ -58,25 +60,25 @@ group_df.apply(subMin).print(); {% tabs %} {% tab title="Output" %} ```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_apply │ D_apply ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ one │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ one │ 5 │ 4 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ two │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ foo │ two │ 3 │ 1 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ foo │ three │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 5 │ bar │ one │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 6 │ bar │ two │ 0 │ 0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 7 │ bar │ three │ 0 │ 0 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C │ D ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 0 │ 0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ one │ 5 │ 4 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ two │ 0 │ 0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ foo │ two │ 3 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ foo │ three │ 0 │ 0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ one │ 0 │ 0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 6 │ bar │ three │ 0 │ 0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 7 │ bar │ two │ 0 │ 0 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` {% endtab %} {% endtabs %} diff --git a/api-reference/groupby/groupby.col.md b/api-reference/groupby/groupby.col.md index 02e7cdd..7ebc5dd 100644 --- a/api-reference/groupby/groupby.col.md +++ b/api-reference/groupby/groupby.col.md @@ -4,102 +4,97 @@ description: Obtain the column(s) per groups # Groupby.col -> danfo.Groupby.col\(col\_names\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L104)\] +> danfo.Groupby.col(col\_names) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L104)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| col\_names | Array | List of column | | +| Parameters | Type | Description | Default | +| ---------- | ----- | -------------- | ------- | +| col\_names | Array | List of column | | Returns: Groupby Data structure -Note: This is similar to pandas `df.groupby(["column"])["col_names"]` +Note: This is similar to pandas `df.groupby(["column"])["colNames"]` **Examples** -Obtain a column +Obtain the column to perform group aggregate operation on {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] } let df = new dfd.DataFrame(data) let grp = df.groupby(["A"]) -grp.col(["C"]) -//for more coumns -grp.col(["C","D"]) +//select single column +let grpColumnC = grp.col(["C"]) + +// convert grouop internal data to dataFrame +grpColumnC.apply(x=> x).print() + +//select multiple column +let grpColumnBD = grp.col(["B", "D"]) + +grpColumnBD.apply(x=> x).print() ``` {% endtab %} {% endtabs %} -Apparently the output are not that useful unless you perform some operations like max\(\), count\(\) and the likes. - -```text -//it returns the groupby data structure -GroupBy { - key_col: [ 'A' ], - col_dict: { - foo: [ [Array], [Array], [Array], [Array], [Array] ], - bar: [ [Array], [Array], [Array] ] - }, - data: [ - [ 'foo', 'one', 1, 3 ], - [ 'bar', 'one', 3, 2 ], - [ 'foo', 'two', 2, 4 ], - [ 'bar', 'three', 4, 1 ], - [ 'foo', 'two', 5, 5 ], - [ 'bar', 'two', 2, 6 ], - [ 'foo', 'one', 6, 7 ], - [ 'foo', 'three', 7, 8 ] - ], - column_name: [ 'A', 'B', 'C', 'D' ], - data_tensors: { - foo: DataFrame { - kwargs: [Object], - series: false, - data: [Array], - row_data_tensor: [Tensor], - index_arr: [Array], - columns: [Array], - col_data: [Array], - col_data_tensor: [Tensor], - col_types: [Array], - A: [Getter/Setter], - B: [Getter/Setter], - C: [Getter/Setter], - D: [Getter/Setter] - }, - bar: DataFrame { - kwargs: [Object], - series: false, - data: [Array], - row_data_tensor: [Tensor], - index_arr: [Array], - columns: [Array], - col_data: [Array], - col_data_tensor: [Tensor], - col_types: [Array], - A: [Getter/Setter], - B: [Getter/Setter], - C: [Getter/Setter], - D: [Getter/Setter] - } - }, - group_col_name: [ 'C' ], - group_col: { foo: [ [Series] ], bar: [ [Series] ] } -} -``` - +Apparently the output are not that useful unless you perform some operations like max(), count() and the likes. +``` +// select single column C + +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ C ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ 1 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ 2 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ 5 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ foo │ 6 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 4 │ foo │ 7 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ 3 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 6 │ bar │ 4 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 7 │ bar │ 2 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + +// select multiple column: B and D + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ D ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ two │ 4 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ two │ 5 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ foo │ one │ 7 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ foo │ three │ 8 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ one │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 6 │ bar │ three │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 7 │ bar │ two │ 6 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` diff --git a/api-reference/groupby/groupby.count.md b/api-reference/groupby/groupby.count.md index 13a36d1..020893b 100644 --- a/api-reference/groupby/groupby.count.md +++ b/api-reference/groupby/groupby.count.md @@ -4,7 +4,7 @@ description: Count the occurrence of values in columns per groups # Groupby.count -> danfo.Groupby.count\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L249)\] +> danfo.Groupby.count() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L249)] **Parameters**: None @@ -12,7 +12,7 @@ description: Count the occurrence of values in columns per groups **Examples** -Obtain the variance of a column for each group, group by one column +Obtain the number of rows per groups {% tabs %} {% tab title="Node" %} @@ -20,26 +20,25 @@ Obtain the variance of a column for each group, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) let grp = df.groupby(["A"]) -grp.col(["C"]).count().print() +let grpColumnC = grp.col(["C"]) +grpColumnC.count().print() ``` {% endtab %} {% endtabs %} -```text - - Shape: (2,2) +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ A │ C_count ║ @@ -50,7 +49,7 @@ grp.col(["C"]).count().print() ╚═══╧═══════════════════╧═══════════════════╝ ``` -Obtain the var for two columns for each group, group by one column +Obtain the count for two columns for each group, group by one column {% tabs %} {% tab title="Node" %} @@ -58,23 +57,24 @@ Obtain the var for two columns for each group, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) let grp = df.groupby(["A"]) + grp.col(["C","D"]).count().print() ``` {% endtab %} {% endtabs %} -```text +``` Shape: (2,3) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -86,6 +86,42 @@ grp.col(["C","D"]).count().print() ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` +Obtain the count for all columns for each group, group by one column + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) + +let grp = df.groupby(["A"]) + +grp.count().print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B_count │ C_count │ D_count ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ 5 │ 5 │ 5 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ bar │ 3 │ 3 │ 3 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` + Obtain the count for a column for each group, group by two columns {% tabs %} @@ -94,13 +130,13 @@ Obtain the count for a column for each group, group by two columns const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -111,22 +147,24 @@ grp.col(["C"]).count().print() {% endtab %} {% endtabs %} -```text - Shape: (5,3) +``` + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C_count ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ two │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ three │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ bar │ one │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ bar │ three │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ two │ 1 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_count ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ one │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ two │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ three │ 1 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ bar │ one │ 1 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ bar │ two │ 1 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` Obtain the count for two columns for each group, group by two columns @@ -137,13 +175,13 @@ Obtain the count for two columns for each group, group by two columns const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -153,24 +191,24 @@ grp.col(["C","D"]).count().print() {% endtab %} {% endtabs %} -```text - - Shape: (5,4) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_count │ D_count ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ one │ 2 │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ two │ 2 │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ three │ 1 │ 1 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ bar │ one │ 1 │ 1 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ bar │ two │ 1 │ 1 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -\*\*\*\* +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C_count │ D_count ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 2 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ two │ 2 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ three │ 1 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ bar │ one │ 1 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ bar │ three │ 1 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ two │ 1 │ 1 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` +**** diff --git a/api-reference/groupby/groupby.cummax.md b/api-reference/groupby/groupby.cumMax.md similarity index 93% rename from api-reference/groupby/groupby.cummax.md rename to api-reference/groupby/groupby.cumMax.md index 8231a61..0f8fe5f 100644 --- a/api-reference/groupby/groupby.cummax.md +++ b/api-reference/groupby/groupby.cumMax.md @@ -2,9 +2,9 @@ description: Obtain the cummulative max per groups for each column --- -# Groupby.cummax +# Groupby.cumMax -> danfo.Groupby.cummax\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L285)\] +> danfo.Groupby.cumMax\(\) \[[source](https://github.com/javascriptdata/danfojs/blob/4993242be7847ba7583dd40ed0188929898b8fd6/src/danfojs-base/aggregators/groupby.ts#L481)\] **Parameters**: None @@ -20,19 +20,19 @@ Obtain the cumulative max of a column for each groups, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) let grp = df.groupby(["A"]) -grp.col(["C"]).cummax().head().print() -grp.col(["C"]).cummax().tail().print() +grp.col(["C"]).cumMax().head().print() +grp.col(["C"]).cumMax().tail().print() ``` {% endtab %} {% endtabs %} @@ -73,7 +73,7 @@ Shape: (5,2) ╚═══╧═══════════════════╧═══════════════════╝ ``` -Obtain the cumsum for two columns for each group, group by one column +Obtain the cumMax for two columns for each group, group by one column {% tabs %} {% tab title="Node" %} @@ -81,19 +81,19 @@ Obtain the cumsum for two columns for each group, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) let grp = df.groupby(["A"]) -grp.col(["C","D"]).cummax().head().print() -grp.col(["C","D"]).cummax().tail().print() +grp.col(["C","D"]).cumMax().head().print() +grp.col(["C","D"]).cumMax().tail().print() ``` {% endtab %} {% endtabs %} @@ -134,7 +134,7 @@ grp.col(["C","D"]).cummax().tail().print() ╚════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -Obtain the cummax for a column for each group, group by two columns +Obtain the cumMax for a column for each group, group by two columns {% tabs %} {% tab title="Node" %} @@ -142,19 +142,19 @@ Obtain the cummax for a column for each group, group by two columns const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) let grp = df.groupby(["A","B"]) -grp.col(["C"]).cummax().head().print() -grp.col(["C"]).cummax().tail().print() +grp.col(["C"]).cumMax().head().print() +grp.col(["C"]).cumMax().tail().print() ``` {% endtab %} @@ -214,8 +214,8 @@ let data ={'A': ['foo', 'bar', 'foo', 'bar', let df = new dfd.DataFrame(data) let grp = df.groupby(["A","B"]) -grp.col(["C","D"]).cummax().head().print() -grp.col(["C","D"]).cummax().tail().print() +grp.col(["C","D"]).cumMax().head().print() +grp.col(["C","D"]).cumMax().tail().print() ``` {% endtab %} {% endtabs %} diff --git a/api-reference/groupby/groupby.cummin.md b/api-reference/groupby/groupby.cumMin.md similarity index 92% rename from api-reference/groupby/groupby.cummin.md rename to api-reference/groupby/groupby.cumMin.md index 7fd9ed6..01f70c3 100644 --- a/api-reference/groupby/groupby.cummin.md +++ b/api-reference/groupby/groupby.cumMin.md @@ -2,9 +2,9 @@ description: Obtain the cummulative minimum per groups for each column --- -# Groupby.cummin +# Groupby.cumMin -> danfo.Groupby.**cummin**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L297)\] +> danfo.Groupby.**cumMin**\(\) \[[source](https://github.com/javascriptdata/danfojs/blob/4993242be7847ba7583dd40ed0188929898b8fd6/src/danfojs-base/aggregators/groupby.ts#L497)\] **Parameters**: None @@ -20,19 +20,21 @@ Obtain the cumulative min of a column for each groups, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) let grp = df.groupby(["A"]) -grp.col(["C"]).cummin().head().print() -grp.col(["C"]).cummin().tail().print() +let grpColC = grp.col(["C"]) +grpColC.cumMin().head().print() +grpColC.cumMin().tail().print() + ``` {% endtab %} {% endtabs %} @@ -73,7 +75,7 @@ grp.col(["C"]).cummin().tail().print() ╚═══╧═══════════════════╧═══════════════════╝ ``` -Obtain the cummin for two columns for each group, group by one column +Obtain the cumMin for two columns for each group, group by one column {% tabs %} {% tab title="Node" %} @@ -81,19 +83,20 @@ Obtain the cummin for two columns for each group, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) let grp = df.groupby(["A"]) -grp.col(["C","D"]).cummin().head().print() -grp.col(["C","D"]).cummin().tail().print() +let grpCol = grp.col("C","D"]) +grpCol.cumMin().head().print() +grpCol.cumMin().tail().print() ``` {% endtab %} {% endtabs %} @@ -134,7 +137,7 @@ grp.col(["C","D"]).cummin().tail().print() ╚════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -Obtain the cummin for a column for each group, group by two columns +Obtain the cumMin for a column for each group, group by two columns {% tabs %} {% tab title="Node" %} @@ -142,19 +145,20 @@ Obtain the cummin for a column for each group, group by two columns const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) let grp = df.groupby(["A","B"]) -grp.col(["C"]).cummin().head().print() -grp.col(["C"]).cummin().tail().print() +let grpCol = grp.col(["C"]) +grpCol.cumMin().head().print() +grpCol.cumMin().tail().print() ``` {% endtab %} @@ -203,19 +207,20 @@ Obtain the cummin for two columns for each group, group by two columns const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) let grp = df.groupby(["A","B"]) -grp.col(["C","D"]).cummin().head().print() -grp.col(["C","D"]).cummin().tail().print() +let grpCol = grp.col(["C","D"]) +grpCol.cumMin().head().print() +grpCol.cumMin().tail().print() ``` {% endtab %} {% endtabs %} diff --git a/api-reference/groupby/groupby.cumProd.md b/api-reference/groupby/groupby.cumProd.md new file mode 100644 index 0000000..fef9f49 --- /dev/null +++ b/api-reference/groupby/groupby.cumProd.md @@ -0,0 +1,221 @@ +--- +description: Obtain the cumulative product per group for each column +--- + +# Groupby.cumProd + +> danfo.Groupby.**cumProd**\(\) \[[source](https://github.com/javascriptdata/danfojs/blob/65f9b3753389b08101d4bb00a2d6488255476aaf/src/danfojs-base/aggregators/groupby.ts#L489)\] + +**Parameters**: None + +**Return**: DataFrame + +**Examples** + +Obtain the cumulative product of a column for each groups, group by one column + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) + +let grp = df.groupby(["A"]) +let grpCol = grp.col(["C"]) +grpCol.cumProd().head().print() +grpCol.cumProd().tail().print() +``` +{% endtab %} +{% endtabs %} + +```text + + Shape: (5,2) + +╔═══╤═══════════════════╤═══════════════════╗ +║ │ A │ C_cumprod ║ +╟───┼───────────────────┼───────────────────╢ +║ 0 │ foo │ 1 ║ +╟───┼───────────────────┼───────────────────╢ +║ 1 │ foo │ 2 ║ +╟───┼───────────────────┼───────────────────╢ +║ 2 │ foo │ 10 ║ +╟───┼───────────────────┼───────────────────╢ +║ 3 │ foo │ 60 ║ +╟───┼───────────────────┼───────────────────╢ +║ 4 │ foo │ 420 ║ +╚═══╧═══════════════════╧═══════════════════╝ + + + Shape: (5,2) + +╔═══╤═══════════════════╤═══════════════════╗ +║ │ A │ C_cumprod ║ +╟───┼───────────────────┼───────────────────╢ +║ 3 │ foo │ 60 ║ +╟───┼───────────────────┼───────────────────╢ +║ 4 │ foo │ 420 ║ +╟───┼───────────────────┼───────────────────╢ +║ 5 │ bar │ 3 ║ +╟───┼───────────────────┼───────────────────╢ +║ 6 │ bar │ 12 ║ +╟───┼───────────────────┼───────────────────╢ +║ 7 │ bar │ 24 ║ +╚═══╧═══════════════════╧═══════════════════╝ +``` + +Obtain the cumProd for two columns for each groups, group by one column + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + + +let data ={'A': ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + 'B': ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + 'C': [1,3,2,4,5,2,6,7], + 'D': [3,2,4,1,5,6,7,8] + } + +let df = new dfd.DataFrame(data) + +let grp = df.groupby(["A"]) +let grpCol = grp.col(["C","D"]) +grpCol.cumProd().print() +``` +{% endtab %} +{% endtabs %} + +```text + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ C_cumprod │ D_cumprod ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ 1 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ 2 │ 12 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ 10 │ 60 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ foo │ 60 │ 420 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ foo │ 420 │ 3360 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ 3 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 6 │ bar │ 12 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 7 │ bar │ 24 │ 12 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +Obtain the cumProd for a column for each group, group by two columns + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + + +let data ={'A': ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + 'B': ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + 'C': [1,3,2,4,5,2,6,7], + 'D': [3,2,4,1,5,6,7,8] + } + +let df = new dfd.DataFrame(data) + +let grp = df.groupby(["A","B"]) +let grpCol = grp.col(["C"]) +grpCol.cumProd().print() + +``` +{% endtab %} +{% endtabs %} + +```text +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C_cumprod ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ one │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ two │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ foo │ two │ 10 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ foo │ three │ 7 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ one │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 6 │ bar │ three │ 4 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 7 │ bar │ two │ 2 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +Obtain the cumProd for two columns for each group, group by two columns + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) + +let grp = df.groupby(["A","B"]) +let grpCol = grp.col(["C","D"]) +grpCol.cumProd().print() +``` +{% endtab %} +{% endtabs %} + +```text + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C_cumprod │ D_cumprod ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 1 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ one │ 6 │ 21 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ two │ 2 │ 4 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ foo │ two │ 10 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ foo │ three │ 7 │ 8 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ one │ 3 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 6 │ bar │ three │ 4 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 7 │ bar │ two │ 2 │ 6 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` + diff --git a/api-reference/groupby/groupby.cumSum.md b/api-reference/groupby/groupby.cumSum.md new file mode 100644 index 0000000..440fa31 --- /dev/null +++ b/api-reference/groupby/groupby.cumSum.md @@ -0,0 +1,200 @@ +--- +description: Obtain the cumulative sum per groups for each column +--- + +# Groupby.cumSum + +> danfo.Groupby.**cumSum**() \[[source](https://github.com/javascriptdata/danfojs/blob/0d33e344b80a3ed54c91c9393ac3b583d4b0b1a4/src/danfojs-base/aggregators/groupby.ts#L473)] + +**Parameters**: None + +**Return**: DataFrame + +**Examples** + +Obtain the cumulative sum of a column for each groups, group by one column + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) + +let grp = df.groupby(["A"]) +grp.col(["C"]).cumSum().print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ C_cumsum ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ 1 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ 3 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ 8 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ foo │ 14 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 4 │ foo │ 21 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ 3 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 6 │ bar │ 7 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 7 │ bar │ 9 ║ +╚════════════╧═══════════════════╧═══════════════════╝ + +``` + +Obtain the cumsum for two columns for each group, group by one column + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) + +let grp = df.groupby(["A"]) +grp.col(["C","D"]).cumSum().print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ C_cumsum │ D_cumsum ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ 1 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ 3 │ 7 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ 8 │ 12 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ foo │ 14 │ 19 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ foo │ 21 │ 27 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ 3 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 6 │ bar │ 7 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 7 │ bar │ 9 │ 9 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +Obtain the cumsum for a column for each group, group by two columns + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) + +let grp = df.groupby(["A","B"]) +grp.col(["C"]).cumSum().print() + +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C_cumsum ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ one │ 7 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ two │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ foo │ two │ 7 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ foo │ three │ 7 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ one │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 6 │ bar │ three │ 4 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 7 │ bar │ two │ 2 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +``` + +Obtain the count for two columns for each group, group by two columns + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) + +let grp = df.groupby(["A","B"]) +grp.col(["C","D"]).cumSum().print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C_cumsum │ D_cumsum ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 1 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ one │ 7 │ 10 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ two │ 2 │ 4 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ foo │ two │ 7 │ 9 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ foo │ three │ 7 │ 8 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ one │ 3 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 6 │ bar │ three │ 4 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 7 │ bar │ two │ 2 │ 6 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +**** diff --git a/api-reference/groupby/groupby.cumprod.md b/api-reference/groupby/groupby.cumprod.md deleted file mode 100644 index af46123..0000000 --- a/api-reference/groupby/groupby.cumprod.md +++ /dev/null @@ -1,258 +0,0 @@ ---- -description: Obtain the cumulative product per group for each column ---- - -# Groupby.cumprod - -> danfo.Groupby.**cumprod**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L291)\] - -**Parameters**: None - -**Return**: DataFrame - -**Examples** - -Obtain the cumulative product of a column for each groups, group by one column - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - - -let data ={'A': ['foo', 'bar', 'foo', 'bar', - 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', - 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } - -let df = new dfd.DataFrame(data) - -let grp = df.groupby(["A"]) -grp.col(["C"]).cumprod().head().print() -grp.col(["C"]).cumprod().tail().print() -``` -{% endtab %} -{% endtabs %} - -```text - - Shape: (5,2) - -╔═══╤═══════════════════╤═══════════════════╗ -║ │ A │ C_cumprod ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ foo │ 1 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ foo │ 2 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ foo │ 10 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ foo │ 60 ║ -╟───┼───────────────────┼───────────────────╢ -║ 4 │ foo │ 420 ║ -╚═══╧═══════════════════╧═══════════════════╝ - - - Shape: (5,2) - -╔═══╤═══════════════════╤═══════════════════╗ -║ │ A │ C_cumprod ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ foo │ 60 ║ -╟───┼───────────────────┼───────────────────╢ -║ 4 │ foo │ 420 ║ -╟───┼───────────────────┼───────────────────╢ -║ 5 │ bar │ 3 ║ -╟───┼───────────────────┼───────────────────╢ -║ 6 │ bar │ 12 ║ -╟───┼───────────────────┼───────────────────╢ -║ 7 │ bar │ 24 ║ -╚═══╧═══════════════════╧═══════════════════╝ -``` - -Obtain the cumprod for two columns for each groups, group by one column - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - - -let data ={'A': ['foo', 'bar', 'foo', 'bar', - 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', - 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } - -let df = new dfd.DataFrame(data) - -let grp = df.groupby(["A"]) -grp.col(["C","D"]).cumprod().head().print() -grp.col(["C","D"]).cumprod().tail().print() -``` -{% endtab %} -{% endtabs %} - -```text - -Shape: (5,3) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ C_cumprod │ D_cumprod ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ 1 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ 2 │ 12 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ 10 │ 60 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ foo │ 60 │ 420 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ foo │ 420 │ 3360 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - Shape: (5,3) - -╔════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ C_cumprod │ D_cumprod ║ -╟────┼───────────────────┼───────────────────┼───────────────────╢ -║ 11 │ bar │ 12 │ 2 ║ -╟────┼───────────────────┼───────────────────┼───────────────────╢ -║ 12 │ bar │ 24 │ 12 ║ -╟────┼───────────────────┼───────────────────┼───────────────────╢ -║ 13 │ bar │ 3 │ 2 ║ -╟────┼───────────────────┼───────────────────┼───────────────────╢ -║ 14 │ bar │ 12 │ 2 ║ -╟────┼───────────────────┼───────────────────┼───────────────────╢ -║ 15 │ bar │ 24 │ 12 ║ -╚════╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` - -Obtain the cumprod for a column for each group, group by two columns - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - - -let data ={'A': ['foo', 'bar', 'foo', 'bar', - 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', - 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } - -let df = new dfd.DataFrame(data) - -let grp = df.groupby(["A","B"]) -grp.col(["C"]).cumprod().head().print() -grp.col(["C"]).cumprod().tail().print() - -``` -{% endtab %} -{% endtabs %} - -```text - Shape: (5,3) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_cumprod ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ one │ 1 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ one │ 6 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ two │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ foo │ two │ 10 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ foo │ three │ 7 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - Shape: (5,3) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_cumprod ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ foo │ two │ 10 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ foo │ three │ 7 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 5 │ bar │ one │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 6 │ bar │ two │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 7 │ bar │ three │ 4 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` - -Obtain the cumprod for two columns for each group, group by two columns - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - - -let data ={'A': ['foo', 'bar', 'foo', 'bar', - 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', - 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } - -let df = new dfd.DataFrame(data) - -let grp = df.groupby(["A","B"]) -grp.col(["C","D"]).cumprod().head().print() -grp.col(["C","D"]).cumprod().tail().print() -``` -{% endtab %} -{% endtabs %} - -```text - - Shape: (5,4) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_cumprod │ D_cumprod ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ one │ 1 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ one │ 6 │ 21 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ two │ 2 │ 4 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ foo │ two │ 10 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ foo │ three │ 7 │ 8 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - Shape: (5,4) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_cumprod │ D_cumprod ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ foo │ two │ 10 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ foo │ three │ 7 │ 8 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 5 │ bar │ one │ 3 │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 6 │ bar │ two │ 2 │ 6 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 7 │ bar │ three │ 4 │ 1 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` - diff --git a/api-reference/groupby/groupby.cumsum.md b/api-reference/groupby/groupby.cumsum.md deleted file mode 100644 index e9ccab8..0000000 --- a/api-reference/groupby/groupby.cumsum.md +++ /dev/null @@ -1,260 +0,0 @@ ---- -description: Obtain the cumulative sum per groups for each column ---- - -# Groupby.cumsum - -> danfo.Groupby.**cumsum**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L280)\] - -**Parameters**: None - -**Return**: DataFrame - -**Examples** - -Obtain the cumulative sum of a column for each groups, group by one column - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - - -let data ={'A': ['foo', 'bar', 'foo', 'bar', - 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', - 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } - -let df = new dfd.DataFrame(data) - -let grp = df.groupby(["A"]) -grp.col(["C"]).cumsum().head().print() -grp.col(["C"]).cumsum().tail().print() -``` -{% endtab %} -{% endtabs %} - -```text - -Shape: (5,2) - -╔═══╤═══════════════════╤═══════════════════╗ -║ │ A │ C_cumsum ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ foo │ 1 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ foo │ 3 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ foo │ 8 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ foo │ 14 ║ -╟───┼───────────────────┼───────────────────╢ -║ 4 │ foo │ 21 ║ -╚═══╧═══════════════════╧═══════════════════╝ - - - Shape: (5,2) - -╔═══╤═══════════════════╤═══════════════════╗ -║ │ A │ C_cumsum ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ foo │ 14 ║ -╟───┼───────────────────┼───────────────────╢ -║ 4 │ foo │ 21 ║ -╟───┼───────────────────┼───────────────────╢ -║ 5 │ bar │ 3 ║ -╟───┼───────────────────┼───────────────────╢ -║ 6 │ bar │ 7 ║ -╟───┼───────────────────┼───────────────────╢ -║ 7 │ bar │ 9 ║ -╚═══╧═══════════════════╧═══════════════════╝ -``` - -Obtain the cumsum for two columns for each group, group by one column - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - - -let data ={'A': ['foo', 'bar', 'foo', 'bar', - 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', - 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } - -let df = new dfd.DataFrame(data) - -let grp = df.groupby(["A"]) -grp.col(["C","D"]).cumsum().head().print() -grp.col(["C","D"]).cumsum().tail().print() -``` -{% endtab %} -{% endtabs %} - -```text - - Shape: (5,3) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ C_cumsum │ D_cumsum ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ 1 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ 3 │ 7 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ 8 │ 12 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ foo │ 14 │ 19 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ foo │ 21 │ 27 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - Shape: (5,3) - -╔════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ C_cumsum │ D_cumsum ║ -╟────┼───────────────────┼───────────────────┼───────────────────╢ -║ 11 │ bar │ 7 │ 3 ║ -╟────┼───────────────────┼───────────────────┼───────────────────╢ -║ 12 │ bar │ 9 │ 9 ║ -╟────┼───────────────────┼───────────────────┼───────────────────╢ -║ 13 │ bar │ 3 │ 2 ║ -╟────┼───────────────────┼───────────────────┼───────────────────╢ -║ 14 │ bar │ 7 │ 3 ║ -╟────┼───────────────────┼───────────────────┼───────────────────╢ -║ 15 │ bar │ 9 │ 9 ║ -╚════╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` - -Obtain the cumsum for a column for each group, group by two columns - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - - -let data ={'A': ['foo', 'bar', 'foo', 'bar', - 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', - 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } - -let df = new dfd.DataFrame(data) - -let grp = df.groupby(["A","B"]) -grp.col(["C"]).cumsum().head().print() -grp.col(["C"]).cumsum().tail().print() - -``` -{% endtab %} -{% endtabs %} - -```text - Shape: (5,3) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_cumsum ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ one │ 1 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ one │ 7 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ two │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ foo │ two │ 7 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ foo │ three │ 7 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - Shape: (5,3) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_cumsum ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ foo │ two │ 7 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ foo │ three │ 7 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 5 │ bar │ one │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 6 │ bar │ two │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 7 │ bar │ three │ 4 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` - -Obtain the count for two columns for each group, group by two columns - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - - -let data ={'A': ['foo', 'bar', 'foo', 'bar', - 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', - 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } - -let df = new dfd.DataFrame(data) - -let grp = df.groupby(["A","B"]) -grp.col(["C","D"]).cumsum().head().print() -grp.col(["C","D"]).cumsum().tail().print() -``` -{% endtab %} -{% endtabs %} - -```text - - Shape: (5,4) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_cumsum │ D_cumsum ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ one │ 1 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ one │ 7 │ 10 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ two │ 2 │ 4 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ foo │ two │ 7 │ 9 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ foo │ three │ 7 │ 8 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - - - Shape: (5,4) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_cumsum │ D_cumsum ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ foo │ two │ 7 │ 9 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ foo │ three │ 7 │ 8 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 5 │ bar │ one │ 3 │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 6 │ bar │ two │ 2 │ 6 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 7 │ bar │ three │ 4 │ 1 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` - -\*\*\*\* - diff --git a/api-reference/groupby/groupby.first.md b/api-reference/groupby/groupby.first.md new file mode 100644 index 0000000..b1bcd26 --- /dev/null +++ b/api-reference/groupby/groupby.first.md @@ -0,0 +1,89 @@ +--- +description: Obtain the first row of each groups +--- + +# Groupby.first + +> danfo.Groupby.first \[[source](https://github.com/javascriptdata/danfojs/blob/9bfda6dcb6b2b620591ec7b3340d35e3f801c8ab/src/danfojs-base/aggregators/groupby.ts#L615)\] + +**Parameters**: None + +**Return**: DataFrame + +**Examples** + +Obtain the first row of each group for dataframe grouped by one column + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] + } + +let df = new dfd.DataFrame(data) + + +let grp = df.groupby(["A"]) +grp.first().print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A_Group │ A │ B │ C │ D ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ foo │ one │ 1 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ bar │ bar │ one │ 3 │ 2 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +Obtain the number of groups in dataframe grouped by two columns + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) +let grp = df.groupby(["A","B"]) +grp.first().print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A_Group │ B_Group │ A │ B │ C │ D ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ foo │ one │ 1 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ two │ foo │ two │ 2 │ 4 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ three │ foo │ three │ 7 │ 8 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ bar │ one │ bar │ one │ 3 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ bar │ three │ bar │ three │ 4 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ two │ bar │ two │ 2 │ 6 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +**** \ No newline at end of file diff --git a/api-reference/groupby/groupby.getGroup.md b/api-reference/groupby/groupby.getGroup.md new file mode 100644 index 0000000..4fed78e --- /dev/null +++ b/api-reference/groupby/groupby.getGroup.md @@ -0,0 +1,129 @@ +--- +description: Obtain the data for each element of the groupby column +--- + +# Groupby.getGroup + +> danfo.Groupby.getGroup(key\) \[[source](https://github.com/javascriptdata/danfojs/blob/0d33e344b80a3ed54c91c9393ac3b583d4b0b1a4/src/danfojs-base/aggregators/groupby.ts#L523)\] + +| Parameters | Type | Description | default | +| :--- | :--- | :--- | :--- | +| key | Array | element of the groupby column | | + +**Returns**: DataFrame + +**Example** + +Group the dataframe by column A and obtain the group belonging to the values in column A + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) + + +let grp = df.groupby(["A"]) + +grp.getGroup(["foo"]).print() + +grp.getGroup(["bar"]).print() +``` +{% endtab %} +{% endtabs %} + +```text +//get groups for key "foo" + Shape: (5,4) + +╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C │ D ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 1 │ 3 ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ two │ 2 │ 4 ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ two │ 5 │ 5 ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ foo │ one │ 6 │ 7 ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ foo │ three │ 7 │ 8 ║ +╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +//get groups for key "bar" + + Shape: (3,4) + +╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C │ D ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ bar │ one │ 3 │ 2 ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ bar │ three │ 4 │ 1 ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ bar │ two │ 2 │ 6 ║ +╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +Group dataframe by two columns and obtain their groups. Since the dataframe is grouped by two columns we most specify two keys in the getGroups belonging to these two columns + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) + + +let grp = df.groupby(["A","B"]) + +grp.getGroup(["foo","one"]).print() + +grp.getGroup(["bar","one"]).print() +``` +{% endtab %} +{% endtabs %} + +```text +//getGroup(["foo","one"] + + + Shape: (2,4) + +╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C │ D ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 1 │ 3 ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ one │ 6 │ 7 ║ +╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + +//getGroup(["bar","one"]) + + + Shape: (1,4) + +╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C │ D ║ +╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ bar │ one │ 3 │ 2 ║ +╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + diff --git a/api-reference/groupby/groupby.get_groups.md b/api-reference/groupby/groupby.get_groups.md index 0cdf912..4450e0a 100644 --- a/api-reference/groupby/groupby.get_groups.md +++ b/api-reference/groupby/groupby.get_groups.md @@ -2,13 +2,13 @@ description: Obtain the data for each element of the groupby column --- -# Groupby.get\_groups +# Groupby.getGroups -> danfo.Groupby.get\_groups\(key\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L313)\] +> danfo.Groupby.getGroups(key) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L313)] -| Parameters | Type | Description | default | -| :--- | :--- | :--- | :--- | -| key | Array | element of the groupby column | | +| Parameters | Type | Description | default | +| ---------- | ----- | ----------------------------- | ------- | +| key | Array | element of the groupby column | | **Returns**: DataFrame @@ -34,14 +34,14 @@ let df = new dfd.DataFrame(data) let grp = df.groupby(["A"]) -grp.get_groups(["foo"]).print() +grp.getGroup(["foo"]).print() -grp.get_groups(["bar"]).print() +grp.getGroup(["bar"]).print() ``` {% endtab %} {% endtabs %} -```text +``` //get groups for key "foo" Shape: (5,4) @@ -74,7 +74,7 @@ grp.get_groups(["bar"]).print() ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -Group dataframe by two columns and obtain their groups. Since the dataframe is grouped by two columns we most specify two keys in the get\_groups belonging to these two columns +Group dataframe by two columns and obtain their groups. Since the dataframe is grouped by two columns we most specify two keys in the getGroups belonging to these two columns {% tabs %} {% tab title="Node" %} @@ -94,15 +94,15 @@ let df = new dfd.DataFrame(data) let grp = df.groupby(["A","B"]) -grp.get_groups(["foo","one"]).print() +grp.getGroup(["foo","one"]).print() -grp.get_groups(["bar","one"]).print() +grp.getGroup(["bar","one"]).print() ``` {% endtab %} {% endtabs %} -```text -//get_groups(["foo","one"] +``` +//getGroup(["foo","one"] Shape: (2,4) @@ -115,7 +115,7 @@ grp.get_groups(["bar","one"]).print() ║ 1 │ foo │ one │ 6 │ 7 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ -//get_groups(["bar","one"]) +//getGroup(["bar","one"]) Shape: (1,4) @@ -126,4 +126,3 @@ grp.get_groups(["bar","one"]).print() ║ 0 │ bar │ one │ 3 │ 2 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` - diff --git a/api-reference/groupby/groupby.groups.md b/api-reference/groupby/groupby.groups.md new file mode 100644 index 0000000..a6208b3 --- /dev/null +++ b/api-reference/groupby/groupby.groups.md @@ -0,0 +1,99 @@ +--- +description: Obtain groupby internal data object +--- + +# Groupby.ngroups + +> danfo.Groupby.groups \[[source](https://github.com/javascriptdata/danfojs/blob/9bfda6dcb6b2b620591ec7b3340d35e3f801c8ab/src/danfojs-base/aggregators/groupby.ts#L598)\] + +**Parameters**: None + +**Return**: Object + +**Examples** + +Obtain the group object for grouped by single column dataframe + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] + } + +let df = new dfd.DataFrame(data) + + +let grp = df.groupby(["A"]) +console.log(grp.groups) +``` +{% endtab %} +{% endtabs %} + +``` +{ + foo: { + A: [ 'foo', 'foo', 'foo', 'foo', 'foo' ], + B: [ 'one', 'two', 'two', 'one', 'three' ], + C: [ 1, 2, 5, 6, 7 ], + D: [ 3, 4, 5, 7, 8 ] + }, + bar: { + A: [ 'bar', 'bar', 'bar' ], + B: [ 'one', 'three', 'two' ], + C: [ 3, 4, 2 ], + D: [ 2, 1, 6 ] + } +} +``` + +Obtain the group object for grouped by two column dataframe + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) +let grp = df.groupby(["A","B"]) +console.log(grp.groups) +``` +{% endtab %} +{% endtabs %} + +``` +{ + 'foo-one': { + A: [ 'foo', 'foo' ], + B: [ 'one', 'one' ], + C: [ 1, 6 ], + D: [ 3, 7 ] + }, + 'bar-one': { A: [ 'bar' ], B: [ 'one' ], C: [ 3 ], D: [ 2 ] }, + 'foo-two': { + A: [ 'foo', 'foo' ], + B: [ 'two', 'two' ], + C: [ 2, 5 ], + D: [ 4, 5 ] + }, + 'bar-three': { A: [ 'bar' ], B: [ 'three' ], C: [ 4 ], D: [ 1 ] }, + 'bar-two': { A: [ 'bar' ], B: [ 'two' ], C: [ 2 ], D: [ 6 ] }, + 'foo-three': { A: [ 'foo' ], B: [ 'three' ], C: [ 7 ], D: [ 8 ] } +} +``` + +**** \ No newline at end of file diff --git a/api-reference/groupby/groupby.last.md b/api-reference/groupby/groupby.last.md new file mode 100644 index 0000000..51174bf --- /dev/null +++ b/api-reference/groupby/groupby.last.md @@ -0,0 +1,87 @@ +--- +description: Obtain the last row of each groups +--- + +# Groupby.last + +> danfo.Groupby.last \[[source](https://github.com/javascriptdata/danfojs/blob/9bfda6dcb6b2b620591ec7b3340d35e3f801c8ab/src/danfojs-base/aggregators/groupby.ts#L625)\] + +**Parameters**: None + +**Return**: DataFrame + +**Examples** + +Obtain the last row of each group for dataframe grouped by one column + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] + } + +let df = new dfd.DataFrame(data) +let grp = df.groupby(["A"]) +grp.last().print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A_Group │ A │ B │ C │ D ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ foo │ three │ 7 │ 8 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ bar │ bar │ two │ 2 │ 6 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +Obtain the number of groups in dataframe grouped by two columns + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) +let grp = df.groupby(["A","B"]) +grp.last().print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A_Group │ B_Group │ A │ B │ C │ D ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ foo │ one │ 6 │ 7 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ two │ foo │ two │ 5 │ 5 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ three │ foo │ three │ 7 │ 8 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ bar │ one │ bar │ one │ 3 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ bar │ three │ bar │ three │ 4 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ two │ bar │ two │ 2 │ 6 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +**** \ No newline at end of file diff --git a/api-reference/groupby/groupby.max.md b/api-reference/groupby/groupby.max.md index 1de767f..98c2c55 100644 --- a/api-reference/groupby/groupby.max.md +++ b/api-reference/groupby/groupby.max.md @@ -4,7 +4,7 @@ description: Obtain the maximum value of columns per groups # Groupby.max -> danfo.Groupby.max\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L309)\] +> danfo.Groupby.max() \[[source](https://github.com/javascriptdata/danfojs/blob/0d33e344b80a3ed54c91c9393ac3b583d4b0b1a4/src/danfojs-base/aggregators/groupby.ts#L506)] **Parameters:** None @@ -19,13 +19,13 @@ Obtain the maximum value for a column for each group, group by one column ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -36,7 +36,7 @@ grp.col(["C"]).max().print() {% endtab %} {% endtabs %} -```text +``` Shape: (2,2) ╔═══╤═══════════════════╤═══════════════════╗ @@ -56,13 +56,13 @@ Obtain the maximum value for two columns for each group, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -73,7 +73,7 @@ grp.col(["C","D"]).max().print() {% endtab %} {% endtabs %} -```text +``` Shape: (2,3) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -92,13 +92,13 @@ Obtain the maximum value for a column for each group, group by two columns ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -109,7 +109,7 @@ grp.col(["C"]).max().print() {% endtab %} {% endtabs %} -```text +``` Shape: (5,3) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -134,13 +134,13 @@ Obtain the maximum value for two columns for each group, group by two columns ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -151,7 +151,7 @@ grp.col(["C","D"]).max().print() {% endtab %} {% endtabs %} -```text +``` Shape: (5,4) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -168,4 +168,3 @@ grp.col(["C","D"]).max().print() ║ 4 │ bar │ two │ 2 │ 6 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` - diff --git a/api-reference/groupby/groupby.mean.md b/api-reference/groupby/groupby.mean.md index bfb0ad0..c411bba 100644 --- a/api-reference/groupby/groupby.mean.md +++ b/api-reference/groupby/groupby.mean.md @@ -4,7 +4,7 @@ description: Obtain the mean per groups for each column(s) # Groupby.mean -> danfo.Series.mean\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L274)\] +> danfo.Series.mean() \[[source](https://github.com/javascriptdata/danfojs/blob/0d33e344b80a3ed54c91c9393ac3b583d4b0b1a4/src/danfojs-base/aggregators/groupby.ts#L464)] **Parameters**: None @@ -19,13 +19,13 @@ Obtain the mean of a column for each group, group by one column ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -36,7 +36,7 @@ grp.col(["C"]).mean().print() {% endtab %} {% endtabs %} -```text +``` Shape: (2,2) @@ -57,13 +57,13 @@ Obtain the mean for two columns for each group, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -74,7 +74,7 @@ grp.col(["C","D"]).mean().print() {% endtab %} {% endtabs %} -```text +``` Shape: (2,3) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -93,13 +93,13 @@ Obtain the mean for a column for each group, group by two columns ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -110,7 +110,7 @@ grp.col(["C"]).mean().print() {% endtab %} {% endtabs %} -```text +``` Shape: (5,3) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -135,24 +135,22 @@ Obtain the mean for two columns for each group, group by two columns ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) - - let grp = df.groupby(["A","B"]) grp.col(["C","D"]).mean().print() ``` {% endtab %} {% endtabs %} -```text +``` Shape: (5,4) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -170,5 +168,4 @@ grp.col(["C","D"]).mean().print() ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -\*\*\*\* - +**** diff --git a/api-reference/groupby/groupby.min.md b/api-reference/groupby/groupby.min.md index 75e1b60..f74be86 100644 --- a/api-reference/groupby/groupby.min.md +++ b/api-reference/groupby/groupby.min.md @@ -4,7 +4,7 @@ description: Obtain the minimum value per groups for a coumn(s) # Groupby.min -> danfo.Groupby.min\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L315)\] +> danfo.Groupby.min() \[[source](https://github.com/javascriptdata/danfojs/blob/9bfda6dcb6b2b620591ec7b3340d35e3f801c8ab/src/danfojs-base/aggregators/groupby.ts#L514)] **Parameters**: None @@ -19,24 +19,23 @@ Obtain the minimum value for a column for each group, group by one column ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) - let grp = df.groupby(["A"]) grp.col(["C"]).min().print() ``` {% endtab %} {% endtabs %} -```text +``` Shape: (2,2) ╔═══╤═══════════════════╤═══════════════════╗ @@ -55,24 +54,22 @@ Obtain the minimum value for two columns for each group, group by one column ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) - - let grp = df.groupby(["A"]) grp.col(["C","D"]).min().print() ``` {% endtab %} {% endtabs %} -```text +``` Shape: (2,3) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -91,39 +88,37 @@ Obtain the maximum value for a column for each group, group by two columns ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) - - let grp = df.groupby(["A","B"]) grp.col(["C"]).min().print() ``` {% endtab %} {% endtabs %} -```text - Shape: (5,3) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_min ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ one │ 1 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ two │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ three │ 7 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ bar │ one │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ bar │ two │ 2 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C_min ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ two │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ three │ 7 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ bar │ one │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ bar │ three │ 4 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ two │ 2 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` Obtain the maximum value for two columns for each group, group by two columns @@ -133,40 +128,37 @@ Obtain the maximum value for two columns for each group, group by two columns ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) - - let grp = df.groupby(["A","B"]) grp.col(["C","D"]).min().print() ``` {% endtab %} {% endtabs %} -```text - Shape: (5,4) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_min │ D_min ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ one │ 1 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ two │ 2 │ 4 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ three │ 7 │ 8 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ bar │ one │ 3 │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ bar │ two │ 2 │ 6 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C_min │ D_min ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 1 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ two │ 2 │ 4 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ three │ 7 │ 8 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ bar │ one │ 3 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ bar │ three │ 4 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ two │ 2 │ 6 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -\*\*\*\* - +**** diff --git a/api-reference/groupby/groupby.ngroups.md b/api-reference/groupby/groupby.ngroups.md new file mode 100644 index 0000000..951c0d7 --- /dev/null +++ b/api-reference/groupby/groupby.ngroups.md @@ -0,0 +1,69 @@ +--- +description: Obtain the number of groups +--- + +# Groupby.ngroups + +> danfo.Groupby.ngroups \[[source](https://github.com/javascriptdata/danfojs/blob/9bfda6dcb6b2b620591ec7b3340d35e3f801c8ab/src/danfojs-base/aggregators/groupby.ts#L598)\] + +**Parameters**: None + +**Return**: Number + +**Examples** + +Obtain the number of groups in a dataframe grouped by one column + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] + } + +let df = new dfd.DataFrame(data) + + +let grp = df.groupby(["A"]) +console.log(grp.ngroups) +``` +{% endtab %} +{% endtabs %} + +``` +2 +``` + +Obtain the number of groups in dataframe grouped by two columns + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) +let grp = df.groupby(["A","B"]) +console.log(grp.ngroups) +``` +{% endtab %} +{% endtabs %} + +``` +6 +``` + +**** \ No newline at end of file diff --git a/api-reference/groupby/groupby.size.md b/api-reference/groupby/groupby.size.md new file mode 100644 index 0000000..a4ae97a --- /dev/null +++ b/api-reference/groupby/groupby.size.md @@ -0,0 +1,87 @@ +--- +description: Obtain the last row of each groups +--- + +# Groupby.last + +> danfo.Groupby.last \[[source](https://github.com/javascriptdata/danfojs/blob/9bfda6dcb6b2b620591ec7b3340d35e3f801c8ab/src/danfojs-base/aggregators/groupby.ts#L635)\] + +**Parameters**: None + +**Return**: DataFrame + +**Examples** + +Obtain the size of each group for dataframe grouped by one column + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] + } + +let df = new dfd.DataFrame(data) +let grp = df.groupby(["A"]) +grp.size().print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ A_Group │ applyOps ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ 5 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ bar │ 3 ║ +╚════════════╧═══════════════════╧═══════════════════╝ +``` + +Obtain the size of each group in dataframe grouped by two columns + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data ={A: ['foo', 'bar', 'foo', 'bar', + 'foo', 'bar', 'foo', 'foo'], + B: ['one', 'one', 'two', 'three', + 'two', 'two', 'one', 'three'], + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} + +let df = new dfd.DataFrame(data) +let grp = df.groupby(["A","B"]) +grp.size().print() +``` +{% endtab %} +{% endtabs %} + +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A_Group │ B_Group │ applyOps ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ two │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ three │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ bar │ one │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ bar │ three │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ two │ 1 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +**** \ No newline at end of file diff --git a/api-reference/groupby/groupby.std.md b/api-reference/groupby/groupby.std.md index 30b22f1..f0d1516 100644 --- a/api-reference/groupby/groupby.std.md +++ b/api-reference/groupby/groupby.std.md @@ -4,7 +4,7 @@ description: Obtain the standard deviation per groups for specified columns # Groupby.std -> danfo.Groupby.**std**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L262)\] +> danfo.Groupby.**std**() \[[source](https://github.com/javascriptdata/danfojs/blob/9bfda6dcb6b2b620591ec7b3340d35e3f801c8ab/src/danfojs-base/aggregators/groupby.ts#L448)] **Parameters**: None @@ -20,24 +20,22 @@ Obtain the standard deviation of a column for each group, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) - - let grp = df.groupby(["A"]) grp.col(["C"]).std().print() ``` {% endtab %} {% endtabs %} -```text +``` Shape: (2,2) @@ -58,13 +56,13 @@ Obtain the std for two columns for each group, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -74,7 +72,7 @@ grp.col(["C","D"]).std().print() {% endtab %} {% endtabs %} -```text +``` Shape: (2,3) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -94,13 +92,13 @@ Obtain the std for a column for each group, group by two columns const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -111,7 +109,7 @@ grp.col(["C"]).std().print() {% endtab %} {% endtabs %} -```text +``` Shape: (5,3) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -137,13 +135,13 @@ Obtain the std for two columns for each group, group by two columns const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -153,7 +151,7 @@ grp.col(["C","D"]).std().print() {% endtab %} {% endtabs %} -```text +``` Shape: (5,4) @@ -172,5 +170,4 @@ grp.col(["C","D"]).std().print() ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -\*\*\*\* - +**** diff --git a/api-reference/groupby/groupby.sum.md b/api-reference/groupby/groupby.sum.md index 8e46a98..6ad83df 100644 --- a/api-reference/groupby/groupby.sum.md +++ b/api-reference/groupby/groupby.sum.md @@ -4,7 +4,7 @@ description: Obtain the sum per groups for columns # Groupby.sum -> danfo.Groupby.sum\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L256)\] +> danfo.Groupby.sum() \[[source](https://github.com/javascriptdata/danfojs/blob/9bfda6dcb6b2b620591ec7b3340d35e3f801c8ab/src/danfojs-base/aggregators/groupby.ts#L440)] **Parameters**: None @@ -19,26 +19,23 @@ Obtain the sum of a column for each group, group by one column ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) - let grp = df.groupby(["A"]) grp.col(["C"]).sum().print() ``` {% endtab %} {% endtabs %} -```text - - Shape: (2,2) +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ A │ C_sum ║ @@ -56,26 +53,23 @@ Obtain the sum for two columns for each group, group by one column ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) - let grp = df.groupby(["A"]) grp.col(["C","D"]).sum().print() ``` {% endtab %} {% endtabs %} -```text - Shape: (2,3) - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ C_sum │ D_sum ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -92,24 +86,23 @@ Obtain the sum for a column for each group, group by two columns ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) - let grp = df.groupby(["A","B"]) grp.col(["C"]).sum().print() ``` {% endtab %} {% endtabs %} -```text +``` Shape: (5,3) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -134,40 +127,38 @@ Obtain the sum for two columns for each group, group by two columns ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) - let grp = df.groupby(["A","B"]) grp.col(["C","D"]).sum().print() ``` {% endtab %} {% endtabs %} -```text - Shape: (5,4) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C_sum │ D_sum ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ foo │ one │ 7 │ 10 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ foo │ two │ 7 │ 9 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ foo │ three │ 7 │ 8 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ bar │ one │ 3 │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ bar │ two │ 2 │ 6 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C_sum │ D_sum ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ foo │ one │ 7 │ 10 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ foo │ two │ 7 │ 9 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ foo │ three │ 7 │ 8 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ bar │ one │ 3 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 4 │ bar │ three │ 4 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 5 │ bar │ two │ 2 │ 6 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -\*\*\*\* - +**** diff --git a/api-reference/groupby/groupby.var.md b/api-reference/groupby/groupby.var.md index 20a3ca8..08a9d97 100644 --- a/api-reference/groupby/groupby.var.md +++ b/api-reference/groupby/groupby.var.md @@ -4,7 +4,7 @@ description: Obtain the variance per groups for a specified column # Groupby.var -> danfo.Groupby.**var**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/groupby.js#L268)\] +> danfo.Groupby.**var**() \[[source](https://github.com/javascriptdata/danfojs/blob/9bfda6dcb6b2b620591ec7b3340d35e3f801c8ab/src/danfojs-base/aggregators/groupby.ts#L456)] **Parameters**: None @@ -20,24 +20,23 @@ Obtain the variance of a column for each group, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) - let grp = df.groupby(["A"]) grp.col(["C"]).var().print() ``` {% endtab %} {% endtabs %} -```text +``` Shape: (2,2) @@ -58,13 +57,13 @@ Obtain the var for two columns for each group, group by one column const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -74,7 +73,7 @@ grp.col(["C","D"]).var().print() {% endtab %} {% endtabs %} -```text +``` Shape: (2,3) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -94,13 +93,13 @@ Obtain the var for a column for each group, group by two columns const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -111,7 +110,7 @@ grp.col(["C"]).var().print() {% endtab %} {% endtabs %} -```text +``` Shape: (5,3) ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -137,13 +136,13 @@ Obtain the var for two columns for each group, group by two columns const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', +let data ={A: ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', + B: ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } + C: [1,3,2,4,5,2,6,7], + D: [3,2,4,1,5,6,7,8] +} let df = new dfd.DataFrame(data) @@ -153,7 +152,7 @@ grp.col(["C","D"]).var().print() {% endtab %} {% endtabs %} -```text +``` Shape: (5,4) @@ -172,5 +171,4 @@ grp.col(["C","D"]).var().print() ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -\*\*\*\* - +**** diff --git a/api-reference/input-output/README.md b/api-reference/input-output/README.md index f071ac9..310be54 100644 --- a/api-reference/input-output/README.md +++ b/api-reference/input-output/README.md @@ -1,18 +1,18 @@ --- -description: >- - Functions and methods to easily read tabular/structured data into DataFrame - and Series Objects +description: Functions for reading tabular/structured data into DataFrame/Series Objects --- # Input/Output ## CSV -| \`\` | | -| :--- | :--- | -| [`read_csv`](danfo.read_csv.md) | Read a comma-separated values \(csv\) file into DataFrame. | -| [`read_excel`](danfo.read_excel.md) | Read an Excel values \(xls\) file into DataFrame. | -| [`read_json`](danfo.read_json.md) | Read a JSON values \(json\) file into DataFrame. | - -Writing `CSV` and `JSON` is done directly from structured types \(e.g. `DataFrame.to_csv`\) +| \`\` | | +| ----------------------------------- | -------------------------------------------------------- | +| [`readCSV`](danfo.read_csv.md) | Read a comma-separated values (csv) file into DataFrame. | +| [`read_excel`](danfo.read_excel.md) | Read an Excel values (xlsx) file into DataFrame. | +| [`readJSON`](danfo.read_json.md) | Read a JSON values (json) file into DataFrame. | +| [toCSV](danfo.to_csv.md) | Writes a DataFrame/Series to CSV file | +| [to_excel](danfo.to_excel.md) | Writes a DataFrame/Series to Excel file | +| [toJSON](danfo.to_json.md) | Writes a DataFrame/Series to JSON file | +Writing to `CSV` and `JSON` can also be done directly from DataFrame or Series objects (e.g. [`DataFrame.toCSV()`](../dataframe/dataframe.to_csv.md)) diff --git a/api-reference/input-output/danfo.read_csv.md b/api-reference/input-output/danfo.read_csv.md index d1ab8f8..c389d5d 100644 --- a/api-reference/input-output/danfo.read_csv.md +++ b/api-reference/input-output/danfo.read_csv.md @@ -4,61 +4,28 @@ description: >- reading of CSV files in chunks. --- -# danfo.read\_csv +# danfo.readCSV -> danfo.**read\_csv**\(source, configs\) [\[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/io/reader.js#L21)\] +> danfo.**readCSV**(source, options) - - - - - - - - - - - - - - - - - - - - - - - -
Parameters - TypeDescriptionDefault
source:str, path or URLAny valid string path is acceptable. The string could be a URL. Valid - URL schemes include https, http, ftp, s3, gs, and file. Local file paths - are only accepted in Nodejs environment.
configs:object, optional -

-

A CSV Config object that contains configurations for reading and decoding - from CSV file(s). Supported params are:

-

start: The index position to start from when reading the CSV file.

-

end: The end position to stop at when reading the CSV file.

-

... csvConfigs: other supported Tensorflow csvConfig parameters. - See https://js.tensorflow.org/api/latest/#data.csv -

-
+| | | | | +| -------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- | +| **Parameters** | Type | Description | Default | +| _**source**_ | File object, File path, URL |

Any valid string path is acceptable. The string could be a URL or a valid local file path.

A browser input file object is also supported.

| | +| **options** | object, optional | Supports all Papaparse config parameters. See [https://www.papaparse.com/docs#config](https://www.papaparse.com/docs#config). |

{

header: true

}

| -**Returns:** +The **readCSV** method can read a CSV file from a local disk, or over the internet (URL). Reading of local files is only supported in Nodejs, while reading of input file objects is only supported in the browser. - ****_**Promise**_. Resolves to DataFrame +### **Reading files from local disk** -### Example - -The **read\_csv** method can read a csv file from local disk, or over the internet \(URL\). Reading of local files are only supported in danfojs-node. +By specifying a valid file path, you can load CSV files from local disk: {% tabs %} {% tab title="Node.js" %} ```javascript const dfd = require("danfojs-node") -dfd.read_csv("user_names.csv") //assumes file is in CWD +dfd.readCSV("./user_names.csv") //assumes file is in CWD .then(df => { df.head().print() @@ -68,54 +35,18 @@ dfd.read_csv("user_names.csv") //assumes file is in CWD }) ``` {% endtab %} - -{% tab title="Browser" %} -```markup - - - - - - - - - Document - - - - -
- - - - - -``` -{% endtab %} {% endtabs %} -**Loading Files from URL** +### **Reading files from a URL** -By specifying a valid URL, you can load CSV files from any location into Danfo**'**s data structure: +By specifying a valid URL, you can load CSV files from any location into Danfo\*\*'\*\*s data structure: {% tabs %} {% tab title="Node.js" %} ```javascript const dfd = require("danfojs-node") -dfd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv") //assumes file is in CWD +dfd.readCSV("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv") //assumes file is in CWD .then(df => { df.head().print() @@ -134,8 +65,8 @@ dfd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-c - - + + Document @@ -144,7 +75,7 @@ dfd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-c
+ Document - -
+ - - - ``` {% endtab %} {% endtabs %} - -```bash -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ Region │ Country │ Item Type │ Sales Channel │ ... │ Unit Cost │ Total Revenue │ Total Cost │ Total Profit ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ Sub-Saharan A... │ South Africa │ Fruits │ Offline │ ... │ 6.92 │ 14862.69 │ 11023.56 │ 3839.13 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ Middle East a... │ Morocco │ Clothes │ Online │ ... │ 35.84 │ 503890.08 │ 165258.24 │ 338631.84 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ Australia and... │ Papua New Guinea │ Meat │ Offline │ ... │ 364.69 │ 151880.4 │ 131288.4 │ 20592 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ Sub-Saharan A... │ Djibouti │ Clothes │ Offline │ ... │ 35.84 │ 61415.36 │ 20142.08 │ 41273.28 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ Europe │ Slovakia │ Beverages │ Offline │ ... │ 31.79 │ 188518.85 │ 126301.67 │ 62217.18 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ Region │ Country │ Item Type │ Sales Channel │ ... │ Unit Cost │ Total Revenue │ Total Cost │ Total Profit ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ Asia │ Taiwan │ Fruits │ Offline │ ... │ 6.92 │ 74957.22 │ 55595.28 │ 19361.94 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ Middle East a... │ Algeria │ Cosmetics │ Online │ ... │ 263.33 │ 4227286.8 │ 2546137.77 │ 1681149.03 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ Asia │ Singapore │ Snacks │ Online │ ... │ 97.44 │ 1171204.08 │ 747949.44 │ 423254.64 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ Australia and... │ Papua New Guinea │ Clothes │ Offline │ ... │ 35.84 │ 993573.76 │ 325857.28 │ 667716.48 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 4 │ Asia │ Vietnam │ Personal Care │ Online │ ... │ 56.67 │ 652532.32 │ 452453.28 │ 200079.04 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` - - - diff --git a/api-reference/input-output/danfo.read_excel.md b/api-reference/input-output/danfo.read_excel.md index d8e3d9e..75d2fe2 100644 --- a/api-reference/input-output/danfo.read_excel.md +++ b/api-reference/input-output/danfo.read_excel.md @@ -1,62 +1,30 @@ --- -description: Reads an excel file into DataFrame. +description: Reads a JSON file from local or remote location into a DataFrame. --- -# danfo.read\_excel - -> danfo.**read\_excel**\(source, configs\) [\[source](https://github.com/opensource9ja/danfojs/blob/849d14c8e7fa79bce4ffa9d0d177639047313520/danfojs/src/io/reader.js#L89)\] - -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> ->
ParametersTypeDescription
sourcestringsource : string, URL or local file path to retreive Excel file.
configsObject ->

{

->

sheet : string, (Optional) Name of the sheet which u want to parse. -> Default will be the first sheet.

->

header_index : int, (Optional) Only used in browser environment. -> The Index of the row which represents the header(columns) of the data. -> Default will be the first non empty row.

->

data_index : int, (Optional) Only used in browser environment. The -> index of the row from which actual data(content) starts. Default will be -> the next row of header_index ->

->

}

->
-> -> **Returns:** -> -> ****return ****{**Promise**} DataFrame structure of parsed Excel data +# danfo.readExcel + +> danfo.**readExcel**(source, options) + +| Parameters | Type | Description | +| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| source | string | **source** : string, URL or local file path to Excel file. | +| options | Object |

{

sheet : string, (Optional) Name of the sheet which u want to parse. Default will be the first sheet.
method: The HTTP method to use.

headers: Additional headers to send with the request if reading JSON from remote url. Supports all the node-fetch options in Nodejs, and all fetch options in browsers.

frameConfig: Optional arguments passed when creating the DataFrame. e.g column names, index. etc.

parsingOptions: supports all xlsx options. See https://docs.sheetjs.com/docs/api/parse-options

}

| ### Example -The **read\_excel** method can read excel files saved from local disk, or over the internet. +The **readExcel** method can read excel files saved on a local disk, or over the internet. {% tabs %} {% tab title="Node.js" %} ```javascript const dfd = require("danfojs-node") +const path = require("path") -local_xcel = 'testexcel.xls' +let local_xcel = path.join(process.cwd(), "data", "testexcel.xlxs") async function load_process_data() { - let df = await dfd.read_excel(local_xcel) + let df = await dfd.readExcel(local_xcel) df.head().print() } @@ -72,7 +40,7 @@ load_process_data() - + Document @@ -81,7 +49,7 @@ load_process_data() + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/input-output/danfo.read_json.md b/api-reference/input-output/danfo.read_json.md index 49528d0..3fd26e6 100644 --- a/api-reference/input-output/danfo.read_json.md +++ b/api-reference/input-output/danfo.read_json.md @@ -2,28 +2,47 @@ description: Reads a JSON file into DataFrame. --- -# danfo.read\_json +# danfo.readJSON -> danfo.**read\_json**\(source,\) [\[source](https://github.com/opensource9ja/danfojs/blob/849d14c8e7fa79bce4ffa9d0d177639047313520/danfojs/src/io/reader.js#L47)\] +> danfo.readJSON(source, options) -| **Parameters** | Type | Description | -| :--- | :--- | :--- | -| _**source**_: | **string**, path or URL | Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, https, ftp, s3, gs, or a local path. Both relative and absolute paths are supported | +| | | | | +| -------------- | -------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | +| **Parameters** | Type | Description | Default | +| _**source**_ | Input file object, string file\*\* \*\*path or URL |

Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, https, ftp, s3, gs, or a local path. Both relative and absolute paths are supported

An input file object is also supported in the browser.

| | +| options | Object |

Configuration options for reading JSON files. Supported options:

{
method: The HTTP method to use.

headers: Additional headers to send with the request if reading JSON from remote url. Supports all the node-fetch options in Nodejs, and all fetch options in browsers.

}

|

{
method: "GET"
}

| -**Returns:** +The **readJSON** method can read JSON files from a local disk, over the internet, or directly from input file objects. - ****_**Promise**_. Resolves to DataFrame +### **Reading JSON files from local disk** -### Example +{% tabs %} +{% tab title="Node.js" %} +```javascript +const dfd = require("danfojs-node") + +dfd.readJSON("./user_names.json") + .then(df => { + + df.head().print() + + }).catch(err=>{ + console.log(err); + }) +``` +{% endtab %} +{% endtabs %} -The **read\_json** method can read JSON file from local disk, or over the internet. For instance, in the example below, _**user\_names.json**_ is a JSON file in this same directory as our script. To read it into DataFrame, you can specify the relative path: +### **Reading JSON files from a URL** + +By specifying a valid URL, you can load JSON files from any location: {% tabs %} {% tab title="Node.js" %} ```javascript const dfd = require("danfojs-node") -dfd.read_json("user_names.json") +dfd.readJSON("https://raw.githubusercontentdatasets/master/finance-charts-apple.json") .then(df => { df.head().print() @@ -36,8 +55,69 @@ dfd.read_json("user_names.json") {% tab title="Browser" %} ```markup + + + + + + + + Document + + + + + + + ``` {% endtab %} {% endtabs %} +### **Reading an input file object in the browser** + +By specifying a valid [file object](https://developer.mozilla.org/en-US/docs/Web/API/File), you can load a JSON file in the browser: + +{% tabs %} +{% tab title="Browser" %} +```markup + + + + + + + + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/input-output/danfo.to_csv.md b/api-reference/input-output/danfo.to_csv.md new file mode 100644 index 0000000..9798a11 --- /dev/null +++ b/api-reference/input-output/danfo.to_csv.md @@ -0,0 +1,115 @@ +--- +description: Writes a DataFrame or Series to CSV format. +--- + +# danfo.toCSV + +> danfo.**toCSV**(data, options) + +| | | | | +| -------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | +| **Parameters** | Type | Description | Default | +| _**data**_ | Series or DataFrame | The Series or DataFrame to write to CSV | | +| **options** | object, optional |

Configuration object:

{

filePath: Local file path to write the CSV file to. If not specified, the CSV will be returned as a string. Only needed in Nodejs version
fileName: The name of the file to download as. Only needed in browser environment.
download: Boolean indicating whether to automatically download the CSV file in the browser. Only needed in the browser environment.

header: Boolean indicating whether to include a header row in the CSV file.

sep: Character to be used as a separator in the CSV file.

}

|

{
download: false,
sep: ","

}

| + +The **toCSV** function can be used to write out a DataFrame or Series to CSV file. The output is configurable and will depend on the environment. In the following examples, we show you how to write/download a CSV file from Node and Browser environments. + +### Convert DataFrame to CSV string and return value + +{% tabs %} +{% tab title="Node.js" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + +const csv = dfd.toCSV(df); +console.log(csv); + +//output +Abs,Count,country code +20.2,34,NG +30,4,FR +47.3,5,GH +``` +{% endtab %} + +{% tab title="Browser" %} +```markup + + + + + + + + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} + +### Convert DataFrame to CSV string and write to file path + +Writing a CSV file to a local file path is only supported in the Nodejs environment + +{% tabs %} +{% tab title="Node.js" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + +dfd.toCSV(df, { filePath: "testOut.csv"}); +``` +{% endtab %} +{% endtabs %} + +### Convert DataFrame to CSV string and download file in Client-side lib + +You can automatically convert and download a CSV file in a browser environment, by specifying a `fileName` and setting `download` to **true**. + +```javascript +const dfd = require("danfojs") + +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + +dfd.toCSV(df, { fileName: "testOut.csv", download: true}); +``` diff --git a/api-reference/input-output/danfo.to_excel.md b/api-reference/input-output/danfo.to_excel.md new file mode 100644 index 0000000..146f70c --- /dev/null +++ b/api-reference/input-output/danfo.to_excel.md @@ -0,0 +1,54 @@ +--- +description: >- + Converts a DataFrame or Series to Excel file, and write file to disk or + download in browser. +--- + +# danfo.toExcel + +> danfo.**toExcel**(data, options) + +| **Parameters** | Type | Description | Default | +| -------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | +| _**data**_ | Series or DataFrame | The Series or DataFrame to write to CSV | | +| **options** | object, optional |

Configuration object:

{

filePath: Local file path to write the CSV file to. If not specified, the CSV will be returned as a string. Only needed in Nodejs version
fileName: The name of the file to download as. Only needed in the browser environment.
sheetName: Name to call the excel sheet.

writingOptions: Supports all xlsx write options. See https://docs.sheetjs.com/docs/api/write-options

}

|

{
filePath: "./output.xlsx",
sheetName: "Sheet1"

}

| + +The **toExcel** function can be used to write out a DataFrame or Series to Excel (**.xlsx**) file. The output format will depend on the environment. In the following examples, we show you how to write/download an Excel file from Node and Browser environments. + +### Convert DataFrame to Excel and write to file path + +You can write a DataFrame or Series in Excel format using the toExcel function and specifying the file path. + +{% tabs %} +{% tab title="Node.js" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + +dfd.toExcel(df, { filePath: "testOut.xlsx"}); +``` +{% endtab %} +{% endtabs %} + +### Convert DataFrame to Excel and download the file in Client-side lib + +You can automatically convert and download an Excel file in a browser environment, by specifying a filename. This will open a download window. + +```javascript +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new DataFrame(data); + +dfd.toExcel(df, { fileName: "testOut.xlsx"}); +``` diff --git a/api-reference/input-output/danfo.to_json.md b/api-reference/input-output/danfo.to_json.md new file mode 100644 index 0000000..18816d7 --- /dev/null +++ b/api-reference/input-output/danfo.to_json.md @@ -0,0 +1,123 @@ +# danfo.toJSON + +> danfo.toJSON(data, options) + +| | | | | +| -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | +| **Parameters** | Type | Description | Default | +| _**data**_ | Series or DataFrame | The Series or DataFrame to write to CSV | | +| **options** | object, optional |

Configuration object:

{

filePath: Local file path to write the CSV file to. If not specified, the CSV will be returned as a string. Only needed in Nodejs version
fileName: The name of the file to download as. Only needed in browser environment.
format: The format of the JSON. Can be one of row or column.

}

|

{
format: "column"
}

| + +The **toJSON** function can be used to write out a DataFrame or Series to JSON format/file. The output is configurable and will depend on the environment. In the following examples, we show you how to write/download a JSON file from Node and Browser environments. + +### Convert DataFrame/Series to JSON and return value + +{% tabs %} +{% tab title="Node.js" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + +const jsonObj = dfd.toJSON(df); //column format +console.log(jsonObj); + +//output +[ + { Abs: 20.2, Count: 34, 'country code': 'NG' }, + { Abs: 30, Count: 4, 'country code': 'FR' }, + { Abs: 47.3, Count: 5, 'country code': 'GH' } +] + +//row format +const jsonObj = dfd.toJSON(df, { + format: "row" +}); + +console.log(jsonObj); +//output +{ + Abs: [ 20.2, 30, 47.3 ], + Count: [ 34, 4, 5 ], + 'country code': [ 'NG', 'FR', 'GH' ] +} +``` +{% endtab %} + +{% tab title="Browser" %} +```markup + + + + + + + + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} + +### Convert DataFrame/Series to JSON and write to file path + +Writing a DataFrame/Series as JSON, to a local file path is only supported in the Nodejs environment + +{% tabs %} +{% tab title="Node.js" %} +```javascript +const dfd = require("danfojs-node") + +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + +dfd.toJSON(df, { filePath: "./testOutput.json" }); +``` +{% endtab %} +{% endtabs %} + +### Convert DataFrame/Series to JSON and download file in browser + +You can automatically convert and download a DataFrame/Series as a JSON file in a browser environment, by specifying a `fileName` and setting `download` to **true**. + +```javascript +let data = { + Abs: [20.2, 30, 47.3], + Count: [34, 4, 5], + "country code": ["NG", "FR", "GH"], +}; + +let df = new dfd.DataFrame(data); + +dfd.toJSON(df, { fileName: "test_out.json", download: true }); +``` diff --git a/api-reference/plotting/bar-charts.md b/api-reference/plotting/bar-charts.md index a946ebe..5dab386 100644 --- a/api-reference/plotting/bar-charts.md +++ b/api-reference/plotting/bar-charts.md @@ -8,8 +8,6 @@ A bar plot presents categorical data with rectangular bars with lengths proporti ## Examples -The **bar** plot is exposed by the .**plot\(\)** function called on a Series or DataFrame. The **.plot\(\)** method accepts an HTML Div id where it renders the plot, while configuration options for the bars drawn can be passed through the config parameter. - ### Bar plot on Series ```markup @@ -19,8 +17,7 @@ The **bar** plot is exposed by the .**plot\(\)** function called on a Series or - - + Document @@ -29,14 +26,13 @@ The **bar** plot is exposed by the .**plot\(\)** function called on a Series or
- ``` ![](../../.gitbook/assets/newplot-6-.png) @@ -50,8 +46,7 @@ The **bar** plot is exposed by the .**plot\(\)** function called on a Series or - - + @@ -59,7 +54,7 @@ The **bar** plot is exposed by the .**plot\(\)** function called on a Series or
- + + + + Document - + - + +
- - + - ``` +{% endtab %} +{% endtabs %} -![](../../.gitbook/assets/newplot-23-.png) +![](<../../.gitbook/assets/newplot (23).png>) ### Box plots on a DataFrame -```markup +{% tabs %} +{% tab title="React" %} +{% code title="App.jsx" %} +```tsx +import { useEffect } from 'react'; +import './App.css'; +import { Series, readCSV } from "danfojs-nightly"; + +function App() { + + useEffect(() => { + readCSV("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv") + .then(df => { + + const sub_df = df.loc({ columns: ["Age", "Fare"] }) + sub_df.plot("plot_div").box() + + }).catch(err => { + console.log(err); + }) + }, []) + + return ( +
+
+
+
+
+ ); +} + +export default App; +``` +{% endcode %} +{% endtab %} + +{% tab title="Browser" %} +```html - - - - - - + + + + Document - + - + +
- - + - ``` +{% endtab %} +{% endtabs %} -![](../../.gitbook/assets/screen-shot-2020-08-11-at-1.20.42-am%20%281%29%20%281%29.png) +![](<../../.gitbook/assets/screen-shot-2020-08-11-at-1.20.42-am (1).png>) ### Box plot for selected columns in a DataFrame -```markup +{% tabs %} +{% tab title="React" %} +{% code title="App.jsx" %} +```tsx +import { useEffect } from 'react'; +import './App.css'; +import { Series, readCSV } from "danfojs-nightly"; + +function App() { + + useEffect(() => { + readCSV("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv") + .then(df => { + + df.plot("plot_div").box({ + config: { + x: "Survived", y: "Age" + }, + layout: { + title: "Box Plot" + } + }) + }).catch(err => { + console.log(err); + }) + }, []) + + return ( +
+
+
+
+
+ ); +} + +export default App; +``` +{% endcode %} +{% endtab %} + +{% tab title="Browser" %} +```html - - - - - - + + + + Document - + - + +
- - + - ``` +{% endtab %} +{% endtabs %} -![](../../.gitbook/assets/newplot-24-.png) - - +![](<../../.gitbook/assets/newplot (24).png>) {% hint style="info" %} -To set configuration for your plots, see the [Configuring your plot page](configuring-your-plots.md) +To customize your plots, see the [Configuring your plot page](configuring-your-plots.md) {% endhint %} - diff --git a/api-reference/plotting/configuring-your-plots.md b/api-reference/plotting/configuring-your-plots.md index 359a802..2ad915e 100644 --- a/api-reference/plotting/configuring-your-plots.md +++ b/api-reference/plotting/configuring-your-plots.md @@ -1,69 +1,142 @@ -# Configuring your plots +# Customizing your plots -danfo.js plotting uses [Plotly.js](https://plotly.com/javascript) as its backend for plotting. This means you have all the configuration, flexibility and interactiveness of Plotly. +Danfo.js currently supports [Plotly.js](https://plotly.com/javascript) for plotting. This means you have all the configuration, flexibility, and interactiveness of Plotly. -All [customization](https://plotly.com/javascript/line-charts/) on the plot can be passed as an object of key-value pairs to the config parameter. For example, in the line plot below, we define a layout for our plot and give it a name. +All [customization](https://plotly.com/javascript/line-charts/) on the plot can be passed in the `config` and `layout` parameter. -For example in the following code, we show how to set some basic configuration as well as layout for a line plot. +## Config Parameter -```markup - - +The config parameter extends the [Plotly.js config](https://plotly.com/javascript/configuration-options/) type. That is, all properties available to the Plotly [config](https://plotly.com/javascript/configuration-options/) argument, are available. Alongside those arguments, Danfo.js uses some custom arguments which we list below: - - - +| Argument | Description | Default value | +| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | +| **x** | Column name to plot on the x-axis. | DataFrame index if required | +| **y** | Column name to plot on the y-axis. | DataFrame index if required | +| **columns** | Array of column names to plot. | All columns in the DataFrame when applicable | +| **values** | Used to configure a `pie` chart. A column name containing values for the pie. Maps 1-1 with labels. | | +| **labels** | Used to configure a `pie` chart. A column name containing labels for the pie. Maps 1-1 with values. | | +| **rowPositions** | Used to configure a `pie` chart. Pie chart domain row. See [https://plotly.com/javascript/reference/pie/#pie-domain-row](https://plotly.com/javascript/reference/pie/#pie-domain-row) | Range of `0 - DataFrame column length` | +| **columnPositions** | Used to configure a `pie` chart. Pie chart domain column. See [https://plotly.com/javascript/reference/pie/#pie-domain-column](https://plotly.com/javascript/reference/pie/#pie-domain-column) | Range of `0 - DataFrame column length` | +| **grid** |

Used to configure a pie chart. Accepts the following parameter:

row: Integer size
column: Integer size

| | +| **tableHeaderStyle** | Table properties used for configuring table header. See [full list](https://plotly.com/javascript/reference/table/#table-header) of supported arguments. | | +| **tableCellStyle** | Table properties used for configuring table cells. See [full list](https://plotly.com/javascript/reference/table/#table-header) of supported arguments | | - +## Layout Parameter - +The `layout` argument object is used to configure the overall display of a chart. See the full list of supported [arguments](https://plotly.com/javascript/reference/layout/) + +In the following example, we show how to set some basic configuration as well as layout for a line plot. + +{% tabs %} +{% tab title="React" %} +```tsx +import { useEffect } from 'react'; +import './App.css'; +import { readCSV } from "danfojs-nightly"; + +function App() { + + useEffect(() => { + + readCSV("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv") + .then(df => { + + const layout = { + title: { + text: "Time series plot of AAPL open and close points", + x: 0 + }, + legend: { + bgcolor: "#fcba03", + bordercolor: "#444", + borderwidth: 1, + font: { family: "Arial", size: 10, color: "#fff" } + }, + width: 1000, + yaxis: { + title: 'AAPL open points', + }, + xaxis: { + title: 'Date', + }, + } + + const config = { + columns: ["AAPL.Open", "AAPL.Close"], //columns to plot + displayModeBar: true, + displaylogo: false, + } + df.plot("plot_div").line({ layout, config }) + }) + }, []) + + return ( +
+
+
+
+
+ ); +} + +export default App; +``` +{% endtab %} + +{% tab title="Browser" %} +```html + + + + + + + Document + + + +
-
- - + ``` +{% endtab %} +{% endtabs %} -![](../../.gitbook/assets/newplot-32-.png) +![](<../../.gitbook/assets/newplot (32).png>) +## diff --git a/api-reference/plotting/histograms.md b/api-reference/plotting/histograms.md index fb63b24..c2691cb 100644 --- a/api-reference/plotting/histograms.md +++ b/api-reference/plotting/histograms.md @@ -1,5 +1,5 @@ --- -description: 'Draw one histogram of the DataFrame’s columns, or single histogram for Series' +description: Draw one histogram of the DataFrame’s columns, or single histogram for Series --- # Histograms @@ -10,54 +10,131 @@ A histogram is a representation of the distribution of data. This function group ### Histogram of a Column in a DataFrame -In the example below, we use the titanic dataset, to show a close to a real-world use case of danfo.js +In the example below, we make an histogram from the `Age` column in the titanic dataset. -```markup +{% tabs %} +{% tab title="React" %} +```tsx +import { useEffect } from 'react'; +import './App.css'; +import { readCSV } from "danfojs-nightly"; + +function App() { + + useEffect(() => { + readCSV("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv") + .then(df => { + + df['Age'].plot("plot_div").hist() + + }).catch(err => { + console.log(err); + }) + }, []) + + return ( +
+
+
+
+
+ ); +} + +export default App; +``` +{% endtab %} + +{% tab title="Browser" %} +```html - - - - - Document + + + + + Document +
-
- + }).catch(err => { + console.log(err); + }) + - ``` +{% endtab %} +{% endtabs %} ![](../../.gitbook/assets/newplot-10-.png) ### Customized Histogram plots on DataFrame -```markup +{% tabs %} +{% tab title="React" %} +```tsx +import { useEffect } from 'react'; +import './App.css'; +import { readCSV } from "danfojs-nightly"; + +function App() { + + useEffect(() => { + readCSV("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv") + .then(df => { + + const layout = { + bargap: 0, + bargroupgap: 0.1, + title: "Histogram of two columns stacked", + xaxis: { title: "Value" }, + yaxis: { title: "Count" } + } + + const sub_df = df.loc({ columns: ["Fare", "Age"] }) + sub_df.plot("plot_div").hist({ layout }) + + }).catch(err => { + console.log(err); + }) + }, []) + + return ( +
+
+
+
+
+ ); +} + +export default App; +a +``` +{% endtab %} + +{% tab title="Browser" %} +```tsx - - + Document @@ -65,56 +142,34 @@ In the example below, we use the titanic dataset, to show a close to a real-worl
- ``` +{% endtab %} +{% endtabs %} ![](../../.gitbook/assets/newplot-20-.png) -### Configuring your plots - -danfo.js plotting uses [Plotly.js](https://plotly.com/javascript) as its backend for plotting. This means you have all the configuration, flexibility and interactiveness of Plotly. - -All [customization](https://plotly.com/javascript/line-charts/) on the plot can be passed as an object of key-value pairs to the config parameter. For example: - -```javascript -var layout = { - title: 'A sample plot', - xaxis: { - title: 'X', - }, - yaxis: { - title: 'Y', - } -} - -df.plot("div_tag").histogram({layout: layout}) -``` - {% hint style="info" %} -For more configuration options for Histograms, see the [Plotly](https://plotly.com/javascript/histograms/) style doc. +For more configuration options for Histograms, see the [Plotly](https://plotly.com/javascript/histograms/) doc. {% endhint %} - diff --git a/api-reference/plotting/line-charts.md b/api-reference/plotting/line-charts.md index edd8726..89a2aea 100644 --- a/api-reference/plotting/line-charts.md +++ b/api-reference/plotting/line-charts.md @@ -10,8 +10,6 @@ description: >- ### Basic Line plot on Series -The **line** plot is exposed by the .**plot\(\)** function called on a Series or DataFrame. The **.plot\(\)** method accepts an HTML Div id where it renders the plot, while configuration options for the lines drawn can be passed through the config parameter. - ```markup @@ -19,8 +17,7 @@ The **line** plot is exposed by the .**plot\(\)** function called on a Series or - - + Document @@ -29,21 +26,20 @@ The **line** plot is exposed by the .**plot\(\)** function called on a Series or
- ``` ![](../../.gitbook/assets/newplot-4-.png) ### Line plots on DataFrame -The example below shows the plot of column values against a common x-axis \(index\) +The example below shows the plot of column values against a common x-axis (index) ```markup @@ -52,8 +48,7 @@ The example below shows the plot of column values against a common x-axis \(inde - - + Document @@ -62,7 +57,7 @@ The example below shows the plot of column values against a common x-axis \(inde
- + Document @@ -93,21 +87,26 @@ The example below shows how to plot two columns in a DataFrame against each othe
- ``` ![](../../.gitbook/assets/newplot-3-.png) {% hint style="info" %} -To set configuration for your plots, see the [Configuring your plot page](configuring-your-plots.md) +To customize your plots, see the [Customize your plot page](configuring-your-plots.md) {% endhint %} - diff --git a/api-reference/plotting/pie-charts.md b/api-reference/plotting/pie-charts.md index 73278d1..096de25 100644 --- a/api-reference/plotting/pie-charts.md +++ b/api-reference/plotting/pie-charts.md @@ -10,37 +10,69 @@ A pie plot is a proportional representation of the numerical data in a column ### Pie Chart from Columns in a DataFrame -```markup +{% tabs %} +{% tab title="React" %} +```tsx +import { useEffect } from 'react'; +import './App.css'; +import { DataFrame } from "danfojs-nightly"; + +function App() { + + useEffect(() => { + const df = new DataFrame({ + Price: [19, 26, 55], + Location: ["NG", "GH", "SA"], + Type: ["Residential", "Non-Residential", "Utility"], + }); + + df.plot("plot_div").pie({ config: { values: "Price", labels: "Type" } }); + }, []) + + return ( +
+
+
+
+
+ ); +} + +export default App; +``` +{% endtab %} + +{% tab title="Browser" %} +```html + + + + - - - - - Document - + - + +
- - + - +e ``` +{% endtab %} +{% endtabs %} ![](../../.gitbook/assets/newplot-12-.png) @@ -54,7 +86,7 @@ A pie plot is a proportional representation of the numerical data in a column - + Document @@ -63,27 +95,34 @@ A pie plot is a proportional representation of the numerical data in a column
- ``` ![](../../.gitbook/assets/newplot-21-.png) ### Configure Position of Pie Charts -If you have more than one pie charts displayed, you can set the grid parameter, and also the position of each pie. For example, in the snippet below, we set our grid to 2 by 2 and also pass a set of row and column index position. Each row/column position index correspond to each pie. +If you have more than one pie chart to display, you can set the grid parameter, and also the position of each pie. + +For example, in the snippet below, we set the `grid` to 2 by 2 and also pass a set of row and column index positions. Each row/column position index corresponds to each pie. ```markup @@ -92,8 +131,7 @@ If you have more than one pie charts displayed, you can set the grid parameter, - - + Document @@ -108,15 +146,20 @@ If you have more than one pie charts displayed, you can set the grid parameter, Type: ['Residential', 'Non-Residential', 'Utility'] }) - df.plot("plot_div").pie({ labels: "Type", - grid: { rows: 2, columns: 2 }, - row_pos: [0, 1], col_pos: [0, 1] }) + df.plot("plot_div").pie({ + config: { + labels: "Location", + columns: ["Price", "Volume"], + columnPositions: [0, 1], + rowPositions: [0, 1], + grid: { rows: 2, columns: 2 } + } + }); - ``` ![](../../.gitbook/assets/newplot-22-.png) @@ -124,4 +167,3 @@ If you have more than one pie charts displayed, you can set the grid parameter, {% hint style="info" %} For more configuration options for Pie Charts, see the [Plotly](https://plotly.com/javascript/pie-charts/) style doc. {% endhint %} - diff --git a/api-reference/plotting/scatter-plots.md b/api-reference/plotting/scatter-plots.md index a05de5d..55e6a39 100644 --- a/api-reference/plotting/scatter-plots.md +++ b/api-reference/plotting/scatter-plots.md @@ -4,7 +4,7 @@ description: Create a scatter plot of columns in a DataFrame # Scatter Plots -The coordinates of each point are defined by two DataFrame columns and filled circles are used to represent each point. Scatter plot is useful for visualizing complex correlations between two variables. +The coordinates of each point are defined by two DataFrame columns and filled circles are used to represent each point. Scatter plot is useful for visualizing complex correlations between two variables. ## Examples @@ -19,8 +19,7 @@ In the example below, we use the titanic dataset, to show a close to real-world - - + Document @@ -29,23 +28,24 @@ In the example below, we use the titanic dataset, to show a close to real-world
- ``` -![](../../.gitbook/assets/newplot-8-%20%281%29.png) +![](<../../.gitbook/assets/newplot-8- (1).png>) ### More Examples @@ -56,8 +56,7 @@ In the example below, we use the titanic dataset, to show a close to real-world - - + Document @@ -66,26 +65,28 @@ In the example below, we use the titanic dataset, to show a close to real-world
- ``` ![](../../.gitbook/assets/newplot-19-.png) {% hint style="info" %} -To set configuration for your plots, see the [Configuring your plot page](configuring-your-plots.md) +To customize your plots, see the [Customize your plot page](configuring-your-plots.md) {% endhint %} - diff --git a/api-reference/plotting/tables.md b/api-reference/plotting/tables.md index 83bf86c..2614b0b 100644 --- a/api-reference/plotting/tables.md +++ b/api-reference/plotting/tables.md @@ -8,90 +8,186 @@ description: Turn DataFrame/Series in D3.js-based tables ### Create Interactive Tables from DataFrame -```markup +{% tabs %} +{% tab title="React" %} +{% code title="App.jsx" %} +```tsx +import { useEffect } from 'react'; +import './App.css'; +import { Series, readCSV } from "danfojs-nightly"; + +function App() { + + useEffect(() => { + readCSV("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv") + .then(df => { + + df.plot("plot_div").table() + }).catch(err => { + console.log(err); + }) + }, []) + + return ( +
+
+
+
+
+ ); +} + +export default App; +``` +{% endcode %} +{% endtab %} + +{% tab title="Browser" %} +```html + + + + + Document + - - - - - - Document - - - + +
- - + ``` +{% endtab %} +{% endtabs %} -![](../../.gitbook/assets/screen-shot-2020-08-11-at-12.34.08-am.png) +![](<../../.gitbook/assets/Screen Shot 2020-08-11 at 12.34.08 AM.png>) ### Configure the header and cell of a table -To configure the header and cell of a table, you can pass header/cell styles to the **header\_style** and **cell\_style** parameter. The [Plotly table](https://plotly.com/javascript/table/) doc shows numerous configuration options you can pass. +To configure the header and cell of a table, you can pass header/cell styles to the **header\_style** and **cell\_style** parameter. The [Plotly table](https://plotly.com/javascript/table/) doc shows numerous configuration options you can pass. + +{% tabs %} +{% tab title="React" %} +{% code title="App.jsx" %} +```tsx +import { useEffect } from 'react'; +import './App.css'; +import { Series, readCSV } from "danfojs-nightly"; + +function App() { + + useEffect(() => { + readCSV("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv") + .then(df => { + + const headerStyle = { + align: "center", + fill: { color: ['gray'] }, + font: { family: "Arial", size: 15, color: "white" }, + + } + const cellStyle = { + align: ["center"], + line: { color: "black", width: 10 } + } + + df.plot("plot_div").table({ + config: { + tableHeaderStyle: headerStyle, + tableCellStyle: cellStyle + }, + layout: { + title: "Table displaying the Titanic dataset", + } + }) + + + }).catch(err => { + console.log(err); + }) + }, []) + + return ( +
+
+
+
+
+ ); +} + +export default App; +``` +{% endcode %} +{% endtab %} -```markup +{% tab title="Browser" %} +```html + + + + - - - - - Document - + - + +
- - + - - ``` +{% endtab %} +{% endtabs %} -![](../../.gitbook/assets/screen-shot-2020-08-11-at-12.38.30-am.png) - +![](<../../.gitbook/assets/Screen Shot 2020-08-11 at 12.38.30 AM.png>) diff --git a/api-reference/plotting/timeseries-plots.md b/api-reference/plotting/timeseries-plots.md index cdbb85d..cc49d74 100644 --- a/api-reference/plotting/timeseries-plots.md +++ b/api-reference/plotting/timeseries-plots.md @@ -6,55 +6,111 @@ description: Timeseries plot are based on date index ## Examples -In the example below, we plot the yearly trend of a financial dataset. First, we reset the index to the Date column. +In the example below, we plot the yearly trend of a financial dataset. First, we reset the index to the Date column. + +{% tabs %} +{% tab title="React" %} +{% code title="App.jsx" %} +```tsx +import { useEffect } from 'react'; +import './App.css'; +import { readCSV } from "danfojs-nightly"; + +function App() { + + useEffect(() => { + readCSV( + "https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv" + ) + .then((df) => { + + const layout = { + title: "A financial charts", + xaxis: { + title: "Date", + }, + yaxis: { + title: "Count", + }, + }; + + const config = { + columns: ["AAPL.Open", "AAPL.High"], + }; + + const new_df = df.setIndex({ column: "Date" }); + new_df.plot("plot_div").line({ config, layout }); + }) + .catch((err) => { + console.log(err); + }); + + }, []) + + return ( +
+
+
+
+
+ ); +} + +export default App; +``` +{% endcode %} +{% endtab %} -```markup +{% tab title="Browser" %} +```html - - - - - - + + + + Document - - - + +
- - - + - ``` +{% endtab %} +{% endtabs %} -![](../../.gitbook/assets/newplot-29-.png) +![](<../../.gitbook/assets/newplot-29- (2) (1) (1) (3).png>) {% hint style="info" %} -To set configuration for your plots, see the [Configuring your plot page](configuring-your-plots.md) +To set customize your charts, see the [Customizing your plot page](configuring-your-plots.md) {% endhint %} - diff --git a/api-reference/plotting/violin-plots.md b/api-reference/plotting/violin-plots.md index 9b55644..3609a01 100644 --- a/api-reference/plotting/violin-plots.md +++ b/api-reference/plotting/violin-plots.md @@ -6,15 +6,45 @@ Make a violin plot from DataFrame columns, optionally grouped by some other colu ### Boxplot for a Series Object -```markup +{% tabs %} +{% tab title="React" %} +{% code title="App.jsx" %} +```tsx +import { useEffect } from 'react'; +import './App.css'; +import { Series } from "danfojs-nightly"; + +function App() { + + useEffect(() => { + const s = new Series([20, 30, 40, 23, 40, 3, 50, 34, 67]) + s.plot("plot_div").violin() + + }, []) + + return ( +
+
+
+
+
+ ); +} + +export default App; +``` +{% endcode %} +{% endtab %} + +{% tab title="Browser" %} +```html - - + Document @@ -30,22 +60,60 @@ Make a violin plot from DataFrame columns, optionally grouped by some other colu - ``` +{% endtab %} +{% endtabs %} ![](../../.gitbook/assets/newplot-25-.png) ### Box plots on a DataFrame -```markup +{% tabs %} +{% tab title="React" %} +{% code title="App.jsx" %} +```tsx +import { useEffect } from 'react'; +import './App.css'; +import { readCSV } from "danfojs-nightly"; + +function App() { + + useEffect(() => { + readCSV( + "https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv" + ) + .then((df) => { + const sub_df = df.loc({ columns: ["Age", "Fare"] }); + sub_df.plot("plot_div").violin(); + }) + .catch((err) => { + console.log(err); + }); + }, []) + + return ( +
+
+
+
+
+ ); +} + +export default App; +``` +{% endcode %} +{% endtab %} + +{% tab title="Browser" %} +```html - - + Document @@ -54,7 +122,7 @@ Make a violin plot from DataFrame columns, optionally grouped by some other colu
- + + + + Document - + - + +
- - + - ``` +{% endtab %} +{% endtabs %} ![](../../.gitbook/assets/newplot-27-.png) {% hint style="info" %} -To set configuration for your plots, see the [Configuring your plot page](configuring-your-plots.md) +To customize your plots, see the [Configuring your plot page](configuring-your-plots.md) {% endhint %} - diff --git a/api-reference/series/README.md b/api-reference/series/README.md index cc25049..5666bf8 100644 --- a/api-reference/series/README.md +++ b/api-reference/series/README.md @@ -4,117 +4,122 @@ description: One-dimensional ndarray with axis labels (including time series). # Series -> `Series`\(data, {**columns:** \[ Array \], **dtypes:** \[ Array \], **index:** \[Array\]}\) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/series.js#L28)\] +> `Series`(data, {**columns:** \[ Array ], **dtypes:** \[ Array ], **index:** \[Array]}) \[[source](https://github.com/opensource9ja/danfojs/blob/3398c2f540c16ac95599a05b6f2db4eff8a258c9/danfojs/src/core/series.js#L28)] ### Attributes -| [`Series.index`](series.index.md) | The index \(axis labels\) of the Series. | -| :--- | :--- | +| [`Series.index`](series.index.md) | The index (axis labels) of the Series. | +| --------------------------------- | -------------------------------------- | - -| [`Series.tensor`](series.tensor.md) | The Tensorflow tensor of the data backing this Series or Index. | -| :--- | :--- | +| [`Series.tensor`](series.tensor.md) | The Tensorflow tensor of the data backing this Series or Index. | +| ----------------------------------- | ---------------------------------------------------------------- | | [`Series.values`](series.values.md) | Return Series as ndarray or ndarray-like depending on the dtype. | -| [`Series.dtype`](series.dtype.md) | Return the dtype object of the underlying data. | -| [`Series.shape`](series.shape.md) | Return a tuple of the shape of the underlying data. | -| [`Series.ndim`](series.ndim.md) | Number of dimensions of the underlying data, by definition 1. | -| [`Series.size`](series.size.md) | Return the number of elements in the underlying data. | +| [`Series.dtype`](series.dtype.md) | Return the dtype object of the underlying data. | +| [`Series.shape`](series.shape.md) | Return a tuple of the shape of the underlying data. | +| [`Series.ndim`](series.ndim.md) | Number of dimensions of the underlying data, by definition 1. | +| [`Series.size`](broken-reference/) | Return the number of elements in the underlying data. | ### Conversion -| [`Series.astype`](../dataframe/dataframe.astype.md) | Cast a Series object to a specified dtype | -| :--- | :--- | -| [`Series.copy`](series.copy.md) | Make a copy of this object’s indices and data. | +| [`Series.asType`](../dataframe/dataframe.astype.md) | Cast a Series object to a specified dtype | +| --------------------------------------------------- | ---------------------------------------------- | +| [`Series.copy`](series.copy.md) | Make a copy of this object’s indices and data. | ### Indexing, iteration -| | | -| :--- | :--- | -| \`\`[`Series.loc`](../dataframe/danfo.dataframe.loc.md)\`\` | Access a group of rows and columns by label\(s\) or a boolean array. | -| [`Series.iloc`](series.iloc.md) | Purely integer-location based indexing for selection by position. | +| | | +| --------------------------------- | ------------------------------------------------------------------ | +| ``[`Series.loc`](series.loc.md)`` | Access a group of rows and columns by label(s) or a boolean array. | +| [`Series.iloc`](series.iloc.md) | Purely integer-location based indexing for selection by position. | ### Binary operator functions -| [`Series.add`](series.add.md) | Return Addition of series and other, element-wise \(binary operator add\). | -| :--- | :--- | -| [`Series.sub`](series.sub.md) | Return Subtraction of series and other, element-wise \(binary operator sub\). | -| [`Series.mul`](series.mul.md) | Return Multiplication of series and other, element-wise \(binary operator mul\). | -| [`Series.div`](series.div.md) | Return Floating division of series and other, element-wise \(binary operator truediv\). | -| [`Series.mod`](series.mod.md) | Return Modulo of series and other, element-wise \(binary operator mod\). | -| [`Series.pow`](series.pow.md) | Return Exponential power of series and other, element-wise \(binary operator pow\). | -| [`Series.round`](series.round.md) | Round each value in a Series to the given number of decimals. | -| [`Series.lt`](series.lt.md) | Return Less than of series and other, element-wise \(binary operator lt\). | -| [`Series.gt`](series.gt.md) | Return Greater than of series and other, element-wise \(binary operator gt\). | -| [`Series.le`](series.le.md) | Return Less than or equal to of series and other, element-wise \(binary operator le\). | -| [`Series.ge`](series.ge.md) | Return Greater than or equal to of series and other, element-wise \(binary operator ge\). | -| [`Series.ne`](series.ne.md) | Return Not equal to of series and other, element-wise \(binary operator ne\). | -| [`Series.eq`](series.eq.md) | Return Equal to of series and other, element-wise \(binary operator eq\). | -| [`Series.dot`](series.dot.md) | Compute the dot product between the Series and the columns of other. | - -### Function application & GroupBy - -| [`Series.apply`](series.apply.md) | Invoke function on values of Series. | -| :--- | :--- | -| [`Series.map`](series.map.md) | Map values of Series according to input correspondence. | +| [`Series.add`](series.add.md) | Return Addition of series and other, element-wise (binary operator add). | +| --------------------------------- | --------------------------------------------------------------------------------------- | +| [`Series.sub`](series.sub.md) | Return Subtraction of series and other, element-wise (binary operator sub). | +| [`Series.mul`](series.mul.md) | Return Multiplication of series and other, element-wise (binary operator mul). | +| [`Series.div`](series.div.md) | Return Floating division of series and other, element-wise (binary operator truediv). | +| [`Series.mod`](series.mod.md) | Return Modulo of series and other, element-wise (binary operator mod). | +| [`Series.pow`](series.pow.md) | Return Exponential power of series and other, element-wise (binary operator pow). | +| [`Series.round`](series.round.md) | Round each value in a Series to the given number of decimals. | +| [`Series.lt`](series.lt.md) | Return Less than of series and other, element-wise (binary operator lt). | +| [`Series.gt`](series.gt.md) | Return Greater than of series and other, element-wise (binary operator gt). | +| [`Series.le`](series.le.md) | Return Less than or equal to of series and other, element-wise (binary operator le). | +| [`Series.ge`](series.ge.md) | Return Greater than or equal to of series and other, element-wise (binary operator ge). | +| [`Series.ne`](series.ne.md) | Return Not equal to of series and other, element-wise (binary operator ne). | +| [`Series.eq`](series.eq.md) | Return Equal to of series and other, element-wise (binary operator eq). | + +### Function application + +| [`Series.apply`](series.apply.md) | Invoke function on values of Series. | +| --------------------------------- | ------------------------------------------------------- | +| [`Series.map`](series.map.md) | Map values of Series according to input correspondence. | ### Computations / descriptive stats -| [`Series.abs`](series.abs.md) | Return a Series with absolute numeric value of each element. | -| :--- | :--- | -| [`Series.corr`](series.corr.md) | Compute correlation with other Series, excluding missing values. | -| [`Series.count`](series.count.md) | Return number of non-NaN observations in the Series. | -| [`Series.cummax`](../dataframe/danfo.dataframe.cummax.md) | Return cumulative maximum over a DataFrame or Series axis. | -| [`Series.cummin`](../dataframe/danfo.dataframe.cummin.md) | Return cumulative minimum over a DataFrame or Series axis. | -| [`Series.cumprod`](../dataframe/danfo.dataframe.cumprod.md) | Return cumulative product over a DataFrame or Series axis. | -| [`Series.cumsum`](../dataframe/danfo.dataframe.cumsum.md) | Return cumulative sum over a DataFrame or Series axis. | -| [`Series.describe`](series.describe.md) | Generate descriptive statistics. | -| [`Series.max`](series.max.md) | Return the maximum of the values for the requested axis. | -| [`Series.mean`](series.mean.md) | Return the mean of the values for the requested axis. | -| [`Series.median`](series.median.md) | Return the median of the values for the requested axis. | -| [`Series.min`](series.min.md) | Return the minimum of the values for the requested axis. | -| [`Series.mode`](series.mode.md) | Return the mode\(s\) of the dataset. | -| [`Series.std`](series.std.md) | Return sample standard deviation over requested axis. | -| [`Series.sum`](series.sum.md) | Return the sum of the values for the requested axis. | -| [`Series.var`](series.var.md) | Return unbiased variance over requested axis. | -| [`Series.unique`](series.unique.md) | Return unique values of Series object. | -| [`Series.nunique`](series.nunique.md) | Return number of unique elements in the object. | -| [`Series.value_counts`](series.value_counts.md) | Return a Series containing counts of unique values. | +| [`Series.abs`](series.abs.md) | Return a Series with absolute numeric value of each element. | +| ----------------------------------------------------------- | ---------------------------------------------------------------- | +| [`Series.corr`](broken-reference/) | Compute correlation with other Series, excluding missing values. | +| [`Series.count`](series.count.md) | Return number of non-NaN observations in the Series. | +| [`Series.cumMax`](../dataframe/danfo.dataframe.cummax.md) | Return cumulative maximum over a DataFrame or Series axis. | +| [`Series.cumMin`](../dataframe/danfo.dataframe.cummin.md) | Return cumulative minimum over a DataFrame or Series axis. | +| [`Series.cumProd`](../dataframe/danfo.dataframe.cumprod.md) | Return cumulative product over a DataFrame or Series axis. | +| [`Series.cumSum`](../dataframe/danfo.dataframe.cumsum.md) | Return cumulative sum over a DataFrame or Series axis. | +| [`Series.describe`](series.describe.md) | Generate descriptive statistics. | +| [`Series.max`](series.max.md) | Return the maximum of the values for the requested axis. | +| [`Series.mean`](series.mean.md) | Return the mean of the values for the requested axis. | +| [`Series.median`](series.median.md) | Return the median of the values for the requested axis. | +| [`Series.min`](series.min.md) | Return the minimum of the values for the requested axis. | +| [`Series.mode`](series.mode.md) | Return the mode(s) of the dataset. | +| [`Series.std`](series.std.md) | Return sample standard deviation over requested axis. | +| [`Series.sum`](series.sum.md) | Return the sum of the values for the requested axis. | +| [`Series.var`](series.var.md) | Return unbiased variance over requested axis. | +| [`Series.unique`](series.unique.md) | Return unique values of Series object. | +| [`Series.nUnique`](series.nunique.md) | Return number of unique elements in the object. | +| [`Series.valueCounts`](series.value\_counts.md) | Return a Series containing counts of unique values. | ### Reindexing / selection / label manipulation -| | | -| :--- | :--- | -| [`Series.drop_duplicates`](series.drop_duplicates.md) | Return Series with duplicate values removed. | -| [`Series.head`](series.head.md) | Return the first n rows. | -| [`Series.reset_index`](series.reset_index.md) | Generate a new DataFrame or Series with the index reset. | -| [`Series.sample`](series.sample.md) | Return a random sample of items from an axis of object. | -| [`Series.tail`](series.tail.md) | Return the last n rows. | +| | | +| ----------------------------------------------------- | -------------------------------------------------------- | +| [`Series.dropDuplicates`](series.drop\_duplicates.md) | Return Series with duplicate values removed. | +| [`Series.head`](series.head.md) | Return the first n rows. | +| [`Series.resetIndex`](series.reset\_index.md) | Generate a new DataFrame or Series with the index reset. | +| [`Series.sample`](series.sample.md) | Return a random sample of items from an axis of object. | +| [`Series.tail`](series.tail.md) | Return the last n rows. | ### Missing data handling -| | | -| :--- | :--- | -| [`Series.dropna`](series.dropna.md) | Return a new Series with missing values removed. | -| [`Series.fillna`](series.fillna.md) | Fill NaN values using the specified method. | -| [`Series.isna`](series.isna.md) | Detect missing values. | -| [`Series.replace`](series.replace.md) | Replace values given in to\_replace with value. | +| | | +| ------------------------------------- | ------------------------------------------------ | +| [`Series.droNa`](series.dropna.md) | Return a new Series with missing values removed. | +| [`Series.fillNa`](series.fillna.md) | Fill NaN values using the specified method. | +| [`Series.isNa`](series.isna.md) | Detect missing values. | +| [`Series.replace`](series.replace.md) | Replace values given in to\_replace with value. | + +### Logical Comparison + +| | | +| ----------------------------- | ---------------------------------------------------------------------------------------------------- | +| [`Series.or`](series.or.md) | Returns the logical OR between Series and other. Supports element-wise operations and broadcasting. | +| [`Series.and`](series.and.md) | Returns the logical AND between Series and other. Supports element-wise operations and broadcasting. | ### Reshaping, sorting -| [`Series.argsort`](series.argsort.md) | Return the integer indices that would sort the Series values. | -| :--- | :--- | -| [`Series.argmin`](series.argmin.md) | Return int position of the smallest value in the Series. | -| [`Series.argmax`](series.argmax.md) | Return int position of the largest value in the Series. | -| [`Series.sort_values`](series.sort_values.md) | Sort by the values. | +| [`Series.argSort`](series.argsort.md) | Return the integer indices that would sort the Series values. | +| --------------------------------------------- | ------------------------------------------------------------- | +| [`Series.argMin`](series.argmin.md) | Return int position of the smallest value in the Series. | +| [`Series.argMax`](series.argmax.md) | Return int position of the largest value in the Series. | +| [`Series.sortValues`](series.sort\_values.md) | Sort by the values. | ### Accessors Danfo provides dtype-specific methods under various accessors. These are separate namespaces within [`Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas.Series) that only apply to specific data types. -| Data Type | Accessor | -| :--- | :--- | -| Datetime | dt | -| String | str | +| Data Type | Accessor | +| -------------------------------------------- | -------- | +| [Datetime](../general-functions/danfo.dt.md) | dt | +| [String](../general-functions/danfo.str.md) | str | #### Datetimelike properties @@ -122,63 +127,65 @@ Danfo provides dtype-specific methods under various accessors. These are separat **Datetime methods** -| | | -| :--- | :--- | -| [`Series.dt.year`](series.dt.year.md) | The year of the datetime. | -| [`Series.dt.month`](series.dt.month.md) | The month as January=1, December=12. | -| [`Series.dt.day`](series.dt.day.md) | The day of the datetime. | -| [`Series.dt.hour`](series.dt.hour.md) | The hours of the datetime. | -| [`Series.dt.minute`](series.dt.minute.md) | The minutes of the datetime. | -| [`Series.dt.second`](series.dt.second.md) | The seconds of the datetime. | -| [`Series.dt.weekdays`](series.dt.weekdays.md) | The day of the week with Monday=0, Sunday=6. | -| [`Series.dt.month_name`](series.dt.month_name.md) | Return the month names of the DateTimeIndex with specified locale. | +| | | +| -------------------------------------------------- | ----------------------------------------------------------------------- | +| [`Series.dt.year`](series.dt.year.md) | The year of the datetime. | +| [`Series.dt.month`](series.dt.month.md) | Returns a numeric representation of the month. January=0 - December=11. | +| [Series.dt.monthName](series.dt.month\_name.md) | | +| [`Series.dt.dayOfWeek`](series.dt.day.md) | Returns the day of the week, in local time | +| [`Series.dt.hour`](series.dt.hour.md) | The hours of the datetime. | +| [`Series.dt.minute`](series.dt.minute.md) | The minutes of the datetime. | +| [`Series.dt.second`](series.dt.second.md) | The seconds of the datetime. | +| [`Series.dt.dayOfWeekName`](series.dt.weekdays.md) | Returns the name of the day, of the week, in local time | +| [`Series.dt.dayOfMonth`](series.dt.month\_name.md) | Returns the day of the month, in local time | #### String handling `Series.str` can be used to access the values of the series as strings and apply several methods to it. These can be accessed like `Series.str.`. -| [`Series.str.capitalize`](series.str.capitalize.md) | Capitalize the first character of each string | -| :--- | :--- | -| [`Series.str.toUpperCase`](series.str.touppercase.md) | Converts all characters to uppercase. | -| [`Series.str.toLowerCase`](series.str.tolowercase.md) | Converts all characters to lowercase. | -| [`Series.str.charAt`](series.str.charat.md) | Returns the character at the specified index \(position\). | -| [`Series.str.concat`](series.str.concat.md) | Joins two or more strings/arrays. | -| [`Series.str.startsWith`](series.str.startswith.md) | Checks whether a string begins with specified characters. | -| [`Series.str.endsWith`](series.str.endswith.md) | Checks whether a string ends with specified characters | -| [`Series.str.includes`](series.str.includes.md) | Checks whether a string contains the specified string/characters. | -| [`Series.str.indexOf`](series.str.indexof.md) | Returns the position of the first found occurrence of a specified value in a string. | -| [`Series.str.lastIndexOf`](series.str.lastindexof.md) | Returns the position of the last found occurrence of a specified value in a string. | -| [`Series.str.repeat`](series.str.repeat.md) | Returns a new string with a specified number of copies of an existing string. | -| [`Series.str.search`](series.str.search.md) | Searches a string for a specified value, or regular expression, and returns the position of the match. | -| [`Series.str.slice`](series.str.slice.md) | Extracts a part of a string and returns a new string. | -| [`Series.str.split`](series.str.split.md) | Splits a string into an array of substrings. | -| [`Series.str.substr`](series.str.substr.md) | Extracts the characters from a string, beginning at a specified start position, and through the specified number of character. | -| [`Series.str.substring`](series.str.substring.md) | Extracts the characters from a string, between two specified indices. | -| [`Series.str.len`](series.str.len.md) | Counts the number of characters in each string. | -| [`Series.str.trim`](series.str.trim.md) | Removes whitespace from both ends of a string. | -| [`Series.str.join`](series.str.join.md) | Joins strings to specified value. | -| [`Series.str.replace`](series.str.replace.md) | Replace each occurrence of pattern/regex in the Series/Index. | +| [`Series.str.capitalize`](series.str.capitalize.md) | Capitalize the first character of each string | +| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| [`Series.str.toUpperCase`](series.str.touppercase.md) | Converts all characters to uppercase. | +| [`Series.str.toLowerCase`](series.str.tolowercase.md) | Converts all characters to lowercase. | +| [`Series.str.charAt`](series.str.charat.md) | Returns the character at the specified index (position). | +| [`Series.str.concat`](series.str.concat.md) | Joins two or more strings/arrays. | +| [`Series.str.startsWith`](series.str.startswith.md) | Checks whether a string begins with specified characters. | +| [`Series.str.endsWith`](series.str.endswith.md) | Checks whether a string ends with specified characters | +| [`Series.str.includes`](series.str.includes.md) | Checks whether a string contains the specified string/characters. | +| [`Series.str.indexOf`](series.str.indexof.md) | Returns the position of the first found occurrence of a specified value in a string. | +| [`Series.str.lastIndexOf`](series.str.lastindexof.md) | Returns the position of the last found occurrence of a specified value in a string. | +| [`Series.str.repeat`](series.str.repeat.md) | Returns a new string with a specified number of copies of an existing string. | +| [`Series.str.search`](series.str.search.md) | Searches a string for a specified value, or regular expression, and returns the position of the match. | +| [`Series.str.slice`](series.str.slice.md) | Extracts a part of a string and returns a new string. | +| [`Series.str.split`](series.str.split.md) | Splits a string into an array of substrings. | +| [`Series.str.substr`](series.str.substr.md) | Extracts the characters from a string, beginning at a specified start position, and through the specified number of character. | +| [`Series.str.substring`](series.str.substring.md) | Extracts the characters from a string, between two specified indices. | +| [`Series.str.len`](series.str.len.md) | Counts the number of characters in each string. | +| [`Series.str.trim`](series.str.trim.md) | Removes whitespace from both ends of a string. | +| [`Series.str.join`](series.str.join.md) | Joins strings to specified value. | +| [`Series.str.replace`](series.str.replace.md) | Replace each occurrence of pattern/regex in the Series/Index. | ### Plotting `Series.plot` is both a callable method and a namespace attribute for specific plotting methods of the form `Series.plot.`. -| | | -| :--- | :--- | -| [`Series.plot.bar`](../plotting/bar-charts.md) | Vertical bar plot. | -| [`Series.plot.box`](../plotting/box-plots.md) | Make a box plot of the DataFrame columns. | -| [`Series.plot.violin`](../plotting/box-plots.md) | Make a violin plot of the DataFrame columns. | -| [`Series.plot.hist`](../plotting/histograms.md) | Draw one histogram of the DataFrame’s columns. | +| | | +| ----------------------------------------------------- | ------------------------------------------------------------- | +| [`Series.plot.bar`](../plotting/bar-charts.md) | Vertical bar plot. | +| [`Series.plot.box`](../plotting/box-plots.md) | Make a box plot of the DataFrame columns. | +| [`Series.plot.violin`](../plotting/box-plots.md) | Make a violin plot of the DataFrame columns. | +| [`Series.plot.hist`](../plotting/histograms.md) | Draw one histogram of the DataFrame’s columns. | | [`Series.plot.scatter`](../plotting/scatter-plots.md) | Generate Kernel Density Estimate plot using Gaussian kernels. | -| [`Series.plot.line`](../plotting/line-charts.md) | Plot Series or DataFrame as lines. | -| [`Series.plot.pie`](../plotting/pie-charts.md) | Generate a pie plot. | -| [`Timeseries Plots`](../plotting/timeseries-plots.md) | Time series plots | -| [`Table`](../plotting/tables.md) | Display Series as Interactive table in Div | +| [`Series.plot.line`](../plotting/line-charts.md) | Plot Series or DataFrame as lines. | +| [`Series.plot.pie`](../plotting/pie-charts.md) | Generate a pie plot. | +| [`Timeseries Plots`](../plotting/timeseries-plots.md) | Time series plots | +| [`Table`](../plotting/tables.md) | Display Series as Interactive table in a Div | ### Serialization / IO / conversion -| | | -| :--- | :--- | -| [`Series.to_csv`](../dataframe/dataframe.to_csv.md) | Write object to a comma-separated values \(csv\) file. | -| [`Series.to_json`](../dataframe/dataframe.to_json.md) | Convert the object to a JSON string. | +| | | +| ----------------------------------------------------- | -------------------------------------------- | +| [`Series.toCSV`](../dataframe/dataframe.to\_csv.md) | Convert DataFrame or Series to CSV. | +| [`Series.toJSON`](../dataframe/dataframe.to\_json.md) | Convert DataFrame or Series to a JSON. | +| Series.toExcel | Convert DataFrame or Series to an excel file | diff --git a/api-reference/series/creating-a-series.md b/api-reference/series/creating-a-series.md new file mode 100644 index 0000000..ef11bc8 --- /dev/null +++ b/api-reference/series/creating-a-series.md @@ -0,0 +1,178 @@ +# Creating a Series + +danfo.**Series**(data, options) + +| Parameters | Type | Description | +| ---------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| data | 1D Array, 1D Tensor, JSON object. | Flat data structure to load into DataFrame | +| options | Object |

Optional configuration object. Supported properties are:

index: Array of numeric or string names for subseting array. If not specified, indexes are auto-generated.

dtypes: Array of data types for each the column. If not specified, dtypes are/is inferred.

config: General configuration object for extending or setting NDframe behavior. See full options here

| + +In order to create a Series, you need to call the new Keyword and pass a flat data structure. In the following examples, we show you how to create a Series by specifying different config options. + +### Creating a Series from an object: + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +obj_data = { 'B': ["bval1", "bval2", "bval3", "bval4"] } +df = new dfd.Series(obj_data) +df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +```markup + + + + + + + + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} + +```javascript +╔═══╤═══════╗ +║ 0 │ bval1 ║ +╟───┼───────╢ +║ 1 │ bval2 ║ +╟───┼───────╢ +║ 2 │ bval3 ║ +╟───┼───────╢ +║ 3 │ bval4 ║ +╚═══╧═══════╝ +``` + +### Creating a Series from an array + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +obj_data = ["bval1", "bval2", "bval3", "bval4"] +df = new dfd.Series(obj_data) +df.print() +``` +{% endtab %} + +{% tab title="Browser" %} +```markup + + + + + + + + Document + + + + + + + + +``` +{% endtab %} +{% endtabs %} + +``` +╔═══╤═══════╗ +║ 0 │ bval1 ║ +╟───┼───────╢ +║ 1 │ bval2 ║ +╟───┼───────╢ +║ 2 │ bval3 ║ +╟───┼───────╢ +║ 3 │ bval4 ║ +╚═══╧═══════╝ +``` + +### Creating a Series and specifying index and dtypes + +You can create a Series and specify options like index, dtypes, as well as configuration options for display, and memory mode etc. + +> Note: Specifing dtypes, and index on Series creation makes the process slightly faster. + +{% tabs %} +{% tab title="Node" %} +```javascript +import { Series } from "danfojs" + +let data1 = [1, 2, 3, 4, 5]; +let index = ["a", "b", "c", "d", "e"]; +let dtypes = ["int32",] + +let df = new Series(data1, { index, dtypes }); +df.print() +``` +{% endtab %} +{% endtabs %} + +``` +╔═══╤═══╗ +║ a │ 1 ║ +╟───┼───╢ +║ b │ 2 ║ +╟───┼───╢ +║ c │ 3 ║ +╟───┼───╢ +║ d │ 4 ║ +╟───┼───╢ +║ e │ 5 ║ +╚═══╧═══╝ +``` + +### Creating a Series and specifying memory mode + +To use less space on Series creation, you can set the low memory mode as demonstrated below: + +```javascript +import { Series } from "danfojs" + +let data1 = [1, 2.3, 3, 4, 5, "girl"]; + +let df = new Series(data1, { + config: { lowMemoryMode: true } +}); +df.print() +``` + +{% hint style="info" %} +**Note**: In low memory mode, less space is used by the Series. +{% endhint %} diff --git a/api-reference/series/series.abs.md b/api-reference/series/series.abs.md index db9a8b4..9f9e155 100644 --- a/api-reference/series/series.abs.md +++ b/api-reference/series/series.abs.md @@ -4,9 +4,11 @@ description: Returns the absolute value in a Series # Series.abs -> danfo.Series.**abs**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L793)\] +> danfo.Series.**abs**(options) -**Parameters**: None +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------------------------------------------- | ------------------------------------- | +| options | Object | **inplace**: Boolean indicating whether to perform the operation in-place or not. Defaults to false |

{

inplace: false

}

| **Returns:** Series @@ -27,25 +29,22 @@ sf.abs().print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 10 ║ -╟───┼──────────────────────╢ -║ 1 │ 45 ║ -╟───┼──────────────────────╢ -║ 2 │ 56 ║ -╟───┼──────────────────────╢ -║ 3 │ 25 ║ -╟───┼──────────────────────╢ -║ 4 │ 23 ║ -╟───┼──────────────────────╢ -║ 5 │ 20 ║ -╟───┼──────────────────────╢ -║ 6 │ 10 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 0 │ 10 ║ +╟───┼────╢ +║ 1 │ 45 ║ +╟───┼────╢ +║ 2 │ 56 ║ +╟───┼────╢ +║ 3 │ 25 ║ +╟───┼────╢ +║ 4 │ 23 ║ +╟───┼────╢ +║ 5 │ 20 ║ +╟───┼────╢ +║ 6 │ 10 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.add.md b/api-reference/series/series.add.md index edde21c..5e6c583 100644 --- a/api-reference/series/series.add.md +++ b/api-reference/series/series.add.md @@ -1,14 +1,15 @@ --- -description: 'Return Addition of series and other, element-wise (binary operator add).' +description: Return Addition of series and other, element-wise (binary operator add). --- # Series.add -> danfo.Series.add\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L129)\] +> danfo.Series.add(other, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series\|int\| | values | | +| Parameters | Type | Description | Default | +| ---------- | ------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------- | +| other | Series\|int\| | values | | +| options | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{

inplace: false

}

| **Return:** Series @@ -32,7 +33,7 @@ sf1.add(sf2).print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -65,7 +66,7 @@ sf1.add(2).print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -82,6 +83,3 @@ sf1.add(2).print() ``` {% endtab %} {% endtabs %} - - - diff --git a/api-reference/series/series.and.md b/api-reference/series/series.and.md new file mode 100644 index 0000000..2a7374f --- /dev/null +++ b/api-reference/series/series.and.md @@ -0,0 +1,131 @@ +--- +description: >- + Returns the logical AND between Series and other. Supports element wise + operations and broadcasting. +--- + +# Series.and + +> danfo.Series.and(other) + +| Parameters | Type | Description | Default | +| ---------- | -------------------------------- | -------------------- | ------- | +| other | Series, Scalar, Array of Scalars | Data to compare with | | + +**Return:** Series + +### **Logical AND between two Series object** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data1 = [false, false, false, true, false, false, true]; +let data2 = [false, false, false, false, false, false, true]; + +let sf = new dfd.Series(data1); +let sf2 = new dfd.Series(data2); +let res = sf.and(sf2) +res.print() +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ false ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ true ║ +╚═══╧═══════╝ +``` +{% endtab %} +{% endtabs %} + +### **Logical AND between Series and Array of the same length** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data1 = [false, false, false, true, false, false, true]; +let data2 = [false, false, false, false, false, false, true]; + +let sf = new dfd.Series(data1); +let res = sf.and(data2) +res.print() +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ false ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ true ║ +╚═══╧═══════╝ +``` +{% endtab %} +{% endtabs %} + +### **Logical AND between a Series and single value with broadcasting** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") +let data1 = [false, false, false, true, false, false, true]; + +let sf = new dfd.Series(data1); +let res = sf.and(false) +res.print() +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ false ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ false ║ +╚═══╧═══════╝ +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/series/series.append.md b/api-reference/series/series.append.md index 473b01a..e734c08 100644 --- a/api-reference/series/series.append.md +++ b/api-reference/series/series.append.md @@ -1,106 +1,127 @@ -# Series.append - -danfo.Series.**append**\(val, inplace\) \[[source](https://github.com/opensource9ja/danfojs/blob/2696f1d8420dd364464aae7c5c175c6cd0ef4c93/danfojs/src/core/frame.js#L2059)\] - -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| val | Array \| Series | Object to append | | -| inplace | Boolean | Whether to perform operation inplace or not | false | +--- +description: Add a new value or values to the end of a Series. +--- -**Returns:** +# Series.append - ****return **Series** +danfo.Series.**append**(newValue, index, options) -## **Examples** +| Parameters | Type | Description | Default | +| ---------- | ------------- | -------------------------------------------------------------------------------------------------------------------------- | ------- | +| newValue | Array, Series | Object to append | | +| index | Array | The new index value(s) to append to the Series. Must contain the same number of values as `newValues` as they map `1 - 1`. | | +| options | Object |

{
inplace: Whether to perform operation in-place or not.

}

| false | -### **Append Series to Series** +### **Append new Series to the end of a Series** {% tabs %} {% tab title="Node" %} ```javascript -let sf1 = new dfd.Series([1, 2, 3, 4]) -let sf2 = new dfd.Series(["a", "b", "c"], {index: ['f1', 'f2', 'f3']}) +const dfd = require("danfojs-node") + +let sf1 = new dfd.Series([1, 2, 3, 4], { index: ['f1', 'f2', 'f3', 'f4'] }) +let sf2 = new dfd.Series(["a", "b", "c"]) -new_sf = sf1.append(sf2) +new_sf = sf1.append(sf2, ["f5", "f6", "f7"]) new_sf.print() ``` {% endtab %} +{% endtabs %} -{% tab title="Browser" %} +{% tabs %} +{% tab title="Output" %} ``` - +╔════╤═══╗ +║ f1 │ 1 ║ +╟────┼───╢ +║ f2 │ 2 ║ +╟────┼───╢ +║ f3 │ 3 ║ +╟────┼───╢ +║ f4 │ 4 ║ +╟────┼───╢ +║ f5 │ a ║ +╟────┼───╢ +║ f6 │ b ║ +╟────┼───╢ +║ f7 │ c ║ +╚════╧═══╝ ``` {% endtab %} {% endtabs %} +### **Append new Series to the end of a Series in-place** + {% tabs %} -{% tab title="Output" %} -```text -╔════╤══════════════════════╗ -║ │ 0 ║ -╟────┼──────────────────────╢ -║ 0 │ 1 ║ -╟────┼──────────────────────╢ -║ 1 │ 2 ║ -╟────┼──────────────────────╢ -║ 2 │ 3 ║ -╟────┼──────────────────────╢ -║ 3 │ 4 ║ -╟────┼──────────────────────╢ -║ f1 │ a ║ -╟────┼──────────────────────╢ -║ f2 │ b ║ -╟────┼──────────────────────╢ -║ f3 │ c ║ -╚════╧══════════════════════╝ +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let sf1 = new dfd.Series([1, 2, 3, 4], { index: ['f1', 'f2', 'f3', 'f4'] }) +let sf2 = new dfd.Series(["a", "b", "c"]) +let newIndex = ["f5", "f6", "f7"] + +sf1.append(sf2, newIndex, { inplace: true }) +sf1.print() ``` {% endtab %} {% endtabs %} -\*\*\*\* +``` +╔════╤═══╗ +║ f1 │ 1 ║ +╟────┼───╢ +║ f2 │ 2 ║ +╟────┼───╢ +║ f3 │ 3 ║ +╟────┼───╢ +║ f4 │ 4 ║ +╟────┼───╢ +║ f5 │ a ║ +╟────┼───╢ +║ f6 │ b ║ +╟────┼───╢ +║ f7 │ c ║ +╚════╧═══╝ +``` -### **Append Array to Series** +### **Append an array to the end of Series** {% tabs %} {% tab title="Node" %} ```javascript -let sf1 = new dfd.Series([1, 2, 3, 4]) -let arr = ['f1', 'f2', 'f3'] +let sf1 = new dfd.Series([1, 2, 3, 4], { index: ['f1', 'f2', 'f3', 'f4'] }) +let sfArr = ["a", "b", "c"] -new_sf = sf1.append(arr) +new_sf = sf1.append(sfArr, ["f5", "f6", "f7"]) new_sf.print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 1 ║ -╟───┼──────────────────────╢ -║ 1 │ 2 ║ -╟───┼──────────────────────╢ -║ 2 │ 3 ║ -╟───┼──────────────────────╢ -║ 3 │ 4 ║ -╟───┼──────────────────────╢ -║ 0 │ f1 ║ -╟───┼──────────────────────╢ -║ 1 │ f2 ║ -╟───┼──────────────────────╢ -║ 2 │ f3 ║ -╚═══╧══════════════════════╝ +``` +╔════╤═══╗ +║ f1 │ 1 ║ +╟────┼───╢ +║ f2 │ 2 ║ +╟────┼───╢ +║ f3 │ 3 ║ +╟────┼───╢ +║ f4 │ 4 ║ +╟────┼───╢ +║ f5 │ a ║ +╟────┼───╢ +║ f6 │ b ║ +╟────┼───╢ +║ f7 │ c ║ +╚════╧═══╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.apply.md b/api-reference/series/series.apply.md index f32717f..f8a01f0 100644 --- a/api-reference/series/series.apply.md +++ b/api-reference/series/series.apply.md @@ -1,20 +1,21 @@ --- -description: invoke a function on Series Value +description: Invoke a function on each value in a Series. --- # Series.apply -> danfo.series.**apply**\(callable\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L718)\] +> danfo.series.**apply**(callable, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| callable | Function | Function \(can be anonymous\) to apply | | +| Parameters | Type | Description | Default | +| ---------- | -------- | ---------------------------------------------------------------------------------------------- | ------------------------------------- | +| callable | Function | Function (can be anonymous) to apply | | +| options | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{

inplace: false

}

| **Returns:** - ****return **Series** +\*\*\*\* return **Series** -\*\*\*\* +*** **Example** @@ -34,33 +35,30 @@ sf.apply(apply_func).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 2 ║ -╟───┼──────────────────────╢ -║ 1 │ 4 ║ -╟───┼──────────────────────╢ -║ 2 │ 6 ║ -╟───┼──────────────────────╢ -║ 3 │ 8 ║ -╟───┼──────────────────────╢ -║ 4 │ 10 ║ -╟───┼──────────────────────╢ -║ 5 │ 12 ║ -╟───┼──────────────────────╢ -║ 6 │ 14 ║ -╟───┼──────────────────────╢ -║ 7 │ 16 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 0 │ 2 ║ +╟───┼────╢ +║ 1 │ 4 ║ +╟───┼────╢ +║ 2 │ 6 ║ +╟───┼────╢ +║ 3 │ 8 ║ +╟───┼────╢ +║ 4 │ 10 ║ +╟───┼────╢ +║ 5 │ 12 ║ +╟───┼────╢ +║ 6 │ 14 ║ +╟───┼────╢ +║ 7 │ 16 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} @@ -78,33 +76,30 @@ sf.apply(Math.log).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 0 ║ -╟───┼──────────────────────╢ -║ 1 │ 0.6931471805599453 ║ -╟───┼──────────────────────╢ -║ 2 │ 1.0986122886681096 ║ -╟───┼──────────────────────╢ -║ 3 │ 1.3862943611198906 ║ -╟───┼──────────────────────╢ -║ 4 │ 1.6094379124341003 ║ -╟───┼──────────────────────╢ -║ 5 │ 1.791759469228055 ║ -╟───┼──────────────────────╢ -║ 6 │ 1.9459101490553132 ║ -╟───┼──────────────────────╢ -║ 7 │ 2.0794415416798357 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════════════════════╗ +║ 0 │ 0 ║ +╟───┼────────────────────╢ +║ 1 │ 0.6931471805599453 ║ +╟───┼────────────────────╢ +║ 2 │ 1.0986122886681096 ║ +╟───┼────────────────────╢ +║ 3 │ 1.3862943611198906 ║ +╟───┼────────────────────╢ +║ 4 │ 1.6094379124341003 ║ +╟───┼────────────────────╢ +║ 5 │ 1.791759469228055 ║ +╟───┼────────────────────╢ +║ 6 │ 1.9459101490553132 ║ +╟───┼────────────────────╢ +║ 7 │ 2.0794415416798357 ║ +╚═══╧════════════════════╝ ``` {% endtab %} {% endtabs %} @@ -124,30 +119,24 @@ sf.apply((x)=>{ {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ rice ║ -╟───┼──────────────────────╢ -║ 1 │ beans ║ -╟───┼──────────────────────╢ -║ 2 │ yam ║ -╟───┼──────────────────────╢ -║ 3 │ banana ║ -╟───┼──────────────────────╢ -║ 4 │ wheat ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════════╗ +║ 0 │ rice ║ +╟───┼────────╢ +║ 1 │ beans ║ +╟───┼────────╢ +║ 2 │ yam ║ +╟───┼────────╢ +║ 3 │ banana ║ +╟───┼────────╢ +║ 4 │ wheat ║ +╚═══╧════════╝ ``` {% endtab %} {% endtabs %} - - - diff --git a/api-reference/series/series.argmax.md b/api-reference/series/series.argmax.md index d7927d2..add684d 100644 --- a/api-reference/series/series.argmax.md +++ b/api-reference/series/series.argmax.md @@ -2,9 +2,9 @@ description: Returns the int position of the largest value in the series --- -# Series.argmax +# Series.argMax -> danfo.Series.argmax\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L975)\] +> danfo.Series.argMax() **Parameters**: None @@ -20,16 +20,15 @@ const dfd = require("danfojs-node") let data = [1,30,20,40,50,70,90,200,10,20,12] let sf = new dfd.Series(data) -sf.argmax() +sf.argMax() ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` 7 ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.argmin.md b/api-reference/series/series.argmin.md index dfc661f..72fabdb 100644 --- a/api-reference/series/series.argmin.md +++ b/api-reference/series/series.argmin.md @@ -2,9 +2,9 @@ description: Returns the int position of the smallest value in the series --- -# Series.argmin +# Series.argMin -> danfo.Series.**argmin**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L987)\] +> danfo.Series.argMin() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L987)] **Parameters**: None @@ -20,16 +20,15 @@ const dfd = require("danfojs-node") let data = [1,30,20,40,50,70,90,200,10,20,12] let sf = new dfd.Series(data) -sf.argmin() +sf.argMin() ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` 0 ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.argsort.md b/api-reference/series/series.argsort.md index 29c19e3..51377f4 100644 --- a/api-reference/series/series.argsort.md +++ b/api-reference/series/series.argsort.md @@ -2,15 +2,15 @@ description: Return the integer indices that would sort the Series values --- -# Series.argsort +# Series.argSort -> danfo.Series.**argsort**\(ascending\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L965\)\] +> danfo.Series.argSort(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| ascending | boolean | How to sort the indices. either **True** or **False** | true | +| Parameters | Type | Description | Default | +| ---------- | ------ | -------------------------------------- | ---------------------------------------------------- | +| options | Object | **ascending**: How to sort the indices |

{
ascending: true

}

| -**Returns:** Series \(int element\) +**Returns:** Series (int element) **Example** @@ -22,34 +22,50 @@ const dfd = require("danfojs-node") let data = [10, 45, 20, 10, 23, 20, 30, 11] let sf = new dfd.Series(data) -sf.argsort().print() +sf.argSort().print() //defaults to ascending order +sf.argSort({ ascending: false }).print() ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 0 ║ -╟───┼──────────────────────╢ -║ 1 │ 3 ║ -╟───┼──────────────────────╢ -║ 2 │ 7 ║ -╟───┼──────────────────────╢ -║ 3 │ 2 ║ -╟───┼──────────────────────╢ -║ 4 │ 5 ║ -╟───┼──────────────────────╢ -║ 5 │ 4 ║ -╟───┼──────────────────────╢ -║ 6 │ 6 ║ -╟───┼──────────────────────╢ -║ 7 │ 1 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══╗ +║ 0 │ 3 ║ +╟───┼───╢ +║ 1 │ 0 ║ +╟───┼───╢ +║ 2 │ 7 ║ +╟───┼───╢ +║ 3 │ 5 ║ +╟───┼───╢ +║ 4 │ 2 ║ +╟───┼───╢ +║ 5 │ 4 ║ +╟───┼───╢ +║ 6 │ 6 ║ +╟───┼───╢ +║ 7 │ 1 ║ +╚═══╧═══╝ + +╔═══╤═══╗ +║ 0 │ 1 ║ +╟───┼───╢ +║ 1 │ 6 ║ +╟───┼───╢ +║ 2 │ 4 ║ +╟───┼───╢ +║ 3 │ 2 ║ +╟───┼───╢ +║ 4 │ 5 ║ +╟───┼───╢ +║ 5 │ 7 ║ +╟───┼───╢ +║ 6 │ 0 ║ +╟───┼───╢ +║ 7 │ 3 ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.at.md b/api-reference/series/series.at.md new file mode 100644 index 0000000..887050c --- /dev/null +++ b/api-reference/series/series.at.md @@ -0,0 +1,31 @@ +--- +description: Access a single value for a row/column label pair. +--- + +# Series.at + +> danfo.Series.at(label) + +| Parameters | Type | Description | Default | +| ---------- | ------ | ----------------- | ------- | +| label | String | label to index by | | + +**Return:** Scalar + + + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let sf = new dfd.Series(["Apples", "Mango", "Banana", "Pear"], + { index: ["a", "b", "c", "d"] } +) + +sf.at("a") + +// "Apples" +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/series/series.copy.md b/api-reference/series/series.copy.md index 323fb47..31c7a3f 100644 --- a/api-reference/series/series.copy.md +++ b/api-reference/series/series.copy.md @@ -1,12 +1,12 @@ --- -description: Make a new copy of a Series +description: Makes a deep copy of a Series --- # Series.copy -> danfo.Series.copy\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L569)\] +> danfo.Series.copy() -**parameter:** +**parameter:** **Return:** Series @@ -28,7 +28,7 @@ sf2.print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -43,4 +43,3 @@ sf2.print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.count.md b/api-reference/series/series.count.md index 222ef23..f3ace91 100644 --- a/api-reference/series/series.count.md +++ b/api-reference/series/series.count.md @@ -1,10 +1,10 @@ --- -description: Obtain the total number of values in a series +description: Returns the total number of non-null elements in a series --- # Series.count -> danfo.Series.count\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L350)\] +> danfo.Series.count() **Parameter:** None @@ -27,11 +27,10 @@ console.log(sf1.count()) {% tabs %} {% tab title="Output" %} -```text +``` 9 ``` {% endtab %} {% endtabs %} -\*\*\*\* - +*** diff --git a/api-reference/series/series.cummax.md b/api-reference/series/series.cummax.md index 201ae11..3f03986 100644 --- a/api-reference/series/series.cummax.md +++ b/api-reference/series/series.cummax.md @@ -2,13 +2,13 @@ description: Returns cumulative maximum over a series --- -# Series.cummax +# Series.cumMax -> danfo.Series.**cummax**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L825)\] +> danfo.Series.**cumMax**(options) -**Parameters:** None - -**Return**: Series +| Parameters | Type | Description | Default | +| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Example** @@ -21,32 +21,29 @@ const dfd = require("danfojs-node") let data1 = [10, 45, 56, 25, 23, 20, 10] let sf1 = new dfd.Series(data1) -sf1.cummax().print() +sf1.cumMax().print() ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 10 ║ -╟───┼──────────────────────╢ -║ 1 │ 45 ║ -╟───┼──────────────────────╢ -║ 2 │ 56 ║ -╟───┼──────────────────────╢ -║ 3 │ 56 ║ -╟───┼──────────────────────╢ -║ 4 │ 56 ║ -╟───┼──────────────────────╢ -║ 5 │ 56 ║ -╟───┼──────────────────────╢ -║ 6 │ 56 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 0 │ 10 ║ +╟───┼────╢ +║ 1 │ 45 ║ +╟───┼────╢ +║ 2 │ 56 ║ +╟───┼────╢ +║ 3 │ 56 ║ +╟───┼────╢ +║ 4 │ 56 ║ +╟───┼────╢ +║ 5 │ 56 ║ +╟───┼────╢ +║ 6 │ 56 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.cummin.md b/api-reference/series/series.cummin.md index f2337a8..0027054 100644 --- a/api-reference/series/series.cummin.md +++ b/api-reference/series/series.cummin.md @@ -2,13 +2,13 @@ description: Returns the cumulative min of a Series --- -# Series.cummin +# Series.cumMin -> danfo.Series.**cummin**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L816)\] +> danfo.Series.**cumMin**(options) -**Parameters:** None - -**Return**: Series +| Parameters | Type | Description | Default | +| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Example** @@ -21,32 +21,29 @@ const dfd = require("danfojs-node") let data1 = [10, 45, 56, 5, 23, 20, 10] let sf1 = new dfd.Series(data1) -sf1.cummin().print() +sf1.cumMin().print() ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 10 ║ -╟───┼──────────────────────╢ -║ 1 │ 10 ║ -╟───┼──────────────────────╢ -║ 2 │ 10 ║ -╟───┼──────────────────────╢ -║ 3 │ 5 ║ -╟───┼──────────────────────╢ -║ 4 │ 5 ║ -╟───┼──────────────────────╢ -║ 5 │ 5 ║ -╟───┼──────────────────────╢ -║ 6 │ 5 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 0 │ 10 ║ +╟───┼────╢ +║ 1 │ 10 ║ +╟───┼────╢ +║ 2 │ 10 ║ +╟───┼────╢ +║ 3 │ 5 ║ +╟───┼────╢ +║ 4 │ 5 ║ +╟───┼────╢ +║ 5 │ 5 ║ +╟───┼────╢ +║ 6 │ 5 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.cumprod.md b/api-reference/series/series.cumprod.md index 6b72547..48cf852 100644 --- a/api-reference/series/series.cumprod.md +++ b/api-reference/series/series.cumprod.md @@ -2,13 +2,13 @@ description: Return the cumulative product of a series --- -# Series.cumprod +# Series.cumProd -> danfo.Series.**cumprod**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L834)\] +> danfo.Series.**cumProd**() -**Parameters:** None - -**Return**: Series +| Parameters | Type | Description | Default | +| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Example** @@ -21,32 +21,29 @@ const dfd = require("danfojs-node") let data1 = [10, 45, 56, 25, 23, 20, 10] let sf1 = new dfd.Series(data1) -sf1.cumprod().print() +sf1.cumProd().print() ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 10 ║ -╟───┼──────────────────────╢ -║ 1 │ 450 ║ -╟───┼──────────────────────╢ -║ 2 │ 25200 ║ -╟───┼──────────────────────╢ -║ 3 │ 630000 ║ -╟───┼──────────────────────╢ -║ 4 │ 14490000 ║ -╟───┼──────────────────────╢ -║ 5 │ 289800000 ║ -╟───┼──────────────────────╢ -║ 6 │ 2898000000 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════════════╗ +║ 0 │ 10 ║ +╟───┼────────────╢ +║ 1 │ 450 ║ +╟───┼────────────╢ +║ 2 │ 25200 ║ +╟───┼────────────╢ +║ 3 │ 630000 ║ +╟───┼────────────╢ +║ 4 │ 14490000 ║ +╟───┼────────────╢ +║ 5 │ 289800000 ║ +╟───┼────────────╢ +║ 6 │ 2898000000 ║ +╚═══╧════════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.cumsum.md b/api-reference/series/series.cumsum.md index 205d777..32db0d0 100644 --- a/api-reference/series/series.cumsum.md +++ b/api-reference/series/series.cumsum.md @@ -2,13 +2,13 @@ description: Return a cumulative sum of a series --- -# Series.cumsum +# Series.cumSum -> danfo.Series.**cumsum**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L807)\] +> danfo.Series.**cumSum**(options) -**Parameters:** None - -**Return**: Series +| Parameters | Type | Description | Default | +| ---------- | ------ | -------------------------------------------------------------- | ------------------------------------------------------ | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Example** @@ -21,7 +21,7 @@ const dfd = require("danfojs-node") let data1 = [10, 45, 56, 25, 23, 20, 10] let sf1 = new dfd.Series(data1) -sf1.cumsum().print() +sf1.cumSum().print() ``` {% endtab %} @@ -53,23 +53,20 @@ sf1.cumsum().print() {% endtab %} {% endtabs %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 10 ║ -╟───┼──────────────────────╢ -║ 1 │ 55 ║ -╟───┼──────────────────────╢ -║ 2 │ 111 ║ -╟───┼──────────────────────╢ -║ 3 │ 136 ║ -╟───┼──────────────────────╢ -║ 4 │ 159 ║ -╟───┼──────────────────────╢ -║ 5 │ 179 ║ -╟───┼──────────────────────╢ -║ 6 │ 189 ║ -╚═══╧══════════════════════╝ ``` - +╔═══╤═════╗ +║ 0 │ 10 ║ +╟───┼─────╢ +║ 1 │ 55 ║ +╟───┼─────╢ +║ 2 │ 111 ║ +╟───┼─────╢ +║ 3 │ 136 ║ +╟───┼─────╢ +║ 4 │ 159 ║ +╟───┼─────╢ +║ 5 │ 179 ║ +╟───┼─────╢ +║ 6 │ 189 ║ +╚═══╧═════╝ +``` diff --git a/api-reference/series/series.describe.md b/api-reference/series/series.describe.md index 020cbb1..56472d3 100644 --- a/api-reference/series/series.describe.md +++ b/api-reference/series/series.describe.md @@ -7,7 +7,7 @@ description: >- # Series.describe -> danfo.Series.describe\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L583)\] +> danfo.Series.describe() **Parameters:** No parameter @@ -28,32 +28,28 @@ sf.describe().print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔══════════╤══════════════════════╗ -║ │ 0 ║ -╟──────────┼──────────────────────╢ -║ count │ 6 ║ -╟──────────┼──────────────────────╢ -║ mean │ 3.5 ║ -╟──────────┼──────────────────────╢ -║ std │ 1.8708286933869707 ║ -╟──────────┼──────────────────────╢ -║ min │ 1 ║ -╟──────────┼──────────────────────╢ -║ median │ 3.5 ║ -╟──────────┼──────────────────────╢ -║ max │ 6 ║ -╟──────────┼──────────────────────╢ -║ variance │ 3.5 ║ -╚══════════╧══════════════════════╝ +``` +╔══════════╤════════════════════╗ +║ count │ 6 ║ +╟──────────┼────────────────────╢ +║ mean │ 3.5 ║ +╟──────────┼────────────────────╢ +║ std │ 1.8708286933869707 ║ +╟──────────┼────────────────────╢ +║ min │ 1 ║ +╟──────────┼────────────────────╢ +║ median │ 3.5 ║ +╟──────────┼────────────────────╢ +║ max │ 6 ║ +╟──────────┼────────────────────╢ +║ variance │ 3.5 ║ +╚══════════╧════════════════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.div.md b/api-reference/series/series.div.md index 4dd4fd0..4bbdae8 100644 --- a/api-reference/series/series.div.md +++ b/api-reference/series/series.div.md @@ -6,12 +6,12 @@ description: >- # Series.div -> danfo.Series.div\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L188)\] +> danfo.Series.div(other, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series\|int\| | values | | -| round | bool | specify if to round off the floating number | true | +| Parameters | Type | Description | Default | +| ---------- | ------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------- | +| other | Series\|int\| | values | | +| options | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{

inplace: false

}

| **Return:** Series @@ -35,7 +35,7 @@ sf1.div(sf2).print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -51,7 +51,7 @@ sf1.div(sf2).print() {% endtab %} {% endtabs %} -divide with a value +### divide with a value {% tabs %} {% tab title="Node" %} @@ -68,7 +68,7 @@ sf1.div(2).print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -85,4 +85,3 @@ sf1.div(2).print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.drop_duplicates.md b/api-reference/series/series.drop_duplicates.md index d5fd7e2..7023f2c 100644 --- a/api-reference/series/series.drop_duplicates.md +++ b/api-reference/series/series.drop_duplicates.md @@ -2,20 +2,19 @@ description: Remove duplicate rows --- -# Series.drop\_duplicates +# Series.dropDuplicates -> danfo.Series.**drop\_duplicates**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L1007)\] +> danfo.Series.dropDuplicates(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs\["**inplace**"\] | bool | return a new series or not. | false | -| kwargs\["**keep**"\] | String | {"**first**"or "**last**"}. Specify if to keep the last or the first duplicate value | first | +| Parameters | Type | Description | Default | +| ---------- | ------ | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | Object | **keep**: "first" |

"last", which duplicate value to keep. Defaults to "first".
inplace: Boolean indicating whether to perform the operation in-place or not. Defaults to false

| **Returns:** Series **Examples** -Drop duplicate by keeping the first value of the duplicate value +### Drop duplicate by keeping the first occurrence of the duplicate value {% tabs %} {% tab title="Node" %} @@ -24,7 +23,7 @@ const dfd = require("danfojs-node") let data1 = [10, 45, 56, 10, 23, 20, 10, 10] let sf = new dfd.Series(data1) -let sf_drop = sf.drop_duplicates() +let sf_drop = sf.dropDuplicates() sf_drop.print() ``` @@ -33,25 +32,23 @@ sf_drop.print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 10 ║ -╟───┼──────────────────────╢ -║ 1 │ 45 ║ -╟───┼──────────────────────╢ -║ 2 │ 56 ║ -╟───┼──────────────────────╢ -║ 4 │ 23 ║ -╟───┼──────────────────────╢ -║ 5 │ 20 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 0 │ 10 ║ +╟───┼────╢ +║ 1 │ 45 ║ +╟───┼────╢ +║ 2 │ 56 ║ +╟───┼────╢ +║ 4 │ 23 ║ +╟───┼────╢ +║ 5 │ 20 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} -Drop duplicate and keep only the last duplicated value +### Drop duplicate and keep only the last duplicated value {% tabs %} {% tab title="Node" %} @@ -60,7 +57,7 @@ const dfd = require("danfojs-node") let data1 = [10, 45, 56, 10, 23, 20, 10, 10] let sf = new dfd.Series(data1) -let sf_drop = sf.drop_duplicates({keep:"last"}) +let sf_drop = sf.dropDuplicates({ keep: "last" }) sf_drop.print() ``` @@ -69,25 +66,23 @@ sf_drop.print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 1 │ 45 ║ -╟───┼──────────────────────╢ -║ 2 │ 56 ║ -╟───┼──────────────────────╢ -║ 4 │ 23 ║ -╟───┼──────────────────────╢ -║ 5 │ 20 ║ -╟───┼──────────────────────╢ -║ 7 │ 10 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 1 │ 45 ║ +╟───┼────╢ +║ 2 │ 56 ║ +╟───┼────╢ +║ 4 │ 23 ║ +╟───┼────╢ +║ 5 │ 20 ║ +╟───┼────╢ +║ 7 │ 10 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} -Remove duplicate value in series without returning a new series +### Remove duplicate value in-place {% tabs %} {% tab title="Node" %} @@ -96,7 +91,7 @@ const dfd = require("danfojs-node") let data1 = ["A", "A", "A", "B", "B", "C", "C", "D"] let sf = new dfd.Series(data1) -sf.drop_duplicates({inplace:true}) +sf.dropDuplicates({ inplace: true }) sf.print() ``` @@ -105,19 +100,16 @@ sf.print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ A ║ -╟───┼──────────────────────╢ -║ 3 │ B ║ -╟───┼──────────────────────╢ -║ 5 │ C ║ -╟───┼──────────────────────╢ -║ 7 │ D ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══╗ +║ 0 │ A ║ +╟───┼───╢ +║ 3 │ B ║ +╟───┼───╢ +║ 5 │ C ║ +╟───┼───╢ +║ 7 │ D ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.dropna.md b/api-reference/series/series.dropna.md index 6fa1100..6786478 100644 --- a/api-reference/series/series.dropna.md +++ b/api-reference/series/series.dropna.md @@ -2,28 +2,24 @@ description: Remove missing values from Series --- -# Series.dropna +# Series.dropNa -> danfo.Series.**dropna**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L931)\] +> danfo.Series.dropNa(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L931)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs\["**inplace**"\] | bool | return a new series or not. | false | +| Parameters | Type | Description | Default | +| ---------- | ------ | ---------------------------------------------------------------------------------------------- | ---------------------------------- | +| options | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{
inplace: false

}

| -**Returns**: Series - -**Examples** - -Drop all nan value and then return New Series. +### Drop all missing values and then return New Series. {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data1 = [10, 45, undefined, 10, 23, 20, undefined, 10] +let data1 = [10, 45, undefined, 10, 23, 20, null, 10] let sf = new dfd.Series(data1) -let sf_rep = sf.dropna() +let sf_rep = sf.dropNa() sf_rep.print() ``` @@ -32,27 +28,25 @@ sf_rep.print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 10 ║ -╟───┼──────────────────────╢ -║ 1 │ 45 ║ -╟───┼──────────────────────╢ -║ 3 │ 10 ║ -╟───┼──────────────────────╢ -║ 4 │ 23 ║ -╟───┼──────────────────────╢ -║ 5 │ 20 ║ -╟───┼──────────────────────╢ -║ 7 │ 10 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 0 │ 10 ║ +╟───┼────╢ +║ 1 │ 45 ║ +╟───┼────╢ +║ 3 │ 10 ║ +╟───┼────╢ +║ 4 │ 23 ║ +╟───┼────╢ +║ 5 │ 20 ║ +╟───┼────╢ +║ 7 │ 10 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} -Drop nan values without returning new series +### Drop nan values in-place {% tabs %} {% tab title="Node" %} @@ -61,7 +55,7 @@ const dfd = require("danfojs-node") let data1 = [10, 45, undefined, 10, 23, 20, undefined, 10] let sf = new dfd.Series(data1) -sf.dropna({inplace:true}) +sf.dropNa({inplace:true}) sf.print() ``` @@ -70,23 +64,20 @@ sf.print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 10 ║ -╟───┼──────────────────────╢ -║ 1 │ 45 ║ -╟───┼──────────────────────╢ -║ 3 │ 10 ║ -╟───┼──────────────────────╢ -║ 4 │ 23 ║ -╟───┼──────────────────────╢ -║ 5 │ 20 ║ -╟───┼──────────────────────╢ -║ 7 │ 10 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 0 │ 10 ║ +╟───┼────╢ +║ 1 │ 45 ║ +╟───┼────╢ +║ 3 │ 10 ║ +╟───┼────╢ +║ 4 │ 23 ║ +╟───┼────╢ +║ 5 │ 20 ║ +╟───┼────╢ +║ 7 │ 10 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.dt.day.md b/api-reference/series/series.dt.day.md index 09334c1..827fd29 100644 --- a/api-reference/series/series.dt.day.md +++ b/api-reference/series/series.dt.day.md @@ -2,13 +2,13 @@ description: Obtain the numerical representation of the week day. --- -# Series.dt.day +# Series.dt.dayOfWeek -> danfo.Series.dt.**day**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L216)\] +> danfo.Series.dt.dayOfWeek() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L216)] **Parameters**: None -**Returns:** Series \(int elements\) +**Returns:** Series (int elements) **Examples** @@ -17,41 +17,63 @@ description: Obtain the numerical representation of the week day. ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":'2016-12-31', "end":'2017-01-08'}) +let data = new dfd.dateRange({"start":'2016-12-31', "end":'2018-01-08'}) let sf = new dfd.Series(data) - -sf.dt.day().print() +//print series +sf.print() +//print days of the week +sf.dt.dayOfWeek().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 6 ║ -╟───┼──────────────────────╢ -║ 1 │ 0 ║ -╟───┼──────────────────────╢ -║ 2 │ 1 ║ -╟───┼──────────────────────╢ -║ 3 │ 2 ║ -╟───┼──────────────────────╢ -║ 4 │ 3 ║ -╟───┼──────────────────────╢ -║ 5 │ 4 ║ -╟───┼──────────────────────╢ -║ 6 │ 5 ║ -╟───┼──────────────────────╢ -║ 7 │ 6 ║ -╟───┼──────────────────────╢ -║ 8 │ 0 ║ -╚═══╧══════════════════════╝ ``` +╔═══╤════════════════════════╗ +║ 0 │ 12/31/2016, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 1 │ 1/1/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 2 │ 1/2/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 3 │ 1/3/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 4 │ 1/4/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 5 │ 1/5/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 6 │ 1/6/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 7 │ 1/7/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 8 │ 1/8/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 9 │ 1/9/2017, 1:00:00 AM ║ +╚═══╧════════════════════════╝ +╔═══╤═══╗ +║ 0 │ 6 ║ +╟───┼───╢ +║ 1 │ 0 ║ +╟───┼───╢ +║ 2 │ 1 ║ +╟───┼───╢ +║ 3 │ 2 ║ +╟───┼───╢ +║ 4 │ 3 ║ +╟───┼───╢ +║ 5 │ 4 ║ +╟───┼───╢ +║ 6 │ 5 ║ +╟───┼───╢ +║ 7 │ 6 ║ +╟───┼───╢ +║ 8 │ 0 ║ +╟───┼───╢ +║ 9 │ 1 ║ +╚═══╧═══╝ +``` diff --git a/api-reference/series/series.dt.hour.md b/api-reference/series/series.dt.hour.md index 1243049..41ae2b3 100644 --- a/api-reference/series/series.dt.hour.md +++ b/api-reference/series/series.dt.hour.md @@ -2,13 +2,13 @@ description: Obtain the hours in a time series --- -# Series.dt.hour +# Series.dt.hours -> danfo.Series.dt.**hour**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L205)\] +> danfo.Series.dt.**hours**() **Parameters:** None -**Returns:** Series \(int elements\) +**Returns:** Series (int elements) **Examples** @@ -17,42 +17,35 @@ description: Obtain the hours in a time series ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":"2000-01-01", period:3, freq:"H"}) +let data = new dfd.dateRange({"start":"2000-01-01", period:3, freq:"H"}) let sf = new dfd.Series(data) // print series sf.print() // print hour series -sf.dt.hour().print() +sf.dt.hours().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ ║ 0 │ 1/1/2000, 1:00:00 AM ║ ╟───┼──────────────────────╢ ║ 1 │ 1/1/2000, 2:00:00 AM ║ ╚═══╧══════════════════════╝ -//print hour series -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 1 ║ -╟───┼──────────────────────╢ -║ 1 │ 2 ║ -╚═══╧══════════════════════╝ +╔═══╤═══╗ +║ 0 │ 1 ║ +╟───┼───╢ +║ 1 │ 2 ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.dt.minute.md b/api-reference/series/series.dt.minute.md index 4fec5c6..e092c07 100644 --- a/api-reference/series/series.dt.minute.md +++ b/api-reference/series/series.dt.minute.md @@ -4,11 +4,11 @@ description: Obtain the minutes in a Time Series # Series.dt.minutes -> danfo.Series.dt.**minutes**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L292)\] +> danfo.Series.dt.**minutes**() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L292)] **Parameters**: None -**Returns:** Series \(int Elements\) +**Returns:** Series (int Elements) **Example** @@ -17,7 +17,7 @@ description: Obtain the minutes in a Time Series ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":"2000-01-01", period:3, freq:"m"}) +let data = new dfd.dateRange({"start":"2000-01-01", period:3, freq:"m"}) let sf = new dfd.Series(data) //print the series sf.print() @@ -28,14 +28,13 @@ sf.dt.minutes().print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -59,4 +58,3 @@ sf.dt.minutes().print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.dt.month.md b/api-reference/series/series.dt.month.md index 0e6dedb..7337900 100644 --- a/api-reference/series/series.dt.month.md +++ b/api-reference/series/series.dt.month.md @@ -4,11 +4,11 @@ description: Obtain the month in a date time series # Series.dt.month -> danfo.Series.dt.**month**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L193)\] +> danfo.Series.dt.**month**() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L193)] **Parameters**: None -**Returns:** Series \(int elements\) +**Returns:** Series (int elements) **Examples** @@ -17,7 +17,7 @@ description: Obtain the month in a date time series ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":'2016-7-31', "end":'2016-12-08', freq:"M"}) +let data = new dfd.dateRange({"start":'2016-7-31', "end":'2016-12-08', freq:"M"}) let sf = new dfd.Series(data) sf.dt.month().print() @@ -26,26 +26,22 @@ sf.dt.month().print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 6 ║ -╟───┼──────────────────────╢ -║ 1 │ 7 ║ -╟───┼──────────────────────╢ -║ 2 │ 9 ║ -╟───┼──────────────────────╢ -║ 3 │ 9 ║ -╟───┼──────────────────────╢ -║ 4 │ 11 ║ -╟───┼──────────────────────╢ -║ 5 │ 11 ║ -╚═══╧══════════════════════╝ ``` - +╔═══╤════╗ +║ 0 │ 6 ║ +╟───┼────╢ +║ 1 │ 7 ║ +╟───┼────╢ +║ 2 │ 9 ║ +╟───┼────╢ +║ 3 │ 9 ║ +╟───┼────╢ +║ 4 │ 11 ║ +╟───┼────╢ +║ 5 │ 11 ║ +╚═══╧════╝ +``` diff --git a/api-reference/series/series.dt.month_name.md b/api-reference/series/series.dt.month_name.md index 82a7d3c..0029d6f 100644 --- a/api-reference/series/series.dt.month_name.md +++ b/api-reference/series/series.dt.month_name.md @@ -2,13 +2,13 @@ description: obtain the month name in a Time Series --- -# Series.dt.month\_name +# Series.dt.monthName -> danfo.Series.dt.month\_name\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L241)\] +> danfo.Series.dt.monthName() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L241)] **Parameters**: None -**Returns:** Series \(String elements\) +**Returns:** Series (String elements) **Examples** @@ -22,23 +22,20 @@ let sf = new dfd.Series(data) //print series sf.print() //print month names -sf.dt.month_name().print() +sf.dt.monthName().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ ║ 0 │ 1/1/2018, 1:00:00 AM ║ ╟───┼──────────────────────╢ ║ 1 │ 2/1/2018, 1:00:00 AM ║ @@ -46,17 +43,13 @@ sf.dt.month_name().print() ║ 2 │ 3/1/2018, 1:00:00 AM ║ ╚═══╧══════════════════════╝ -//print month name series -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ Jan ║ -╟───┼──────────────────────╢ -║ 1 │ Feb ║ -╟───┼──────────────────────╢ -║ 2 │ Mar ║ -╚═══╧══════════════════════╝ +╔═══╤═════╗ +║ 0 │ Jan ║ +╟───┼─────╢ +║ 1 │ Feb ║ +╟───┼─────╢ +║ 2 │ Mar ║ +╚═══╧═════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.dt.monthday.md b/api-reference/series/series.dt.monthday.md index 1c7e556..03f1c45 100644 --- a/api-reference/series/series.dt.monthday.md +++ b/api-reference/series/series.dt.monthday.md @@ -2,13 +2,13 @@ description: Obtain the day of the month --- -# Series.dt.monthday +# Series.dt.dayOfMonth -> danfo.Series.dt.**monthday**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L268)\] +> danfo.Series.dt.dayOfMonth() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L268)] **Parameters:** None -**Returns**: Series \(Int elements\) +**Returns**: Series (Int elements) **Examples** @@ -17,28 +17,25 @@ description: Obtain the day of the month ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":"2000-01-01", period:4, freq:"D"}) +let data = new dfd.dateRange({"start":"2000-01-01", period:4, freq:"D"}) let sf = new dfd.Series(data) //print series sf.print() //print monthdays -sf.dt.monthday().print() +sf.dt.dayOfMonth().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ ║ 0 │ 1/1/2000, 1:00:00 AM ║ ╟───┼──────────────────────╢ ║ 1 │ 1/2/2000, 1:00:00 AM ║ @@ -46,17 +43,13 @@ sf.dt.monthday().print() ║ 2 │ 1/3/2000, 1:00:00 AM ║ ╚═══╧══════════════════════╝ -//print monthdays -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 1 ║ -╟───┼──────────────────────╢ -║ 1 │ 2 ║ -╟───┼──────────────────────╢ -║ 2 │ 3 ║ -╚═══╧══════════════════════╝ +╔═══╤═══╗ +║ 0 │ 1 ║ +╟───┼───╢ +║ 1 │ 2 ║ +╟───┼───╢ +║ 2 │ 3 ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.dt.second.md b/api-reference/series/series.dt.second.md index e6fd771..1ccee42 100644 --- a/api-reference/series/series.dt.second.md +++ b/api-reference/series/series.dt.second.md @@ -4,11 +4,11 @@ description: Obtain the seconds in Date series # Series.dt.seconds -> danfo.Series.dt.**seconds**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L280)\] +> danfo.Series.dt.**seconds**() **Parameters**: None -**Returns:** Series \(Int elements\) +**Returns:** Series (Int elements) **Example** @@ -19,30 +19,26 @@ Obtain the seconds of the datetime ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":"2000-01-01", period:3, freq:"s"}) +let data = new dfd.dateRange({"start":"2000-01-01", period:3, freq:"s"}) let sf = new dfd.Series(data) //print the series frame sf.print() //print the seconds obtained -sf.seconds().print() +sf.dt.seconds().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text - +``` ╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ ║ 0 │ 1/1/2000, 1:00:00 AM ║ ╟───┼──────────────────────╢ ║ 1 │ 1/1/2000, 1:00:01 AM ║ @@ -50,18 +46,13 @@ sf.seconds().print() ║ 2 │ 1/1/2000, 1:00:02 AM ║ ╚═══╧══════════════════════╝ -//the seconds obtained -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 0 ║ -╟───┼──────────────────────╢ -║ 1 │ 1 ║ -╟───┼──────────────────────╢ -║ 2 │ 2 ║ -╚═══╧══════════════════════╝ - +╔═══╤═══╗ +║ 0 │ 0 ║ +╟───┼───╢ +║ 1 │ 1 ║ +╟───┼───╢ +║ 2 │ 2 ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.dt.weekdays.md b/api-reference/series/series.dt.weekdays.md index dc79e6c..05996c3 100644 --- a/api-reference/series/series.dt.weekdays.md +++ b/api-reference/series/series.dt.weekdays.md @@ -2,13 +2,13 @@ description: Obtain the days of the weeks --- -# Series.dt.weekdays +# Series.dt.dayOfWeek -> danfo.Series.dt.**weekdays**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L255)\] +> danfo.Series.dt.dayOfWeek() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L255)] **Parameters**: None -**Returns:** Series \(String elements\) +**Returns:** Series (String elements) **Examples** @@ -17,66 +17,63 @@ description: Obtain the days of the weeks ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":'2016-12-31', "end":'2017-01-08'}) +let data = new dfd.dateRange({"start":'2016-12-31', "end":'2018-01-08'}) let sf = new dfd.Series(data) //print series sf.print() //print days of the week -sf.dt.weekdays().print() +sf.dt.dayOfWeek().print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 12/31/2016, 1:00:... ║ -╟───┼──────────────────────╢ -║ 1 │ 1/1/2017, 1:00:00 AM ║ -╟───┼──────────────────────╢ -║ 2 │ 1/2/2017, 1:00:00 AM ║ -╟───┼──────────────────────╢ -║ 3 │ 1/3/2017, 1:00:00 AM ║ -╟───┼──────────────────────╢ -║ 4 │ 1/4/2017, 1:00:00 AM ║ -╟───┼──────────────────────╢ -║ 5 │ 1/5/2017, 1:00:00 AM ║ -╟───┼──────────────────────╢ -║ 6 │ 1/6/2017, 1:00:00 AM ║ -╟───┼──────────────────────╢ -║ 7 │ 1/7/2017, 1:00:00 AM ║ -╟───┼──────────────────────╢ -║ 8 │ 1/8/2017, 1:00:00 AM ║ -╚═══╧══════════════════════╝ - -//print days of the week -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ Sat ║ -╟───┼──────────────────────╢ -║ 1 │ Sun ║ -╟───┼──────────────────────╢ -║ 2 │ Mon ║ -╟───┼──────────────────────╢ -║ 3 │ Tue ║ -╟───┼──────────────────────╢ -║ 4 │ Wed ║ -╟───┼──────────────────────╢ -║ 5 │ Thu ║ -╟───┼──────────────────────╢ -║ 6 │ Fri ║ -╟───┼──────────────────────╢ -║ 7 │ Sat ║ -╟───┼──────────────────────╢ -║ 8 │ Sun ║ -╚═══╧══════════════════════╝ ``` +╔═══╤════════════════════════╗ +║ 0 │ 12/31/2016, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 1 │ 1/1/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 2 │ 1/2/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 3 │ 1/3/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 4 │ 1/4/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 5 │ 1/5/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 6 │ 1/6/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 7 │ 1/7/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 8 │ 1/8/2017, 1:00:00 AM ║ +╟───┼────────────────────────╢ +║ 9 │ 1/9/2017, 1:00:00 AM ║ +╚═══╧════════════════════════╝ +╔═══╤═══╗ +║ 0 │ 6 ║ +╟───┼───╢ +║ 1 │ 0 ║ +╟───┼───╢ +║ 2 │ 1 ║ +╟───┼───╢ +║ 3 │ 2 ║ +╟───┼───╢ +║ 4 │ 3 ║ +╟───┼───╢ +║ 5 │ 4 ║ +╟───┼───╢ +║ 6 │ 5 ║ +╟───┼───╢ +║ 7 │ 6 ║ +╟───┼───╢ +║ 8 │ 0 ║ +╟───┼───╢ +║ 9 │ 1 ║ +╚═══╧═══╝ +``` diff --git a/api-reference/series/series.dt.year.md b/api-reference/series/series.dt.year.md index a594255..48fbbea 100644 --- a/api-reference/series/series.dt.year.md +++ b/api-reference/series/series.dt.year.md @@ -4,11 +4,11 @@ description: Obtain the year in a date time series # Series.dt.year -> danfo.Series.dt.**year**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/timeseries.js#L228)\] +> danfo.Series.dt.**year**() **Parameters**: None -**Returns:** Series \(int elements\) +**Returns:** Series (int elements) **Examples** @@ -17,7 +17,7 @@ description: Obtain the year in a date time series ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":"2000-01-01", period:3, freq:"Y"}) +let data = new dfd.dateRange({"start":"2000-01-01", period:3, freq:"Y"}) let sf = new dfd.Series(data) sf.print() sf.dt.year().print() @@ -25,11 +25,9 @@ sf.dt.year().print() {% endtab %} {% endtabs %} -```text +``` //print date time series ╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ ║ 0 │ 1/1/2000, 1:00:00 AM ║ ╟───┼──────────────────────╢ ║ 1 │ 1/1/2001, 1:00:00 AM ║ @@ -37,15 +35,11 @@ sf.dt.year().print() ║ 2 │ 1/1/2002, 1:00:00 AM ║ ╚═══╧══════════════════════╝ -//print the year series -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 2000 ║ -╟───┼──────────────────────╢ -║ 1 │ 2001 ║ -╟───┼──────────────────────╢ -║ 2 │ 2002 ║ -╚═══╧══════════════════════╝ +╔═══╤══════╗ +║ 0 │ 2000 ║ +╟───┼──────╢ +║ 1 │ 2001 ║ +╟───┼──────╢ +║ 2 │ 2002 ║ +╚═══╧══════╝ ``` - diff --git a/api-reference/series/series.dtype.md b/api-reference/series/series.dtype.md index b59170e..75b4614 100644 --- a/api-reference/series/series.dtype.md +++ b/api-reference/series/series.dtype.md @@ -4,7 +4,7 @@ description: Obtain the dtype of a series # Series.dtype -> danfo.Series.dtype \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L197)\] +> danfo.Series.dtype \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L197)] **Parameters**: None @@ -27,9 +27,8 @@ console.log(sf1.dtype) {% tabs %} {% tab title="Output" %} -```text +``` float32 ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.eq.md b/api-reference/series/series.eq.md index 341dbb9..f711b5c 100644 --- a/api-reference/series/series.eq.md +++ b/api-reference/series/series.eq.md @@ -4,13 +4,13 @@ description: Check all the values in a series is equal to another value # Series.eq -> danfo.Series.eq\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L894)\] +> danfo.Series.eq(other) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series**\|** int\|String\|float | value to compare | | +| Parameters | Type | Description | Default | +| ---------- | ----------------------- | ---------------- | ------- | +| other | Series, Array or number | value to compare | | -**Returns**: Series \(Boolean element\) +**Returns**: Series (Boolean element) **Examples** @@ -33,24 +33,22 @@ sf1.eq(sf2).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ true ║ -╟───┼──────────────────────╢ -║ 1 │ false ║ -╟───┼──────────────────────╢ -║ 2 │ true ║ -╟───┼──────────────────────╢ -║ 3 │ false ║ -╟───┼──────────────────────╢ -║ 4 │ false ║ -╟───┼──────────────────────╢ -║ 5 │ false ║ -╟───┼──────────────────────╢ -║ 6 │ false ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ true ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ true ║ +╟───┼───────╢ +║ 3 │ false ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ false ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} @@ -72,25 +70,22 @@ sf1.eq(10).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ true ║ -╟───┼──────────────────────╢ -║ 1 │ false ║ -╟───┼──────────────────────╢ -║ 2 │ false ║ -╟───┼──────────────────────╢ -║ 3 │ false ║ -╟───┼──────────────────────╢ -║ 4 │ false ║ -╟───┼──────────────────────╢ -║ 5 │ false ║ -╟───┼──────────────────────╢ -║ 6 │ true ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ true ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ false ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ true ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.fillna.md b/api-reference/series/series.fillna.md index b1bea1b..b263a06 100644 --- a/api-reference/series/series.fillna.md +++ b/api-reference/series/series.fillna.md @@ -2,20 +2,18 @@ description: Replace all NaN value with specified value --- -# Series.fillna +# Series.fillNa -> danfo.Series.**fillna**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L470)\] +> danfo.Series.fillNa(options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs\["**value**"\] | int \| String\| bool | value to replace the NaN values | | -| kwargs\["**inplace**"\] | bool | return a new series or not. | false | - -**Returns:** Series +| Parameters | Type | Description | Default | +| ----------- | ------ | -------------------------------------------------------------------------------------------------- | ------------------------------------- | +| **value** | Any |

The value to replace all missing value with.

| | +| **options** | Object | **inplace**: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{

inplace: false

}

| **Examples** -Fill nan value and then return new series +### Fill nan value and then return new series {% tabs %} {% tab title="Node" %} @@ -25,7 +23,7 @@ const dfd = require("danfojs-node") let data1 = [NaN, 1, 2, 33, 4, NaN, 5, 6, 7, 8] let sf = new dfd.Series(data1) -let sf_rep = sf.fillna({ value: -999}) +let sf_rep = sf.fillNa(-999) sf_rep.print() ``` @@ -34,44 +32,42 @@ sf_rep.print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ -999 ║ -╟───┼──────────────────────╢ -║ 1 │ 1 ║ -╟───┼──────────────────────╢ -║ 2 │ 2 ║ -╟───┼──────────────────────╢ -║ 3 │ 33 ║ -╟───┼──────────────────────╢ -║ 4 │ 4 ║ -╟───┼──────────────────────╢ -║ 5 │ -999 ║ -╟───┼──────────────────────╢ -║ 6 │ 5 ║ -╟───┼──────────────────────╢ -║ 7 │ 6 ║ -╟───┼──────────────────────╢ -║ 8 │ 7 ║ -╟───┼──────────────────────╢ -║ 9 │ 8 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤══════╗ +║ 0 │ -999 ║ +╟───┼──────╢ +║ 1 │ 1 ║ +╟───┼──────╢ +║ 2 │ 2 ║ +╟───┼──────╢ +║ 3 │ 33 ║ +╟───┼──────╢ +║ 4 │ 4 ║ +╟───┼──────╢ +║ 5 │ -999 ║ +╟───┼──────╢ +║ 6 │ 5 ║ +╟───┼──────╢ +║ 7 │ 6 ║ +╟───┼──────╢ +║ 8 │ 7 ║ +╟───┼──────╢ +║ 9 │ 8 ║ +╚═══╧══════╝ ``` {% endtab %} {% endtabs %} -Fill nan value without returning new Series +### Fill nan value inplace {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data1 = [NaN, 1, 2, 33, 4, NaN, 5, 6, 7, 8] +let data1 = [NaN, 1, 2, 33, 4, undefined, 5, 6, 7, 8] let sf = new dfd.Series(data1) -sf.fillna({ value: -999, inplace: true }) +sf.fillNa(-999, { inplace: true }) sf.print() ``` @@ -80,31 +76,28 @@ sf.print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ -999 ║ -╟───┼──────────────────────╢ -║ 1 │ 1 ║ -╟───┼──────────────────────╢ -║ 2 │ 2 ║ -╟───┼──────────────────────╢ -║ 3 │ 33 ║ -╟───┼──────────────────────╢ -║ 4 │ 4 ║ -╟───┼──────────────────────╢ -║ 5 │ -999 ║ -╟───┼──────────────────────╢ -║ 6 │ 5 ║ -╟───┼──────────────────────╢ -║ 7 │ 6 ║ -╟───┼──────────────────────╢ -║ 8 │ 7 ║ -╟───┼──────────────────────╢ -║ 9 │ 8 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤══════╗ +║ 0 │ -999 ║ +╟───┼──────╢ +║ 1 │ 1 ║ +╟───┼──────╢ +║ 2 │ 2 ║ +╟───┼──────╢ +║ 3 │ 33 ║ +╟───┼──────╢ +║ 4 │ 4 ║ +╟───┼──────╢ +║ 5 │ -999 ║ +╟───┼──────╢ +║ 6 │ 5 ║ +╟───┼──────╢ +║ 7 │ 6 ║ +╟───┼──────╢ +║ 8 │ 7 ║ +╟───┼──────╢ +║ 9 │ 8 ║ +╚═══╧══════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.ge.md b/api-reference/series/series.ge.md index b3d8b69..8ceae56 100644 --- a/api-reference/series/series.ge.md +++ b/api-reference/series/series.ge.md @@ -4,17 +4,17 @@ description: Check if all the values in a series is greater than or equal a valu # Series.ge -> danfo.Series.ge\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L874)\] +> danfo.Series.ge(other) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series**\|** int\|float | value\(s\) to compare | | +| Parameters | Type | Description | Default | +| ---------- | ----------------------- | ------------------- | ------- | +| other | Series, Array or number | value(s) to compare | | -**Returns:** Series \(Boolean element\) +**Returns:** Series (Boolean element) **Example** -Compare all the value in a Series to the values in another series +Compare all the values in a Series to the values in another series {% tabs %} {% tab title="Node" %} @@ -33,29 +33,27 @@ sf1.ge(sf2).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ true ║ -╟───┼──────────────────────╢ -║ 1 │ false ║ -╟───┼──────────────────────╢ -║ 2 │ true ║ -╟───┼──────────────────────╢ -║ 3 │ true ║ -╟───┼──────────────────────╢ -║ 4 │ false ║ -╟───┼──────────────────────╢ -║ 5 │ true ║ -╟───┼──────────────────────╢ -║ 6 │ true ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ true ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ true ║ +╟───┼───────╢ +║ 3 │ true ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ true ║ +╟───┼───────╢ +║ 6 │ true ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} -Check if all the value in a Series is greater than or equal a value. +Check if all the value in a Series is greater than or equal to a scalar value. {% tabs %} {% tab title="Node" %} @@ -72,25 +70,22 @@ sf1.ge(20).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ false ║ -╟───┼──────────────────────╢ -║ 1 │ true ║ -╟───┼──────────────────────╢ -║ 2 │ true ║ -╟───┼──────────────────────╢ -║ 3 │ true ║ -╟───┼──────────────────────╢ -║ 4 │ true ║ -╟───┼──────────────────────╢ -║ 5 │ true ║ -╟───┼──────────────────────╢ -║ 6 │ false ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ true ║ +╟───┼───────╢ +║ 2 │ true ║ +╟───┼───────╢ +║ 3 │ true ║ +╟───┼───────╢ +║ 4 │ true ║ +╟───┼───────╢ +║ 5 │ true ║ +╟───┼───────╢ +║ 6 │ false ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.gt.md b/api-reference/series/series.gt.md index a98f618..f76171d 100644 --- a/api-reference/series/series.gt.md +++ b/api-reference/series/series.gt.md @@ -4,13 +4,13 @@ description: Check if all the value in a series is greater than a value # Series.gt -> danfo.Series.gt\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L856)\] +> danfo.Series.gt(other) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series**\|** int\|float | value\(s\) to compare | | +| Parameters | Type | Description | Default | +| ---------- | ----------------------- | ------------------- | ------- | +| other | Series, Array or number | value(s) to compare | | -**Returns**: Series \(boolean element\) +**Returns**: Series (boolean element) **Example** @@ -31,24 +31,22 @@ sf1.gt(20).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ false ║ -╟───┼──────────────────────╢ -║ 1 │ true ║ -╟───┼──────────────────────╢ -║ 2 │ true ║ -╟───┼──────────────────────╢ -║ 3 │ true ║ -╟───┼──────────────────────╢ -║ 4 │ true ║ -╟───┼──────────────────────╢ -║ 5 │ false ║ -╟───┼──────────────────────╢ -║ 6 │ false ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ true ║ +╟───┼───────╢ +║ 2 │ true ║ +╟───┼───────╢ +║ 3 │ true ║ +╟───┼───────╢ +║ 4 │ true ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ false ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} @@ -72,25 +70,22 @@ sf1.gt(sf2).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ false ║ -╟───┼──────────────────────╢ -║ 1 │ false ║ -╟───┼──────────────────────╢ -║ 2 │ false ║ -╟───┼──────────────────────╢ -║ 3 │ true ║ -╟───┼──────────────────────╢ -║ 4 │ false ║ -╟───┼──────────────────────╢ -║ 5 │ true ║ -╟───┼──────────────────────╢ -║ 6 │ true ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ true ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ true ║ +╟───┼───────╢ +║ 6 │ true ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.head.md b/api-reference/series/series.head.md index 2892263..1601c9e 100644 --- a/api-reference/series/series.head.md +++ b/api-reference/series/series.head.md @@ -4,13 +4,13 @@ description: Obtain the first n rows for the object based on position. # Series.head -> danfo.Series.head\(rows\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L76)\] +> danfo.Series.head(rows) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| rows | Int | number of first n values | 5 | +| Parameters | Type | Description | Default | +| ---------- | ---- | ------------------------ | ------- | +| rows | Int | number of first n values | 5 | - **Return:** Series +**Return:** Series **Example** @@ -29,7 +29,7 @@ sf1.head().print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -46,6 +46,3 @@ sf1.head().print() ``` {% endtab %} {% endtabs %} - - - diff --git a/api-reference/series/series.iat.md b/api-reference/series/series.iat.md new file mode 100644 index 0000000..3f17e6b --- /dev/null +++ b/api-reference/series/series.iat.md @@ -0,0 +1,31 @@ +--- +description: Access a single value for a row/column pair by integer position. +--- + +# Series.iat + +> danfo.Series.iat(index) + +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------ | ------- | +| index | Number | index value | | + +**Return:** Scalar + + + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let sf = new dfd.Series(["Apples", "Mango", "Banana", "Pear"], + { index: ["a", "b", "c", "d"] } +) + +sf.iat(1) + +// "Mango" +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/series/series.iloc.md b/api-reference/series/series.iloc.md index e580803..8adadff 100644 --- a/api-reference/series/series.iloc.md +++ b/api-reference/series/series.iloc.md @@ -1,26 +1,23 @@ # Series.iloc -danfo.Series.**iloc**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L254)\] +danfo.Series.**iloc**() -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| rows | Array | Array, slice or index of row position to return | | - -**Returns:** - - ****return **Series** +| Parameters | Type | Description | Default | +| ---------- | --------------------- | ---------------------------------------------------------------------- | ------- | +| rows | Array or String slice | Array, string slice, index of row positions boolean mask to filter by. | | ## **Examples** -`.iloc()` is primarily integer position based \(from `0` to `length-1` of the axis\). +`.iloc()` is primarily integer position based (from `0` to `length-1` of the axis). Allowed inputs are: * An integer, e.g. `5`. * A list or array of integers, e.g. `[4, 3, 0]`. +* A boolean mask. E.g \[ true, false, false ] * A string slice object with ints, e.g. `"1:7"` -_**Note:** only ****the start label is included._ +_**Note:** only \*\*\*\* the start label is included, and the end label is ignored._ `.iloc` will raise`IndexError` if a requested indexer is out-of-bounds. @@ -30,39 +27,33 @@ _**Note:** only ****the start label is included._ {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -// const tf = require("@tensorflow/tfjs-node") - let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7]) s.iloc([0,5]).print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 12 ║ -╟───┼──────────────────────╢ -║ 5 │ 30 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 0 │ 12 ║ +╟───┼────╢ +║ 5 │ 30 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} ### **Index by a slice of row** -The [**iloc**](../dataframe/danfo.dataframe.iloc.md) function also accepts string slices of the form \[start: end\], e.g "\[1: 4\]". This will return all values between index position 1 and 3. +The [**iloc**](../dataframe/danfo.dataframe.iloc.md) function also accepts string slices of the form \[start: end], e.g "\[0: 5]". This will return all values from index positions 0 to 4. {% tabs %} {% tab title="Node" %} @@ -76,32 +67,29 @@ s.iloc(["0:5"]).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 12 ║ -╟───┼──────────────────────╢ -║ 1 │ 34 ║ -╟───┼──────────────────────╢ -║ 2 │ 2.2 ║ -╟───┼──────────────────────╢ -║ 3 │ 2 ║ -╟───┼──────────────────────╢ -║ 4 │ 30 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═════╗ +║ 0 │ 12 ║ +╟───┼─────╢ +║ 1 │ 34 ║ +╟───┼─────╢ +║ 2 │ 2.2 ║ +╟───┼─────╢ +║ 3 │ 2 ║ +╟───┼─────╢ +║ 4 │ 30 ║ +╚═══╧═════╝ ``` {% endtab %} {% endtabs %} -By specifying a start index in a slice, all values after that index are returned. +By specifying a start index in a slice, all values after that index are returned. {% tabs %} {% tab title="Node" %} @@ -115,26 +103,44 @@ s.iloc(["5:"]).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 5 │ 30 ║ -╟───┼──────────────────────╢ -║ 6 │ 2.1 ║ -╟───┼──────────────────────╢ -║ 7 │ 7 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═════╗ +║ 5 │ 30 ║ +╟───┼─────╢ +║ 6 │ 2.1 ║ +╟───┼─────╢ +║ 7 │ 7 ║ +╚═══╧═════╝ ``` {% endtab %} {% endtabs %} +### Slice Series by boolean condition + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") +let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7]) +s.iloc(s.gt(20)).print() +``` +{% endtab %} +{% endtabs %} + +``` +╔═══╤════╗ +║ 1 │ 34 ║ +╟───┼────╢ +║ 4 │ 30 ║ +╟───┼────╢ +║ 5 │ 30 ║ +╚═══╧════╝ +``` diff --git a/api-reference/series/series.index.md b/api-reference/series/series.index.md index 1cc95da..9a79c76 100644 --- a/api-reference/series/series.index.md +++ b/api-reference/series/series.index.md @@ -4,7 +4,7 @@ description: Obtain the index of a Series # Series.index -> danfo.Series.index \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L234)\] +> danfo.Series.index **Returns**: Array @@ -25,9 +25,8 @@ console.log(sf1.index) {% tabs %} {% tab title="Output" %} -```text +``` [ 0, 1, 2, 3 ] ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.isna.md b/api-reference/series/series.isna.md index cdf6343..6dfe2e9 100644 --- a/api-reference/series/series.isna.md +++ b/api-reference/series/series.isna.md @@ -2,13 +2,13 @@ description: Detect Missing values --- -# Series.isna +# Series.isNa -> danfo.Series.**isna**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L449)\] +> danfo.Series.isNa() **Parameters**: None -**Returns**: Series \(Boolean element\) +**Returns**: Series (Boolean element) **Example** @@ -20,26 +20,23 @@ const dfd = require("danfojs-node") let data1 = [NaN, undefined, "girl", "Man"] let sf = new dfd.Series(data1) -sf.isna().print() +sf.isNa().print() ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ true ║ -╟───┼──────────────────────╢ -║ 1 │ true ║ -╟───┼──────────────────────╢ -║ 2 │ false ║ -╟───┼──────────────────────╢ -║ 3 │ false ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ true ║ +╟───┼───────╢ +║ 1 │ true ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ false ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.le.md b/api-reference/series/series.le.md index e9056d7..2e1111d 100644 --- a/api-reference/series/series.le.md +++ b/api-reference/series/series.le.md @@ -4,17 +4,17 @@ description: Check if all the values in a series is less than or equal to a valu # Series.le -> danfo.Series.le\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L865)\] +> danfo.Series.le(other) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series**\|** int\|float | value\(s\) to compare | | +| Parameters | Type | Description | Default | +| ---------- | ----------------------- | ------------------- | ------- | +| other | Series, Array or number | value(s) to compare | | -**Returns:** Series \(Boolean Element\) +**Returns:** Series (Boolean Element) **Example** -Check if all the values in a series is less than or equal to a value +Check if all the values in a series are less than or equal to a value {% tabs %} {% tab title="Node" %} @@ -31,24 +31,22 @@ sf1.le(20).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ true ║ -╟───┼──────────────────────╢ -║ 1 │ false ║ -╟───┼──────────────────────╢ -║ 2 │ false ║ -╟───┼──────────────────────╢ -║ 3 │ false ║ -╟───┼──────────────────────╢ -║ 4 │ false ║ -╟───┼──────────────────────╢ -║ 5 │ true ║ -╟───┼──────────────────────╢ -║ 6 │ true ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ true ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ false ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ true ║ +╟───┼───────╢ +║ 6 │ true ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} @@ -72,27 +70,22 @@ sf1.le(sf2).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ true ║ -╟───┼──────────────────────╢ -║ 1 │ true ║ -╟───┼──────────────────────╢ -║ 2 │ true ║ -╟───┼──────────────────────╢ -║ 3 │ false ║ -╟───┼──────────────────────╢ -║ 4 │ true ║ -╟───┼──────────────────────╢ -║ 5 │ false ║ -╟───┼──────────────────────╢ -║ 6 │ false ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ true ║ +╟───┼───────╢ +║ 1 │ true ║ +╟───┼───────╢ +║ 2 │ true ║ +╟───┼───────╢ +║ 3 │ false ║ +╟───┼───────╢ +║ 4 │ true ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ false ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} - - - diff --git a/api-reference/series/series.loc.md b/api-reference/series/series.loc.md new file mode 100644 index 0000000..8f9bcbb --- /dev/null +++ b/api-reference/series/series.loc.md @@ -0,0 +1,192 @@ +--- +description: Access a group of rows by label(s) or a boolean array. +--- + +# Series.loc + +danfo.Series.**loc**() + +| Parameters | Type | Description | Default | +| ---------- | ------------- | ---------------------------------------------------------------------- | ------- | +| rows | Array, String | Array, string slice, index of row positions boolean mask to filter by. | | + +## **Examples** + +`.loc()` is label position based (from `0` to `length-1` of the row axis). + +Allowed inputs are: + +* An integer, e.g. `"r1"`. +* A list or array of integers, e.g. `["a", "b", "d"]`. +* A boolean mask. E.g \[ true, false, false ] +* A string slice object with ints, e.g. `[`'`"a":"d"'], ["1:4"]` + +_**Note:** only \*\*\*\* the start label is included, and the end label is ignored._ + +`.loc` will raise a `ValueEror` if a requested label is not found. + +### **Indexing by specific row index** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + + +const data = [12, 34, 2.2, 2, 30, 30, 2.1, 7] +const index = ["a", "b", "c", "d", "e", "f", "g", "h"] +let s = new dfd.Series(data, { index }) +s.print() + +s.loc(["a", "g"]).print() +``` +{% endtab %} + +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔═══╤═════╗ +║ a │ 12 ║ +╟───┼─────╢ +║ b │ 34 ║ +╟───┼─────╢ +║ c │ 2.2 ║ +╟───┼─────╢ +║ d │ 2 ║ +╟───┼─────╢ +║ e │ 30 ║ +╟───┼─────╢ +║ f │ 30 ║ +╟───┼─────╢ +║ g │ 2.1 ║ +╟───┼─────╢ +║ h │ 7 ║ +╚═══╧═════╝ + +╔═══╤═════╗ +║ a │ 12 ║ +╟───┼─────╢ +║ g │ 2.1 ║ +╚═══╧═════╝ +``` +{% endtab %} +{% endtabs %} + +### **Index by a slice of row** + +The **loc** function also accepts string slices of the form \[start: end], e.g **\[\`"a":"e"\`]**. This will return all values from label positions `a` to `e`. + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +const data = [12, 34, 2.2, 2, 30, 30, 2.1, 7] +const index = ["a", "b", "c", "d", "e", "f", "g", "h"] +let s = new dfd.Series(data, { index }) +s.print() + +s.loc([`"a":"e"`]).print() +``` +{% endtab %} + +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔═══╤═════╗ +║ a │ 12 ║ +╟───┼─────╢ +║ b │ 34 ║ +╟───┼─────╢ +║ c │ 2.2 ║ +╟───┼─────╢ +║ d │ 2 ║ +╚═══╧═════╝ +``` +{% endtab %} +{% endtabs %} + +{% hint style="info" %} +Note that when using loc. We expect you to pass labels in the correct format. That is, string labels must be explicitly quoted. For example, the following loc slice will throw an error:\ +`s.loc(["a:e"]).print()`\ +For the slice above to work, you must quote each slice, e.g:\ +`s.loc(["a":"e"]).print()`\ +\ +_**Inner quotes are not needed for numeric indices!**_ +{% endhint %} + +### By specifying a start index in a slice, all values after that index are returned. + +{% tabs %} +{% tab title="Node" %} +```javascript +const data = [12, 34, 2.2, 2, 30, 30, 2.1, 7] +let s = new dfd.Series(data) + +s.loc([`1:`]).print() +``` +{% endtab %} + +{% tab title="Browser" %} +``` +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔═══╤═════╗ +║ 1 │ 34 ║ +╟───┼─────╢ +║ 2 │ 2.2 ║ +╟───┼─────╢ +║ 3 │ 2 ║ +╟───┼─────╢ +║ 4 │ 30 ║ +╟───┼─────╢ +║ 5 │ 30 ║ +╟───┼─────╢ +║ 6 │ 2.1 ║ +╟───┼─────╢ +║ 7 │ 7 ║ +╚═══╧═════╝ +``` +{% endtab %} +{% endtabs %} + +### Slice Series by boolean condition + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + + +let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7]) +s.loc(s.gt(20)).print() +``` +{% endtab %} +{% endtabs %} + +``` +╔═══╤════╗ +║ 1 │ 34 ║ +╟───┼────╢ +║ 4 │ 30 ║ +╟───┼────╢ +║ 5 │ 30 ║ +╚═══╧════╝ +``` diff --git a/api-reference/series/series.lt.md b/api-reference/series/series.lt.md index bb18486..0807c50 100644 --- a/api-reference/series/series.lt.md +++ b/api-reference/series/series.lt.md @@ -4,13 +4,13 @@ description: Check if all values in a Series are less than a value. # Series.lt -> danfo.Series.lt\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L847)\] +> danfo.Series.lt(other) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series**\|** int\|float | value\(s\) to compare | | +| Parameters | Type | Description | Default | +| ---------- | ----------------------- | ------------------- | ------- | +| other | Series, Array or number | value(s) to compare | | -**Returns**: Series \(boolean element\) +**Returns**: Series (boolean element) **Example** @@ -31,24 +31,22 @@ sf1.lt(20).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ false ║ -╟───┼──────────────────────╢ -║ 1 │ true ║ -╟───┼──────────────────────╢ -║ 2 │ true ║ -╟───┼──────────────────────╢ -║ 3 │ true ║ -╟───┼──────────────────────╢ -║ 4 │ true ║ -╟───┼──────────────────────╢ -║ 5 │ false ║ -╟───┼──────────────────────╢ -║ 6 │ false ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ true ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ false ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ true ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} @@ -72,26 +70,22 @@ sf1.lt(sf2).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ false ║ -╟───┼──────────────────────╢ -║ 1 │ true ║ -╟───┼──────────────────────╢ -║ 2 │ false ║ -╟───┼──────────────────────╢ -║ 3 │ false ║ -╟───┼──────────────────────╢ -║ 4 │ true ║ -╟───┼──────────────────────╢ -║ 5 │ false ║ -╟───┼──────────────────────╢ -║ 6 │ false ║ -╚═══╧══════════════════════╝ - +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ true ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ false ║ +╟───┼───────╢ +║ 4 │ true ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ false ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.map.md b/api-reference/series/series.map.md index 1071a1f..13ea329 100644 --- a/api-reference/series/series.map.md +++ b/api-reference/series/series.map.md @@ -1,52 +1,49 @@ --- -description: Map the value of a series to it representation +description: Map the value of a series to a function or Object --- # Series.map -> danfo.series.**map**\(callable\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L685)\] +> danfo.series.**map**(callable) -| Parameter | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| callable | Function or Object | callable can either be a function or an object\({}\) | | +| Parameter | Type | Description | Default | +| --------- | ------------------ | ---------------------------------------------------------------------------------------------- | ------------------------------------- | +| callable | Function or Object | A function or object({}) | | +| options | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{

inplace: false

}

| **Example** -Mapping the element in a Series to a word +Mapping the element in a Series words in an Object {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let sf = new dfd.Series([1,2,3,4]) +let sf = new dfd.Series([1, 2, 3, 4]) let map = { 1: "ok", 2: "okie", 3: "frit", 4: "gop" } sf.map(map).print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ ok ║ -╟───┼──────────────────────╢ -║ 1 │ okie ║ -╟───┼──────────────────────╢ -║ 2 │ frit ║ -╟───┼──────────────────────╢ -║ 3 │ gop ║ -╚═══╧══════════════════════╝ +``` +╔═══╤══════╗ +║ 0 │ ok ║ +╟───┼──────╢ +║ 1 │ okie ║ +╟───┼──────╢ +║ 2 │ frit ║ +╟───┼──────╢ +║ 3 │ gop ║ +╚═══╧══════╝ ``` {% endtab %} {% endtabs %} @@ -63,32 +60,27 @@ let sf = new dfd.Series([1,2,3,4]) sf.map((x)=>{ return `I have ${x} cat(s)` }).print() - ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ I have 1 cat(s) ║ -╟───┼──────────────────────╢ -║ 1 │ I have 2 cat(s) ║ -╟───┼──────────────────────╢ -║ 2 │ I have 3 cat(s) ║ -╟───┼──────────────────────╢ -║ 3 │ I have 4 cat(s) ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═════════════════╗ +║ 0 │ I have 1 cat(s) ║ +╟───┼─────────────────╢ +║ 1 │ I have 2 cat(s) ║ +╟───┼─────────────────╢ +║ 2 │ I have 3 cat(s) ║ +╟───┼─────────────────╢ +║ 3 │ I have 4 cat(s) ║ +╚═══╧═════════════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.max.md b/api-reference/series/series.max.md index 34195a2..3b8d696 100644 --- a/api-reference/series/series.max.md +++ b/api-reference/series/series.max.md @@ -4,7 +4,7 @@ description: Obtain the maximum value in a Series # Series.max -> danfo.Series.max\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L317)\] +> danfo.Series.max() **Parameter:** None @@ -27,11 +27,10 @@ console.log(sf1.max()) {% tabs %} {% tab title="Output" %} -```text +``` 89 ``` {% endtab %} {% endtabs %} -\*\*\*\* - +*** diff --git a/api-reference/series/series.maximum.md b/api-reference/series/series.maximum.md index afc5a48..da34106 100644 --- a/api-reference/series/series.maximum.md +++ b/api-reference/series/series.maximum.md @@ -4,11 +4,11 @@ description: Obtain the maximum number between two series # Series.maximum -> danfo.Series.maximum\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L363)\] +> danfo.Series.maximum(other) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series | series to match | | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------- | ------- | +| other | Series | series to match | | **Return:** {Series} @@ -30,21 +30,17 @@ sf1.maximum(sf2).print() {% tabs %} {% tab title="output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 30 ║ -╟───┼──────────────────────╢ -║ 1 │ 41 ║ -╟───┼──────────────────────╢ -║ 2 │ 3 ║ -╟───┼──────────────────────╢ -║ 3 │ 5 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 0 │ 30 ║ +╟───┼────╢ +║ 1 │ 41 ║ +╟───┼────╢ +║ 2 │ 3 ║ +╟───┼────╢ +║ 3 │ 5 ║ +╚═══╧════╝ + ``` {% endtab %} {% endtabs %} - - - diff --git a/api-reference/series/series.mean.md b/api-reference/series/series.mean.md index ace7e71..29d23a4 100644 --- a/api-reference/series/series.mean.md +++ b/api-reference/series/series.mean.md @@ -1,10 +1,10 @@ --- -description: Obtain the mean of a series +description: Returns the mean of a series --- # Series.mean -> danfo.Series.mean\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L253)\] +> danfo.Series.mean() **Parameter:** None @@ -27,11 +27,10 @@ console.log(sf1.mean()) {% tabs %} {% tab title="Output" %} -```text +``` 23.000001907348633 ``` {% endtab %} {% endtabs %} -\*\*\*\* - +*** diff --git a/api-reference/series/series.median.md b/api-reference/series/series.median.md index 280a565..b1b8524 100644 --- a/api-reference/series/series.median.md +++ b/api-reference/series/series.median.md @@ -1,10 +1,10 @@ --- -description: Obtain the median of a series +description: Returns the median of a series --- # Series.median -> danfo.Series.median\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L274)\] +> danfo.Series.median() **Parameter:** None @@ -27,11 +27,10 @@ console.log(sf1.median()) {% tabs %} {% tab title="Output" %} -```text +``` 4 ``` {% endtab %} {% endtabs %} -\*\*\*\* - +*** diff --git a/api-reference/series/series.min.md b/api-reference/series/series.min.md index 3f57bd1..2ec7533 100644 --- a/api-reference/series/series.min.md +++ b/api-reference/series/series.min.md @@ -4,7 +4,7 @@ description: Obtain the minimum value in a series # Series.min -> danfo.Series.min\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L303)\] +> danfo.Series.min() **Parameter:** None @@ -27,11 +27,10 @@ console.log(sf1.min()) {% tabs %} {% tab title="Output" %} -```text +``` 0 ``` {% endtab %} {% endtabs %} -\*\*\*\* - +*** diff --git a/api-reference/series/series.minimum.md b/api-reference/series/series.minimum.md index a06ba69..0be491f 100644 --- a/api-reference/series/series.minimum.md +++ b/api-reference/series/series.minimum.md @@ -1,14 +1,14 @@ --- -description: Obtain the minimum value between two series (element wise) +description: Return the minimum between two series (element wise) --- # Series.minimum -> danfo.Series.minimum\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L383)\] +> danfo.Series.minimum(other) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series | series to match | | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------- | ------- | +| other | Series | series to match | | **Return:** {Series} @@ -30,19 +30,16 @@ sf1.minimum(sf2).print() {% tabs %} {% tab title="output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 10 ║ -╟───┼──────────────────────╢ -║ 1 │ 40 ║ -╟───┼──────────────────────╢ -║ 2 │ 2 ║ -╟───┼──────────────────────╢ -║ 3 │ 0 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 0 │ 10 ║ +╟───┼────╢ +║ 1 │ 40 ║ +╟───┼────╢ +║ 2 │ 2 ║ +╟───┼────╢ +║ 3 │ 0 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.mod.md b/api-reference/series/series.mod.md index 59a0320..0f8a584 100644 --- a/api-reference/series/series.mod.md +++ b/api-reference/series/series.mod.md @@ -1,14 +1,15 @@ --- -description: 'Return Modulo of series and other, element-wise (binary operator mod).' +description: Returns Modulo of series and other, element-wise (binary operator mod). --- # Series.mod -> danfo.Series.mod\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L235)\] +> danfo.Series.mod(other, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series\|int\|float | values | | +| Parameters | Type | Description | Default | +| ---------- | ------------------ | ---------------------------------------------------------------------------------------------- | ------------------------------------- | +| other | Series\|int\|float | values | | +| options | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{

inplace: false

}

| **Return:** Series @@ -32,18 +33,16 @@ sf1.mod(sf2).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 0.8999999761581421 ║ -╟───┼──────────────────────╢ -║ 1 │ 1.3999993801116943 ║ -╟───┼──────────────────────╢ -║ 2 │ 0.7000000476837158 ║ -╟───┼──────────────────────╢ -║ 3 │ 0.19999980926513672 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═════════════════════╗ +║ 0 │ 0.8999999999999999 ║ +╟───┼─────────────────────╢ +║ 1 │ 1.3999999999999977 ║ +╟───┼─────────────────────╢ +║ 2 │ 0.7000000000000002 ║ +╟───┼─────────────────────╢ +║ 3 │ 0.20000000000000018 ║ +╚═══╧═════════════════════╝ ``` {% endtab %} {% endtabs %} @@ -65,21 +64,18 @@ sf1.mod(2).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 1 ║ -╟───┼──────────────────────╢ -║ 1 │ 0 ║ -╟───┼──────────────────────╢ -║ 2 │ 1 ║ -╟───┼──────────────────────╢ -║ 3 │ 0 ║ -╟───┼──────────────────────╢ -║ 4 │ 1 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══╗ +║ 0 │ 1 ║ +╟───┼───╢ +║ 1 │ 0 ║ +╟───┼───╢ +║ 2 │ 1 ║ +╟───┼───╢ +║ 3 │ 0 ║ +╟───┼───╢ +║ 4 │ 1 ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.mode.md b/api-reference/series/series.mode.md index 5c93091..24317e9 100644 --- a/api-reference/series/series.mode.md +++ b/api-reference/series/series.mode.md @@ -1,10 +1,10 @@ --- -description: Obtain the center value in a series +description: Returns the mode of elements in a series --- # Series.mode -> danfo.Series.min\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L303)\] +> danfo.Series.mode() **Parameter:** None @@ -27,11 +27,10 @@ console.log(sf1.mode()) {% tabs %} {% tab title="Output" %} -```text +``` [ 4 ] ``` {% endtab %} {% endtabs %} -\*\*\*\* - +*** diff --git a/api-reference/series/series.mul.md b/api-reference/series/series.mul.md index 855173b..fed6958 100644 --- a/api-reference/series/series.mul.md +++ b/api-reference/series/series.mul.md @@ -1,14 +1,15 @@ --- -description: 'Return Multiplication of series and other, element-wise (binary operator mul).' +description: Return Multiplication of series and other, element-wise (binary operator mul). --- # Series.mul -> danfo.Series.mul\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L168)\] +> danfo.Series.mul(other, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series\|int\| | values | | +| Parameters | Type | Description | Default | +| ---------- | ------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------- | +| other | Series\|int\| | values | | +| options | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{

inplace: false

}

| **Return:** Series @@ -32,7 +33,7 @@ sf1.mul(sf2).print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -65,7 +66,7 @@ sf1.mul(2).print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -82,6 +83,3 @@ sf1.mul(2).print() ``` {% endtab %} {% endtabs %} - - - diff --git a/api-reference/series/series.ndim.md b/api-reference/series/series.ndim.md index f7f466e..9981c95 100644 --- a/api-reference/series/series.ndim.md +++ b/api-reference/series/series.ndim.md @@ -4,7 +4,7 @@ description: Obtain the dimension of a series # Series.ndim -> danfo.Series.ndim \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L209)\] +> danfo.Series.ndim **Parameters:** None @@ -27,9 +27,8 @@ console.log(sf1.ndim) {% tabs %} {% tab title="Output" %} -```text +``` 1 ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.ne.md b/api-reference/series/series.ne.md index 9901dcd..5cb2173 100644 --- a/api-reference/series/series.ne.md +++ b/api-reference/series/series.ne.md @@ -4,13 +4,13 @@ description: Check if all values in a series is not equal to a value(s) # Series.ne -> danfo.Series.ne\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L883)\] +> danfo.Series.ne(other) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series**\|** int\|String\|float | value to compare | | +| Parameters | Type | Description | Default | +| ---------- | ----------------------- | --------------------- | ------- | +| other | Series, Array or number | value to compare with | | -**Returns**: Series \(Boolean element\) +**Returns**: Series (Boolean element) **Example** @@ -33,24 +33,22 @@ sf1.ne(sf2).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ false ║ -╟───┼──────────────────────╢ -║ 1 │ true ║ -╟───┼──────────────────────╢ -║ 2 │ false ║ -╟───┼──────────────────────╢ -║ 3 │ true ║ -╟───┼──────────────────────╢ -║ 4 │ true ║ -╟───┼──────────────────────╢ -║ 5 │ true ║ -╟───┼──────────────────────╢ -║ 6 │ true ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ true ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ true ║ +╟───┼───────╢ +║ 4 │ true ║ +╟───┼───────╢ +║ 5 │ true ║ +╟───┼───────╢ +║ 6 │ true ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} @@ -72,25 +70,22 @@ sf1.ne(10).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ false ║ -╟───┼──────────────────────╢ -║ 1 │ true ║ -╟───┼──────────────────────╢ -║ 2 │ true ║ -╟───┼──────────────────────╢ -║ 3 │ true ║ -╟───┼──────────────────────╢ -║ 4 │ true ║ -╟───┼──────────────────────╢ -║ 5 │ true ║ -╟───┼──────────────────────╢ -║ 6 │ false ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ true ║ +╟───┼───────╢ +║ 2 │ true ║ +╟───┼───────╢ +║ 3 │ true ║ +╟───┼───────╢ +║ 4 │ true ║ +╟───┼───────╢ +║ 5 │ true ║ +╟───┼───────╢ +║ 6 │ false ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.nunique.md b/api-reference/series/series.nunique.md index 8ddafe4..55fe86b 100644 --- a/api-reference/series/series.nunique.md +++ b/api-reference/series/series.nunique.md @@ -1,10 +1,10 @@ --- -description: Obtain the number of unique values in a series +description: Returns the number of unique values in a series --- -# Series.nunique +# Series.nUnique -> danfo.Series.**nunique**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L750)\] +> danfo.Series.nUnique() \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L750)] **Parameters**: None @@ -20,16 +20,15 @@ const dfd = require("danfojs-node") let data1 = [1, 2, 3, 4, 5, 6, 7, 8, 1, 1, 22, 8, 5, 5, 5] let sf = new dfd.Series(data1) -console.log(sf.nunique()) +console.log(sf.nUnique()) ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Ouptut" %} -```text +``` 9 ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.or.md b/api-reference/series/series.or.md new file mode 100644 index 0000000..a7af323 --- /dev/null +++ b/api-reference/series/series.or.md @@ -0,0 +1,131 @@ +--- +description: >- + Returns the logical OR between Series and other. Supports element wise + operations and broadcasting. +--- + +# Series.or + +> danfo.Series.**or**(other) + +| Parameters | Type | Description | Default | +| ---------- | -------------------------------- | -------------------- | ------- | +| other | Series, Scalar, Array of Scalars | Data to compare with | | + +**Return:** Series + +### **Logical OR between two Series object** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data1 = [false, false, false, true, false, false, true]; +let data2 = [false, false, false, false, false, false, true]; + +let sf = new dfd.Series(data1); +let sf2 = new dfd.Series(data2); +let res = sf.or(sf2) +res.print() +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ true ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ true ║ +╚═══╧═══════╝ +``` +{% endtab %} +{% endtabs %} + +### **Logical OR between Series and Array of the same length** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") + +let data1 = [false, false, false, true, false, false, true]; +let data2 = [false, false, false, false, false, false, true]; + +let sf = new dfd.Series(data1); +let res = sf.or(data2) +res.print() +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ true ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ true ║ +╚═══╧═══════╝ +``` +{% endtab %} +{% endtabs %} + +### **Logical OR between a Series and single value with broadcasting** + +{% tabs %} +{% tab title="Node" %} +```javascript +const dfd = require("danfojs-node") +let data1 = [false, false, false, true, false, false, true]; + +let sf = new dfd.Series(data1); +let res = sf.or(false) +res.print() +``` +{% endtab %} +{% endtabs %} + +{% tabs %} +{% tab title="Output" %} +``` +╔═══╤═══════╗ +║ 0 │ false ║ +╟───┼───────╢ +║ 1 │ false ║ +╟───┼───────╢ +║ 2 │ false ║ +╟───┼───────╢ +║ 3 │ true ║ +╟───┼───────╢ +║ 4 │ false ║ +╟───┼───────╢ +║ 5 │ false ║ +╟───┼───────╢ +║ 6 │ true ║ +╚═══╧═══════╝ +``` +{% endtab %} +{% endtabs %} diff --git a/api-reference/series/series.pow.md b/api-reference/series/series.pow.md index 6a67b3b..761d60b 100644 --- a/api-reference/series/series.pow.md +++ b/api-reference/series/series.pow.md @@ -1,16 +1,17 @@ --- description: >- - Return Exponential power of series and other, element-wise (binary operator - pow). + Returns the exponential power of series and other, element-wise (binary + operator pow). --- # Series.pow -> danfo.Series.pow\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L216)\] +> danfo.Series.pow(other, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series\|int\| | values | | +| Parameters | Type | Description | Default | +| ---------- | ------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------- | +| other | Series\|int\| | values | | +| options | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{

inplace: false

}

| **Return:** Series @@ -34,7 +35,7 @@ sf1.pow(sf2).print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -67,7 +68,7 @@ sf1.pow(2).print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -84,4 +85,3 @@ sf1.pow(2).print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.replace.md b/api-reference/series/series.replace.md index 4b49fa2..3ad3402 100644 --- a/api-reference/series/series.replace.md +++ b/api-reference/series/series.replace.md @@ -4,19 +4,19 @@ description: Replace values given in replace param with value # Series.replace -> danfo.Series.**replace**\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L892)\] +> danfo.Series.**replace**(oldValue, newValue, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs\["**replace**"\] | int \| String\| bool | value to be replaced | | -| kwargs\["**with**"\] | int \| String \| bool | value to replace the previous value | | -| kwargs\["**inplace**"\] | Bool | mutate the series or create the new series | false | +| Parameters | Type | Description | Default | +| ------------ | ------ | --------------------------------------------------------------------------------- | ------------------------------------- | +| **oldValue** | Any |

The value you want to replace.

| | +| **newValue** | Any | The new value you want to replace with. | | +| options | Object | **inplace**: Boolean, indicating whether to perform the operation inplace or not. |

{

inplace: false

}

| **Returns**: Series **Examples** -Replace a value in a series and return a new series +### Replace a value in a series and return a new series {% tabs %} {% tab title="Node" %} @@ -25,7 +25,7 @@ const dfd = require("danfojs-node") let data1 = [10, 45, 56, 25, 23, 20, 10] let sf = new dfd.Series(data1) -let sf_rep = sf.replace({ replace: 10, with: -50 }) +let sf_rep = sf.replace(10, -50) sf_rep.print() ``` @@ -34,29 +34,27 @@ sf_rep.print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ -50 ║ -╟───┼──────────────────────╢ -║ 1 │ 45 ║ -╟───┼──────────────────────╢ -║ 2 │ 56 ║ -╟───┼──────────────────────╢ -║ 3 │ 25 ║ -╟───┼──────────────────────╢ -║ 4 │ 23 ║ -╟───┼──────────────────────╢ -║ 5 │ 20 ║ -╟───┼──────────────────────╢ -║ 6 │ -50 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═════╗ +║ 0 │ -50 ║ +╟───┼─────╢ +║ 1 │ 45 ║ +╟───┼─────╢ +║ 2 │ 56 ║ +╟───┼─────╢ +║ 3 │ 25 ║ +╟───┼─────╢ +║ 4 │ 23 ║ +╟───┼─────╢ +║ 5 │ 20 ║ +╟───┼─────╢ +║ 6 │ -50 ║ +╚═══╧═════╝ ``` {% endtab %} {% endtabs %} -Replace a value in a series , with out returning a new series +### Replace a value in-place {% tabs %} {% tab title="Node" %} @@ -65,30 +63,27 @@ const dfd = require("danfojs-node") let data1 = [10, 45, 56, 25, 23, 20, 10] let sf = new dfd.Series(data1) -sf.replace({ replace: 10, with: -50, inplace:true }) +sf.replace(10, -50, { inplace: true}) sf.print() ``` {% endtab %} {% endtabs %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ -50 ║ -╟───┼──────────────────────╢ -║ 1 │ 45 ║ -╟───┼──────────────────────╢ -║ 2 │ 56 ║ -╟───┼──────────────────────╢ -║ 3 │ 25 ║ -╟───┼──────────────────────╢ -║ 4 │ 23 ║ -╟───┼──────────────────────╢ -║ 5 │ 20 ║ -╟───┼──────────────────────╢ -║ 6 │ -50 ║ -╚═══╧══════════════════════╝ ``` - +╔═══╤═════╗ +║ 0 │ -50 ║ +╟───┼─────╢ +║ 1 │ 45 ║ +╟───┼─────╢ +║ 2 │ 56 ║ +╟───┼─────╢ +║ 3 │ 25 ║ +╟───┼─────╢ +║ 4 │ 23 ║ +╟───┼─────╢ +║ 5 │ 20 ║ +╟───┼─────╢ +║ 6 │ -50 ║ +╚═══╧═════╝ +``` diff --git a/api-reference/series/series.reset_index.md b/api-reference/series/series.reset_index.md index e03ea87..7f46d6f 100644 --- a/api-reference/series/series.reset_index.md +++ b/api-reference/series/series.reset_index.md @@ -2,142 +2,109 @@ description: Reset the index of a series. --- -# Series.reset\_index +# Series.resetIndex -> danfo.series.reset\_index\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L614)\] +> danfo.series.resetIndex(options) -Generate a new Series with the index reset. This is useful when the index needs to be treated as a column, or when the index is meaningless and needs to be reset to the default before another operation. +| Parameters | Type | Description | Default | +| ---------- | ------ | -------------------------------------------------------------------------------------------------- | ---------------- | +| options | Object | **inplace:** Boolean indicating whether to perform the operation inplace or not. Defaults to false | { inplace:false} | -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs | Object | kwargs is an object {} with key **inplace** with a boolean value. e.g {inplace: false} | inplace:false | +`resetIndex` is useful when the index needs to be treated as a column, or when the index is meaningless and needs to be reset to default, before another operation. -**Returns :** Series - -**Example** +### **Reset index to default values** {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") +let data = [20, 30, 40] +let sf = new dfd.Series(data, { index: ["a", "b", "c"] }) +sf.print() -let data = [{ alpha: "A", count: 1 }, { alpha: "B", count: 2 }, { alpha: "C", count: 3 }] -let sf = new dfd.Series(data) -let sf_new = sf.set_index({ "index": ["one", "two", "three"] }) -let sf_reset = sf_new.reset_index() +let sf_reset = sf.resetIndex() sf_reset.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ {"alpha":"A","cou... ║ -╟───┼──────────────────────╢ -║ 1 │ {"alpha":"B","cou... ║ -╟───┼──────────────────────╢ -║ 2 │ {"alpha":"C","cou... ║ -╚═══╧══════════════════════╝ -``` -{% endtab %} -{% endtabs %} - -{% tabs %} -{% tab title="Node" %} -```javascript -const dfd = require("danfojs-node") - -let data = [1,2,3,4,5,6] -let sf = new dfd.Series(data) - -sf.set_index({ "index": ["one", "two", "three", "four", "five", "six"], "inplace": true }) -let sf_reset = sf.reset_index() -sf_reset.print() - -``` -{% endtab %} - -{% tab title="Browser" %} -``` - ``` -{% endtab %} -{% endtabs %} - -{% tabs %} -{% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 1 ║ -╟───┼──────────────────────╢ -║ 1 │ 2 ║ -╟───┼──────────────────────╢ -║ 2 │ 3 ║ -╟───┼──────────────────────╢ -║ 3 │ 4 ║ -╟───┼──────────────────────╢ -║ 4 │ 5 ║ -╟───┼──────────────────────╢ -║ 5 │ 6 ║ -╚═══╧══════════════════════╝ +╔═══╤════╗ +║ a │ 20 ║ +╟───┼────╢ +║ b │ 30 ║ +╟───┼────╢ +║ c │ 40 ║ +╚═══╧════╝ + +╔═══╤════╗ +║ 0 │ 20 ║ +╟───┼────╢ +║ 1 │ 30 ║ +╟───┼────╢ +║ 2 │ 40 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} -Reset index without returning a new Series +### Reset index to new values in-place {% tabs %} {% tab title="Node" %} ```javascript -const dfd = require("danfojs-node") - -let data = [1,2,3,4,5,6] -let sf = new dfd.Series(data) +let data = [1, 2, 3, 4, 5, 6] +let sf = new dfd.Series(data, { index: ['a', 'b', 'c', 'd', 'e', 'f'] }) +sf.print() -sf.set_index({ "index": ["one", "two", "three", "four", "five", "six"], "inplace": true }) -sf.reset_index({"inplace":true}) +sf.resetIndex({ inplace: true }) sf.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 1 ║ -╟───┼──────────────────────╢ -║ 1 │ 2 ║ -╟───┼──────────────────────╢ -║ 2 │ 3 ║ -╟───┼──────────────────────╢ -║ 3 │ 4 ║ -╟───┼──────────────────────╢ -║ 4 │ 5 ║ -╟───┼──────────────────────╢ -║ 5 │ 6 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══╗ +║ a │ 1 ║ +╟───┼───╢ +║ b │ 2 ║ +╟───┼───╢ +║ c │ 3 ║ +╟───┼───╢ +║ d │ 4 ║ +╟───┼───╢ +║ e │ 5 ║ +╟───┼───╢ +║ f │ 6 ║ +╚═══╧═══╝ + +╔═══╤═══╗ +║ 0 │ 1 ║ +╟───┼───╢ +║ 1 │ 2 ║ +╟───┼───╢ +║ 2 │ 3 ║ +╟───┼───╢ +║ 3 │ 4 ║ +╟───┼───╢ +║ 4 │ 5 ║ +╟───┼───╢ +║ 5 │ 6 ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.round.md b/api-reference/series/series.round.md index 3dcc39f..6b05e45 100644 --- a/api-reference/series/series.round.md +++ b/api-reference/series/series.round.md @@ -4,11 +4,12 @@ description: round off floating values in series # Series.round -> danfo.Series.round\(dp\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L404)\] +> danfo.Series.round(dp, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| dp | int | decimal place to round off to | | +| Parameters | Type | Description | Default | +| ---------- | ------ | ---------------------------------------------------------------------------------------------- | ------------------------------------- | +| dp | int | decimal place to round off to | | +| options | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{

inplace: false

}

| **Returns:** Series @@ -29,21 +30,16 @@ sf1.round(2).print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 30.21 ║ -╟───┼──────────────────────╢ -║ 1 │ 40.19 ║ -╟───┼──────────────────────╢ -║ 2 │ 3.56 ║ -╟───┼──────────────────────╢ -║ 3 │ 5.02 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══════╗ +║ 0 │ 30.21 ║ +╟───┼───────╢ +║ 1 │ 40.19 ║ +╟───┼───────╢ +║ 2 │ 3.56 ║ +╟───┼───────╢ +║ 3 │ 5.02 ║ +╚═══╧═══════╝ ``` {% endtab %} {% endtabs %} - - - diff --git a/api-reference/series/series.sample.md b/api-reference/series/series.sample.md index 4ab195e..368f549 100644 --- a/api-reference/series/series.sample.md +++ b/api-reference/series/series.sample.md @@ -1,52 +1,64 @@ --- -description: Return a random sample of items from an axis of object. +description: Returns a random sample of items from an axis of object. --- # Series.sample -> danfo.Series.sample\(num\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L98)\] +> danfo.Series.sample(num) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| num | Int | The number of rows to return. Defaults to -1, which shuffles and return all rows. | -1 | -| seed | int | An integer specifying the random seed that will be used to create the distribution. Ensures reproducibility of generated samples. | 1 | +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | +| num | Int | The number of rows to return. | | +| options | Object | **seed**: An integer specifying the random seed that will be used to create the distribution. Ensures reproducibility of generated samples. |

{

seed: 1

}

| **Returns:** - ****return **{Promies} resolves to Series** +\*\*\*\* return **{Promies} resolves to Series** **Example** ```javascript const dfd = require("danfojs-node") -async function load_data() { - let data1 = [1, 2, 3, 4, 5, 620, 30, 40, 39, 89, 78]; - let sf1 = new dfd.Series(data1); - let sample = await sf1.sample(5) - sample.print() - +async function sample_data() { + let data1 = [1, 2, 3, 4, 5, 620, 30, 40, 39, 89, 78]; + let sf1 = new dfd.Series(data1); + let sample = await sf1.sample(5) + sample.print() + } -load_data() +sample_data() ``` {% tabs %} {% tab title="Output" %} ```javascript -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 2 │ 3 ║ -╟───┼──────────────────────╢ -║ 4 │ 5 ║ -╟───┼──────────────────────╢ -║ 0 │ 1 ║ -╟───┼──────────────────────╢ -║ 7 │ 40 ║ -╟───┼──────────────────────╢ -║ 6 │ 30 ║ -╚═══╧══════════════════════╝ +╔═══╤════╗ +║ 2 │ 3 ║ +╟───┼────╢ +║ 4 │ 5 ║ +╟───┼────╢ +║ 0 │ 1 ║ +╟───┼────╢ +║ 7 │ 40 ║ +╟───┼────╢ +║ 6 │ 30 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} +### Specify a seed when sampling + +```javascript +const dfd = require("danfojs-node") + +async function sample_data() { + let data1 = [1, 2, 3, 4, 5, 620, 30, 40, 39, 89, 78]; + let sf1 = new dfd.Series(data1); + let sample = await sf1.sample(5, { seed: 5 }) + sample.print() + +} +sample_data() +``` diff --git a/api-reference/series/series.set_index.md b/api-reference/series/series.set_index.md index 91adf23..c8cd012 100644 --- a/api-reference/series/series.set_index.md +++ b/api-reference/series/series.set_index.md @@ -2,14 +2,14 @@ description: Assign new Index to Series --- -# Series.set\_index +# Series.setIndex -> danfo.series.**set\_index\(**kwargs**\)** \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L635)\] +> danfo.series.setIndex**(options)** -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs\["index"\] | Array | index to replace the former index | | -| kwargs\["inplace"\] | Boolean | return new series or not | false | +| Parameter | Type | Description | Default | +| --------- | ------ | ---------------------------------------------------------------------------------------------- | ------------------------------------- | +| index | Array | new index values | | +| options | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{

inplace: false

}

| **Returns:** Series @@ -22,30 +22,37 @@ const dfd = require("danfojs-node") let data = [{ alpha: "A", count: 1 }, { alpha: "B", count: 2 }, { alpha: "C", count: 3 }] let sf = new dfd.Series(data) -let sf_new = sf.set_index({ "index": ["one", "two", "three"] }) +sf.print() + +let sf_new = sf.setIndex(["one", "two", "three"]) sf_new.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══════╤══════════════════════╗ -║ │ 0 ║ -╟───────┼──────────────────────╢ -║ one │ {"alpha":"A","cou... ║ -╟───────┼──────────────────────╢ -║ two │ {"alpha":"B","cou... ║ -╟───────┼──────────────────────╢ -║ three │ {"alpha":"C","cou... ║ -╚═══════╧══════════════════════╝ +``` +╔═══╤═════════════════════════╗ +║ 0 │ {"alpha":"A","count":1} ║ +╟───┼─────────────────────────╢ +║ 1 │ {"alpha":"B","count":2} ║ +╟───┼─────────────────────────╢ +║ 2 │ {"alpha":"C","count":3} ║ +╚═══╧═════════════════════════╝ + +╔═══════╤═════════════════════════╗ +║ one │ {"alpha":"A","count":1} ║ +╟───────┼─────────────────────────╢ +║ two │ {"alpha":"B","count":2} ║ +╟───────┼─────────────────────────╢ +║ three │ {"alpha":"C","count":3} ║ +╚═══════╧═════════════════════════╝ ``` {% endtab %} {% endtabs %} @@ -57,78 +64,71 @@ const dfd = require("danfojs-node") let data = ["Humans","Life","Meaning","Fact","Truth"] let sf = new dfd.Series(data) -let sf_new = sf.set_index({ "index": ["H", "L", "M","F","T"] }) +let sf_new = sf.setIndex(["H", "L", "M","F","T"]) sf_new.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ H │ Humans ║ -╟───┼──────────────────────╢ -║ L │ Life ║ -╟───┼──────────────────────╢ -║ M │ Meaning ║ -╟───┼──────────────────────╢ -║ F │ Fact ║ -╟───┼──────────────────────╢ -║ T │ Truth ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═════════╗ +║ H │ Humans ║ +╟───┼─────────╢ +║ L │ Life ║ +╟───┼─────────╢ +║ M │ Meaning ║ +╟───┼─────────╢ +║ F │ Fact ║ +╟───┼─────────╢ +║ T │ Truth ║ +╚═══╧═════════╝ ``` {% endtab %} {% endtabs %} -set index without creating a new series by using `inplace = true` +### Set index in-place {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs") -let data = [1,2,3,4,5,6] +let data = [1, 2, 3, 4, 5, 6] let sf = new dfd.Series(data) -sf.set_index({ "index": ["one", "two", "three", "four", "five", "six"], "inplace": true }) +sf.setIndex(["one", "two", "three", "four", "five", "six"], { inplace: true }) sf.print() ``` {% endtab %} {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══════╤══════════════════════╗ -║ │ 0 ║ -╟───────┼──────────────────────╢ -║ one │ 1 ║ -╟───────┼──────────────────────╢ -║ two │ 2 ║ -╟───────┼──────────────────────╢ -║ three │ 3 ║ -╟───────┼──────────────────────╢ -║ four │ 4 ║ -╟───────┼──────────────────────╢ -║ five │ 5 ║ -╟───────┼──────────────────────╢ -║ six │ 6 ║ -╚═══════╧══════════════════════╝ +``` +╔═══════╤═══╗ +║ one │ 1 ║ +╟───────┼───╢ +║ two │ 2 ║ +╟───────┼───╢ +║ three │ 3 ║ +╟───────┼───╢ +║ four │ 4 ║ +╟───────┼───╢ +║ five │ 5 ║ +╟───────┼───╢ +║ six │ 6 ║ +╚═══════╧═══╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.shape.md b/api-reference/series/series.shape.md index 9eb5031..feb93b9 100644 --- a/api-reference/series/series.shape.md +++ b/api-reference/series/series.shape.md @@ -4,11 +4,11 @@ description: Obtain the shape of a Series # Series.shape -> danfo.Series.shape \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L266)\] +> danfo.Series.shape **Parameters**: None -**Returns**: Array \[int, int\] +**Returns**: Array \[int, int] **Example** @@ -27,9 +27,8 @@ console.log(sf1.shape) {% tabs %} {% tab title="Output" %} -```text +``` [ 4, 1 ] ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.sort_values.md b/api-reference/series/series.sort_values.md index 54966ac..8933511 100644 --- a/api-reference/series/series.sort_values.md +++ b/api-reference/series/series.sort_values.md @@ -1,21 +1,18 @@ --- -description: Sort a Series in ascending or descending order +description: Sorts a Series in ascending or descending order --- -# Series.sort\_values +# Series.sortValues -> danfo.Series.sort\_values\(kwargs\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L511)\] +> danfo.Series.sortValues(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L511)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| kwargs\["inplace"\] | Boolean | return new series or not | false | -| kwargs\["ascending"\] | Boolean | select if to sort by ascending or descending | true | +| Parameters | Type | Description | Default | +| ---------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | +| options | Object |

inplace: Boolean indicating whether to perform the operation in-place or not. Defaults to false

ascending: Whether to return sorted values in ascending order or not. Defaults to true

|

{
ascending: true,

inplace: false

}

| - **Return:** Series +**Return:** Series -**Examples** - -Sort series values using the default settings +### Sort values in a Series {% tabs %} {% tab title="Node" %} @@ -24,7 +21,7 @@ const dfd = require("danfojs-node") let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4] let sf1 = new dfd.Series(data1) -let sf2 = sf1.sort_values() +let sf2 = sf1.sortValues() sf2.print() ``` @@ -33,33 +30,31 @@ sf2.print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 7 │ 0 ║ -╟───┼──────────────────────╢ -║ 2 │ 1 ║ -╟───┼──────────────────────╢ -║ 3 │ 2 ║ -╟───┼──────────────────────╢ -║ 4 │ 4 ║ -╟───┼──────────────────────╢ -║ 8 │ 4 ║ -╟───┼──────────────────────╢ -║ 0 │ 20 ║ -╟───┼──────────────────────╢ -║ 1 │ 30 ║ -╟───┼──────────────────────╢ -║ 5 │ 57 ║ -╟───┼──────────────────────╢ -║ 6 │ 89 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 7 │ 0 ║ +╟───┼────╢ +║ 2 │ 1 ║ +╟───┼────╢ +║ 3 │ 2 ║ +╟───┼────╢ +║ 8 │ 4 ║ +╟───┼────╢ +║ 4 │ 4 ║ +╟───┼────╢ +║ 0 │ 20 ║ +╟───┼────╢ +║ 1 │ 30 ║ +╟───┼────╢ +║ 5 │ 57 ║ +╟───┼────╢ +║ 6 │ 89 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} -Sort series value without returning a new series +### Sort Series inplace {% tabs %} {% tab title="Node" %} @@ -68,7 +63,7 @@ const dfd = require("danfojs-node") let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4] let sf1 = new dfd.Series(data1) -sf1.sort_values({ "inplace": true }) +sf1.sort_values({ inplace: true }) sf1.print() ``` @@ -77,33 +72,31 @@ sf1.print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 7 │ 0 ║ -╟───┼──────────────────────╢ -║ 2 │ 1 ║ -╟───┼──────────────────────╢ -║ 3 │ 2 ║ -╟───┼──────────────────────╢ -║ 4 │ 4 ║ -╟───┼──────────────────────╢ -║ 8 │ 4 ║ -╟───┼──────────────────────╢ -║ 0 │ 20 ║ -╟───┼──────────────────────╢ -║ 1 │ 30 ║ -╟───┼──────────────────────╢ -║ 5 │ 57 ║ -╟───┼──────────────────────╢ -║ 6 │ 89 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 7 │ 0 ║ +╟───┼────╢ +║ 2 │ 1 ║ +╟───┼────╢ +║ 3 │ 2 ║ +╟───┼────╢ +║ 8 │ 4 ║ +╟───┼────╢ +║ 4 │ 4 ║ +╟───┼────╢ +║ 0 │ 20 ║ +╟───┼────╢ +║ 1 │ 30 ║ +╟───┼────╢ +║ 5 │ 57 ║ +╟───┼────╢ +║ 6 │ 89 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} -Sort series value in descending order +Sort Series values in descending order {% tabs %} {% tab title="Node" %} @@ -112,7 +105,7 @@ const dfd = require("danfojs-node") let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4] let sf1 = new dfd.Series(data1) -sf1.sort_values({ "ascending": false, "inplace": true }) +sf1.sortValues({ "ascending": false, "inplace": true }) sf1.print() ``` @@ -121,29 +114,26 @@ sf1.print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 6 │ 89 ║ -╟───┼──────────────────────╢ -║ 5 │ 57 ║ -╟───┼──────────────────────╢ -║ 1 │ 30 ║ -╟───┼──────────────────────╢ -║ 0 │ 20 ║ -╟───┼──────────────────────╢ -║ 8 │ 4 ║ -╟───┼──────────────────────╢ -║ 4 │ 4 ║ -╟───┼──────────────────────╢ -║ 3 │ 2 ║ -╟───┼──────────────────────╢ -║ 2 │ 1 ║ -╟───┼──────────────────────╢ -║ 7 │ 0 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 6 │ 89 ║ +╟───┼────╢ +║ 5 │ 57 ║ +╟───┼────╢ +║ 1 │ 30 ║ +╟───┼────╢ +║ 0 │ 20 ║ +╟───┼────╢ +║ 4 │ 4 ║ +╟───┼────╢ +║ 8 │ 4 ║ +╟───┼────╢ +║ 3 │ 2 ║ +╟───┼────╢ +║ 2 │ 1 ║ +╟───┼────╢ +║ 7 │ 0 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.std.md b/api-reference/series/series.std.md index 8d83e32..13801e5 100644 --- a/api-reference/series/series.std.md +++ b/api-reference/series/series.std.md @@ -4,7 +4,7 @@ description: Obtain the standard deviation for a series # Series.std -> danfo.Series.std\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L422)\] +> danfo.Series.std() **Parameter:** None @@ -27,13 +27,10 @@ console.log(sf1.std()) {% tabs %} {% tab title="Output" %} -```text +``` 31.11671576500322 ``` {% endtab %} {% endtabs %} - **** - - - +\*\*\*\* diff --git a/api-reference/series/series.str.capitalize.md b/api-reference/series/series.str.capitalize.md index 5df261a..aea9e91 100644 --- a/api-reference/series/series.str.capitalize.md +++ b/api-reference/series/series.str.capitalize.md @@ -4,11 +4,13 @@ description: Capitalize the first character of each string # Series.str.capitalize -> danfo.Series.str.**capitalize**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L46)\] +> danfo.Series.str.**capitalize**(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L46)] -**Parameters:** None +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| -**Returns**: Series \(String element\) +**Returns**: Series (String element) **Example** @@ -27,14 +29,13 @@ sf.str.capitalize().print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -49,4 +50,3 @@ sf.str.capitalize().print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.charat.md b/api-reference/series/series.str.charat.md index 3df2bbc..931bb48 100644 --- a/api-reference/series/series.str.charat.md +++ b/api-reference/series/series.str.charat.md @@ -4,13 +4,14 @@ description: Obtain the character at the specified index (position) # Series.str.charAt -> danfo.Series.str.**charAt**\(index\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L64)\] +> danfo.Series.str.**charAt**(index) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L64)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| index | int | the index at which to obtain the character | 0 | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| index | int | the index at which to obtain the character | 0 | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| -**Returns**: Series \(Character element\) +**Returns**: Series (Character element) **Example** @@ -29,14 +30,13 @@ sf.str.charAt(2).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -51,4 +51,3 @@ sf.str.charAt(2).print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.concat.md b/api-reference/series/series.str.concat.md index 0a24597..e3abe54 100644 --- a/api-reference/series/series.str.concat.md +++ b/api-reference/series/series.str.concat.md @@ -4,14 +4,15 @@ description: Joins two or more strings/arrays # Series.str.concat -> danfo.Series.str.**concat**\(other, position\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L80)\] +> danfo.Series.str.**concat**(other, position, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L80)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | string or Array | string or list of strings to add to each string element of the series | "" | -| position | Int | The position to add the **other** \(string or array\) is either 0 or 1. 0 is to add the other at the beginning of each of the string element, and 1 is to add to the end of the string element | 1 | +| Parameters | Type | Description | Default | +| ---------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ | +| other | string or Array | string or list of strings to add to each string element of the series | "" | +| position | Int | The position to add the **other** (string or array) is either 0 or 1. 0 is to add the other at the beginning of each of the string element, and 1 is to add to the end of the string element | 1 | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| -**Returns:** Series \(String element\) +**Returns:** Series (String element) **Examples** @@ -31,14 +32,13 @@ sf.str.concat(data2,0).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -70,14 +70,13 @@ sf.str.concat(data2,1).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -109,14 +108,13 @@ sf.str.concat("pre",0).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -148,12 +146,11 @@ sf.str.concat("post",1).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -166,4 +163,3 @@ sf.str.concat("post",1).print() ║ 3 │ SwApCaSepost ║ ╚═══╧══════════════════════╝ ``` - diff --git a/api-reference/series/series.str.endswith.md b/api-reference/series/series.str.endswith.md index 645294d..2fb44cc 100644 --- a/api-reference/series/series.str.endswith.md +++ b/api-reference/series/series.str.endswith.md @@ -4,13 +4,14 @@ description: Checks whether a string ends with specified characters # Series.str.endsWith -> danfo.Series.str.**endsWith**\(str\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L133)\] +> danfo.Series.str.**endsWith**(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L133)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| str | string | the character\(s\) to check | "" | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| str | string | the character(s) to check | "" | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| -**Returns**: Series \(Boolean element\) +**Returns**: Series (Boolean element) **Example** @@ -27,14 +28,13 @@ sf.str.endsWith("e").print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -49,4 +49,3 @@ sf.str.endsWith("e").print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.includes.md b/api-reference/series/series.str.includes.md index c2cb4af..8918773 100644 --- a/api-reference/series/series.str.includes.md +++ b/api-reference/series/series.str.includes.md @@ -4,13 +4,14 @@ description: Checks whether a string contains the specified string/characters # Series.str.includes -> danfo.Series.str.includes\(str\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L147)\] +> danfo.Series.str.includes(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L147)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| str | string | the character\(s\) to check | "" | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| str | string | the character(s) to check | "" | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| -**Returns**: Series \(boolean element\) +**Returns**: Series (boolean element) **Example** @@ -27,14 +28,13 @@ sf.str.includes("C").print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -49,4 +49,3 @@ sf.str.includes("C").print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.indexof.md b/api-reference/series/series.str.indexof.md index a823d20..1d9e64f 100644 --- a/api-reference/series/series.str.indexof.md +++ b/api-reference/series/series.str.indexof.md @@ -4,11 +4,12 @@ description: the position of the first found occurrence of a specified value in # Series.str.indexOf -> danfo.Series.str.indexOf\(str\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L161)\] +> danfo.Series.str.indexOf(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L161)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| str | string | the string to obtain its index | "" | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| str | string | the string to obtain its index | "" | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Returns:** Series @@ -27,14 +28,13 @@ sf.str.indexOf("C").print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -49,4 +49,3 @@ sf.str.indexOf("C").print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.join.md b/api-reference/series/series.str.join.md index 4c17295..5bb77fe 100644 --- a/api-reference/series/series.str.join.md +++ b/api-reference/series/series.str.join.md @@ -4,16 +4,17 @@ description: Join a new string value to all string elements in a Series. # Series.str.join -> danfo.Series.str.**join**\(valToJoin,joinChar\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L308)\] +> danfo.Series.str.**join**(valToJoin, joinChar, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L308)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| valToJoin | String | the string value you want to | "" | -| joinChar | String | The delimiter to specify the joining | " " | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| valToJoin | String | the string value you want to | "" | +| joinChar | String | The delimiter to specify the joining | " " | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Returns:** - ****return **Series** + **** return **Series** **Examples** @@ -30,26 +31,22 @@ sf.str.join("new", "_").print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ lower part_new ║ -╟───┼──────────────────────╢ -║ 1 │ CAPITALS city_new ║ -╟───┼──────────────────────╢ -║ 2 │ this is a sentenc... ║ -╟───┼──────────────────────╢ -║ 3 │ SwAp CaSe_new ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════════════════════════╗ +║ 0 │ lower part_new ║ +╟───┼────────────────────────╢ +║ 1 │ CAPITALS city_new ║ +╟───┼────────────────────────╢ +║ 2 │ this is a sentence_new ║ +╟───┼────────────────────────╢ +║ 3 │ SwAp CaSe_new ║ +╚═══╧════════════════════════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.lastindexof.md b/api-reference/series/series.str.lastindexof.md index 130c50c..889a1f4 100644 --- a/api-reference/series/series.str.lastindexof.md +++ b/api-reference/series/series.str.lastindexof.md @@ -6,11 +6,12 @@ description: >- # Series.str.lastIndexOf -danfo.Series.str.lastIndexOf\(str\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L175)\] +danfo.Series.str.lastIndexOf(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L175)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| str | string | the string to search for | "" | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| str | string | the string to search for | "" | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Returns**: Series @@ -29,14 +30,13 @@ sf.str.lastIndexOf("r").print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -52,5 +52,3 @@ sf.str.lastIndexOf("r").print() {% endtab %} {% endtabs %} - - diff --git a/api-reference/series/series.str.len.md b/api-reference/series/series.str.len.md index 60153e8..0ef06b2 100644 --- a/api-reference/series/series.str.len.md +++ b/api-reference/series/series.str.len.md @@ -4,24 +4,22 @@ description: Obtain the length of each string element in a Series # Series.str.len -> danfo.Series.str.**len**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L324)\] +> danfo.Series.str.**len**(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L324)] -**Parameters**: None - -**Returns:** - - return Series +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Examples** -Returns the length \(number of character\) of a string, and also return the length \(number of elements\) of Array +Returns the length (number of character) of a string, and also return the length (number of elements) of Array {% tabs %} {% tab title="JavaScript" %} ```javascript const dfd = require("danfojs-node") -let data = ["dog", 5,"cat",["fog","mug"],"animals"] +let data = ["dog", 5,"cat","fog","mug","animals"] let sf = new dfd.Series(data) sf.str.len().print() ``` @@ -29,28 +27,26 @@ sf.str.len().print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 3 ║ -╟───┼──────────────────────╢ -║ 1 │ NaN ║ -╟───┼──────────────────────╢ -║ 2 │ 3 ║ -╟───┼──────────────────────╢ -║ 3 │ 2 ║ -╟───┼──────────────────────╢ -║ 4 │ 7 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤═══╗ +║ 0 │ 3 ║ +╟───┼───╢ +║ 1 │ 1 ║ +╟───┼───╢ +║ 2 │ 3 ║ +╟───┼───╢ +║ 3 │ 3 ║ +╟───┼───╢ +║ 4 │ 3 ║ +╟───┼───╢ +║ 5 │ 7 ║ +╚═══╧═══╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.repeat.md b/api-reference/series/series.str.repeat.md index e6c1f32..703be26 100644 --- a/api-reference/series/series.str.repeat.md +++ b/api-reference/series/series.str.repeat.md @@ -4,11 +4,12 @@ description: Repeat the the character(s) in a string for a specified number of t # Series.str.repeat -> danfo.Series.str.**repeat**\(num\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L205)\] +> danfo.Series.str.**repeat**(num, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L205)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| num | integer | the string to search for | 1 | +| Parameters | Type | Description | Default | +| ---------- | ------- | --------------------------------------------------------------- | ------------------------------------------------------ | +| num | integer | the string to search for | 1 | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Returns:** Series @@ -27,14 +28,13 @@ sf.str.repeat(4).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -49,4 +49,3 @@ sf.str.repeat(4).print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.replace.md b/api-reference/series/series.str.replace.md index c96137c..2b06b1f 100644 --- a/api-reference/series/series.str.replace.md +++ b/api-reference/series/series.str.replace.md @@ -4,12 +4,13 @@ description: Replace a word or character(s) in a String element # Series.str.replace -> danfo.Series.str.replace\(searchValue, replaceValue\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L191)\] +> danfo.Series.str.replace(searchValue, replaceValue, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L191)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| searchValue | string | the string to search for | "" | -| replaceValue | String | string to replace the searched string | "" | +| Parameters | Type | Description | Default | +| ------------ | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| searchValue | string | String \| Character value to replace. Supports regex. | "" | +| replaceValue | String | string to replace the searched string | "" | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Returns:** Series @@ -26,14 +27,13 @@ sf.str.replace("A", "XXX").print() {% tab title="Browse" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -48,4 +48,3 @@ sf.str.replace("A", "XXX").print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.search.md b/api-reference/series/series.str.search.md index 8824095..99fc428 100644 --- a/api-reference/series/series.str.search.md +++ b/api-reference/series/series.str.search.md @@ -4,17 +4,18 @@ description: Obtain the index position of a searched character in a String # Series.str.search -> danfo.Series.str.**search**\(str\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L220)\] +> danfo.Series.str.**search**(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L220)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| str | String | the string to search for | "" | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| str | String | the string to search for | "" | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Returns:** - ****return Series: Series of index position + **** return Series: Series of index position **Example** @@ -33,14 +34,13 @@ sf.str.search("S").print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -71,14 +71,13 @@ sf.str.search("city").print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -93,4 +92,3 @@ sf.str.search("city").print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.slice.md b/api-reference/series/series.str.slice.md index d314066..cef7a86 100644 --- a/api-reference/series/series.str.slice.md +++ b/api-reference/series/series.str.slice.md @@ -4,16 +4,17 @@ description: Obtain the substring of each element in a series # Series.str.slice -> danfo.Series.str.slice\(startIndex, endIndex\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L235)\] +> danfo.Series.str.slice(startIndex, endIndex, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L235)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| startIndex | Number | specify the index to start obtaining the substring | 0 | -| endIndex | Number | specify the index to end the substring | 1 | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| startIndex | Number | specify the index to start obtaining the substring | 0 | +| endIndex | Number | specify the index to end the substring | 1 | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Returns:** - ****return Series. + **** return Series. **Example** @@ -30,14 +31,13 @@ sf.str.slice(2, 4).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -52,4 +52,3 @@ sf.str.slice(2, 4).print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.split.md b/api-reference/series/series.str.split.md index 65a82c7..57c1d2c 100644 --- a/api-reference/series/series.str.split.md +++ b/api-reference/series/series.str.split.md @@ -6,15 +6,12 @@ description: >- # Series.str.split -> danfo.Series.str.**split**\(splitVal\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L250)\] +> danfo.Series.str.**split**(splitVal, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| splitVal | String | separator or delimiter used to split the string | " " | - -**Returns** - - return **Series** +| Parameters | Type | Description | Default | +| ---------- | ------ | ---------------------------------------------------------- | ------------------------------- | +| splitVal | String | separator or delimiter used to split the string | " " | +| options | Object | **inplace**: Whether to perform operation in-place or not. |

{
inplace: false
}

| **Examples** @@ -33,12 +30,11 @@ console.log(sf.str.split().values) {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} -**OUTPUT:** `[ 'king,of,the,music', 'the,lamba,queen', 'I,love,the,hat' ]` +**OUTPUT:** `[ 'king,of,the,music', 'the,lamba,queen', 'I,love,the,hat' ]` {% tabs %} {% tab title="JavaScript" %} @@ -53,14 +49,13 @@ sf.str.split("_").print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -73,4 +68,3 @@ sf.str.split("_").print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.startswith.md b/api-reference/series/series.str.startswith.md index 311bb2f..835809e 100644 --- a/api-reference/series/series.str.startswith.md +++ b/api-reference/series/series.str.startswith.md @@ -4,13 +4,14 @@ description: Test whether a string begins with specified characters # Series.str.startsWith -> danfo.Series.str.**startsWith**\(str\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L119)\] +> danfo.Series.str.**startsWith**(str, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L119)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| str | string | the character\(s\) to check | "" | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| str | string | the character(s) to check | "" | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| -**Returns:** Series \(Boolean element\) +**Returns:** Series (Boolean element) **Examples** @@ -27,14 +28,13 @@ sf.str.startsWith("S").print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -49,4 +49,3 @@ sf.str.startsWith("S").print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.substr.md b/api-reference/series/series.str.substr.md index 1512f02..0a391bb 100644 --- a/api-reference/series/series.str.substr.md +++ b/api-reference/series/series.str.substr.md @@ -6,20 +6,21 @@ description: >- # Series.str.substr -> danfo.Series.str.substr\(startIndex, num\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L265)\] +> danfo.Series.str.substr(startIndex, num, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L265)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| startIndex | Number | specify the index to start obtaining the substring | 0 | -| num | Number | The number of character to obtain starting from the startIndex | 1 | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| startIndex | Number | specify the index to start obtaining the substring | 0 | +| num | Number | The number of character to obtain starting from the startIndex | 1 | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Returns:** - ****return Series + **** return Series **Example** -Obtain substring\( containing 4 characters\) starting from the third character \(2nd index\). +Obtain substring( containing 4 characters) starting from the third character (2nd index). ```javascript const dfd = require("danfojs-node") @@ -47,4 +48,3 @@ sf.str.substr(2, 4).print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.substring.md b/api-reference/series/series.str.substring.md index 73ab3a8..b54702e 100644 --- a/api-reference/series/series.str.substring.md +++ b/api-reference/series/series.str.substring.md @@ -4,16 +4,17 @@ description: Obtain the substring of each element in a series # Series.str.substring -> danfo.Series.str.**substring**\(startIndex, endIndex\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L280)\] +> danfo.Series.str.**substring**(startIndex, endIndex, options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L280)] -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| startIndex | Number | specify the index to start obtaining the substring | 0 | -| endIndex | Number | specify the index to end the substring | 1 | +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| startIndex | Number | specify the index to start obtaining the substring | 0 | +| endIndex | Number | specify the index to end the substring | 1 | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Returns** - ****return **Series** + **** return **Series** **Example** @@ -32,14 +33,13 @@ sf.str.substring(2, 4).print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -54,4 +54,3 @@ sf.str.substring(2, 4).print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.tolowercase.md b/api-reference/series/series.str.tolowercase.md index ada457b..9abe0f5 100644 --- a/api-reference/series/series.str.tolowercase.md +++ b/api-reference/series/series.str.tolowercase.md @@ -4,11 +4,11 @@ description: Converts all characters to lower case. # Series.str.toLowerCase -> danfo.Series.str.toLowerCase\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L20)\] +> danfo.Series.str.toLowerCase(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L20)] -**Parameters:** None - -**Returns**: Series \(String element\) +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Example** @@ -27,14 +27,13 @@ sf.str.toLowerCase().print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -49,4 +48,3 @@ sf.str.toLowerCase().print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.touppercase.md b/api-reference/series/series.str.touppercase.md index 7e23c08..f484390 100644 --- a/api-reference/series/series.str.touppercase.md +++ b/api-reference/series/series.str.touppercase.md @@ -4,11 +4,13 @@ description: Converts all characters to uppercase. # Series.str.toUpperCase -> danfo.Series.str.toUpperCase\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L33)\] +> danfo.Series.str.toUpperCase(options) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L33)] -**Parameters:** None +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| -**Returns**: Series \(String element\) +**Returns**: Series (String element) **Example** @@ -27,14 +29,13 @@ sf.str.toUpperCase().print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -49,4 +50,3 @@ sf.str.toUpperCase().print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.str.trim.md b/api-reference/series/series.str.trim.md index 7e30db5..58b7b16 100644 --- a/api-reference/series/series.str.trim.md +++ b/api-reference/series/series.str.trim.md @@ -4,13 +4,15 @@ description: Remove leading and trailing Whitespace from a String element # Series.str.trim -> danfo.Series.str.**trim**\(\) **\[**[**source**](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L293)**\]** +> danfo.Series.str.**trim**(options) **\[**[**source**](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/strings.js#L293)**]** -**Parameters:** None +| Parameters | Type | Description | Default | +| ---------- | ------ | --------------------------------------------------------------- | ------------------------------------------------------ | +| options | Object | **inplace**: Whether to perform the operation in-place or not. |

{

inplace: false

}

| **Returns:** - ****return Series + **** return Series {% tabs %} {% tab title="Node" %} @@ -25,14 +27,13 @@ sf.str.trim().print() {% tab title="Browser" %} ``` - ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -47,4 +48,3 @@ sf.str.trim().print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.sub.md b/api-reference/series/series.sub.md index 95da267..8a367f6 100644 --- a/api-reference/series/series.sub.md +++ b/api-reference/series/series.sub.md @@ -1,14 +1,15 @@ --- -description: 'Return Subtraction of series and other, element-wise (binary operator sub).' +description: Return Subtraction of series and other, element-wise (binary operator sub). --- # Series.sub -> danfo.Series.sub\(other\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L148)\] +> danfo.Series.sub(other, options) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| other | Series\|int\| | values | | +| Parameters | Type | Description | Default | +| ---------- | ------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------- | +| other | Series\|int\| | values | | +| options | Object | inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false |

{

inplace: false

}

| **Return:** Series @@ -32,7 +33,7 @@ sf1.sub(sf2).print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -65,7 +66,7 @@ sf1.sub(2).print() {% tabs %} {% tab title="Output" %} -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -82,6 +83,3 @@ sf1.sub(2).print() ``` {% endtab %} {% endtabs %} - - - diff --git a/api-reference/series/series.sum.md b/api-reference/series/series.sum.md index 838283c..2abfcaf 100644 --- a/api-reference/series/series.sum.md +++ b/api-reference/series/series.sum.md @@ -4,7 +4,7 @@ description: Return the sum of the values in a series. # Series.sum -> danfo.Series.sum\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L333)\] +> danfo.Series.sum() **Parameter:** None @@ -27,11 +27,10 @@ console.log(sf1.sum()) {% tabs %} {% tab title="Output" %} -```text +``` 207 ``` {% endtab %} {% endtabs %} -\*\*\*\* - +*** diff --git a/api-reference/series/series.tail.md b/api-reference/series/series.tail.md index 7f986a1..88bb5f4 100644 --- a/api-reference/series/series.tail.md +++ b/api-reference/series/series.tail.md @@ -4,13 +4,13 @@ description: Prints the last n values in a Series # Series.tail -> danfo.Series.tail\(rows\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L76)\] +> danfo.Series.tail(rows) -| Parameters | Type | Description | Default | -| :--- | :--- | :--- | :--- | -| rows | Int | number of last n values | 5 | +| Parameters | Type | Description | Default | +| ---------- | ---- | ----------------------- | ------- | +| rows | Int | number of last n values | 5 | - **Return:** Series +**Return:** Series **Example** @@ -29,7 +29,7 @@ sf1.tail().print() {% tabs %} {% tab title="Output" %} -```text +``` ╔════╤══════════════════════╗ ║ │ 0 ║ ╟────┼──────────────────────╢ @@ -46,4 +46,3 @@ sf1.tail().print() ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.tensor.md b/api-reference/series/series.tensor.md index a5c112c..698f743 100644 --- a/api-reference/series/series.tensor.md +++ b/api-reference/series/series.tensor.md @@ -4,7 +4,7 @@ description: Obtain the tensor representation of the values in a Series # Series.tensor -> danfo.Series.tensor \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L45)\] +> danfo.Series.tensor **Parameters**: None @@ -27,7 +27,7 @@ console.log(sf1.tensor) {% tabs %} {% tab title="Output" %} -```text +``` Tensor { kept: false, isDisposedInternal: false, @@ -43,4 +43,3 @@ Tensor { ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.unique.md b/api-reference/series/series.unique.md index c89d187..e3128e1 100644 --- a/api-reference/series/series.unique.md +++ b/api-reference/series/series.unique.md @@ -4,7 +4,7 @@ description: Obtain the unique value in a Series # Series.unique -> danfo.Series.**unique**\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L736)\] +> danfo.Series.**unique**() **Parameters**: None @@ -27,29 +27,26 @@ sf.unique().print() {% tabs %} {% tab title="Output" %} -```text -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 1 ║ -╟───┼──────────────────────╢ -║ 1 │ 2 ║ -╟───┼──────────────────────╢ -║ 2 │ 3 ║ -╟───┼──────────────────────╢ -║ 3 │ 4 ║ -╟───┼──────────────────────╢ -║ 4 │ 5 ║ -╟───┼──────────────────────╢ -║ 5 │ 6 ║ -╟───┼──────────────────────╢ -║ 6 │ 7 ║ -╟───┼──────────────────────╢ -║ 7 │ 8 ║ -╟───┼──────────────────────╢ -║ 8 │ 22 ║ -╚═══╧══════════════════════╝ +``` +╔═══╤════╗ +║ 0 │ 1 ║ +╟───┼────╢ +║ 1 │ 2 ║ +╟───┼────╢ +║ 2 │ 3 ║ +╟───┼────╢ +║ 3 │ 4 ║ +╟───┼────╢ +║ 4 │ 5 ║ +╟───┼────╢ +║ 5 │ 6 ║ +╟───┼────╢ +║ 6 │ 7 ║ +╟───┼────╢ +║ 7 │ 8 ║ +╟───┼────╢ +║ 8 │ 22 ║ +╚═══╧════╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.value_counts.md b/api-reference/series/series.value_counts.md index 7d99ff2..007fc15 100644 --- a/api-reference/series/series.value_counts.md +++ b/api-reference/series/series.value_counts.md @@ -2,13 +2,13 @@ description: Count the number of occurrence for each element in a Series --- -# Series.value\_counts +# Series.valueCounts -> danfo.Series.value\_counts\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L750)\] +> danfo.Series.valueCounts() **Parameters:** None -**Returns:** Series \(int element\) +**Returns:** Series (int element) **Example** @@ -20,36 +20,33 @@ const dfd = require("danfojs-node") let data1 = [1, 2, 3, 4, 5, 6, 7, 8, 1, 1, 22, 8, 5, 5, 5] let sf = new dfd.Series(data1) -sf.value_counts().print() +sf.valueCounts().print() ``` {% endtab %} {% endtabs %} {% tabs %} {% tab title="Output" %} -```text -╔════╤══════════════════════╗ -║ │ 0 ║ -╟────┼──────────────────────╢ -║ 1 │ 3 ║ -╟────┼──────────────────────╢ -║ 2 │ 1 ║ -╟────┼──────────────────────╢ -║ 3 │ 1 ║ -╟────┼──────────────────────╢ -║ 4 │ 1 ║ -╟────┼──────────────────────╢ -║ 5 │ 4 ║ -╟────┼──────────────────────╢ -║ 6 │ 1 ║ -╟────┼──────────────────────╢ -║ 7 │ 1 ║ -╟────┼──────────────────────╢ -║ 8 │ 2 ║ -╟────┼──────────────────────╢ -║ 22 │ 1 ║ -╚════╧══════════════════════╝ +``` +╔════╤═══╗ +║ 1 │ 3 ║ +╟────┼───╢ +║ 2 │ 1 ║ +╟────┼───╢ +║ 3 │ 1 ║ +╟────┼───╢ +║ 4 │ 1 ║ +╟────┼───╢ +║ 5 │ 4 ║ +╟────┼───╢ +║ 6 │ 1 ║ +╟────┼───╢ +║ 7 │ 1 ║ +╟────┼───╢ +║ 8 │ 2 ║ +╟────┼───╢ +║ 22 │ 1 ║ +╚════╧═══╝ ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.values.md b/api-reference/series/series.values.md index 4857487..e34e113 100644 --- a/api-reference/series/series.values.md +++ b/api-reference/series/series.values.md @@ -4,11 +4,11 @@ description: Obtain the values in a series # Series.values -> danfo.Series.values \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L279)\] +> danfo.Series.values **Parameters:** None -**Returns**: Array +**Returns**: Array **Example** @@ -27,9 +27,8 @@ console.log(sf1.values) {% tabs %} {% tab title="Output" %} -```text +``` [ 30.21091, 40.190901, 3.564, 5.0212 ] ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/series/series.var.md b/api-reference/series/series.var.md index 4fdcbc2..b28bf5a 100644 --- a/api-reference/series/series.var.md +++ b/api-reference/series/series.var.md @@ -4,7 +4,7 @@ description: Calculate the variance of a Series # Series.var -> danfo.Series.var\(\) \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L436)\] +> danfo.Series.var() **Parameter:** None @@ -27,9 +27,8 @@ console.log(sf1.var()) {% tabs %} {% tab title="Output" %} -```text +``` 968.25 ``` {% endtab %} {% endtabs %} - diff --git a/api-reference/untitled.md b/api-reference/untitled.md deleted file mode 100644 index 4e0b10f..0000000 --- a/api-reference/untitled.md +++ /dev/null @@ -1,109 +0,0 @@ -# Untitled - -## Examples - -### Basic Line plot on Series - -The **line** plot is exposed by the .**plot\(\)** function called on a Series or DataFrame. The **.plot\(\)** method accepts an HTML Div id where it renders the plot, while configuration options for the lines drawn can be passed through the config parameter. - -```markup - - - - - - - - - Document - - - - -
- - - - - -``` - -![](../.gitbook/assets/newplot-4-.png) - -### Line plots on DataFrame - -The example below shows the plot of column values against a common x-axis \(index\) - -```markup - - - - - - - - - Document - - - - -
- - - - - -``` - -![](../.gitbook/assets/newplot-2-%20%281%29%20%281%29.png) - -The example below shows how to plot two columns in a DataFrame against each other. - -```markup - - - - - - - - - Document - - - - -
- - - - - -``` - -![](../.gitbook/assets/newplot-3-.png) - -{% hint style="info" %} -To set configuration for your plots, see the [Configuring your plot page]() -{% endhint %} - - - diff --git a/building-data-driven-applications-with-danfo.js-book.md b/building-data-driven-applications-with-danfo.js-book.md new file mode 100644 index 0000000..0a40dc9 --- /dev/null +++ b/building-data-driven-applications-with-danfo.js-book.md @@ -0,0 +1,40 @@ +# Building Data Driven Applications with Danfo.js - Book + +## Purchase on [Packt](https://www.packtpub.com/product/building-data-driven-applications-with-danfo-js/9781801070850) + +## What this book is about + +The book then shows you how to load different datasets, combine and analyze them by performing operations such as handling missing values and string manipulations. You'll also get to grips with data plotting, visualization, aggregation, and group operations by combining Danfo.js with Plotly. As you advance, you'll create a no-code data analysis and handling system and create-react-app, react-table, react-chart, Draggable.js, and tailwind, and understand how to use TensorFlow.js and Danfo.js to build a recommendation system. Finally, you'll build a Twitter analytics dashboard powered by Danfo.js, Next.js, node-nlp, and Twit.js. + +By the end of this app development book, you'll be able to build and embed data analytics, visualization, and ML capabilities into any JavaScript app in server-side Node.js or the browser. + +![Danfo.js book cover](.gitbook/assets/B17076\_Cover.jpg) + +## **What you will learn** + +* Perform data experimentation and analysis with Danfo.js and Dnotebook +* Build machine learning applications using Danfo.js integrated with TensorFlow.js +* Connect Danfo.js with popular database applications to aid data analysis +* Create a no-code data analysis and handling system using internal libraries +* Develop a recommendation system with Danfo.js and TensorFlow.js +* Build a Twitter analytics dashboard for sentiment analysis and other types of data insights + +## **Who this book is for** + +This book is for data analysts, data scientists, and JavaScript developers who want to create data-driven applications in the JavaScript/Node.js environment. Intermediate-level knowledge of JavaScript programming and data science using pandas is expected + +## Table of content + +1. An Overview of Modern JavaScript +2. Dnotebook - An Interactive Computing Environment for JavaScript +3. Getting Started with Danfo.js +4. Data Analysis, Wrangling, and Transformation +5. Data Visualization with Plotly.js +6. Data Visualization with Danfo.js +7. Data Aggregation and Group Operations +8. Creating a No-Code Data Analysis/Handling System +9. Basics of Machine Learning +10. Introduction to TensorFlow.js +11. Building a Recommendation System with Danfo.js and TensorFlow.js +12. Building a Twitter Analysis Dashboard +13. Appendix: Essential JavaScript Concepts diff --git a/contributing-guide.md b/contributing-guide.md index 878a606..60f4f4b 100644 --- a/contributing-guide.md +++ b/contributing-guide.md @@ -25,84 +25,71 @@ description: >- * Committing your code * Pushing your changes * Review your code and finally, make the pull request -* Danfojs internal \(Brief\) +* Danfojs internal (Brief) ## TL:DR -All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome. +All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome. -For contributors familiar with open-source, below is a quick guide to setting up danfojs locally. +For contributors familiar with open-source, below is a quick guide to setting up danfojs locally. -```text -git clone https://github.com/opensource9ja/danfojs.git +``` +git clone https://github.com/javascriptdata/danfojs.git cd danfojs git checkout -b ``` -There are two folders, **danfojs-browser** and **danfojs-node**. If you are contributing a new feature, then you should include it in both versions. If you are doing a bug fix for a single version, then open that folder and install packages. - -For instance, if I want to do some bug fixes in danfojs-node. I can do the following: +There are three main folders in the `src` folder, **danfojs-base**, **danfojs-browser,** and **danfojs-node**. -```text -cd danfojs-node -yarn ##install all packages -``` - -Add my bug fixes and ensure test passes: - -```text -yarn test ## run test -``` +The **danfojs-base** folder holds all shared classes, modules, and functions used by both danfojs-browser and danfojs-node. So features or bug fixes that work the same way in both versions will generally be done in the **danfojs-base** folder. ## Where to start? -For first time contributors, you can find pending issues on the GitHub “issues” page. There are a number of issues listed and "good first issue" where you could start out. Once you’ve found an interesting issue, and have an improvement in mind, next thing is to set up your development environment. +For first-time contributors, you can find pending issues on the GitHub “issues” page. There are a number of issues listed and "good first issue" where you could start out. Once you’ve found an interesting issue, and have an improvement in mind, next thing is to set up your development environment. ## Working with the code -Now that you have an issue you want to fix, an enhancement to add, or documentation to improve, you need to learn how to work with GitHub and the danfojs code base. +If you have an issue you want to fix, an enhancement to add, or documentation to improve, you need to learn how to work with GitHub and the Danfojs code base. ### **Version control, Git, and GitHub** -The danfojs code is hosted on GitHub. To contribute you will need to sign up for a free GitHub account. We use Git for version control to allow many people to work together on this project. +Danfojs code is hosted on GitHub. To contribute you will need to sign up for a free GitHub account. We use Git for version control to allow many people to work together on this project. Some great resources for learning Git: * Official [GitHub pages](http://help.github.com). -### **Getting started with Git¶** +### **Getting started with Git** Find [Instructions](http://help.github.com/set-up-git-redirect) for installing git, setting up your SSH key, and configuring git. These steps need to be completed before you can work seamlessly between your local repository and GitHub. -## **Forking the danfojs repo** +## **Forking the Danfojs repo** You will need your own fork to work on the code. Go to the danfojs [project page](https://github.com/opensource9ja/danfojs) and hit the Fork button. Next, you will clone your fork to your local machine: -```text -git clone https://github.com/opensource9ja/danfojs.git +``` +git clone https://github.com/javascriptdata/danfojs.git cd danfojs ``` -This creates the directory danfojs and connects your repository to the upstream \(main project\) repository. +This creates the directory danfojs and connects your repository to the upstream (main project) repository. -> **All development are done in two folders--**[**danfojs-browser**](https://github.com/opensource9ja/danfojs/tree/master/danfojs-browser) **and** [**danfojs-node**](https://github.com/opensource9ja/danfojs/tree/master/danfojs-node) **folders. The two folders are similar and it is always recommended to pull latest changes from master before development in any of the folder.** +Some Javascript features are supported both in the browser and node environment, and it is recommended to add features in the **danfojs-base** folder. + +For features that work differently or only in a specific environment, you can add them in the corresponding danfojs-node or danfojs-browser folder. -Some Javascript features are supported both in the browser and node environment, and it is recommended to add these to both versions. -For features that work only in NodeJs environment, especially file related issues, these should be developed and tested in the danfojs-node folder, and the corresponding tests are written there. ## **Creating a development environment** To test out code changes, you’ll need to build danfojs, which requires a Nodejs environment. ```python -git clone https://github.com/opensource9ja/danfojs.git +git clone https://github.com/javascriptdata/danfojs.git cd danfojs -cd danfojs-browser && yarn ## installs required packages in browser version -cd .. && cd danfojs-node && yarn ## installs required packages in node version -cd .. ## Go back to root folder +yarn install ## automatically installs all required packages yarn test ##Runs test in both node and browser folder ``` @@ -127,10 +114,9 @@ function add_series(series1, series2){ return new Series() } - ``` -And for functions that contain more than two argument, keyword argument should be used. Parsing of keyword argument is also applicable to most of the methods in a class +And for functions that contain more than two arguments, a keyword argument can be used. Parsing of keyword argument is also applicable to most of the methods in a class ```javascript /** @@ -151,9 +137,9 @@ function join_df(kwargs){ ## **Writing tests** -We strongly encourage contributors to write tests for their code. Like many packages, danfojs uses mocha +We strongly encourage contributors to write tests for their code. Like many packages, Danfojs uses mocha. -All tests should go into the tests subdirectory and place in the corresponding module. The tests folder contains some current examples of tests, and we suggest looking to these for inspiration. +All tests should go into the tests subdirectory and placed in the corresponding module. The tests folder contains some current examples of tests, and we suggest looking to these for inspiration. Below is the general Framework to write a test for each module. @@ -205,7 +191,7 @@ describe("Name of the class|module", function(){ }); ``` -**Example**: Let write a test, to test if the values in a dataframe are off a certain length. Assuming the method to obtain length is values\_len\(\) +**Example**: Let write a test, to test if the values in a dataframe are off a certain length. Assuming the method to obtain length is values\_len() ```javascript import { assert } from "chai" @@ -236,22 +222,22 @@ describe("DataFrame", function(){ To run the test for the module you created, -**1\)** Open the package.json +**1)** Open the package.json -**2\)** change the name of the test file to the file name you want. and don't forget the file is in the test folder +**2)** change the name of the test script to the file name you want to test. ```python "scripts": { "test": "....... danfojs/tests/sub_directory_name/filename", ``` -**3\)** run the test, in the danfojs directory terminal +**3)** run the test, in the danfojs directory terminal ```python yarn test ``` -Learn more about mocha [here](https://mochajs.org/) +Learn more about mocha [here](https://mochajs.org) ## Contributing your changes to danfojs @@ -259,19 +245,19 @@ Learn more about mocha [here](https://mochajs.org/) Once you’ve made changes, you can see them by typing: -```text +``` git status ``` Next, you can track your changes using -```text +``` git add . ``` Next, you commit changes using: -```text +``` git commit -m "Enter any commit message here" ``` @@ -279,7 +265,7 @@ git commit -m "Enter any commit message here" When you want your changes to appear publicly on your GitHub page, you can push to your forked repo with: -```text +``` git push ``` @@ -300,31 +286,7 @@ This request then goes to the repository maintainers, and they will review the c In other to contribute to the code base of danfojs, there are some functions and properties provided to make implementation easy. -The main exposed modules are the **Frame** and **Series** module. This module inherits from the **Generic** module. - -The **Generic** module consists of the following methods and properties - -* `.dtypes` \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L213)\] is used to obtain the dtype for each column -* `.index` \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L250)\] to obtain the index for Dataframe or Series -* `.__set_index(label)` \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L257)\] to set the index value -* `.__reset_index()` \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L271)\] to reset the index in DataFrame and Series -* `.values` Obtain the values in DataFrame and Series per rows -* `.col_data` Obtain the values in DataFrame and Series per columns -* `.column_names` \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L305)\] Obtain the list of column names -* `.__set_col_types` \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/generic.js#L165)\] set the dtype for a column or infer the dtype from it -* `.columns` to access the column names directly -* `row_data_tensor` store the tensor representation of the data in DataFrame and Series - -The **Frame** module consists of the following methods and properties to aid implementation. - -* `__frame_is_compactible_for_operation` \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/frame.js#L1754)\]: check if all the values in a DataFrame are numerical. This helps to check if the numerical operation can be done using the dataframe. -* `.__get_ops_tensors(tensors, axis)` \[[source\]](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/frame.js#L1767) : obtain tensors from dataframes along axis 0 or 1. -* `.__get_df_from_tensor(val, col_names)` \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/frame.js#L1741)\]: Obtain dataframe from tensor. -* `.__get_tensor_and_idx(df, axis)` \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/frame.js#L928)\]: Obtain tensors, their index value and their axis from dataframe. - -The **Series** module contains mostly Generic properties and less special internal properties. +The folder **danfojs-base** contains the bulk of Danfojs modules, and these are simply extended or exported by the **danfojs-browser** and **danfojs-node** folders. The base class for Frames and Series is the NdFrame class which is found in the `danfojs-base/core/generic` file. -* `__check_series_op_compactibility(other)` \[[source](https://github.com/opensource9ja/danfojs/blob/master/danfojs/src/core/series.js#L666)\] check if two series are compatible for numerical operation -Lastly, the **Utils** module contains important utility functions. diff --git a/examples/migrating-to-the-stable-version-of-danfo.js.md b/examples/migrating-to-the-stable-version-of-danfo.js.md new file mode 100644 index 0000000..9f3869f --- /dev/null +++ b/examples/migrating-to-the-stable-version-of-danfo.js.md @@ -0,0 +1,69 @@ +--- +description: >- + This page contains migration guides and tips for pre-v1 users of Danfo.js who + want to migrate their projects to the latest stable release of Danfo.js. +--- + +# Migrating to the stable version of Danfo.js + +We recently released the first stable version of Danfo.js. See release note here. This new version improves previous versions, by standardizing the API. As such we now have better naming conventions, class structures, and error messages. + +The following list summarizes some of these updates: + +* **Typescript support:** This new version has been completely re-written using Typescript. This means we now have well-defined types that increase the developer experience. +* **Standard naming convention:** Functions, methods, classes, and variable names have been standardized to follow JavaScript best practices. +* Standardize function argument: Functions and methods have been updated to accept arguments and parameters intuitively resulting in improved developer experience. +* **New features**: We added a couple of new features which users have been requesting for. For example: + * Stream and process large CSV data +* General bug fixes and improvements +* Better error messages + +## Breaking Updates + +There are two major breaking changes in the new stable version. + +### Naming convention + +Update your function and/or method names to use camelCase instead of snake\_case. For example: + +```javascript +read_csv ==> readCSV +to_json ==> toJSON +drop_duplicates ==> dropDuplicates +``` + +**Note:** that your code editor will generally suggest the new function or method names, so it will be easier to update to the new names. If using Typescript, then it is even easier as the TS compiler will show you warnings. + +### Functions and Methods argument structure + +Another major breaking change of v1, is that the structure of arguments/parameters in most functions has been updated to be more intuitive. + +In general, it is important to understand our thought process behind this, so, here goes: + +Assuming we take the method called _**rename**_, which takes the required argument **mapper**, as well as, an optional configuration argument. In pre-v1 version of Danfojs, the function signature is as follows: + +``` +rename( { mapper, axis, inplace } ) => DataFrame +``` + +The structure above combines both required and optional arguments as a single object argument, which is less intuitive. A better method signature will/should take into account the required and optional arguments, as well as their position. Hence we need something like: + +``` +rename(mapper, options: {axis, inplace}) //where mapper is required, and options argument is optional. +``` + +Re-designing functions and methods to follow this intuitive format is the bulk of the breaking change in this new version, as such, when migrating, you have to make these updates. + +{% hint style="info" %} +If using Typescript, then the TS compiler will help in migration, else, you have to manually identify and update your function/method signature. +{% endhint %} + +### Axis Order + +In this new version, we have flipped the result of the axis ordering for all operations. This ordering is now consistent with Pandas and Tensorflow.js. That is, the axis row (0), represents the operations carried out horizontally on a DataFrame, and the axis columns (1) represent operations carried out vertically down the DataFrame. + +{% hint style="info" %} +In short, when migrating to the new version, you should flip the axis number so as to get the same result. That is, change all `axis: 0` to `axis: 1`, to get the same result. +{% endhint %} + +All examples in this doc have been updated to reflect this update. diff --git a/examples/titanic-survival-prediction-using-danfo.js-and-tensorflow.js.md b/examples/titanic-survival-prediction-using-danfo.js-and-tensorflow.js.md index 573f2e7..219b123 100644 --- a/examples/titanic-survival-prediction-using-danfo.js-and-tensorflow.js.md +++ b/examples/titanic-survival-prediction-using-danfo.js-and-tensorflow.js.md @@ -7,21 +7,19 @@ description: >- # Titanic Survival Prediction using Danfo.js and Tensorflow.js -> The RMS Titanic was a British passenger liner that sank in the North Atlantic Ocean in the early morning hours of 15 April 1912, after it collided with an iceberg during its maiden voyage from Southampton to New York City. There were an estimated 2,224 passengers and crew aboard the ship, and more than 1,500 died, making it one of the deadliest commercial peacetime maritime disasters in modern history. The RMS Titanic was the largest ship afloat at the time it entered service and was the second of three Olympic-class ocean liners operated by the White Star Line. The Titanic was built by the Harland and Wolff shipyard in Belfast. Thomas Andrews, her architect, died in the disaster. \([Wikipedia](https://en.wikipedia.org/wiki/Titanic)\) +> The RMS Titanic was a British passenger liner that sank in the North Atlantic Ocean in the early morning hours of 15 April 1912, after it collided with an iceberg during its maiden voyage from Southampton to New York City. There were an estimated 2,224 passengers and crew aboard the ship, and more than 1,500 died, making it one of the deadliest commercial peacetime maritime disasters in modern history. The RMS Titanic was the largest ship afloat at the time it entered service and was the second of three Olympic-class ocean liners operated by the White Star Line. The Titanic was built by the Harland and Wolff shipyard in Belfast. Thomas Andrews, her architect, died in the disaster. ([Wikipedia](https://en.wikipedia.org/wiki/Titanic)) - - -In this tutorial, I will show you how to load and process the famous Titanic dataset with danfo.js, and also how to create a deep learning model with Tensorflow.js to predict survival. This is a classic problem used to introduce new concepts in the field of Machine Learning. +In this tutorial, I will show you how to load and process the famous Titanic dataset with danfo.js, and also how to create a deep learning model with Tensorflow.js to predict survival. This is a classic problem used to introduce new concepts in the field of Machine Learning. The main objective of this tutorial is to show you how to use danfo.js to load and process data easily in JavaScript, so we won't be doing anything too advanced. Also, I assumed that you're familiar with basic deep learning with Tensorflow.js and Pandas as well. If you do not have any background in ML, these are good resources to get started: -* [Introduction to Machine Learning](https://developers.google.com/machine-learning/crash-course/ml-intro) +* [Introduction to Machine Learning](https://developers.google.com/machine-learning/crash-course/ml-intro) * [Deep Learning and Neural Networks](https://www.tensorflow.org/resources/learn-ml/basics-of-machine-learning) * [A Gentle Introduction to TensorFlow.js](https://blog.tensorflow.org/2018/04/a-gentle-introduction-to-tensorflowjs.html) -### Setting up your environment +## Setting up your environment -Danfo.js comes in two builds. There's the browser-based build, optimized for browser environments, and there is the node.js version optimized for Node.js environment. +Danfo.js comes in two builds. There's the browser-based build, optimized for browser environments, and there is the node.js version optimized for Node.js environment. In this tutorial, you're going to use the Node.js build. If you do not have Node.js installed, following the guide [here](https://nodejs.org/en/). When you're done, create a new project by running the command below in a terminal opened in your preferred terminal. @@ -31,9 +29,9 @@ npm init Fill in the necessary details to create your app. Next, in your terminal, install danfo.js: -**Update \(14th Feb 2021\):** +**Update (14th Feb 2021):** -Danfo now ships with an exported version of tensorflow \(v2.8.5\). This is exported under the namespace `tf`. This fixes the **double registration of runtime** issue many users have faced in the past. +Danfo now ships with an exported version of tensorflow (v2.8.5). This is exported under the namespace `tf`. This fixes the **double registration of runtime** issue many users have faced in the past. ```javascript npm install danfojs-node @@ -43,28 +41,27 @@ When you're done, create a file called app.js and import the packages: ```javascript const dfd = require("danfojs-node") -const tf = dfd.tf //Reference to the exported tensorflowjs library +const tf = dfd.tensorflow //Reference to the exported tensorflowjs library ``` -### Loading and processing your data +## Loading and processing your data -To load a CSV dataset, you can use the [read\_csv](../api-reference/input-output/danfo.read_csv.md) function. This can load a file from both a local path, as well as over the internet. In this tutorial, you'll load the titanic dataset from the internet. +To load a CSV dataset, you can use the [readCSV](../api-reference/input-output/danfo.read\_csv.md) function. This can load a file from both a local path, as well as over the internet. In this tutorial, you'll load the titanic dataset from the internet. Below your import add the following lines of code: ```javascript async function load_process_data() { - - let df = await dfd.read_csv("https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv") + + let df = await dfd.readCSV("https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv") df.head().print() - - + + } ``` -```text - Shape: (5,8) - +``` + ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Survived │ Pclass │ Name │ Sex │ ... │ Age │ Siblings/Spou... │ Parents/Child... │ Fare ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -80,7 +77,7 @@ async function load_process_data() { ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -You wrote an async function because loading dataset over the internet takes a few seconds depending on your network. Inside the async function, you pass in the url of the titanic dataset to the read\_csv function. +You wrote an async function because loading a dataset over the internet takes a few seconds depending on your network. Inside the async function, you pass in the url of the titanic dataset to the readCSV function. Next you'll perform some basic data preprocessing. The [ctypes](../api-reference/dataframe/dataframe.dtypes.md) attribute returns the column data types: @@ -110,21 +107,21 @@ df.ctypes.print() ╚═════════════════════════╧══════════════════════╝ ``` -From the data types table above, you'll notice that there are two strong columns. The first is the Name column which contains Names of each passenger. From the head of the dataset you printed above, you'll confirm that each name has a title. So you can extract these titles from the names and this can serve as a new feature. +From the data types table above, you'll notice that there are two string columns. The first is the Name column which contains Names of each passenger. From the head of the dataset you printed above, you'll confirm that each name has a title. So you can extract these titles from the names and this can serve as a new feature. ```javascript //A feature engineering: Extract all titles from names columns let title = df['Name'].apply((x) => { return x.split(".")[0] }).values //replace in df -df.addColumn({ column: "Name", value: title }) +df.addColumn("Name", title, { inplace: true }) ``` -In the code above, you are calling the [apply](../api-reference/series/series.apply.md) function on the _**Name**_ column. The parameter to the [apply](../api-reference/series/series.apply.md) function is a function that gets called on each element of the column. This function can be any JavaScript function. +In the code above, you are calling the [apply](../api-reference/series/series.apply.md) function on the _**Name**_ column. The parameter to the [apply](../api-reference/series/series.apply.md) function is a function that gets called on each element of the column. This function can be any JavaScript function. So what exactly is the function doing? Well, it is basically slicing each name and extracting the title. And finally, you are using the result to replace the original name column. When you're done, your output becomes: -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Survived │ Pclass │ Name │ Sex │ ... │ Age │ Siblings/Spou... │ Parents/Child... │ Fare ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -138,7 +135,6 @@ So what exactly is the function doing? Well, it is basically slicing each name a ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ ║ 4 │ 0 │ 3 │ Mr │ male │ ... │ 35 │ 0 │ 0 │ 8.05 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ - ``` You notice we now have titles inplace of names. You can easily one hot encode this feature. You will do that below: @@ -149,8 +145,8 @@ let encoder = new dfd.LabelEncoder() let cols = ["Sex", "Name"] cols.forEach(col => { encoder.fit(df[col]) - enc_val = encoder.transform(df[col]) - df.addColumn({ column: col, value: enc_val }) + const enc_val = encoder.transform(df[col]) + df.addColumn( col, enc_val, { inplace: true }) }) df.head().print() @@ -158,8 +154,7 @@ df.head().print() In code cell above, you're[ label encoding](../api-reference/general-functions/danfo.labelencoder.md) the Sex and Name column. You loop over each column name, fit the encoder to the column, transform it and finally reassign it to the DataFrame. The output is shown below: -```text - +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Survived │ Pclass │ Name │ Sex │ ... │ Age │ Siblings/Spou... │ Parents/Child... │ Fare ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -183,7 +178,7 @@ Xtrain = df.iloc({ columns: [`1:`] }) ytrain = df['Survived'] ``` -Next, you'll scale the data using [MinMaxScaler](../api-reference/general-functions/danfo.minmaxscaler.md). It is important to scale your data before model training, as this will affect training. +Next, you'll scale the data using [MinMaxScaler](../api-reference/general-functions/danfo.minmaxscaler.md). It is important to scale your data before model training, as this will affect training. ```javascript // Standardize the data with MinMaxScaler @@ -193,9 +188,9 @@ Xtrain = scaler.transform(Xtrain) return [Xtrain.tensor, ytrain.tensor] ``` -In the code cell above, first, you create an instance from the MinMaxScaler class. Next, you fit the train data and finally, you transform. The output from the scaler is a DataFrame of same size with the values scaled. +In the code cell above, first, you create an instance from the MinMaxScaler class. Next, you fit the train data and finally, you transform. The output from the scaler is a DataFrame of same size with the values scaled. -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -218,27 +213,27 @@ const dfd = require("danfojs-node") const tf = dfd.tf; async function load_process_data() { - let df = await dfd.read_csv("https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv") + let df = await dfd.readCSV("https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv") //A feature engineering: Extract all titles from names columns let title = df['Name'].apply((x) => { return x.split(".")[0] }).values //replace in df - df.addColumn({ column: "Name", value: title }) + df.addColumn("Name", title, { inplace: true }) //label Encode Name feature let encoder = new dfd.LabelEncoder() let cols = ["Sex", "Name"] cols.forEach(col => { encoder.fit(df[col]) - enc_val = encoder.transform(df[col]) - df.addColumn({ column: col, value: enc_val }) + const enc_val = encoder.transform(df[col]) + df.addColumn( col, enc_val, { inplace: true }) }) - let Xtrain,ytrain; + let Xtrain, ytrain; Xtrain = df.iloc({ columns: [`1:`] }) ytrain = df['Survived'] - + // Standardize the data with MinMaxScaler let scaler = new dfd.MinMaxScaler() scaler.fit(Xtrain) @@ -250,11 +245,11 @@ async function load_process_data() { load_process_data() ``` -### Model Building With Tensorflow.js +## Model Building With Tensorflow.js -In this section, you'll build a simple classification model using tensorflow.js. If you're not familiar with Tensorflow.js, you can start [here](https://blog.tensorflow.org/2018/04/a-gentle-introduction-to-tensorflowjs.html). +In this section, you'll build a simple classification model using tensorflow.js. If you're not familiar with Tensorflow.js, you can start [here](https://blog.tensorflow.org/2018/04/a-gentle-introduction-to-tensorflowjs.html). -Create a simple function called get\_model. This will construct and return a model when called. +Create a simple function called get\_model. This will construct and return a model when called. ```javascript function get_model() { @@ -268,12 +263,11 @@ function get_model() { } ``` -In the code cell above, you created a neural network with 4 layers. Note the input shape, this should be the same as your column numbers. Also, note that you used a sigmoid in the output layer. This is because you're working on a binary classification problem. +In the code cell above, you created a neural network with 4 layers. Note the input shape, this should be the same as your column numbers. Also, note that you used a sigmoid in the output layer. This is because you're working on a binary classification problem. Next, you will create a function called _**train:**_ ```javascript - async function train() { const model = get_model() const data = await load_process_data() @@ -285,7 +279,7 @@ async function train() { loss: 'binaryCrossentropy', metrics: ['accuracy'], }); - + console.log("Training started....") await model.fit(Xtrain, ytrain,{ batchSize: 32, @@ -298,27 +292,27 @@ async function train() { } } }); - + } ``` This function calls the _**load\_process\_data**_ function to retrieve training data as tensors and also calls the _**get\_model**_ to retrieve the model. Next, you compile the model by specifying an optimizer, a loss function and a metric to report. -Next, you call the **fit** function on the model, by passing the training data and labels \(tensors\), specify batch size, epoch size, validation split size, and also a callback function to track training progress. +Next, you call the **fit** function on the model, by passing the training data and labels (tensors), specify batch size, epoch size, validation split size, and also a callback function to track training progress. -The training progress is printed to the console at the end of each Epoch. Below is the full code from loading data to training your model: +The training progress is printed to the console at the end of each Epoch. Below is the full code from loading data to training your model: ```javascript -const dfd = require("danfojs-node") -const tf = dfd.tf; +const dfd = require("danfojs-node-nightly") +const tf = dfd.tensorflow async function load_process_data() { - let df = await dfd.read_csv("https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv") + let df = await dfd.readCSV("https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv") //A feature engineering: Extract all titles from names columns let title = df['Name'].apply((x) => { return x.split(".")[0] }).values //replace in df - df.addColumn({ column: "Name", value: title }) + df.addColumn("Name", title, { inplace: true }) //label Encode Name feature let encoder = new dfd.LabelEncoder() @@ -326,11 +320,11 @@ async function load_process_data() { cols.forEach(col => { encoder.fit(df[col]) enc_val = encoder.transform(df[col]) - df.addColumn({ column: col, value: enc_val }) + df.addColumn( col, enc_val, { inplace: true }) }) - let Xtrain,ytrain; + let Xtrain, ytrain; Xtrain = df.iloc({ columns: [`1:`] }) ytrain = df['Survived'] @@ -338,7 +332,6 @@ async function load_process_data() { let scaler = new dfd.MinMaxScaler() scaler.fit(Xtrain) Xtrain = scaler.transform(Xtrain) - return [Xtrain.tensor, ytrain.tensor] //return the data as tensors } @@ -392,8 +385,7 @@ node app.js This runs the script, and displays training progress after each Epoch as shown below: -```text - +``` Epoch 12 / 15 eta=0.0 ===============================================================================================> 322ms 455us/step - acc=0.812 loss=0.433 val_acc=0.826 val_loss=0.371 @@ -419,13 +411,12 @@ EPOCH (15): Train Accuracy: 80.39, Val Accuracy: 83.15 ``` -After 15 epochs, you reach an accuracy of about 83%. This can definitely be improved, but for the sake of simplicity, we'll stop here. - -In this tutorial, you have seen how to use danfo.js with tensorflow.js to load and process data, as well as train a neural network. This is similar to the Pandas-Tensorflow packages in Python. +After 15 epochs, you reach an accuracy of about 83%. This can definitely be improved, but for the sake of simplicity, we'll stop here. -You also notice that danfo.js provides similar API as Pandas and can easily be picked up by Python developers. +In this tutorial, you have seen how to use danfo.js with tensorflow.js to load and process data, as well as train a neural network. This is similar to the Pandas-Tensorflow packages in Python. -As an extra task, you can try to do more feature engineering using danfo.js and try to improve the accuracy of your model. +You also notice that danfo.js provides a similar API as Pandas and can easily be picked up by Python developers. -Go danfo! 😎 +As an extra task, you can try to do more feature engineering using danfo.js and try to improve the accuracy of your model. +Go Danfo! 😎 diff --git a/examples/using-danfojs-in-react.md b/examples/using-danfojs-in-react.md index 118de23..682a0d7 100644 --- a/examples/using-danfojs-in-react.md +++ b/examples/using-danfojs-in-react.md @@ -2,9 +2,9 @@ **TL:DR** See Example react application using danfojs [here](https://github.com/opensource9ja/Data-aRT) -Danfojs works for both browser and NodeJs environment, and as such is available to frontend frameworks like React and Vue. +Danfojs works for both browser and NodeJs environment, and as such is available to frontend frameworks like React and Vue. -In order to use Danfojs in a library like React, you must install the [browser side version ](https://www.npmjs.com/package/danfojs)from npm. +In order to use Danfojs in a library like React, you must install the [browser side version ](https://www.npmjs.com/package/danfojs)from npm. ```bash npm install danfojs @@ -18,14 +18,14 @@ Follow the steps here to bootstrap a React app, and in your App.js or any file w ```bash import "./App.css"; -import * as dfd from "danfojs/src/index"; +import * as dfd from "danfojs"; ``` Now you have access to all features under the `dfd` namespace. Below is a sample App.js file using danfojs: ```bash import "./App.css"; -import * as dfd from "danfojs/src/index"; +import * as dfd from "danfojs"; function App() { @@ -53,18 +53,16 @@ function App() { } export default App; - ``` On running the app, we get the following output in the console: -![](../.gitbook/assets/screen-shot-2021-02-14-at-7.22.16-pm.png) +![](<../.gitbook/assets/Screen Shot 2021-02-14 at 7.22.16 PM.png>) Note that you can also import specific modules. For instance, in the code below we import only the DataFrame module: ```bash -import { DataFrame } from "danfojs/src/index"; +import { DataFrame } from "danfojs"; ``` -Following these steps, you can use danfojs in any client-side library. - +Following these steps, you can use danfojs in any client-side library. diff --git a/getting-started.md b/getting-started.md index c18e8ca..b0510f1 100644 --- a/getting-started.md +++ b/getting-started.md @@ -6,34 +6,59 @@ description: >- # Getting Started +{% hint style="info" %} +A stable version of Danfojs (v1), has been released, and it comes with full Typescript support, new features, and many bug fixes. See release note [here](release-notes.md#latest-release-node-v1.0.0-browser-v1.0.0). + +There are a couple of breaking changes, so we have prepared a short migration [guide](examples/migrating-to-the-stable-version-of-danfo.js.md) for pre-v1 users. +{% endhint %} + ## Installation -There are two ways to get danfo.js. We built an optimized and fast version for node.js and its available under the [danfojs-node](https://www.npmjs.com/package/danfojs-node) namespace. To install it via npm, you can do the following: +There are three ways to install and use Danfo.js in your application + +For Nodejs applications, you can install the [danfojs-node](https://www.npmjs.com/package/danfojs-node) version via package managers like yarn and npm: -```text +``` npm install danfojs-node + +or + +yarn add danfojs-node +``` + +For client-side applications built with frameworks like React, Vue, Next.js, etc, you can install the [danfojs](https://www.npmjs.com/package/danfojs) version: + ``` +npm install danfojs -You can also install and use it in the browsers by using the CDN below: +or + +yarn add danfojs +``` + +For use directly in HTML files, you can add the latest script tag from [JsDelivr](https://www.jsdelivr.com/package/npm/danfojs): ```markup - + ``` {% hint style="info" %} -To play with Danfo.js in a Notebook-like environment without doing an local installation, use [Dnotebooks](https://dnotebook.jsdata.org/getting-started) [here](https://playnotebook.jsdata.org/demo) +To play with Danfo.js in a Notebook-like environment, see [Dnotebooks](https://dnotebook.jsdata.org/getting-started) [here](https://playnotebook.jsdata.org/demo) or the [VS-Code Nodejs notebook extension](https://marketplace.visualstudio.com/items?itemName=donjayamanne.typescript-notebook). {% endhint %} ## 10 minutes to danfo.js -This is a short introduction to danfo.js, and its flow is adapted from the official [10 minutes to Pandas](https://pandas.pydata.org/pandas-docs/stable/user_guide/10min.html#min) +This is a short introduction to Danfo.js, and its flow is adapted from the official [10 minutes to Pandas](https://pandas.pydata.org/pandas-docs/stable/user\_guide/10min.html#min) -We will show you how to use danfo.js in both browser environment and Node.js environment. Most functions except [plotting](https://jsdata.gitbook.io/danfojs/api-reference/plotting) which require a DOM works the same way in both environments. +We will show you how to use danfo.js in a browser, client-side libraries, and Node.js environments. Most functions except [plotting](https://jsdata.gitbook.io/danfojs/api-reference/plotting) which require a DOM work the same way in all environments. {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") + +//or using ES6 +import * as dfd from "danfojs-node" ``` {% endtab %} @@ -45,7 +70,7 @@ const dfd = require("danfojs-node") - + @@ -62,15 +87,26 @@ const dfd = require("danfojs-node") ``` {% endtab %} + +{% tab title="React" %} +```jsx +import * as dfd from "danfojs" + +//import specific methods/classes +import { readCSV, DataFrame } from "danfojs" +``` +{% endtab %} {% endtabs %} -### Object creation +### Creating a DataFrame/Series -Creating a [`Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas.Series) by passing a list of values, letting danfo.js create a default integer index: +You can create a [`Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas.Series) by passing a list of values, letting Danfo.js create a default integer index: {% tabs %} {% tab title="Node" %} ```javascript +import * as dfd from "danfojs-node" + s = new dfd.Series([1, 3, 5, undefined, 6, 8]) s.print() ``` @@ -84,7 +120,7 @@ s.print() - Document + Document @@ -103,7 +139,7 @@ s.print() {% endtab %} {% endtabs %} -```text +``` //output ╔═══╤══════════════════════╗ ║ │ 0 ║ @@ -114,7 +150,7 @@ s.print() ╟───┼──────────────────────╢ ║ 2 │ 5 ║ ╟───┼──────────────────────╢ -║ 3 │ NaN ║ +║ 3 │ undefined ║ ╟───┼──────────────────────╢ ║ 4 │ 6 ║ ╟───┼──────────────────────╢ @@ -128,7 +164,7 @@ Creating a [`Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -const tf = require("@tensorflow/tfjs-node") +const tf = dfd.tensorflow //Tensorflow.js is exportedfrom Danfojs let tensor_arr = tf.tensor([12,34,56,2]) @@ -145,7 +181,7 @@ s.print() - + Document @@ -153,7 +189,7 @@ s.print() Document + +Document @@ -237,7 +272,7 @@ Creating a [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/ {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -const tf = require("@tensorflow/tfjs-node") +const tf = dfd.tensorflow //Tensorflow.js is exported from Danfojs let tensor_arr = tf.tensor2d([[12, 34, 2.2, 2], [30, 30, 2.1, 7]]) @@ -256,7 +291,7 @@ df.ctypes.print() - Document + Document @@ -279,7 +314,7 @@ df.ctypes.print() {% endtab %} {% endtabs %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -304,12 +339,12 @@ df.ctypes.print() Creating a [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame) by passing a dictionary of objects with the same length {% tabs %} -{% tab title="Node" %} +{% tab title="Nodejs" %} ```javascript const dfd = require("danfojs-node") - -dates = new dfd.date_range({ start: '2017-01-01', end: "2020-01-01", period: 4, freq: "Y" }) +// Danfojs v1.0.0 and above +dates = new dfd.dateRange({ start: '2017-01-01', end: "2020-01-01", period: 4, freq: "Y" }) console.log(dates); @@ -334,14 +369,14 @@ df.print() - Document + Document Document + Document @@ -450,7 +483,7 @@ df.print() {% endtab %} {% endtabs %} -```text +``` //output in console ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ @@ -470,12 +503,12 @@ df.print() Here is how to view the top and bottom rows of the frame above: -```text +``` df.head(2).print() df.tail(2).print() ``` -```text +``` //output from head ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ 0 │ 1 │ 2 │ 3 ║ @@ -502,22 +535,27 @@ Display the index, columns: {% tabs %} {% tab title="JavaScript" %} ```javascript -const dfd = require("danfojs-node") - -dates = new dfd.date_range({ start: '2017-01-01', end: "2020-01-01", period: 4, freq: "Y" }) - - -obj_data = {'A': dates, - 'B': ["bval1", "bval2", "bval3", "bval4"], - 'C': [10, 20, 30, 40], - 'D': [1.2, 3.45, 60.1, 45], - 'E': ["test", "train", "test", "train"] - } - -df = new dfd.DataFrame(obj_data) - -console.log(df.index); -console.log(df.columns); +const dfd = require('danfojs-node') + +let dates = new dfd.dateRange({ + start: "2017-01-01", + end: "2020-01-01", + period: 4, + freq: "Y", + }); + + let obj_data = { + A: dates, + B: ["bval1", "bval2", "bval3", "bval4"], + C: [10, 20, 30, 40], + D: [1.2, 3.45, 60.1, 45], + E: ["test", "train", "test", "train"], + }; + + let df = new dfd.DataFrame(obj_data); + df.print(); + console.log(df.index); + console.log(df.columns); ``` {% endtab %} @@ -530,28 +568,32 @@ console.log(df.columns); - Document + Document @@ -560,15 +602,28 @@ console.log(df.columns); {% endtab %} {% endtabs %} -```text +``` //output + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C │ D │ E ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1/1/2017, 1:00:… │ bval1 │ 10 │ 1.2 │ test ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1/1/2018, 1:00:… │ bval2 │ 20 │ 3.45 │ train ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 1/1/2019, 1:00:… │ bval3 │ 30 │ 60.1 │ test ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 1/1/2020, 1:00:… │ bval4 │ 40 │ 45 │ train ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + [ 0, 1, 2, 3 ] [ 'A', 'B', 'C', 'D', 'E' ] ``` -[`DataFrame.tensor`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html#pandas.DataFrame.to_numpy) returns a Tensorflow tensor representation of the underlying data. Note that **Tensorflow tensors have one dtype for the entire array, while danfo DataFrames have one dtype per column**. +[`DataFrame.tensor`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to\_numpy.html#pandas.DataFrame.to\_numpy) returns a Tensorflow tensor representation of the underlying data. Note that **Tensorflow tensors have one dtype for the entire array, while danfo DataFrames have one dtype per column**. -For `df`, our [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame) of all floating-point values, [`DataFrame.tensor`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html#pandas.DataFrame.to_numpy)is fast and doesn’t require copying data. +For `df`, our [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame) of all floating-point values, [`DataFrame.tensor`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to\_numpy.html#pandas.DataFrame.to\_numpy)is fast and doesn’t require copying data. {% tabs %} {% tab title="Node" %} @@ -576,12 +631,12 @@ For `df`, our [`DataFrame`](https://pandas.pydata.org/pandas-docs/stable/referen const dfd = require("danfojs-node") -json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 }, +j son_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 }, { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 }, { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 }, { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }] -df = new dfd.DataFrame(json_data) +let df = new dfd.DataFrame(json_data) console.log(df.tensor); //or @@ -598,7 +653,7 @@ df.tensor.print() - Document + Document @@ -624,7 +679,7 @@ df.tensor.print() {% endtab %} {% endtabs %} -```text +``` //output Tensor { @@ -648,7 +703,7 @@ Tensor **Note** -[`DataFrame.tensor`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html#pandas.DataFrame.to_numpy) does _not_ include the index or column labels in the output. +[`DataFrame.tensor`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to\_numpy.html#pandas.DataFrame.to\_numpy) does _not_ include the index or column labels in the output. [`describe()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.describe.html#pandas.DataFrame.describe) shows a quick statistic summary of your data: @@ -658,12 +713,12 @@ Tensor const dfd = require("danfojs-node") -json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 }, +let json_data = [{ A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 }, { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 }, { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 }, { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 }] -df = new dfd.DataFrame(json_data) +let df = new dfd.DataFrame(json_data) df.describe().print() ``` @@ -678,7 +733,7 @@ df.describe().print() - Document + Document @@ -702,25 +757,29 @@ df.describe().print() {% endtab %} {% endtabs %} -```text -//output in console - -╔════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C │ D ║ -╟────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ count │ 4 │ 4 │ 4 │ 4 ║ -╟────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ mean │ 0.533175 │ 0.484235 │ -0.474898 │ 1.5816 ║ -╟────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ std │ 0.107543 │ 2.569317 │ 3.437147 │ 2.200545 ║ -╟────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ min │ 0.4612 │ -1.28863 │ -3.39059 │ -1.1352 ║ -╟────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ median │ 0.4902 │ -0.52863 │ -1.50745 │ 1.6492 ║ -╚════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` +//output in console -Sorting by values \(Defaults to ascending\): +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C │ D ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ count │ 4 │ 4 │ 4 │ 4 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ mean │ 0.533175 │ 0.4842349999999… │ -0.474897500000… │ 1.5816 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ std │ 0.1075428712963… │ 2.5693167249095… │ 3.4371471031498… │ 2.2005448052698… ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ min │ 0.4612 │ -1.28863 │ -3.39059 │ -1.1352 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ median │ 0.4901999999999… │ -0.528629999999… │ -1.50745 │ 1.6492 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ max │ 0.6911 │ 4.28283 │ 4.5059 │ 4.1632 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ variance │ 0.0115654691666… │ 6.6013884328999… │ 11.813980208691… │ 4.84239744 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` + +Sorting by values (Defaults to ascending): {% tabs %} {% tab title="Node" %} @@ -733,7 +792,7 @@ let data = {"A": [-20, 30, 47.3, NaN], let df = new dfd.DataFrame(data) -df.sort_values({by: "C", inplace: true}) +df.sortValues("C", {inplace: true}) df.print() ``` {% endtab %} @@ -747,7 +806,7 @@ df.print() - Document + Document @@ -760,7 +819,7 @@ df.print() let df = new dfd.DataFrame(data) - df.sort_values({by: "C", inplace: true}) + df.sortValues("C", {inplace: true}) df.print() @@ -771,16 +830,18 @@ df.print() {% endtab %} {% endtabs %} -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 30 │ -4 │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 47.3 │ 5 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ -20 │ 34 │ 20 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 30 │ -4 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 47.3 │ 5 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ -20 │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ NaN │ 6 │ 30 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` ### Selection @@ -815,7 +876,7 @@ df['A'].print() - Document + Document @@ -840,7 +901,7 @@ df['A'].print() {% endtab %} {% endtabs %} -```text +``` //output ╔═══╤══════════════════════╗ ║ │ A ║ @@ -873,7 +934,7 @@ let sub_df = df.loc({rows: ["a", "c"]}) sub_df.print() ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -914,7 +975,7 @@ let sub_df = df.loc({ rows: [0,1], columns: ["Name", "Price"] }) sub_df.print() ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -939,7 +1000,7 @@ sub_df.print() ╚═══╧═══════════════════╧═══════════════════╝ ``` -Showing label slicing, both endpoints are _included_: +Showing label slicing: ```javascript const dfd = require("danfojs-node") @@ -955,7 +1016,7 @@ let sub_df = df.loc({ rows: ["0:2"], columns: ["Name", "Price"] }) sub_df.print() ``` -```text +``` //before slicing ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ @@ -970,17 +1031,15 @@ sub_df.print() ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ //after slicing - Shape: (3,2) + -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Name │ Price ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ Apples │ 200 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ Mango │ 300 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ Banana │ 40 ║ -╚═══╧═══════════════════╧═══════════════════╝ +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Price ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ Apples │ 200 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ Mango │ 300 ║ +╚════════════╧═══════════════════╧═══════════════════╝ ``` #### Selection by position @@ -1000,7 +1059,7 @@ let sub_df = df.iloc({rows: [1,3]}) sub_df.print() ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -1025,16 +1084,14 @@ let sub_df = df.iloc({rows: ["1:3"]}) sub_df.print() ``` -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ Name │ Count │ Price ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ Mango │ 5 │ 300 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ Banana │ 30 │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ Pear │ 10 │ 250 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Count │ Price ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ Mango │ 5 │ 300 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ Banana │ 30 │ 40 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` By lists of integer position locations: @@ -1052,7 +1109,7 @@ let sub_df = df.iloc({rows: [1,3], columns: [0,2]}) sub_df.print() ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Name │ Price ║ ╟───┼───────────────────┼───────────────────╢ @@ -1077,14 +1134,12 @@ let sub_df = df.iloc({rows: ["2:3"], columns: [":"]}) sub_df.print() ``` -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ Name │ Count │ Price ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ Banana │ 30 │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ Pear │ 10 │ 250 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Name │ Count │ Price ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ Banana │ 30 │ 40 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` For slicing columns explicitly: @@ -1102,134 +1157,108 @@ let sub_df = df.iloc({rows: [":"], columns: ["1:2"]}) sub_df.print() ``` -```text -╔═══╤═══════════════════╤═══════════════════╗ -║ │ Count │ Price ║ -╟───┼───────────────────┼───────────────────╢ -║ 0 │ 21 │ 200 ║ -╟───┼───────────────────┼───────────────────╢ -║ 1 │ 5 │ 300 ║ -╟───┼───────────────────┼───────────────────╢ -║ 2 │ 30 │ 40 ║ -╟───┼───────────────────┼───────────────────╢ -║ 3 │ 10 │ 250 ║ -╚═══╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╗ +║ │ Count ║ +╟────────────┼───────────────────╢ +║ 0 │ 21 ║ +╟────────────┼───────────────────╢ +║ 1 │ 5 ║ +╟────────────┼───────────────────╢ +║ 2 │ 30 ║ +╟────────────┼───────────────────╢ +║ 3 │ 10 ║ +╚════════════╧═══════════════════╝ ``` -#### Boolean Querying/Filtering +#### Selection with Boolean Mask -Using a single column’s values to select data. +You can select subsections from a DataFrame by a booelan condition mask. E.g. In the following code, we select and return only rows where the column `Count` is greater than 10. -{% tabs %} -{% tab title="Node" %} ```javascript -const dfd = require("danfojs-node") - -let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]] -let cols = ["A", "B", "C"] +let data = { + "Name": ["Apples", "Mango", "Banana", "Pear"], + "Count": [21, 5, 30, 10], + "Price": [200, 300, 40, 250] +} -let df = new dfd.DataFrame(data, { columns: cols }) -df.print() //before query +let df = new dfd.DataFrame(data) -let query_df = df.query({ "column": "B", "is": ">", "to": 5 }) -query_df.print() //after query +let sub_df = df.iloc({ rows: df["Count"].gt(10) }) +sub_df.print() ``` -{% endtab %} - -{% tab title="Browser" %} -```markup - - - - - - - Document - - - - - - +```javascript +let sub_df = df.iloc({ + rows: df["Count"].gt(10).and(df["Name"].eq("Apples")), + columns: [0] +}) +sub_df.print() - +//output +╔════════════╤═══════════════════╗ +║ │ Name ║ +╟────────────┼───────────────────╢ +║ 0 │ Apples ║ +╚════════════╧═══════════════════╝ ``` -{% endtab %} -{% endtabs %} - -```text -//before query -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 2 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 4 │ 5 │ 6 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 20 │ 30 │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 39 │ 89 │ 78 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -//after query -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 20 │ 30 │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 39 │ 89 │ 78 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -``` +#### Boolean Querying/Filtering -Selecting values from a DataFrame works on string columns: +The best way to query data is to use a boolean mask just as we demonstrated above with iloc and loc. For example, in the following code, we use a condition parameter to query the DataFrame: ```javascript -let data = [{"A": ["Ng", "Yu", "Mo", "Ng"]}, - {"B": [34, 4, 5, 6]}, - {"C": [20, 20, 30, 40]}] +let data = { + "A": ["Ng", "Yu", "Mo", "Ng"], + "B": [34, 4, 5, 6], + "C": [20, 20, 30, 40] +} let df = new dfd.DataFrame(data) -df.print() +let query_df = df.query(df["B"].gt(5)) +query_df.print() +``` -let query_df = df.query({ column: "A", is: "==", to: "Ng"}) -query_df.print() //after query +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Ng │ 34 │ 20 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ Ng │ 6 │ 40 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ Ng │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ Yu │ 4 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ Mo │ 5 │ 30 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ Ng │ 6 │ 40 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +Querying by a boolean condition is supported from v0.3.0 and above. It also supports condition chaining as long as the final boolean mask is the same lenght as the DataFrame rows. For example in the following code, we use multiple chaining conditions: -//after query +```javascript +let data = { + "A": ["Ng", "Yu", "Mo", "Ng"], + "B": [34, 4, 5, 6], + "C": [20, 20, 30, 40] +} +let query_df = df.query( df["B"].gt(5).and(df["C"].lt(0))) +query_df.print() //after query -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ Ng │ 34 │ 20 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ Ng │ 6 │ 40 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +//output +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ Ng │ 34 │ 20 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` #### Adding a new column @@ -1249,7 +1278,7 @@ let df = new dfd.DataFrame(data) df.print() let new_col = [1, 2, 3, 4] -df.addColumn({ "column": "D", "value": new_col }); //happens inplace +df.addColumn("D", new_col, { inplace: true }); //happens inplace df.print() ``` @@ -1264,7 +1293,7 @@ df.print() - Document + Document @@ -1280,7 +1309,7 @@ df.print() df.print() let new_col = [1, 2, 3, 4] - df.addColumn({ "column": "D", "value": new_col }); //happens inplace + df.addColumn({ "column": "D", "values": new_col, inplace: true }); //happens inplace df.print() @@ -1292,7 +1321,7 @@ df.print() {% endtab %} {% endtabs %} -```text +``` //before adding column ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ @@ -1309,37 +1338,37 @@ df.print() //after adding column Shape: (4,3) -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C │ D ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 30 │ 34 │ 20 │ 1 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 1 │ 4 │ 20 │ 2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 2 │ 5 │ 30 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 3 │ 6 │ 40 │ 4 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C │ D ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 30 │ 34 │ 20 │ 1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 1 │ 4 │ 20 │ 2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 2 │ 5 │ 30 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 3 │ 6 │ 40 │ 4 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` ### Missing data -danfo primarily uses the value **NaN** to represent missing data. It converts **undefined** type to **NaN** by default when creating DataFrames/Series with missing values. +**NaN, null,** and **undefined** represent missing data in Danfo.js. These values can be dropped or filled using some functions available in Danfo.js. -To drop any rows that have missing data: +To drop any columns that have missing data: {% tabs %} {% tab title="Node" %} ```javascript const dfd = require("danfojs-node") -let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, undefined, 78]] +let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, 20, 78]] let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) df.print() -let df_drop = df.dropna({axis: 0}) +let df_drop = df.dropNa({ axis: 0 }) df_drop.print() ``` {% endtab %} @@ -1353,7 +1382,7 @@ df_drop.print() - Document + Document @@ -1367,7 +1396,7 @@ df_drop.print() df.print() - let df_drop = df.dropna({axis: 0}) + let df_drop = df.dropNa({axis: 0}) df_drop.print() @@ -1378,74 +1407,74 @@ df_drop.print() {% endtab %} {% endtabs %} -```text -//Before dropping -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 2 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ NaN │ 5 │ 6 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ NaN │ 30 │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 39 │ NaN │ 78 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - - -//after droppping - Shape: (1,3) - -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 2 │ 3 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` - -To drop any columns with have missing data, set the axis to 1: +//Before dropping +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 2 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ NaN │ 5 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ NaN │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 39 │ 20 │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + + +//after dropping +╔════════════╤═══════════════════╤═══════════════════╗ +║ │ B │ C ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 0 │ 2 │ 3 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 1 │ 5 │ 6 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 2 │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────╢ +║ 3 │ 20 │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╝ +``` + +To drop row(s) with have missing data, set the axis to 1: ```javascript const dfd = require("danfojs-node") -let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, undefined, 78]] +let data = [[1, 2, 3], [NaN, 5, 6], [20, 30, 40], [39, 34, 78]] let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) df.print() -let df_drop = df.dropna({axis: 1}) +let df_drop = df.dropNa({ axis: 1 }) df_drop.print() ``` -```text +``` //Before dropping -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 1 │ 2 │ 3 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ NaN │ 5 │ 6 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ NaN │ 30 │ 40 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 39 │ NaN │ 78 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - - -//after droppping - -╔═══╤═══════════════════╗ -║ │ C ║ -╟───┼───────────────────╢ -║ 0 │ 3 ║ -╟───┼───────────────────╢ -║ 1 │ 6 ║ -╟───┼───────────────────╢ -║ 2 │ 40 ║ -╟───┼───────────────────╢ -║ 3 │ 78 ║ -╚═══╧═══════════════════╝ +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 2 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ NaN │ 5 │ 6 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 20 │ 30 │ 40 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 39 │ 34 │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ + + +//after dropping + +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 1 │ 2 │ 3 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 39 │ 20 │ 78 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` Filling missing data: @@ -1455,18 +1484,18 @@ const dfd = require("danfojs-node") let data = { - "Name": ["Apples", "Mango", "Banana", undefined], - "Count": [NaN, 5, NaN, 10], - "Price": [200, 300, 40, 250] - } + "Name": ["Apples", "Mango", "Banana", NaN], + "Count": [NaN, 5, NaN, 10], + "Price": [200, 300, 40, 250] + } let df = new dfd.DataFrame(data) -let df_filled = df.fillna({ values: ["Apples"] }) +let df_filled = df.fillNa("Apples") df_filled.print() ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -1485,18 +1514,20 @@ Filling missing values in specific columns with specific values: ```javascript const dfd = require("danfojs-node") -let data = {"Name":["Apples", "Mango", "Banana", undefined], - "Count": [NaN, 5, NaN, 10], - "Price": [200, 300, 40, 250]} +let data = { + "Name": ["Apples", "Mango", "Banana", NaN], + "Count": [NaN, 5, NaN, 10], + "Price": [200, 300, 40, 250] +} let df = new dfd.DataFrame(data) df.print() -let df_filled = df.fillna({columns: ["Name", "Count"], values: ["Apples", df["Count"].mean()]}) +let df_filled = df.fillNa(["Apples", df["Count"].mean()], { columns: ["Name", "Count"] }) df_filled.print() ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -1520,10 +1551,10 @@ let data = {"Name":["Apples", "Mango", "Banana", undefined], "Price": [200, 300, 40, 250]} let df = new dfd.DataFrame(data) -df.isna().print() +df.isNa().print() ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Name │ Count │ Price ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -1554,9 +1585,9 @@ data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]] cols = ["A", "B", "C"] -let df = new dfd.DataFrame(data) +let df = new dfd.DataFrame(data, { columns: cols }) df.print() -df.mean().print() //defaults to column axis +df.mean().print() //defaults to column (1) axis ``` {% endtab %} @@ -1569,7 +1600,7 @@ df.mean().print() //defaults to column axis - Document + Document @@ -1592,7 +1623,7 @@ df.mean().print() //defaults to column axis {% endtab %} {% endtabs %} -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ 0 │ 1 │ 2 ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -1605,15 +1636,15 @@ df.mean().print() //defaults to column axis ║ 3 │ 2 │ 89 │ 78 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 4 ║ -╟───┼──────────────────────╢ -║ 1 │ 38.5 ║ -╟───┼──────────────────────╢ -║ 2 │ 31.75 ║ -╚═══╧══════════════════════╝ +╔═══╤════════════════════╗ +║ 0 │ 11.333333333333334 ║ +╟───┼────────────────────╢ +║ 1 │ 7.333333333333333 ║ +╟───┼────────────────────╢ +║ 2 │ 24 ║ +╟───┼────────────────────╢ +║ 3 │ 56.333333333333336 ║ +╚═══╧════════════════════╝ ``` Same operation on the row axis: @@ -1627,10 +1658,10 @@ cols = ["A", "B", "C"] let df = new dfd.DataFrame(data) df.print() -df.mean(0).print() //row axis=0, column=1 +df.mean({ axis: 0 }).print() //row axis=0, column=1 ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ 0 │ 1 │ 2 ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -1643,20 +1674,16 @@ df.mean(0).print() //row axis=0, column=1 ║ 3 │ 2 │ 89 │ 78 ║ ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ 11.333333015441895 ║ -╟───┼──────────────────────╢ -║ 1 │ 7.333333492279053 ║ -╟───┼──────────────────────╢ -║ 2 │ 24 ║ -╟───┼──────────────────────╢ -║ 3 │ 56.33333206176758 ║ -╚═══╧══════════════════════╝ +╔═══╤═══════╗ +║ A │ 4 ║ +╟───┼───────╢ +║ B │ 38.5 ║ +╟───┼───────╢ +║ C │ 31.75 ║ +╚═══╧═══════╝ ``` -Operations on objects with different dimensionality and need alignment. danfo automatically broadcasts along the specified dimension. +Operations on objects with different dimensionality and need alignment. Danfo automatically broadcasts along the specified dimension. ```javascript const dfd = require("danfojs-node") @@ -1666,12 +1693,12 @@ let data = { "Col1": [1, 4, 5, 1], "Col2": [3, 2, 0, 4] } let df = new dfd.DataFrame(data) let sf = new dfd.Series([4, 5]) -let df_new = df.sub(sf, axis = 1) +let df_new = df.sub(sf, { axis: 1 }) df_new.print() ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ Col1 │ Col2 ║ ╟───┼───────────────────┼───────────────────╢ @@ -1687,7 +1714,7 @@ df_new.print() #### Apply -Applying JavaScript functions to the data: +Applying functions to the data along a specified axis. If axis = 1 (default), then the specified function (`callable)` will be called with each row data, and vice versa: ```javascript const dfd = require("danfojs") @@ -1696,15 +1723,15 @@ let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]] let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -function sum_vals(x) { - return x + 20 +function sum_vals(col) { + return col.reduce((a, b) => a + b, 0); } -let df_new = df.apply({callable: sum_vals }) +let df_new = df.apply(sum_vals, { axis: 1 }) df_new.print() ``` -```text +``` //before applying ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ @@ -1721,22 +1748,20 @@ df_new.print() //after applying -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ 21 │ 22 │ 23 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ 24 │ 25 │ 26 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ 40 │ 50 │ 60 ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ 59 │ 109 │ 98 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +╔═══╤═════╗ +║ 0 │ 6 ║ +╟───┼─────╢ +║ 1 │ 15 ║ +╟───┼─────╢ +║ 2 │ 90 ║ +╟───┼─────╢ +║ 3 │ 206 ║ +╚═══╧═════╝ ``` -Applying Tensorflow functions to the data: +Applying Element wise operations to the data: -You can call any compatible [Tensorflow](https://js.tensorflow.org/api/latest/) function on a DataFrame across a specified axis. For functions that operate _**element-wise**_ and returns the same shape as the original DataFrame, you must specify an axis of 0. +You can use the `applyMap` function if you need to apply a function to each element in the DataFrame. `applyMap` works element-wise. ```javascript const dfd = require("danfojs-node") @@ -1745,17 +1770,15 @@ let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]] let cols = ["A", "B", "C"] let df = new dfd.DataFrame(data, { columns: cols }) -df.print() - -function log_sig(x) { - return x.logSigmoid() +function sum_vals(x) { + return x + 10 } -let df_new = df.apply({axis: 0, callable: log_sig }) +let df_new = df.applyMap(sum_vals) df_new.print() ``` -```text +``` //before applying ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C ║ @@ -1770,34 +1793,34 @@ df_new.print() ╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ - //after applying + //after applyMap -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ A │ B │ C ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ -0.3132616579... │ -0.1269280463... │ -0.0485873296... ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ -0.0181499607... │ -0.0067153489... │ -0.0024756519... ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ -2.0611536921... │ -9.3576229122... │ -4.2483541311... ║ -╟───┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ -1.1548223864... │ -2.2273639090... │ -1.3336148713... ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝ +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ A │ B │ C ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ 11 │ 12 │ 13 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ 14 │ 15 │ 16 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ 30 │ 40 │ 50 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ 49 │ 99 │ 88 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` #### String Methods -Series is equipped with a set of string processing methods in the **str** attribute that make it easy to operate on each element of the array, as in the code snippet below. Note that pattern-matching in **str** generally uses JavaScript [regular expressions](https://docs.python.org/3/library/re.html) by default \(and in some cases always uses them\). +Series is equipped with a set of string processing methods in the **str** attribute that make it easy to operate on each element of the array, as in the code snippet below. Note that pattern-matching in **str** generally uses JavaScript [regular expressions](https://docs.python.org/3/library/re.html) by default (and in some cases always uses them). ```javascript const dfd = require("danfojs-node") -s = new dfd.Series(['A', 'B', 'C', 'Aaba', 'Baca', 'CABA', 'dog', 'cat']) -lower_s = s.str.toLowerCase() +let s = new dfd.Series(['A', 'B', 'C', 'Aaba', 'Baca', 'CABA', 'dog', 'cat']) +let lower_s = s.str.toLowerCase() lower_s.print() ``` -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -1846,25 +1869,25 @@ let df1 = new dfd.DataFrame(data, { columns: colum1 }) let df2 = new dfd.DataFrame(data2, { columns: colum2 }) -let com_df = dfd.concat({ df_list: [df1, df2], axis: 1 }) //along column axis +let com_df = dfd.concat({ dfList: [df1, df2], axis: 1 }) //along column axis com_df.print() ``` -```text -╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ -║ │ Key1 │ Key2 │ A │ ... │ Key1_2 │ Key2_2 │ A_2 │ D ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 0 │ K0 │ k0 │ A0 │ ... │ K0 │ k0 │ C0 │ D0 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 1 │ k0 │ K1 │ A1 │ ... │ K1 │ K0 │ C1 │ D1 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 2 │ K1 │ K0 │ A2 │ ... │ K1 │ K0 │ C2 │ D2 ║ -╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ -║ 3 │ K2 │ K2 │ A3 │ ... │ K2 │ K0 │ C3 │ D3 ║ -╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ +``` +╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ +║ │ Key1 │ Key2 │ A │ B │ Key11 │ Key21 │ A1 │ D ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 0 │ K0 │ k0 │ A0 │ B0 │ K0 │ k0 │ C0 │ D0 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 1 │ k0 │ K1 │ A1 │ B1 │ K1 │ K0 │ C1 │ D1 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 2 │ K1 │ K0 │ A2 │ B2 │ K1 │ K0 │ C2 │ D2 ║ +╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ +║ 3 │ K2 │ K2 │ A3 │ B3 │ K2 │ K0 │ C3 │ D3 ║ +╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝ ``` -Concatenate along row axis \(0\). +Concatenate along row axis (0). ```javascript const dfd = require("danfojs-node") @@ -1883,11 +1906,11 @@ let df1 = new dfd.DataFrame(data, { columns: colum1 }) let df2 = new dfd.DataFrame(data2, { columns: colum2 }) -let com_df = dfd.concat({ df_list: [df1, df2], axis: 0 }) //along row axis +let com_df = dfd.concat({ dfList: [df1, df2], axis: 0 }) //along row axis com_df.print() ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Key1 │ Key2 │ A │ B │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -1911,7 +1934,7 @@ com_df.print() #### Join -SQL style merges. See the Pandas [Database style joining](https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#merging-join) section for more info. +SQL style merges. See the Pandas [Database style joining](https://pandas.pydata.org/pandas-docs/stable/user\_guide/merging.html#merging-join) section for more info. ```javascript const dfd = require("danfojs-node") @@ -1930,11 +1953,11 @@ let df2 = new dfd.DataFrame(data2, { columns: colum2 }) df1.print() df2.print() -let merge_df = dfd.merge({ "left": df1, "right": df2, "on": ["Key1"]}) +let merge_df = dfd.merge({ "left": df1, "right": df2, "on": ["Key1"], how: "inner" }) merge_df.print() ``` -```text +``` //first DataFrame ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ Key1 │ Key2 │ A │ B ║ @@ -2007,12 +2030,12 @@ let df = new dfd.DataFrame(data) let grp = df.groupby(["A"]) -grp.get_groups(["foo"]).print() +grp.getGroup(["foo"]).print() -grp.get_groups(["bar"]).print() +grp.getGroup(["bar"]).print() ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C │ D ║ ╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢ @@ -2046,22 +2069,20 @@ Grouping and then applying the[`sum()`](api-reference/groupby/groupby.sum.md) fu ```javascript const dfd = require("danfojs-node") -let data ={'A': ['foo', 'bar', 'foo', 'bar', - 'foo', 'bar', 'foo', 'foo'], - 'B': ['one', 'one', 'two', 'three', - 'two', 'two', 'one', 'three'], - 'C': [1,3,2,4,5,2,6,7], - 'D': [3,2,4,1,5,6,7,8] - } - -let df = new dfd.DataFrame(data) +let data = { + A: ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"], + B: ["one", "one", "two", "three", "two", "two", "one", "three"], + C: [1, 3, 2, 4, 5, 2, 6, 7], + D: [3, 2, 4, 1, 5, 6, 7, 8], +}; +let df = new dfd.DataFrame(data); -let grp = df.groupby(["A"]) -grp.col(["C"]).sum().print() +let grp = df.groupby(["A"]); +grp.col(["C"]).sum().print(); ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╗ ║ │ A │ C_sum ║ ╟───┼───────────────────┼───────────────────╢ @@ -2091,7 +2112,7 @@ let grp = df.groupby(["A","B"]) grp.col(["C"]).sum().print() ``` -```text +``` ╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗ ║ │ A │ B │ C_sum ║ ╟───┼───────────────────┼───────────────────┼───────────────────╢ @@ -2116,15 +2137,15 @@ danfo provides a simple but powerful, and efficient functionality for working wi ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":'2018-01', freq:'M', period:3}) +let data = new dfd.dateRange({"start":'2018-01', freq:'M', period:3}) let sf = new dfd.Series(data) //print series sf.print() //print month names -sf.dt.month_name().print() +sf.dt.monthName().print() ``` -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -2135,15 +2156,13 @@ sf.dt.month_name().print() ║ 2 │ 3/1/2018, 1:00:00 AM ║ ╚═══╧══════════════════════╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ Jan ║ -╟───┼──────────────────────╢ -║ 1 │ Feb ║ -╟───┼──────────────────────╢ -║ 2 │ Mar ║ -╚═══╧══════════════════════╝ +╔═══╤══════════╗ +║ 0 │ January ║ +╟───┼──────────╢ +║ 1 │ February ║ +╟───┼──────────╢ +║ 2 │ March ║ +╚═══╧══════════╝ ``` More Examples: @@ -2151,15 +2170,15 @@ More Examples: ```javascript const dfd = require("danfojs-node") -let data = new dfd.date_range({"start":'2018-01', freq:'M', period:3}) +let data = new dfd.dateRange({"start":'2018-01', freq:'M', period:3}) let sf = new dfd.Series(data) //print series sf.print() -//print month names -sf.dt.weekdays().print() +//print week day names +sf.dt.dayOfWeekName().print() ``` -```text +``` ╔═══╤══════════════════════╗ ║ │ 0 ║ ╟───┼──────────────────────╢ @@ -2170,24 +2189,22 @@ sf.dt.weekdays().print() ║ 2 │ 3/1/2018, 1:00:00 AM ║ ╚═══╧══════════════════════╝ -╔═══╤══════════════════════╗ -║ │ 0 ║ -╟───┼──────────────────────╢ -║ 0 │ Mon ║ -╟───┼──────────────────────╢ -║ 1 │ Thu ║ -╟───┼──────────────────────╢ -║ 2 │ Thu ║ -╚═══╧════════════════════ +╔═══╤══════════╗ +║ 0 │ Monday ║ +╟───┼──────────╢ +║ 1 │ Thursday ║ +╟───┼──────────╢ +║ 2 │ Thursday ║ +╚═══╧══════════╝ ``` ### Plotting See the [Plotting](api-reference/plotting/) docs. -We use [Plotly.js](https://plotly.com/javascript/) as our backend for plotting. This gives you the ability to make interactive plots from DataFrame and Series. Plotting only works in the browser version of danfo.js, and requires an HTML div to show plots. +We currently support [Plotly.js](https://plotly.com/javascript/) for plotting. In the future, we plan other JS plotting libraries like Vega, D3. -**Update**: As of `v0.2.3`, we stopped bundling Danfojs with Plotly. This has greatly reduced bundle size by about 80%. See more details in the release notes here. In order to make Plots, you must explicitly add the Plotly CDN to your file as we show in the updated examples: +Using the `plot` API, you can make interactive plots from DataFrame and Series. Plotting only works in the browser/client-side version of Danfo.js, and requires an HTML div to display plots. ```markup @@ -2196,8 +2213,7 @@ We use [Plotly.js](https://plotly.com/javascript/) as our backend for plotting. - - + Document @@ -2206,25 +2222,30 @@ We use [Plotly.js](https://plotly.com/javascript/) as our backend for plotting.
@@ -2232,7 +2253,7 @@ We use [Plotly.js](https://plotly.com/javascript/) as our backend for plotting. ``` -![](.gitbook/assets/newplot-29-%20%281%29.png) +![](<.gitbook/assets/newplot-29- (2) (1).png>) On a DataFrame, the [`plot()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.html#pandas.DataFrame.plot)method exposes various [plot types](api-reference/plotting/). And by default, all columns are plotted unless specified otherwise. @@ -2244,7 +2265,7 @@ On a DataFrame, the [`plot()`](https://pandas.pydata.org/pandas-docs/stable/refe - + Document @@ -2263,54 +2284,63 @@ On a DataFrame, the [`plot()`](https://pandas.pydata.org/pandas-docs/stable/refe ``` -![](.gitbook/assets/newplot-2-.png) +![](<.gitbook/assets/newplot-2- (1) (1).png>) ### Getting data in/out #### CSV -[Writing to a csv file.](api-reference/dataframe/dataframe.to_csv.md) +[Writing to a CSV file.](api-reference/dataframe/dataframe.to\_csv.md) Convert any DataFrame to csv format. +In NodeJs, if a file path is specified, then the CSV is saved to the path, else it is returned as a string. + +In the browser, you can automatically download the file as CSV by setting the `download` paramater to `true`. + ```javascript const dfd = require("danfojs-node") - let data = { - "Abs": [20.2, 30, 47.3], - "Count": [34, 4, 5], - "country code": ["NG", "FR", "GH"] - } + "Abs": [20.2, 30, 47.3], + "Count": [34, 4, 5], + "country code": ["NG", "FR", "GH"] +} let df = new dfd.DataFrame(data) -df.to_csv().then((csv) => { - console.log(csv); +const csv = dfd.toCSV(df) +console.log(csv); +//output +Abs,Count,country code +20.2,34,NG +30,4,FR +47.3,5,GH + -}).catch((err) => { +dfd.toCSV(df, {filePath: "testOut.csv" }) //writes to file system in Nodejs - console.log(err); -}) + +dfd.toCSV(df, {fileName: "testOut", download: true }) //downloads the file in browser version ``` -```text +``` Abs,Count,country code 20.2,34,NG 30,4,FR 47.3,5,GH ``` -[Reading from a CSV file.](https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#io-read-csv-table) +[Reading from a CSV file.](https://pandas.pydata.org/pandas-docs/stable/user\_guide/io.html#io-read-csv-table) -The **read\_csv** method can read CSV file from local disk, or over the internet. If the file is to be read from a local disk in Node environment, you have to prefix the full path name with a "**file://**" prefix. For instance, to read a CSV file at the path **/home/Desktop/titanic.csv**, you can do the following: +The **readCSV** method can read CSV files from local disk, or over the internet. Both full and relative paths are supported. For example, to read a CSV file at the path **/home/Desktop/titanic.csv**, you can do the following: {% tabs %} {% tab title="JavaScript" %} ```javascript const dfd = require("danfojs") -dfd.read_csv("file:///home/Desktop/titanic.csv") +dfd.readCSV("/home/Desktop/titanic.csv") .then(df => { //do something with the CSV file @@ -2330,7 +2360,7 @@ dfd.read_csv("file:///home/Desktop/titanic.csv") - + Document @@ -2338,7 +2368,7 @@ dfd.read_csv("file:///home/Desktop/titanic.csv") - + Document @@ -75,22 +224,22 @@ A simple example: }) - + ``` -### Release [ \(v0.2.2\)](https://github.com/opensource9ja/danfojs/releases/tag/v0.2.2) +### Release [(v0.2.2)](https://github.com/opensource9ja/danfojs/releases/tag/v0.2.2) **Date:** 14th February 2021 We added/updated the following features: -* Fix babel runtime issue in node version -* Smaller size in browser version in this version. From ~8mb to about ~5mb +* Fix babel runtime issue in node version +* Smaller size in browser version in this version. From \~8mb to about \~5mb * Fix browser tag issue and returns back to specific versioning instead of @latest -* Danfojs now ships with an exported version of tensorflowjs-node \(2.8.5\). This fixes the double dependency issue when building ML models, as you no longer need to install/import tensorflowjs separately. +* Danfojs now ships with an exported version of tensorflowjs-node (2.8.5). This fixes the double dependency issue when building ML models, as you no longer need to install/import tensorflowjs separately. To use tensoflowjs-node, you can reference it from danfo as shown below: @@ -104,24 +253,24 @@ model.add(tf.layers.dense({ units: 64, activation: 'relu' })); model.summary(); ``` -### Release \(v0.1.5\) +### Release (v0.1.5) **Date:** 25th September 2020 We added/updated the following features: -* [Read JSON](api-reference/input-output/danfo.read_json.md) files from local and remote URL into DataFrame \(New feature\) -* [Read Excel](api-reference/input-output/danfo.read_excel.md) files from local or remote URL into DataFrame \(New feature\) -* Fix string comparison bug in [query](api-reference/dataframe/danfo.dataframe.query.md) function \(Fix\) -* Add append function for [DataFrame](api-reference/dataframe/dataframe.append.md) and [Series](api-reference/series/series.append.md) \(New feature\) -* Fix null value bug when creating DataFrame from JSON files \(Fix\) +* [Read JSON](api-reference/input-output/danfo.read\_json.md) files from local and remote URL into DataFrame (New feature) +* [Read Excel](api-reference/input-output/danfo.read\_excel.md) files from local or remote URL into DataFrame (New feature) +* Fix string comparison bug in [query](api-reference/dataframe/danfo.dataframe.query.md) function (Fix) +* Add append function for [DataFrame](api-reference/dataframe/dataframe.append.md) and [Series](api-reference/series/series.append.md) (New feature) +* Fix null value bug when creating DataFrame from JSON files (Fix) * Add relative import for reading files into DataFrame -* Add [sort\_index](api-reference/dataframe/dataframe.sort_index.md) function to DataFrame and Series \(New feature\) -* Minor patch and overall optimizations \(Fix\) +* Add [sort\_index](api-reference/dataframe/dataframe.sort\_index.md) function to DataFrame and Series (New feature) +* Minor patch and overall optimizations (Fix) -**Contributors**: [Rising Odegua](https://github.com/risenW), [Stephen Oni](https://github.com/steveoni), [Jhenner Tigreros](https://github.com/JhennerTigreros), [Aditya Zope](https://github.com/adzo261) +**Contributors**: [Rising Odegua](https://github.com/risenW), [Stephen Oni](https://github.com/steveoni), [Jhenner Tigreros](https://github.com/JhennerTigreros), [Aditya Zope](https://github.com/adzo261) -### Release \(v0.1.0-beta\) +### Release (v0.1.0-beta) **Date:** 15th August 2020 @@ -136,6 +285,3 @@ This is a minor release for browser-based environments. We added/updated the fol * Fixed upper bound bug in indexing **Contributors**: Rising Odegua, Stephen Oni - - -