@@ -527,7 +527,8 @@ DataFrame >> atAll: indexes [
527527
528528{ #category : #statistics }
529529DataFrame >> average [
530-
530+ " Average is the ratio of sum of values in a set to the number of values in the set"
531+
531532 ^ self applyToAllColumns: #average
532533]
533534
@@ -1068,7 +1069,8 @@ DataFrame >> indexOfRowNamed: rowName ifAbsent: exceptionBlock [
10681069
10691070{ #category : #printing }
10701071DataFrame >> info [
1071-
1072+ " Prints the number of entries and number of columns of a data frame. For each column of the data frame, it prints the column index, column name, number of non-nil values in the column and the data type of the contents of the column"
1073+
10721074 ^ String streamContents: [ :aStream |
10731075 aStream
10741076 nextPutAll: ' DataFrame: ' ;
@@ -1309,7 +1311,8 @@ DataFrame >> leftJoin: aDataFrame onLeft: leftColumn onRight: rightColumn [
13091311
13101312{ #category : #statistics }
13111313DataFrame >> max [
1312-
1314+ " Max is the largest value present in a set of values"
1315+
13131316 ^ self applyToAllColumns: #max
13141317]
13151318
@@ -1322,6 +1325,7 @@ DataFrame >> median [
13221325
13231326{ #category : #statistics }
13241327DataFrame >> min [
1328+ " Min is the smallest value present in a set of values"
13251329
13261330 ^ self applyToAllColumns: #min
13271331]
@@ -1356,6 +1360,7 @@ DataFrame >> numberOfColumns [
13561360
13571361{ #category : #replacing }
13581362DataFrame >> numberOfNils [
1363+ " Returns a dictionary which indicates the number of nil values column wise"
13591364
13601365 | dictionary count |
13611366 dictionary := Dictionary new .
@@ -1493,14 +1498,17 @@ DataFrame >> range [
14931498
14941499{ #category : #removing }
14951500DataFrame >> removeColumn: columnName [
1496-
1501+ " Removes the column named columnName from a data frame"
1502+
14971503 | index |
14981504 index := self indexOfColumnNamed: columnName.
14991505 self removeColumnAt: index
15001506]
15011507
15021508{ #category : #removing }
15031509DataFrame >> removeColumnAt: columnNumber [
1510+ " Removes the column at column index columnNumber from a data frame"
1511+
15041512 (columnNumber < 1 or : [ columnNumber > self numberOfColumns ])
15051513 ifTrue: [ SubscriptOutOfBounds signalFor: columnNumber ].
15061514
@@ -1512,13 +1520,17 @@ DataFrame >> removeColumnAt: columnNumber [
15121520
15131521{ #category : #removing }
15141522DataFrame >> removeColumns: aCollectionOfColumnNames [
1523+ " Removes all columns from a data frame whose names are present in the collection aCollectionOfColumnNames"
1524+
15151525 aCollectionOfColumnNames do: [ :each |
15161526 self removeColumn: each.
15171527 ]
15181528]
15191529
15201530{ #category : #removing }
15211531DataFrame >> removeColumnsAt: aCollectionOfColumnIndices [
1532+ " Removes all columns from a data frame whose column indices are present in the collection aCollectionOfColumnIndices"
1533+
15221534 | columnNamesToRemove |
15231535 columnNamesToRemove := aCollectionOfColumnIndices collect: [ :i |
15241536 columnNames at: i ].
@@ -1527,6 +1539,7 @@ DataFrame >> removeColumnsAt: aCollectionOfColumnIndices [
15271539
15281540{ #category : #removing }
15291541DataFrame >> removeColumnsOfRowElementsSatisfing: aBlock onRowNamed: rowName [
1542+ " Removes columns from a data frame whose row elements at the row named rowName satisfy a given block"
15301543
15311544 | index |
15321545 index := self indexOfRowNamed: rowName.
@@ -1535,6 +1548,7 @@ DataFrame >> removeColumnsOfRowElementsSatisfing: aBlock onRowNamed: rowName [
15351548
15361549{ #category : #removing }
15371550DataFrame >> removeColumnsOfRowElementsSatisfying: aBlock onRow: rowNumber [
1551+ " Removes columns from a data frame whose row elements at the row index rowNumber satisfy a given block"
15381552
15391553 | columnNamesCopy |
15401554 (rowNumber < 1 or : [ rowNumber > self numberOfRows ])
@@ -1552,16 +1566,21 @@ DataFrame >> removeColumnsOfRowElementsSatisfying: aBlock onRow: rowNumber [
15521566
15531567{ #category : #' handling nils' }
15541568DataFrame >> removeColumnsWithNilsAtRow: rowNumber [
1569+ " Removes all columns with nil values at row number rowNumber from the data frame"
1570+
15551571 self removeColumnsOfRowElementsSatisfying: [ :ele | ele isNil ] onRow: rowNumber
15561572]
15571573
15581574{ #category : #' handling nils' }
15591575DataFrame >> removeColumnsWithNilsAtRowNamed: rowName [
1576+ " Removes all columns with nil values at a row named rowName from the data frame"
1577+
15601578 self removeColumnsOfRowElementsSatisfing: [ :ele | ele isNil ] onRowNamed: rowName
15611579]
15621580
15631581{ #category : #removing }
15641582DataFrame >> removeRow: rowName [
1583+ " Removes the row named rowName from a data frame"
15651584
15661585 | index |
15671586 index := self indexOfRowNamed: rowName.
@@ -1570,6 +1589,8 @@ DataFrame >> removeRow: rowName [
15701589
15711590{ #category : #removing }
15721591DataFrame >> removeRowAt: rowNumber [
1592+ " Removes the row at row index rowNumber from a data frame"
1593+
15731594 (rowNumber < 1 or : [ rowNumber > self numberOfRows ])
15741595 ifTrue: [ SubscriptOutOfBounds signalFor: rowNumber ].
15751596
@@ -1579,12 +1600,16 @@ DataFrame >> removeRowAt: rowNumber [
15791600
15801601{ #category : #removing }
15811602DataFrame >> removeRows: aCollectionOfRowNames [
1603+ " Removes all rows from a data frame whose names are present in the collection aCollectionOfRowNames"
1604+
15821605 aCollectionOfRowNames do: [ :each |
15831606 self removeRow: each ]
15841607]
15851608
15861609{ #category : #removing }
15871610DataFrame >> removeRowsAt: aCollectionOfRowIndices [
1611+ " Removes all rows from a data frame whose row indices are present in the collection aCollectionOfRowIndices"
1612+
15881613 | rowNamesToRemove |
15891614 rowNamesToRemove := aCollectionOfRowIndices collect: [ :i |
15901615 rowNames at: i ].
@@ -1593,6 +1618,7 @@ DataFrame >> removeRowsAt: aCollectionOfRowIndices [
15931618
15941619{ #category : #removing }
15951620DataFrame >> removeRowsOfColumnElementsSatisfing: aBlock onColumnNamed: columnName [
1621+ " Removes rows from a data frame whose column elements at the column named columnName satisfy a given block"
15961622
15971623 | index |
15981624 index := self indexOfColumnNamed: columnName.
@@ -1601,6 +1627,7 @@ DataFrame >> removeRowsOfColumnElementsSatisfing: aBlock onColumnNamed: columnNa
16011627
16021628{ #category : #removing }
16031629DataFrame >> removeRowsOfColumnElementsSatisfying: aBlock onColumn: columnNumber [
1630+ " Removes rows from a data frame whose column elements at the column index columnNumber satisfy a given block"
16041631
16051632 | rowNamesCopy |
16061633 (columnNumber < 1 or : [ columnNumber > self numberOfColumns ])
@@ -1618,7 +1645,8 @@ DataFrame >> removeRowsOfColumnElementsSatisfying: aBlock onColumn: columnNumber
16181645
16191646{ #category : #removing }
16201647DataFrame >> removeRowsWithNils [
1621-
1648+ " Removes all rows from a data frame which have atleast one nil value"
1649+
16221650 1 to: self numberOfColumns do: [ :i |
16231651 self
16241652 removeRowsOfColumnElementsSatisfying: [ :ele | ele isNil ]
@@ -1627,11 +1655,15 @@ DataFrame >> removeRowsWithNils [
16271655
16281656{ #category : #' handling nils' }
16291657DataFrame >> removeRowsWithNilsAtColumn: columnNumber [
1658+ " Removes all rows with nil values at column number columnNumber from the data frame"
1659+
16301660 self removeRowsOfColumnElementsSatisfying: [ :ele | ele isNil ] onColumn: columnNumber
16311661]
16321662
16331663{ #category : #' handling nils' }
16341664DataFrame >> removeRowsWithNilsAtColumnNamed: columnName [
1665+ " Removes all rows with nil values at a column named columnName from the data frame"
1666+
16351667 self removeRowsOfColumnElementsSatisfing: [ :ele | ele isNil ] onColumnNamed: columnName
16361668]
16371669
@@ -1664,7 +1696,8 @@ DataFrame >> replaceAllNilsWithZeros [
16641696
16651697{ #category : #replacing }
16661698DataFrame >> replaceNilsWith: anObject [
1667-
1699+ " Replaces all nil values of a data frame with the object anObject"
1700+
16681701 1 to: self numberOfColumns do: [ :columnIndex |
16691702 1 to: self numberOfRows do: [ :rowIndex |
16701703 (self at: rowIndex at: columnIndex) ifNil:
@@ -1674,6 +1707,7 @@ DataFrame >> replaceNilsWith: anObject [
16741707
16751708{ #category : #replacing }
16761709DataFrame >> replaceNilsWithAverage [
1710+ " Replaces all nil values of a data frame with the average value of the column in which it is present"
16771711
16781712 | averageOfColumn |
16791713 1 to: self numberOfColumns do: [ :i |
@@ -1686,6 +1720,7 @@ DataFrame >> replaceNilsWithAverage [
16861720
16871721{ #category : #replacing }
16881722DataFrame >> replaceNilsWithMedian [
1723+ " Replaces all nil values of a data frame with the median of the column in which it is present"
16891724
16901725 | medianOfColumn |
16911726 1 to: self numberOfColumns do: [ :i |
@@ -1698,6 +1733,7 @@ DataFrame >> replaceNilsWithMedian [
16981733
16991734{ #category : #replacing }
17001735DataFrame >> replaceNilsWithMode [
1736+ " Replaces all nil values of a data frame with the mode of the column in which it is present"
17011737
17021738 1 to: self numberOfColumns do: [ :i |
17031739 | modeOfColumn |
@@ -1708,6 +1744,7 @@ DataFrame >> replaceNilsWithMode [
17081744
17091745{ #category : #replacing }
17101746DataFrame >> replaceNilsWithPreviousRowValue [
1747+ " Replaces all nil values of a data frame with the previous non-nil value of the column in which it is present"
17111748
17121749 |value |
17131750 1 to: self numberOfColumns do: [ :i |
@@ -1724,6 +1761,7 @@ DataFrame >> replaceNilsWithPreviousRowValue [
17241761
17251762{ #category : #replacing }
17261763DataFrame >> replaceNilsWithZero [
1764+ " Replaces all nil values of a data frame with xero"
17271765
17281766 self replaceNilsWith: 0
17291767]
@@ -2001,11 +2039,14 @@ DataFrame >> size [
20012039
20022040{ #category : #sorting }
20032041DataFrame >> sortBy: columnName [
2042+ " Rearranges the rows of the data frame in ascending order of the values in the column named columnName"
2043+
20042044 self sortBy: columnName using: [ :a :b | a <= b ]
20052045]
20062046
20072047{ #category : #sorting }
20082048DataFrame >> sortBy: columnName using: aBlock [
2049+ " Rearranges the rows of the data frame by applying the given block on the column named columnName"
20092050
20102051 | column sortedKeys newContents |
20112052 column := self column: columnName.
@@ -2024,6 +2065,8 @@ DataFrame >> sortBy: columnName using: aBlock [
20242065
20252066{ #category : #sorting }
20262067DataFrame >> sortDescendingBy: columnName [
2068+ " Rearranges the rows of the data frame in descending order of the values in the column named columnName"
2069+
20272070 self sortBy: columnName using: [ :a :b | a >= b ]
20282071]
20292072
@@ -2059,6 +2102,8 @@ DataFrame >> thirdQuartile [
20592102
20602103{ #category : #applying }
20612104DataFrame >> toColumn: columnName applyElementwise: aBlock [
2105+ " Applies a given block to a column named columnName of a data frame"
2106+
20622107 | column |
20632108 column := (self column: columnName) asArray.
20642109 column := column collect: [ :each | aBlock value: each ].
@@ -2067,20 +2112,24 @@ DataFrame >> toColumn: columnName applyElementwise: aBlock [
20672112
20682113{ #category : #applying }
20692114DataFrame >> toColumnAt: columnNumber applyElementwise: aBlock [
2115+ " Applies a given block to a column whose column index is columnNumber of a data frame"
2116+
20702117 | columnName |
20712118 columnName := self columnNames at: columnNumber.
20722119 ^ self toColumn: columnName applyElementwise: aBlock
20732120]
20742121
20752122{ #category : #applying }
20762123DataFrame >> toColumns: arrayOfColumnNames applyElementwise: aBlock [
2124+ " Applies a given block to columns whose names are present in the array arrayOfColumnNames of a data frame"
20772125
20782126 arrayOfColumnNames do: [ :each |
20792127 self toColumn: each applyElementwise: aBlock ]
20802128]
20812129
20822130{ #category : #applying }
20832131DataFrame >> toColumnsAt: arrayOfColumnNumbers applyElementwise: aBlock [
2132+ " Applies a given block to columns whose indices are present in the array arrayOfColumnNumbers of a data frame"
20842133
20852134 arrayOfColumnNumbers do: [ :each |
20862135 self toColumnAt: each applyElementwise: aBlock ]
0 commit comments