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.
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 + + + + + + + +{
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- {column : str, name of the column to add -value: Series, Array. New values to add } - |
- - |
| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- {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 | -
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- {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} - |
-
| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- {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. -} - |
- - |
{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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- { -rows: Array, index of row position -columns: Array, index of position along columns -} - |
- - |
{
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- { -rows: Array, labels of row index -columns: Array, labels of column names -} - |
- - |
{
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- {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} | -
{
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- {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. -} - |
- - |
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- { -column: Array, label/column name of column to cast -dtype: dtype to cast to. One of [string, float32, int32] -} - |
- - |
{
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- { -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} | -
{
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- { -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} | -
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- { -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} | -
{
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- { -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} | -
{
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| kwargs | -Object | -
- { -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} | -
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: ","
}
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"
}
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"
}
| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| 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} | -
{
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)\] - -| Parameters | -Type | -Description | -Default | -
|---|---|---|---|
| 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'} | -
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);