You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
4.[loading a built-in dataset](#4-loading-the-built-in-datasets)
85
+
[1. from an array of rows or columns](#1-creating-dataframe-from-an-array-of-rows-or-columns)
86
+
[2. from matrix](#2-creating-dataframe-from-a-matrix)
87
+
[3. from file](#3-reading-data-from-file)
88
+
[4. loading a built-in dataset](#4-loading-the-built-in-datasets)
89
89
90
90
#### 1. Creating DataFrame from an array of rows or columns
91
91
The easiest and most straightforward way of creating a DataFrame is by passing all data in an array of arrays to `fromRows:` or `fromColumns:` message. Here is an example of initializing a DataFrame with rows:
@@ -194,6 +194,34 @@ df rowsFrom: 3 to: 1.
194
194
195
195
The result will be a data frame with requested rows and columns in a given order. For example, the last line will give you a data frame "flipped upside-down" (with row indexes going in the descending order).
196
196
197
+
You can change the values of a specific row or column by passing an array or series of the same size to one of the messages: `row:put:`, `column:put:`, `rowAt:put:`, `columnAt:put:`. Be careful though, because these messages modify the data frame and may result in the loss of data.
198
+
199
+
```smalltalk
200
+
df column: #BeenThere put: #(false true false).
201
+
```
202
+
203
+
As it was mentioned above, single cell of a data frame can be accessed with `at:at:` and `at:at:put:` messages
204
+
205
+
```smalltalk
206
+
df at: 3 at: 2.
207
+
df at: 3 at: 2 put: true.
208
+
```
209
+
210
+
### Adding new rows and columns to DataFrame
211
+
New rows and columns can be appended to the data frame using messages `addRow:named` and `addColumn:named`. Like in the case of DataSeries, you must provide a name for these new elements, since it can not continue the existing sequence of names.
212
+
213
+
```smalltalk
214
+
df addRow: #('Lviv' 0.724 true) named: #D.
215
+
df addColumn: #(4 3 4) named: #Rating.
216
+
```
217
+
218
+
The same can be done using messages `row:put:` and `column:put:` with non-existing keys. DataFrame will append the new key and associate it with a given row or column
219
+
220
+
```smalltalk
221
+
df at: #D put: #('Lviv' 0.724 true).
222
+
df at: #Rating put: #(4 3 4).
223
+
```
224
+
197
225
#### Head & tail
198
226
Now let's take a look at some bigger dataset, for example, Boston Housing Data
0 commit comments