File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3694,6 +3694,26 @@ DataFrameTest >> testRemoveColumnsWithNilsAtRowOutOfRange [
36943694 self should: [ df removeColumnsWithNilsAtRow: 100 ] raise: SubscriptOutOfBounds
36953695]
36963696
3697+ { #category : #tests }
3698+ DataFrameTest >> testRemoveDuplicatedRows [
3699+
3700+ |dataFrame |
3701+
3702+ dataFrame := DataFrame withRows: #(
3703+ (Barcelona 1.609 true)
3704+ (Dubai 2.789 true )
3705+ (London 8.788 false )
3706+ (Barcelona 1.609 true )
3707+ (London 8.788 false )).
3708+
3709+ dataFrame rowNames: #(A B C D E) .
3710+ dataFrame columnNames: #(City Population BeenThere) .
3711+
3712+ dataFrame removeDuplicatedRows.
3713+ self assert: df equals: dataFrame.
3714+
3715+ ]
3716+
36973717{ #category : #removing }
36983718DataFrameTest >> testRemoveRow [
36993719
Original file line number Diff line number Diff line change @@ -1667,6 +1667,22 @@ DataFrame >> removeColumnsWithNilsAtRowNamed: rowName [
16671667 self removeColumnsOfRowElementsSatisfing: [ :ele | ele isNil ] onRowNamed: rowName
16681668]
16691669
1670+ { #category : #removing }
1671+ DataFrame >> removeDuplicatedRows [
1672+ " Removes duplicate rows of a dataframe except the first unique row"
1673+
1674+ | numberOfRows nextRowIndex currentRow row aSet |
1675+ aSet := Set new .
1676+ numberOfRows := self numberOfRows.
1677+ 1 to: numberOfRows do: [ :currentRowIndex |
1678+ currentRow := self rowAt: currentRowIndex.
1679+ nextRowIndex := currentRowIndex + 1 .
1680+ nextRowIndex to: numberOfRows do: [ :index |
1681+ row := self rowAt: index.
1682+ row values = currentRow values ifTrue: [ aSet add: index ] ] ].
1683+ ^ self removeRowsAt: aSet
1684+ ]
1685+
16701686{ #category : #removing }
16711687DataFrame >> removeRow: rowName [
16721688 " Removes the row named rowName from a data frame"
You can’t perform that action at this time.
0 commit comments