Skip to content

Commit 8b00384

Browse files
committed
Add examples for Regex-related Split operations
1 parent 2311daa commit 8b00384

File tree

1 file changed

+22
-1
lines changed
  • core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api

1 file changed

+22
-1
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/split.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ public fun <T, C> Split<T, C>.by(
9999
}
100100
}
101101

102+
/**
103+
* Example:
104+
* ```
105+
* dataFrameOf("str" to listOf("1 2 3 4"))
106+
* .split("str").by("\\s+".toRegex())
107+
* // when the list of explicitly specified columnNames is not long enough (or none at all),
108+
* // names for additional columns are generates
109+
* .into()
110+
* ```
111+
* Result:
112+
* ```
113+
* split1 split2 split3 split4
114+
* 1 2 3 4
115+
* ```
116+
*/
102117
@Interpretable("ByRegex")
103118
public fun <T, C> Split<T, C>.by(
104119
regex: Regex,
@@ -138,7 +153,13 @@ internal inline fun <T, C, R> Split<T, C>.by(
138153
// region match
139154

140155
/**
141-
* Creates new String columns according to MatchResult [capturing groups](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/-match-result/group-values.html)
156+
* Creates new String columns according to MatchResult [capturing groups](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/-match-result/group-values.html),
157+
* excluding the first group which is entire matched String.
158+
* Example:
159+
* ```
160+
* dataFrameOf("str" to listOf("100 ml", "1 L"))
161+
* .split { "str"<String>() }.match("(\\d+)\\s*(ml|l|L)").into("volume", "unit")
162+
* ```
142163
* Created columns will be nullable if [regex] doesn't match some rows or there are nulls in original column
143164
* Check [Split.by] overload with regex parameter if you're looking to split String value by [Regex] delimiter
144165
*/

0 commit comments

Comments
 (0)