dataframe-js
Version:
Immutable and functional data structure for datascientists and developpers
1,927 lines (1,187 loc) • 45.7 kB
Markdown
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
- [DataFrame][1]
- [Parameters][2]
- [toDSV][3]
- [Parameters][4]
- [Examples][5]
- [toCSV][6]
- [Parameters][7]
- [Examples][8]
- [toTSV][9]
- [Parameters][10]
- [Examples][11]
- [toPSV][12]
- [Parameters][13]
- [Examples][14]
- [toText][15]
- [Parameters][16]
- [Examples][17]
- [toJSON][18]
- [Parameters][19]
- [Examples][20]
- [toDict][21]
- [Examples][22]
- [toArray][23]
- [Parameters][24]
- [Examples][25]
- [toCollection][26]
- [Parameters][27]
- [Examples][28]
- [show][29]
- [Parameters][30]
- [Examples][31]
- [dim][32]
- [Examples][33]
- [transpose][34]
- [Parameters][35]
- [Examples][36]
- [count][37]
- [Examples][38]
- [countValue][39]
- [Parameters][40]
- [Examples][41]
- [push][42]
- [Parameters][43]
- [Examples][44]
- [replace][45]
- [Parameters][46]
- [Examples][47]
- [distinct][48]
- [Parameters][49]
- [Examples][50]
- [unique][51]
- [Parameters][52]
- [Examples][53]
- [listColumns][54]
- [Examples][55]
- [select][56]
- [Parameters][57]
- [Examples][58]
- [withColumn][59]
- [Parameters][60]
- [Examples][61]
- [restructure][62]
- [Parameters][63]
- [Examples][64]
- [renameAll][65]
- [Parameters][66]
- [Examples][67]
- [rename][68]
- [Parameters][69]
- [Examples][70]
- [castAll][71]
- [Parameters][72]
- [Examples][73]
- [cast][74]
- [Parameters][75]
- [Examples][76]
- [drop][77]
- [Parameters][78]
- [Examples][79]
- [chain][80]
- [Parameters][81]
- [Examples][82]
- [filter][83]
- [Parameters][84]
- [Examples][85]
- [where][86]
- [Parameters][87]
- [Examples][88]
- [find][89]
- [Parameters][90]
- [Examples][91]
- [map][92]
- [Parameters][93]
- [Examples][94]
- [reduce][95]
- [Parameters][96]
- [Examples][97]
- [reduceRight][98]
- [Parameters][99]
- [Examples][100]
- [dropDuplicates][101]
- [Parameters][102]
- [Examples][103]
- [dropMissingValues][104]
- [Parameters][105]
- [Examples][106]
- [fillMissingValues][107]
- [Parameters][108]
- [Examples][109]
- [shuffle][110]
- [Examples][111]
- [sample][112]
- [Parameters][113]
- [Examples][114]
- [bisect][115]
- [Parameters][116]
- [Examples][117]
- [groupBy][118]
- [Parameters][119]
- [Examples][120]
- [sortBy][121]
- [Parameters][122]
- [Examples][123]
- [union][124]
- [Parameters][125]
- [Examples][126]
- [join][127]
- [Parameters][128]
- [Examples][129]
- [innerJoin][130]
- [Parameters][131]
- [Examples][132]
- [fullJoin][133]
- [Parameters][134]
- [Examples][135]
- [outerJoin][136]
- [Parameters][137]
- [Examples][138]
- [leftJoin][139]
- [Parameters][140]
- [Examples][141]
- [rightJoin][142]
- [Parameters][143]
- [Examples][144]
- [diff][145]
- [Parameters][146]
- [Examples][147]
- [head][148]
- [Parameters][149]
- [Examples][150]
- [tail][151]
- [Parameters][152]
- [Examples][153]
- [slice][154]
- [Parameters][155]
- [Examples][156]
- [getRow][157]
- [Parameters][158]
- [Examples][159]
- [setRow][160]
- [Parameters][161]
- [Examples][162]
- [setDefaultModules][163]
- [Parameters][164]
- [Examples][165]
- [fromDSV][166]
- [Parameters][167]
- [Examples][168]
- [fromText][169]
- [Parameters][170]
- [Examples][171]
- [fromCSV][172]
- [Parameters][173]
- [Examples][174]
- [fromTSV][175]
- [Parameters][176]
- [Examples][177]
- [fromPSV][178]
- [Parameters][179]
- [Examples][180]
- [fromJSON][181]
- [Parameters][182]
- [Examples][183]
## DataFrame
[src/dataframe.js:11-1246][184]
DataFrame data structure providing an immutable, flexible and powerfull way to manipulate data with columns and rows.
### Parameters
- `data` **([Array][185] \| [Object][186] \| [DataFrame][187])** The data of the DataFrame.
- `columns` **[Array][185]** The DataFrame column names.
- `options` **[Object][186]** Additional options. Example: modules. (optional, default `{}`)
### toDSV
[src/dataframe.js:314-316][188]
Convert the DataFrame into a text delimiter separated values. You can also save the file if you are using nodejs.
#### Parameters
- `args` **...any**
- `sep` **[String][189]** Column separator. (optional, default `' '`)
- `header` **[Boolean][190]** Writing the header in the first line. If false, there will be no header. (optional, default `true`)
- `path` **[String][189]?** The path to save the file. /!\\ Works only on node.js, not into the browser.
#### Examples
```javascript
df.toDSV()
df.toDSV(';')
df.toDSV(';', true)
// From node.js only
df.toDSV(';', true, '/my/absolute/path/dataframe.txt')
```
Returns **[String][189]** The text file in raw string.
### toCSV
[src/dataframe.js:329-331][191]
Convert the DataFrame into a comma separated values string. You can also save the file if you are using nodejs.
#### Parameters
- `args` **...any**
- `header` **[Boolean][190]** Writing the header in the first line. If false, there will be no header. (optional, default `true`)
- `path` **[String][189]?** The path to save the file. /!\\ Works only on node.js, not into the browser.
#### Examples
```javascript
df.toCSV()
df.toCSV(true)
// From node.js only
df.toCSV(true, '/my/absolute/path/dataframe.csv')
```
Returns **[String][189]** The csv file in raw string.
### toTSV
[src/dataframe.js:344-346][192]
Convert the DataFrame into a tab separated values string. You can also save the file if you are using nodejs.
#### Parameters
- `args` **...any**
- `header` **[Boolean][190]** Writing the header in the first line. If false, there will be no header. (optional, default `true`)
- `path` **[String][189]?** The path to save the file. /!\\ Works only on node.js, not into the browser.
#### Examples
```javascript
df.toCSV()
df.toCSV(true)
// From node.js only
df.toCSV(true, '/my/absolute/path/dataframe.csv')
```
Returns **[String][189]** The csv file in raw string.
### toPSV
[src/dataframe.js:359-361][193]
Convert the DataFrame into a pipe separated values string. You can also save the file if you are using nodejs.
#### Parameters
- `args` **...any**
- `header` **[Boolean][190]** Writing the header in the first line. If false, there will be no header. (optional, default `true`)
- `path` **[String][189]?** The path to save the file. /!\\ Works only on node.js, not into the browser.
#### Examples
```javascript
df.toPSV()
df.toPSV(true)
// From node.js only
df.toPSV(true, '/my/absolute/path/dataframe.csv')
```
Returns **[String][189]** The csv file in raw string.
### toText
[src/dataframe.js:376-378][194]
Convert the DataFrame into a text delimiter separated values. Alias for .toDSV. You can also save the file if you are using nodejs.
#### Parameters
- `args` **...any**
- `sep` **[String][189]** Column separator. (optional, default `' '`)
- `header` **[Boolean][190]** Writing the header in the first line. If false, there will be no header. (optional, default `true`)
- `path` **[String][189]?** The path to save the file. /!\\ Works only on node.js, not into the browser.
#### Examples
```javascript
df.toText()
df.toText(';')
df.toText(';', true)
// From node.js only
df.toText(';', true, '/my/absolute/path/dataframe.txt')
```
Returns **[String][189]** The text file in raw string.
### toJSON
[src/dataframe.js:390-392][195]
Convert the DataFrame into a json string. You can also save the file if you are using nodejs.
#### Parameters
- `args` **...any**
- `asCollection` **[Boolean][190]** Writing the JSON as collection of Object. (optional, default `false`)
- `path` **[String][189]?** The path to save the file. /!\\ Works only on node.js, not into the browser.
#### Examples
```javascript
df.toJSON()
// From node.js only
df.toJSON('/my/absolute/path/dataframe.json')
```
Returns **[String][189]** The json file in raw string.
### toDict
[src/dataframe.js:400-407][196]
Convert DataFrame into dict / hash / object.
#### Examples
```javascript
df.toDict()
```
Returns **[Object][186]** The DataFrame converted into dict.
### toArray
[src/dataframe.js:416-420][197]
Convert DataFrame into Array of Arrays. You can also extract only one column as Array.
#### Parameters
- `columnName` **[String][189]?** Column Name to extract. By default, all columns are transformed.
#### Examples
```javascript
df.toArray()
```
Returns **[Array][185]** The DataFrame (or the column) converted into Array.
### toCollection
[src/dataframe.js:429-433][198]
Convert DataFrame into Array of dictionnaries. You can also return Rows instead of dictionnaries.
#### Parameters
- `ofRows` **[Boolean][190]?** Return a collection of Rows instead of dictionnaries.
#### Examples
```javascript
df.toCollection()
```
Returns **[Array][185]** The DataFrame converted into Array of dictionnaries (or Rows).
### show
[src/dataframe.js:445-474][199]
Display the DataFrame as String Table. Can only return a sring instead of displaying the DataFrame.
#### Parameters
- `rows` **[Number][200]** The number of lines to display. (optional, default `10`)
- `quiet` **[Boolean][190]** Quiet mode. If true, only returns a string instead of console.log(). (optional, default `false`)
#### Examples
```javascript
df.show()
df.show(10)
const stringDF = df.show(10, true)
```
Returns **[String][189]** The DataFrame as String Table.
### dim
[src/dataframe.js:482-484][201]
Get the DataFrame dimensions.
#### Examples
```javascript
const [height, width] = df.dim()
```
Returns **[Array][185]** The DataFrame dimensions. [height, width]
### transpose
[src/dataframe.js:493-508][202]
Transpose a DataFrame. Rows become columns and conversely. n x p => p x n.
#### Parameters
- `tranposeColumnNames`
- `transposeColumnNames` **[Boolean][190]** An option to transpose columnNames in a rowNames column. (optional, default `false`)
#### Examples
```javascript
df.transpose()
```
Returns **ÐataFrame** A new transposed DataFrame.
### count
[src/dataframe.js:516-518][203]
Get the rows number.
#### Examples
```javascript
df.count()
```
Returns **Int** The number of DataFrame rows.
### countValue
[src/dataframe.js:529-533][204]
Get the count of a value into a column.
#### Parameters
- `valueToCount` The value to count into the selected column.
- `columnName` **[String][189]** The column to count the value. (optional, default `this.listColumns()[0]`)
#### Examples
```javascript
df.countValue(5, 'column2')
df.select('column1').countValue(5)
```
Returns **Int** The number of times the selected value appears.
### push
[src/dataframe.js:542-544][205]
Push new rows into the DataFrame.
#### Parameters
- `rows` **([Array][185] | Row)** The rows to add.
#### Examples
```javascript
df.push([1,2,3], [1,4,9])
```
Returns **[DataFrame][187]** A new DataFrame with the new rows.
### replace
[src/dataframe.js:555-568][206]
Replace a value by another in all the DataFrame or in a column.
#### Parameters
- `value` The value to replace.
- `replacement` The new value.
- `columnNames` **([String][189] \| [Array][185])** The columns to apply the replacement. (optional, default `this.listColumns()`)
#### Examples
```javascript
df.replace(undefined, 0, 'column1', 'column2')
```
Returns **[DataFrame][187]** A new DataFrame with replaced values.
### distinct
[src/dataframe.js:577-582][207]
Compute unique values into a column.
#### Parameters
- `columnName` **[String][189]** The column to distinct.
#### Examples
```javascript
df.distinct('column1')
```
Returns **[DataFrame][187]** A DataFrame containing the column with distinct values.
### unique
[src/dataframe.js:592-594][208]
Compute unique values into a column.
Alias from .distinct()
#### Parameters
- `columnName` **[String][189]** The column to distinct.
#### Examples
```javascript
df.unique('column1')
```
Returns **[DataFrame][187]** A DataFrame containing the column with distinct values.
### listColumns
[src/dataframe.js:602-604][209]
List DataFrame columns.
#### Examples
```javascript
df.listColumns()
```
Returns **[Array][185]** An Array containing DataFrame columnNames.
### select
[src/dataframe.js:613-618][210]
Select columns in the DataFrame.
#### Parameters
- `columnNames` **...[String][189]** The columns to select.
#### Examples
```javascript
df.select('column1', 'column3')
```
Returns **[DataFrame][187]** A new DataFrame containing selected columns.
### withColumn
[src/dataframe.js:629-638][211]
Add a new column or set an existing one.
#### Parameters
- `columnName` **[String][189]** The column to modify or to create.
- `func` **[Function][212]** The function to create the column. (optional, default `(row,index)=>undefined`)
#### Examples
```javascript
df.withColumn('column4', () => 2)
df.withColumn('column2', (row) => row.get('column2') * 2)
```
Returns **[DataFrame][187]** A new DataFrame containing the new or modified column.
### restructure
[src/dataframe.js:649-651][213]
Modify the structure of the DataFrame by changing columns order, creating new columns or removing some columns.
#### Parameters
- `newColumnNames` **[Array][185]** The new columns of the DataFrame.
#### Examples
```javascript
df.restructure(['column1', 'column4', 'column2', 'column3'])
df.restructure(['column1', 'column4'])
df.restructure(['column1', 'newColumn', 'column4'])
```
Returns **[DataFrame][187]** A new DataFrame with restructured columns (renamed, add or deleted).
### renameAll
[src/dataframe.js:660-665][214]
Rename each column.
#### Parameters
- `newColumnNames` **[Array][185]** The new column names of the DataFrame.
#### Examples
```javascript
df.renameAll(['column1', 'column3', 'column4'])
```
Returns **[DataFrame][187]** A new DataFrame with the new column names.
### rename
[src/dataframe.js:675-680][215]
Rename a column.
#### Parameters
- `columnName` **[String][189]** The column to rename.
- `replacement` **[String][189]** The new name for the column.
#### Examples
```javascript
df.rename('column1', 'columnRenamed')
```
Returns **[DataFrame][187]** A new DataFrame with the new column name.
### castAll
[src/dataframe.js:689-702][216]
Cast each column into a given type.
#### Parameters
- `typeFunctions` **[Array][185]** The functions used to cast columns.
#### Examples
```javascript
df.castAll([Number, String, (val) => new CustomClass(val)])
```
Returns **[DataFrame][187]** A new DataFrame with the columns having new types.
### cast
[src/dataframe.js:713-717][217]
Cast a column into a given type.
#### Parameters
- `columnName` **[String][189]** The column to cast.
- `typeFunction`
- `ObjectType` **[Function][212]** The function used to cast the column.
#### Examples
```javascript
df.cast('column1', Number)
df.cast('column1', (val) => new MyCustomClass(val))
```
Returns **[DataFrame][187]** A new DataFrame with the column having a new type.
### drop
[src/dataframe.js:726-731][218]
Remove a single column.
#### Parameters
- `columnName` **[String][189]** The column to drop.
#### Examples
```javascript
df.drop('column2')
```
Returns **[DataFrame][187]** A new DataFrame without the dropped column.
### chain
[src/dataframe.js:746-751][219]
Chain maps and filters functions on DataFrame by optimizing their executions.
If a function returns boolean, it's a filter. Else it's a map.
It can be 10 - 100 x faster than standard chains of .map() and .filter().
#### Parameters
- `funcs` **...[Function][212]** Functions to apply on the DataFrame rows taking the row as parameter.
#### Examples
```javascript
df.chain(
row => row.get('column1') > 3, // filter
row => row.set('column1', 3), // map
row => row.get('column2') === '5' // filter
)
```
Returns **[DataFrame][187]** A new DataFrame with modified rows.
### filter
[src/dataframe.js:761-775][220]
Filter DataFrame rows.
#### Parameters
- `condition` **([Function][212] \| [Object][186])** A filter function or a column/value object.
#### Examples
```javascript
df.filter(row => row.get('column1') >= 3)
df.filter({'column2': 5, 'column1': 3}))
```
Returns **[DataFrame][187]** A new filtered DataFrame.
### where
[src/dataframe.js:786-788][221]
Filter DataFrame rows.
Alias of .filter()
#### Parameters
- `condition` **([Function][212] \| [Object][186])** A filter function or a column/value object.
#### Examples
```javascript
df.where(row => row.get('column1') >= 3)
df.where({'column2': 5, 'column1': 3}))
```
Returns **[DataFrame][187]** A new filtered DataFrame.
### find
[src/dataframe.js:798-800][222]
Find a row (the first met) based on a condition.
#### Parameters
- `condition` **([Function][212] \| [Object][186])** A filter function or a column/value object.
#### Examples
```javascript
df.find(row => row.get('column1') === 3)
df.find({'column1': 3})
```
Returns **Row** The targeted Row.
### map
[src/dataframe.js:809-814][223]
Map on DataFrame rows. /!\\ Prefer to use .chain().
#### Parameters
- `func` **[Function][212]** A function to apply on each row taking the row as parameter.
#### Examples
```javascript
df.map(row => row.set('column1', row.get('column1') * 2))
```
Returns **[DataFrame][187]** A new DataFrame with modified rows.
### reduce
[src/dataframe.js:828-832][224]
Reduce DataFrame into a value.
#### Parameters
- `func` **[Function][212]** The reduce function taking 2 parameters, previous and next.
- `init` The initial value of the reducer.
#### Examples
```javascript
df.reduce((p, n) => n.get('column1') + p, 0)
df2.reduce((p, n) => (
n.set('column1', p.get('column1') + n.get('column1'))
.set('column2', p.get('column2') + n.get('column2'))
))
```
Returns **any** A reduced value.
### reduceRight
[src/dataframe.js:842-846][225]
Reduce DataFrame into a value, starting from the last row (see .reduce()).
#### Parameters
- `func` **[Function][212]** The reduce function taking 2 parameters, previous and next.
- `init` The initial value of the reducer.
#### Examples
```javascript
df.reduceRight((p, n) => p > n ? p : n, 0)
```
Returns **any** A reduced value.
### dropDuplicates
[src/dataframe.js:855-861][226]
Return a DataFrame without duplicated columns.
#### Parameters
- `columnNames` **...[String][189]** The columns used to check unicity of rows. If omitted, unicity is checked on all columns.
#### Examples
```javascript
df.dropDuplicates('id', 'name')
```
Returns **[DataFrame][187]** A DataFrame without duplicated rows.
### dropMissingValues
[src/dataframe.js:870-884][227]
Return a DataFrame without rows containing missing values (undefined, NaN, null).
#### Parameters
- `columnNames` **[Array][185]** The columns to consider. All columns are considered by default.
#### Examples
```javascript
df.dropMissingValues(['id', 'name'])
```
Returns **[DataFrame][187]** A DataFrame without rows containing missing values.
### fillMissingValues
[src/dataframe.js:894-896][228]
Return a DataFrame with missing values (undefined, NaN, null) fill with default value.
#### Parameters
- `replacement` The new value.
- `columnNames` **[Array][185]** The columns to consider. All columns are considered by default.
#### Examples
```javascript
df.fillMissingValues(0, ['id', 'name'])
```
Returns **[DataFrame][187]** A DataFrame with missing values replaced.
### shuffle
[src/dataframe.js:904-915][229]
Return a shuffled DataFrame rows.
#### Examples
```javascript
df.shuffle()
```
Returns **[DataFrame][187]** A shuffled DataFrame.
### sample
[src/dataframe.js:924-938][230]
Return a random sample of rows.
#### Parameters
- `percentage` **[Number][200]** A percentage of the orignal DataFrame giving the sample size.
#### Examples
```javascript
df.sample(0.3)
```
Returns **[DataFrame][187]** A sample DataFrame
### bisect
[src/dataframe.js:947-964][231]
Randomly split a DataFrame into 2 DataFrames.
#### Parameters
- `percentage` **[Number][200]** A percentage of the orignal DataFrame giving the first DataFrame size. The second takes the rest.
#### Examples
```javascript
const [30DF, 70DF] = df.bisect(0.3)
```
Returns **[Array][185]** An Array containing the two DataFrames. First, the X% DataFrame then the rest DataFrame.
### groupBy
[src/dataframe.js:977-979][232]
Group DataFrame rows by columns giving a GroupedDataFrame object. See its doc for more examples.
#### Parameters
- `args` **...any**
- `columnNames` **...[String][189]** The columns used for the groupBy.
#### Examples
```javascript
df.groupBy('column1')
df.groupBy('column1', 'column2')
df.groupBy('column1', 'column2').listGroups()
df.groupBy('column1', 'column2').show()
df.groupBy('column1', 'column2').aggregate((group) => group.count())
```
Returns **GroupedDataFrame** A GroupedDataFrame object.
### sortBy
[src/dataframe.js:992-1056][233]
Sort DataFrame rows based on column values. The row should contains only one variable type. Columns are sorted left-to-right.
#### Parameters
- `columnNames` **([String][189] \| [Array][185]<[string][189]>)** The columns giving order.
- `reverse` **[Boolean][190]** Reverse mode. Reverse the order if true. (optional, default `false`)
- `missingValuesPosition` **[String][189]** Define the position of missing values (undefined, nulls and NaN) in the order. (optional, default `'first'`)
#### Examples
```javascript
df.sortBy('id')
df.sortBy(['id1', 'id2'])
df.sortBy(['id1'], true)
```
Returns **[DataFrame][187]** An ordered DataFrame.
### union
[src/dataframe.js:1065-1078][234]
Concat two DataFrames.
#### Parameters
- `dfToUnion` **[DataFrame][187]** The DataFrame to concat.
#### Examples
```javascript
df.union(df2)
```
Returns **[DataFrame][187]** A new concatenated DataFrame resulting of the union.
### join
[src/dataframe.js:1089-1098][235]
Join two DataFrames.
#### Parameters
- `dfToJoin` **[DataFrame][187]** The DataFrame to join.
- `columnNames` **([String][189] \| [Array][185])** The selected columns for the join.
- `how` **[String][189]** The join mode. Can be: full, inner, outer, left, right. (optional, default `'inner'`)
#### Examples
```javascript
df.join(df2, 'column1', 'full')
```
Returns **[DataFrame][187]** The joined DataFrame.
### innerJoin
[src/dataframe.js:1110-1112][236]
Join two DataFrames with inner mode.
#### Parameters
- `dfToJoin` **[DataFrame][187]** The DataFrame to join.
- `columnNames` **([String][189] \| [Array][185])** The selected columns for the join.
#### Examples
```javascript
df.innerJoin(df2, 'id')
df.join(df2, 'id')
df.join(df2, 'id', 'inner')
```
Returns **[DataFrame][187]** The joined DataFrame.
### fullJoin
[src/dataframe.js:1123-1125][237]
Join two DataFrames with full mode.
#### Parameters
- `dfToJoin` **[DataFrame][187]** The DataFrame to join.
- `columnNames` **([String][189] \| [Array][185])** The selected columns for the join.
#### Examples
```javascript
df.fullJoin(df2, 'id')
df.join(df2, 'id', 'full')
```
Returns **[DataFrame][187]** The joined DataFrame.
### outerJoin
[src/dataframe.js:1136-1138][238]
Join two DataFrames with outer mode.
#### Parameters
- `dfToJoin` **[DataFrame][187]** The DataFrame to join.
- `columnNames` **([String][189] \| [Array][185])** The selected columns for the join.
#### Examples
```javascript
df2.outerJoin(df2, 'id')
df2.join(df2, 'id', 'outer')
```
Returns **[DataFrame][187]** The joined DataFrame.
### leftJoin
[src/dataframe.js:1149-1151][239]
Join two DataFrames with left mode.
#### Parameters
- `dfToJoin` **[DataFrame][187]** The DataFrame to join.
- `columnNames` **([String][189] \| [Array][185])** The selected columns for the join.
#### Examples
```javascript
df.leftJoin(df2, 'id')
df.join(df2, 'id', 'left')
```
Returns **[DataFrame][187]** The joined DataFrame.
### rightJoin
[src/dataframe.js:1162-1164][240]
Join two DataFrames with right mode.
#### Parameters
- `dfToJoin` **[DataFrame][187]** The DataFrame to join.
- `columnNames` **([String][189] \| [Array][185])** The selected columns for the join.
#### Examples
```javascript
df.rightJoin(df2, 'id')
df.join(df2, 'id', 'right')
```
Returns **[DataFrame][187]** The joined DataFrame.
### diff
[src/dataframe.js:1174-1176][241]
Find the differences between two DataFrames (reverse of join).
#### Parameters
- `dfToDiff` **[DataFrame][187]** The DataFrame to diff.
- `columnNames` **([String][189] \| [Array][185])** The selected columns for the diff.
#### Examples
```javascript
df2.diff(df2, 'id')
```
Returns **[DataFrame][187]** The differences DataFrame.
### head
[src/dataframe.js:1186-1188][242]
Create a new subset DataFrame based on the first rows.
#### Parameters
- `nRows` **[Number][200]** The number of first rows to get. (optional, default `10`)
#### Examples
```javascript
df2.head()
df2.head(5)
```
Returns **[DataFrame][187]** The subset DataFrame.
### tail
[src/dataframe.js:1198-1200][243]
Create a new subset DataFrame based on the last rows.
#### Parameters
- `nRows` **[Number][200]** The number of last rows to get. (optional, default `10`)
#### Examples
```javascript
df2.tail()
df2.tail(5)
```
Returns **[DataFrame][187]** The subset DataFrame.
### slice
[src/dataframe.js:1213-1221][244]
Create a new subset DataFrame based on given indexs. Similar to Array.slice.
#### Parameters
- `startIndex` **[Number][200]** The index to start the slice (included). (optional, default `0`)
- `endIndex` **[Number][200]** The index to end the slice (excluded). (optional, default `this.count()`)
#### Examples
```javascript
df2.slice()
df2.slice(0)
df2.slice(0, 20)
df2.slice(10, 30)
```
Returns **[DataFrame][187]** The subset DataFrame.
### getRow
[src/dataframe.js:1230-1232][245]
Return a Row by its index.
#### Parameters
- `index` **[Number][200]** The index to select the row. (optional, default `0`)
#### Examples
```javascript
df2.getRow(1)
```
Returns **Row** The Row.
### setRow
[src/dataframe.js:1241-1245][246]
Modify a Row a the given index.
#### Parameters
- `index` **[Number][200]** The index to select the row. (optional, default `0`)
- `func` (optional, default `row=>row`)
#### Examples
```javascript
df2.setRowByIndex(1, row => row.set("column1", 33))
```
Returns **[DataFrame][187]** A new DataFrame with the modified Row.
### setDefaultModules
[src/dataframe.js:18-20][247]
Set the default modules used in DataFrame instances.
#### Parameters
- `defaultModules` **...[Object][186]** DataFrame modules used by default.
#### Examples
```javascript
DataFrame.setDefaultModules(SQL, Stat)
```
### fromDSV
[src/dataframe.js:35-37][248]
Create a DataFrame from a delimiter separated values text file. It returns a Promise.
#### Parameters
- `args` **...any**
- `pathOrFile` **([String][189] | File)** A path to the file (url or local) or a browser File object.
- `sep` **[String][189]** The separator used to parse the file.
- `header` **[Boolean][190]** A boolean indicating if the text has a header or not. (optional, default `true`)
#### Examples
```javascript
DataFrame.fromDSV('http://myurl/myfile.txt').then(df => df.show())
// In browser Only
DataFrame.fromDSV(myFile).then(df => df.show())
// From node.js only Only
DataFrame.fromDSV('/my/absolue/path/myfile.txt').then(df => df.show())
DataFrame.fromDSV('/my/absolue/path/myfile.txt', ';', true).then(df => df.show())
```
### fromText
[src/dataframe.js:52-54][249]
Create a DataFrame from a delimiter separated values text file. It returns a Promise. Alias of DataFrame.fromDSV.
#### Parameters
- `args` **...any**
- `pathOrFile` **([String][189] | File)** A path to the file (url or local) or a browser File object.
- `sep` **[String][189]** The separator used to parse the file.
- `header` **[Boolean][190]** A boolean indicating if the text has a header or not. (optional, default `true`)
#### Examples
```javascript
DataFrame.fromText('http://myurl/myfile.txt').then(df => df.show())
// In browser Only
DataFrame.fromText(myFile).then(df => df.show())
// From node.js only Only
DataFrame.fromText('/my/absolue/path/myfile.txt').then(df => df.show())
DataFrame.fromText('/my/absolue/path/myfile.txt', ';', true).then(df => df.show())
```
### fromCSV
[src/dataframe.js:68-70][250]
Create a DataFrame from a comma separated values file. It returns a Promise.
#### Parameters
- `args` **...any**
- `pathOrFile` **([String][189] | File)** A path to the file (url or local) or a browser File object.
- `header` **[Boolean][190]** A boolean indicating if the csv has a header or not. (optional, default `true`)
#### Examples
```javascript
DataFrame.fromCSV('http://myurl/myfile.csv').then(df => df.show())
// For browser only
DataFrame.fromCSV(myFile).then(df => df.show())
// From node.js only
DataFrame.fromCSV('/my/absolue/path/myfile.csv').then(df => df.show())
DataFrame.fromCSV('/my/absolue/path/myfile.csv', true).then(df => df.show())
```
### fromTSV
[src/dataframe.js:84-86][251]
Create a DataFrame from a tab separated values file. It returns a Promise.
#### Parameters
- `args` **...any**
- `pathOrFile` **([String][189] | File)** A path to the file (url or local) or a browser File object.
- `header` **[Boolean][190]** A boolean indicating if the tsv has a header or not. (optional, default `true`)
#### Examples
```javascript
DataFrame.fromTSV('http://myurl/myfile.tsv').then(df => df.show())
// For browser only
DataFrame.fromTSV(myFile).then(df => df.show())
// From node.js only
DataFrame.fromTSV('/my/absolue/path/myfile.tsv').then(df => df.show())
DataFrame.fromTSV('/my/absolue/path/myfile.tsv', true).then(df => df.show())
```
### fromPSV
[src/dataframe.js:100-102][252]
Create a DataFrame from a pipe separated values file. It returns a Promise.
#### Parameters
- `args` **...any**
- `pathOrFile` **([String][189] | File)** A path to the file (url or local) or a browser File object.
- `header` **[Boolean][190]** A boolean indicating if the psv has a header or not. (optional, default `true`)
#### Examples
```javascript
DataFrame.fromPSV('http://myurl/myfile.psv').then(df => df.show())
// For browser only
DataFrame.fromPSV(myFile).then(df => df.show())
// From node.js only
DataFrame.fromPSV('/my/absolue/path/myfile.psv').then(df => df.show())
DataFrame.fromPSV('/my/absolue/path/myfile.psv', true).then(df => df.show())
```
### fromJSON
[src/dataframe.js:114-116][253]
Create a DataFrame from a JSON file. It returns a Promise.
#### Parameters
- `args` **...any**
- `pathOrFile` **([String][189] | File)** A path to the file (url or local) or a browser File object.
#### Examples
```javascript
DataFrame.fromJSON('http://myurl/myfile.json').then(df => df.show())
// For browser only
DataFrame.fromJSON(myFile).then(df => df.show())
// From node.js only
DataFrame.fromJSON('/my/absolute/path/myfile.json').then(df => df.show())
```
[1]: #dataframe
[2]: #parameters
[3]: #todsv
[4]: #parameters-1
[5]: #examples
[6]: #tocsv
[7]: #parameters-2
[8]: #examples-1
[9]: #totsv
[10]: #parameters-3
[11]: #examples-2
[12]: #topsv
[13]: #parameters-4
[14]: #examples-3
[15]: #totext
[16]: #parameters-5
[17]: #examples-4
[18]: #tojson
[19]: #parameters-6
[20]: #examples-5
[21]: #todict
[22]: #examples-6
[23]: #toarray
[24]: #parameters-7
[25]: #examples-7
[26]: #tocollection
[27]: #parameters-8
[28]: #examples-8
[29]: #show
[30]: #parameters-9
[31]: #examples-9
[32]: #dim
[33]: #examples-10
[34]: #transpose
[35]: #parameters-10
[36]: #examples-11
[37]: #count
[38]: #examples-12
[39]: #countvalue
[40]: #parameters-11
[41]: #examples-13
[42]: #push
[43]: #parameters-12
[44]: #examples-14
[45]: #replace
[46]: #parameters-13
[47]: #examples-15
[48]: #distinct
[49]: #parameters-14
[50]: #examples-16
[51]: #unique
[52]: #parameters-15
[53]: #examples-17
[54]: #listcolumns
[55]: #examples-18
[56]: #select
[57]: #parameters-16
[58]: #examples-19
[59]: #withcolumn
[60]: #parameters-17
[61]: #examples-20
[62]: #restructure
[63]: #parameters-18
[64]: #examples-21
[65]: #renameall
[66]: #parameters-19
[67]: #examples-22
[68]: #rename
[69]: #parameters-20
[70]: #examples-23
[71]: #castall
[72]: #parameters-21
[73]: #examples-24
[74]: #cast
[75]: #parameters-22
[76]: #examples-25
[77]: #drop
[78]: #parameters-23
[79]: #examples-26
[80]: #chain
[81]: #parameters-24
[82]: #examples-27
[83]: #filter
[84]: #parameters-25
[85]: #examples-28
[86]: #where
[87]: #parameters-26
[88]: #examples-29
[89]: #find
[90]: #parameters-27
[91]: #examples-30
[92]: #map
[93]: #parameters-28
[94]: #examples-31
[95]: #reduce
[96]: #parameters-29
[97]: #examples-32
[98]: #reduceright
[99]: #parameters-30
[100]: #examples-33
[101]: #dropduplicates
[102]: #parameters-31
[103]: #examples-34
[104]: #dropmissingvalues
[105]: #parameters-32
[106]: #examples-35
[107]: #fillmissingvalues
[108]: #parameters-33
[109]: #examples-36
[110]: #shuffle
[111]: #examples-37
[112]: #sample
[113]: #parameters-34
[114]: #examples-38
[115]: #bisect
[116]: #parameters-35
[117]: #examples-39
[118]: #groupby
[119]: #parameters-36
[120]: #examples-40
[121]: #sortby
[122]: #parameters-37
[123]: #examples-41
[124]: #union
[125]: #parameters-38
[126]: #examples-42
[127]: #join
[128]: #parameters-39
[129]: #examples-43
[130]: #innerjoin
[131]: #parameters-40
[132]: #examples-44
[133]: #fulljoin
[134]: #parameters-41
[135]: #examples-45
[136]: #outerjoin
[137]: #parameters-42
[138]: #examples-46
[139]: #leftjoin
[140]: #parameters-43
[141]: #examples-47
[142]: #rightjoin
[143]: #parameters-44
[144]: #examples-48
[145]: #diff
[146]: #parameters-45
[147]: #examples-49
[148]: #head
[149]: #parameters-46
[150]: #examples-50
[151]: #tail
[152]: #parameters-47
[153]: #examples-51
[154]: #slice
[155]: #parameters-48
[156]: #examples-52
[157]: #getrow
[158]: #parameters-49
[159]: #examples-53
[160]: #setrow
[161]: #parameters-50
[162]: #examples-54
[163]: #setdefaultmodules
[164]: #parameters-51
[165]: #examples-55
[166]: #fromdsv
[167]: #parameters-52
[168]: #examples-56
[169]: #fromtext
[170]: #parameters-53
[171]: #examples-57
[172]: #fromcsv
[173]: #parameters-54
[174]: #examples-58
[175]: #fromtsv
[176]: #parameters-55
[177]: #examples-59
[178]: #frompsv
[179]: #parameters-56
[180]: #examples-60
[181]: #fromjson
[182]: #parameters-57
[183]: #examples-61
[184]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L11-L1246 "Source code on GitHub"
[185]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[186]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[187]: #dataframe
[188]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L314-L316 "Source code on GitHub"
[189]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[190]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[191]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L329-L331 "Source code on GitHub"
[192]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L344-L346 "Source code on GitHub"
[193]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L359-L361 "Source code on GitHub"
[194]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L376-L378 "Source code on GitHub"
[195]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L390-L392 "Source code on GitHub"
[196]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L400-L407 "Source code on GitHub"
[197]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L416-L420 "Source code on GitHub"
[198]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L429-L433 "Source code on GitHub"
[199]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L445-L474 "Source code on GitHub"
[200]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[201]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L482-L484 "Source code on GitHub"
[202]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L493-L508 "Source code on GitHub"
[203]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L516-L518 "Source code on GitHub"
[204]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L529-L533 "Source code on GitHub"
[205]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L542-L544 "Source code on GitHub"
[206]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L555-L568 "Source code on GitHub"
[207]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L577-L582 "Source code on GitHub"
[208]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L592-L594 "Source code on GitHub"
[209]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L602-L604 "Source code on GitHub"
[210]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L613-L618 "Source code on GitHub"
[211]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L629-L638 "Source code on GitHub"
[212]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[213]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L649-L651 "Source code on GitHub"
[214]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L660-L665 "Source code on GitHub"
[215]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L675-L680 "Source code on GitHub"
[216]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L689-L702 "Source code on GitHub"
[217]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L713-L717 "Source code on GitHub"
[218]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L726-L731 "Source code on GitHub"
[219]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L746-L751 "Source code on GitHub"
[220]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L761-L775 "Source code on GitHub"
[221]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L786-L788 "Source code on GitHub"
[222]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L798-L800 "Source code on GitHub"
[223]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L809-L814 "Source code on GitHub"
[224]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L828-L832 "Source code on GitHub"
[225]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L842-L846 "Source code on GitHub"
[226]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L855-L861 "Source code on GitHub"
[227]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L870-L884 "Source code on GitHub"
[228]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L894-L896 "Source code on GitHub"
[229]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L904-L915 "Source code on GitHub"
[230]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L924-L938 "Source code on GitHub"
[231]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L947-L964 "Source code on GitHub"
[232]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L977-L979 "Source code on GitHub"
[233]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L992-L1056 "Source code on GitHub"
[234]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1065-L1078 "Source code on GitHub"
[235]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1089-L1098 "Source code on GitHub"
[236]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1110-L1112 "Source code on GitHub"
[237]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1123-L1125 "Source code on GitHub"
[238]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1136-L1138 "Source code on GitHub"
[239]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1149-L1151 "Source code on GitHub"
[240]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1162-L1164 "Source code on GitHub"
[241]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1174-L1176 "Source code on GitHub"
[242]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1186-L1188 "Source code on GitHub"
[243]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1198-L1200 "Source code on GitHub"
[244]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1213-L1221 "Source code on GitHub"
[245]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1230-L1232 "Source code on GitHub"
[246]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L1241-L1245 "Source code on GitHub"
[247]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L18-L20 "Source code on GitHub"
[248]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L35-L37 "Source code on GitHub"
[249]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L52-L54 "Source code on GitHub"
[250]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L68-L70 "Source code on GitHub"
[251]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L84-L86 "Source code on GitHub"
[252]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L100-L102 "Source code on GitHub"
[253]: https://github.com/Gmousse/dataframe-js/blob/add47391719e84537fdc30c80f762b3a8b38ba9a/src/dataframe.js#L114-L116 "Source code on GitHub"