Skip to content

Commit 8d2051d

Browse files
risenWgitbook-bot
authored andcommitted
GitBook: [master] 12 pages modified
1 parent 1350eed commit 8d2051d

12 files changed

+1507
-268
lines changed

api-reference/dataframe/danfo.dataframe.add.md

+175-7
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,189 @@ description: 'Get Addition of DataFrame and other, element-wise (binary operator
44

55
# DataFrame.add
66

7-
Equivalent to `dataframe + other`, but with support to substitute a fill\_value for missing data in one of the inputs. With reverse version, radd.
7+
danfo.DataFrame.**add**\(axis\) \[[source](https://github.com/opensource9ja/danfojs/blob/fe56860b0a303d218d60ba71dee6abf594401556/danfojs/src/core/frame.js#L347)\]
88

9-
Among flexible wrappers \(add, sub, mul, div, mod, pow\) to arithmetic operators: +, -, \*, /, //, %, \*\*.
9+
| Parameters | Type | Description | Default |
10+
| :--- | :--- | :--- | :--- |
11+
| other | DataFrame, Series, Array or Scalar | Object to modulo with | |
12+
| axis | Int | 0 for row, 1 for column | 0 |
1013

11-
**parameter:** {other} DataFrame, Series, Array or Number to add
14+
**Returns:**
1215

13-
**return:** {DataFrame}
16+
****return **DataFrame**
1417

18+
## **Examples**
19+
20+
### Addition of **scalar to** DataFrame:
21+
22+
{% tabs %}
23+
{% tab title="Node" %}
24+
```javascript
25+
const dfd = require("danfojs")
26+
27+
let data = [{"Col1": [10, 45, 56, 10]}, {"Col2": [23, 20, 10, 24]}]
28+
let df = new dfd.DataFrame(data)
29+
30+
let df_new = df.add(2)
31+
32+
df_new.print()
33+
```
34+
{% endtab %}
35+
36+
{% tab title="Browser" %}
37+
```
38+
39+
```
40+
{% endtab %}
41+
{% endtabs %}
42+
43+
{% tabs %}
44+
{% tab title="Output" %}
45+
```text
46+
╔═══╤═══════════════════╤═══════════════════╗
47+
║ │ Col1 │ Col2 ║
48+
╟───┼───────────────────┼───────────────────╢
49+
║ 0 │ 12 │ 25 ║
50+
╟───┼───────────────────┼───────────────────╢
51+
║ 1 │ 47 │ 22 ║
52+
╟───┼───────────────────┼───────────────────╢
53+
║ 2 │ 58 │ 12 ║
54+
╟───┼───────────────────┼───────────────────╢
55+
║ 3 │ 12 │ 26 ║
56+
╚═══╧═══════════════════╧═══════════════════╝
57+
```
58+
{% endtab %}
59+
{% endtabs %}
60+
61+
### Addition of **Series to** DataFrame along the column axis:
62+
63+
{% tabs %}
64+
{% tab title="Node" %}
1565
```javascript
16-
let data = [[0, 2, 4], [360, 180, 360]]
17-
let df = new DataFrame(data)
18-
df.add(2)
66+
const dfd = require("danfojs")
67+
68+
69+
let data = [{ "Col1": [1, 4, 5, 1] }, { "Col2": [3, 2, 0, 4] }]
70+
let df = new dfd.DataFrame(data)
71+
let sf = new dfd.Series([4, 5])
72+
73+
let df_new = df.add(sf, axis = 1)
74+
75+
df_new.print()
1976
```
77+
{% endtab %}
2078

79+
{% tab title="Browser" %}
80+
```
2181
82+
```
83+
{% endtab %}
84+
{% endtabs %}
85+
86+
{% tabs %}
87+
{% tab title="Output" %}
88+
```text
89+
╔═══╤═══════════════════╤═══════════════════╗
90+
║ │ Col1 │ Col2 ║
91+
╟───┼───────────────────┼───────────────────╢
92+
║ 0 │ 5 │ 8 ║
93+
╟───┼───────────────────┼───────────────────╢
94+
║ 1 │ 8 │ 7 ║
95+
╟───┼───────────────────┼───────────────────╢
96+
║ 2 │ 9 │ 5 ║
97+
╟───┼───────────────────┼───────────────────╢
98+
║ 3 │ 5 │ 9 ║
99+
╚═══╧═══════════════════╧═══════════════════╝
100+
```
101+
{% endtab %}
102+
{% endtabs %}
103+
104+
### Addition of ****DataFrame to a DataFrame
105+
106+
{% tabs %}
107+
{% tab title="Node" %}
108+
```javascript
109+
const dfd = require("danfojs")
110+
111+
let data = [{"Col1": [1, 4, 5, 0]}, {"Col2": [2, 0, 1, 4]}]
112+
let data2 = [{"new_col1": [1, 5, 20, 10]}, {"new_Col2": [20, 2, 1, 2]}]
113+
114+
let df = new dfd.DataFrame(data)
115+
let df2 = new dfd.DataFrame(data2)
116+
117+
let df_new = df.add(df2)
118+
119+
df_new.print()
120+
121+
```
122+
{% endtab %}
123+
124+
{% tab title="Browser" %}
125+
```
126+
127+
```
128+
{% endtab %}
129+
{% endtabs %}
130+
131+
{% tabs %}
132+
{% tab title="Output" %}
133+
```text
134+
╔═══╤═══════════════════╤═══════════════════╗
135+
║ │ Col1 │ Col2 ║
136+
╟───┼───────────────────┼───────────────────╢
137+
║ 0 │ 2 │ 22 ║
138+
╟───┼───────────────────┼───────────────────╢
139+
║ 1 │ 9 │ 2 ║
140+
╟───┼───────────────────┼───────────────────╢
141+
║ 2 │ 25 │ 2 ║
142+
╟───┼───────────────────┼───────────────────╢
143+
║ 3 │ 10 │ 6 ║
144+
╚═══╧═══════════════════╧═══════════════════╝
145+
```
146+
{% endtab %}
147+
{% endtabs %}
148+
149+
### Addition of ****JavaScript Array to DataFrame
150+
151+
{% tabs %}
152+
{% tab title="Node" %}
153+
```javascript
154+
const dfd = require("danfojs")
155+
156+
let data = [{"Col1": [10, 45, 56, 10]}, {"Col2": [23, 20, 10, 24]}]
157+
let df = new dfd.DataFrame(data)
158+
let val = [2,2]
159+
160+
let df_new = df.add(val, axis=1)
161+
162+
df_new.print()
163+
```
164+
{% endtab %}
165+
166+
{% tab title="Browser" %}
167+
```
168+
169+
```
170+
{% endtab %}
171+
{% endtabs %}
172+
173+
{% tabs %}
174+
{% tab title="Output" %}
175+
```text
176+
╔═══╤═══════════════════╤═══════════════════╗
177+
║ │ Col1 │ Col2 ║
178+
╟───┼───────────────────┼───────────────────╢
179+
║ 0 │ 12 │ 25 ║
180+
╟───┼───────────────────┼───────────────────╢
181+
║ 1 │ 47 │ 22 ║
182+
╟───┼───────────────────┼───────────────────╢
183+
║ 2 │ 58 │ 12 ║
184+
╟───┼───────────────────┼───────────────────╢
185+
║ 3 │ 12 │ 26 ║
186+
╚═══╧═══════════════════╧═══════════════════╝
187+
```
188+
{% endtab %}
189+
{% endtabs %}
22190

23191

24192

0 commit comments

Comments
 (0)