@@ -662,7 +662,7 @@ DataFrame >> firstQuartile [
662662 ^ self applyToAllColumns: #firstQuartile
663663]
664664
665- { #category : #queries }
665+ { #category : #grouping }
666666DataFrame >> group: colNameOrArray by: colName [
667667
668668 | left right |
@@ -676,7 +676,7 @@ DataFrame >> group: colNameOrArray by: colName [
676676 ^ left groupBy: right.
677677]
678678
679- { #category : #queries }
679+ { #category : #grouping }
680680DataFrame >> groupBy: colName [
681681
682682 | groupedColNames |
@@ -689,7 +689,7 @@ DataFrame >> groupBy: colName [
689689 by: (self column: colName)
690690]
691691
692- { #category : #queries }
692+ { #category : #grouping }
693693DataFrame >> groupBy: colName aggregate: selector [
694694
695695 ^ (self groupBy: colName) perform: selector.
@@ -733,30 +733,20 @@ DataFrame >> head: aNumber [
733733
734734{ #category : #private }
735735DataFrame >> indexOfColumnNamed: columnName [
736-
737- | index |
738- index := self columnNames indexOf: columnName.
739-
740- " If a column with that name does not exist"
741- index = 0
742- ifTrue: [ NotFoundError signal :
736+ " Answer the index of a column with a given name or signal an exception if the column with that name was not found"
737+ ^ self columnNames
738+ indexOf: columnName
739+ ifAbsent: [ NotFoundError signal :
743740 (' Column ' , columnName, ' was not found' ) ].
744-
745- ^ index
746741]
747742
748743{ #category : #private }
749744DataFrame >> indexOfRowNamed: rowName [
750-
751- | index |
752- index := self rowNames indexOf: rowName.
753-
754- " If a row with that name does not exist"
755- index = 0
756- ifTrue: [ NotFoundError signal :
745+ " Answer the index of a row with a given name or signal an exception if the row with that name was not found"
746+ ^ self rowNames
747+ indexOf: rowName
748+ ifAbsent: [ NotFoundError signal :
757749 (' Row ' , rowName, ' was not found' ) ].
758-
759- ^ index
760750]
761751
762752{ #category : #initialization }
@@ -895,6 +885,22 @@ DataFrame >> removeRowAt: rowNumber [
895885 rowNames := rowNames copyWithoutIndex: rowNumber.
896886]
897887
888+ { #category : #renaming }
889+ DataFrame >> renameColumn: oldName to: newName [
890+ " Find a column with oldName and rename it to newName"
891+ | index |
892+ index := self indexOfColumnNamed: oldName.
893+ self columnNames at: index put: newName.
894+ ]
895+
896+ { #category : #renaming }
897+ DataFrame >> renameRow: oldName to: newName [
898+ " Find a row with oldName and rename it to newName"
899+ | index |
900+ index := self indexOfRowNamed: oldName.
901+ self rowNames at: index put: newName.
902+ ]
903+
898904{ #category : #accessing }
899905DataFrame >> row: rowName [
900906
@@ -1127,12 +1133,7 @@ DataFrame >> thirdQuartile [
11271133DataFrame >> toColumn: columnName applyElementwise: aBlock [
11281134
11291135 | index |
1130- index := self columnNames indexOf: columnName.
1131-
1132- " If a column with that name does not exist"
1133- index = 0
1134- ifTrue: [ NotFoundError signal ].
1135-
1136+ index := self indexOfColumnNamed: columnName.
11361137 self toColumnAt: index applyElementwise: aBlock.
11371138]
11381139
0 commit comments