@@ -543,7 +543,7 @@ DataFrame >> average [
543543{ #category : #' data-types' }
544544DataFrame >> calculateDataTypes [
545545
546- self columns doWithIndex: [ :column :i | self dataTypes at: (self columnNames at: i) put: column calculateDataType ]
546+ self asArrayOfColumns doWithIndex: [ :column :i | self dataTypes at: (self columnNames at: i) put: column calculateDataType ]
547547]
548548
549549{ #category : #comparing }
@@ -722,10 +722,9 @@ DataFrame >> columnNames: aCollection [
722722
723723{ #category : #accessing }
724724DataFrame >> columns [
725-
726725 " Returns a collection of all columns"
727726
728- ^ self asArrayOfColumns
727+ ^ ( 1 to: self numberOfColumns) collect: [ :j | self columnAt: j ]
729728]
730729
731730{ #category : #accessing }
@@ -1098,7 +1097,7 @@ DataFrame >> hasNils [
10981097 " Returns true if there is atleast one nil value in the data frame. Returns false if there are no nil values in the dataframe"
10991098
11001099 | arrayOfColumns |
1101- arrayOfColumns := self columns .
1100+ arrayOfColumns := self asArrayOfColumns .
11021101 1 to: self numberOfColumns do: [ :column |
11031102 1 to: self numberOfRows do: [ :row |
11041103 ((arrayOfColumns at: column) at: row) ifNil: [ ^ true ] ] ].
@@ -1442,7 +1441,7 @@ DataFrame >> normalized [
14421441 ' DataFrame will remove the dependency over normalization in the next version. You can use pharo-ai/data-preprocessing project to normalize your DataFrame and even more!' .
14431442 normalizers := (1 to: self anyOne size) collect: [ :e | self class defaultNormalizerClass new ].
14441443
1445- normalizedColumns := self columns with: normalizers collect: [ :col :normalizer | col normalizedUsing: normalizer ].
1444+ normalizedColumns := self asArrayOfColumns with: normalizers collect: [ :col :normalizer | col normalizedUsing: normalizer ].
14461445
14471446 ^ self class withColumns: normalizedColumns columnNames: self columnNames
14481447]
@@ -1473,6 +1472,22 @@ DataFrame >> numberOfRows [
14731472 ^ contents numberOfRows
14741473]
14751474
1475+ { #category : #accessing }
1476+ DataFrame >> numericalColumnNames [
1477+ " Returns the names of all numerical columns of the dataframe"
1478+
1479+ ^ self columnNames select: [ :columnName |
1480+ (self dataTypes at: columnName) includesBehavior: Number ]
1481+ ]
1482+
1483+ { #category : #accessing }
1484+ DataFrame >> numericalColumns [
1485+ " Returns all numerical columns of the dataframe"
1486+
1487+ ^ self columns select: [ :column |
1488+ (self dataTypes at: column name) includesBehavior: Number ]
1489+ ]
1490+
14761491{ #category : #splitjoin }
14771492DataFrame >> outerJoin: aDataFrame [
14781493 " Performs outer join on aDataFrame with rowNames as keys"
@@ -1838,6 +1853,18 @@ DataFrame >> replaceNilsWithMode [
18381853 modeOfColumn := nil ]
18391854]
18401855
1856+ { #category : #replacing }
1857+ DataFrame >> replaceNilsWithNextRowValue [
1858+
1859+ | value numberOfRows |
1860+ numberOfRows := self numberOfRows.
1861+ 1 to: self numberOfColumns do: [ :i |
1862+ self numberOfRows to: 1 by: - 1 do: [ :j |
1863+ j < numberOfRows ifTrue: [
1864+ (self at: j at: i) ifNil: [ self at: j at: i put: value ] ].
1865+ value := self at: j at: i ] ]
1866+ ]
1867+
18411868{ #category : #replacing }
18421869DataFrame >> replaceNilsWithPreviousRowValue [
18431870 " Replaces all nil values of a data frame with the previous non-nil value of the column in which it is present"
0 commit comments