You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Counts the number of rows in this [DataFrame] that satisfy the given [predicate].
70
+
*
71
+
* The [predicate] is a [RowFilter][org.jetbrains.kotlinx.dataframe.RowFilter] — a lambda that receives each [DataRow][org.jetbrains.kotlinx.dataframe.DataRow] both as `this` and `it`,
72
+
* allowing you to define a [Boolean] condition using the row's values,
73
+
* including through [extension properties][org.jetbrains.kotlinx.dataframe.documentation.ExtensionPropertiesAPIDocs] for convenient access.
74
+
*
75
+
* See also:
76
+
* - [filter][DataFrame.filter] — filters rows using a [RowFilter] condition.
77
+
* - [countDistinct][DataFrame.countDistinct] — counts distinct rows or values.
78
+
*
79
+
* For more information: [See `count` on the documentation website.](https://kotlin.github.io/dataframe/count.html)
80
+
*
81
+
* ### Example
82
+
* ```kotlin
83
+
* // Count rows where the value in the "age" column is greater than 18
84
+
* // and the "name/firstName" column starts with 'A'
85
+
* df.count { age > 18 && name.firstName.startsWith("A") }
86
+
* // Count rows
87
+
* df.count { prev()?.length >= 50.0 ?: false }
88
+
* ```
89
+
*
90
+
* @param T The schema marker type of the [DataFrame].
91
+
* @param predicate A [RowFilter] that returns `true` for rows that should be counted.
92
+
* @return The number of rows that satisfy the predicate.
* Aggregates this [GroupBy] by counting the number of rows in each group
131
+
* that satisfy the given [predicate].
132
+
*
133
+
* The [predicate] is a [RowFilter][org.jetbrains.kotlinx.dataframe.RowFilter] — a lambda that receives each [DataRow][org.jetbrains.kotlinx.dataframe.DataRow] both as `this` and `it`,
134
+
* allowing you to define a [Boolean] condition using the row's values,
135
+
* including through [extension properties][org.jetbrains.kotlinx.dataframe.documentation.ExtensionPropertiesAPIDocs] for convenient access.
136
+
*
137
+
* Returns a new [DataFrame] where each row corresponds to a group.
138
+
* The resulting frame contains:
139
+
* - the original group key columns,
140
+
* - a new column (named [resultName], defaults to `"count"`)
141
+
* that stores the number of rows in each group matching the [predicate].
142
+
*
143
+
* This is equivalent to calling `.aggregate { count(predicate) }`, but more efficient.
144
+
*
145
+
* See also [DataFrame.groupBy] and common [aggregate][Grouped.aggregate].
146
+
*
147
+
* For more information: [See `count` on the documentation website.](https://kotlin.github.io/dataframe/count.html)
148
+
*
149
+
* ### Example
150
+
* ```kotlin
151
+
* // Count rows for each city where the "income" value is greater than 30.0.
152
+
* // Returns a new DataFrame with columns "city" and "pointsCount".
153
+
* df.groupBy { city }.count("pointsCount") { income >= 30.0 }
154
+
* ```
155
+
*
156
+
* @param resultName The name of the result column containing the group sizes. Defaults to `"count"`.
157
+
* @return A new [DataFrame] with group keys and filtered row counts per group.
158
+
*/
47
159
@Refine
48
160
@Interpretable("GroupByCount0")
49
161
publicinlinefun <T> Grouped<T>.count(
@@ -55,20 +167,159 @@ public inline fun <T> Grouped<T>.count(
55
167
56
168
// region Pivot
57
169
170
+
/**
171
+
* Aggregates this [Pivot] by counting the number of rows in each group.
172
+
*
173
+
* Returns a single [DataRow] where:
174
+
* - each column corresponds to a [pivot] group — if multiple pivot keys were used,
175
+
* the result will contain column groups for each pivot key, with columns inside
176
+
* corresponding to the values of that key;
177
+
* - each value contains the number of rows in that group.
178
+
*
179
+
* The original [Pivot] column structure is preserved.
180
+
* If the [Pivot] was created using multiple or nested keys
181
+
* (e.g., via [and][PivotDsl.and] or [then][PivotDsl.then]),
182
+
* the structure remains unchanged — only the contents of each group
183
+
* are replaced with the number of rows in that group.
184
+
*
185
+
* This is equivalent to calling `.aggregate { count() }`, but more efficient.
* Aggregates this [Pivot] by counting the number of rows in each group
207
+
* that satisfy the given [predicate].
208
+
*
209
+
* The [predicate] is a [RowFilter][org.jetbrains.kotlinx.dataframe.RowFilter] — a lambda that receives each [DataRow][org.jetbrains.kotlinx.dataframe.DataRow] both as `this` and `it`,
210
+
* allowing you to define a [Boolean] condition using the row's values,
211
+
* including through [extension properties][org.jetbrains.kotlinx.dataframe.documentation.ExtensionPropertiesAPIDocs] for convenient access.
212
+
*
213
+
* Returns a single [DataRow] where:
214
+
* - each column corresponds to a [pivot] group — if multiple pivot keys were used,
215
+
* the result will contain column groups for each pivot key, with columns inside
216
+
* corresponding to the values of that key;
217
+
* - each value contains the number of rows in that group matching the [predicate].
218
+
*
219
+
* The original [Pivot] column structure is preserved.
220
+
* If the [Pivot] was created using multiple or nested keys
221
+
* (e.g., via [and][PivotDsl.and] or [then][PivotDsl.then]),
222
+
* the structure remains unchanged — only the contents of each group
223
+
* are replaced with the number of rows (matching the [predicate]) in that group.
224
+
*
225
+
* This is equivalent to calling `.aggregate { count(predicate) }`, but more efficient.
0 commit comments