Skip to content

Commit d9941b8

Browse files
committed
Add an example in the documentation for List<List<T>>.toDataFrame
1 parent e76f826 commit d9941b8

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Create.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,22 @@ class Create : TestBase() {
425425
val df = files.toDataFrame(columnName = "data")
426426
// SampleEnd
427427
}
428+
429+
@Test
430+
@TransformDataFrameExpressions
431+
fun toDataFrameLists() {
432+
// SampleStart
433+
val lines = """
434+
1
435+
00:00:05,000 --> 00:00:07,500
436+
This is the first subtitle.
437+
438+
2
439+
00:00:08,000 --> 00:00:10,250
440+
This is the second subtitle.
441+
""".trimIndent().lines()
442+
443+
lines.chunked(4) { it.take(3) }.toDataFrame(header = listOf("n", "timestamp", "text"))
444+
// SampleEnd
445+
}
428446
}

docs/StardustDocs/topics/_shadow_resources.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<resource src="org.jetbrains.kotlinx.dataframe.samples.api.Analyze.statisticGroupBySingle.html"></resource>
8989
<resource src="org.jetbrains.kotlinx.dataframe.samples.api.Access.takeLast.html"></resource>
9090
<resource src="org.jetbrains.kotlinx.dataframe.samples.api.Create.toDataFrameColumn.html"></resource>
91+
<resource src="org.jetbrains.kotlinx.dataframe.samples.api.Create.toDataFrameLists.html"></resource>
9192
<resource src="org.jetbrains.kotlinx.dataframe.samples.api.Modify.updateWith.html"></resource>
9293
<resource src="org.jetbrains.kotlinx.dataframe.samples.api.Modify.addRecurrent.html"></resource>
9394
<resource src="org.jetbrains.kotlinx.dataframe.samples.api.Analyze.groupByWithoutAggregation.html"></resource>
@@ -199,4 +200,4 @@
199200
<resource src="formatHeader.html"></resource>
200201
<resource src="notebook_test_rename_3.html"></resource>
201202
<resource src="notebook_test_rename_4.html"></resource>
202-
<resource src="notebook_test_rename_5.html"></resource>
203+
<resource src="notebook_test_rename_5.html"></resource>

docs/StardustDocs/topics/createDataFrame.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,29 @@ val df = files.toDataFrame(columnName = "data")
160160
<inline-frame src="resources/org.jetbrains.kotlinx.dataframe.samples.api.Create.toDataFrameColumn.html" width="100%"/>
161161
<!---END-->
162162

163+
Creates a [`DataFrame`](DataFrame.md) from a `List<List<T>>`:
164+
165+
This is useful for parsing text files. For example, the `.srt` subtitle format can be parsed like this:
166+
167+
<!---FUN toDataFrameLists-->
168+
169+
```kotlin
170+
val lines = """
171+
1
172+
00:00:05,000 --> 00:00:07,500
173+
This is the first subtitle.
174+
175+
2
176+
00:00:08,000 --> 00:00:10,250
177+
This is the second subtitle.
178+
""".trimIndent().lines()
179+
180+
lines.chunked(4) { it.take(3) }.toDataFrame(header = listOf("n", "timestamp", "text"))
181+
```
182+
183+
<inline-frame src="resources/org.jetbrains.kotlinx.dataframe.samples.api.Create.toDataFrameLists.html" width="100%"/>
184+
<!---END-->
185+
163186
Creates a [`DataFrame`](DataFrame.md) from an [`Iterable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-iterable/) of objects:
164187

165188
<!---FUN readDataFrameFromObject-->

0 commit comments

Comments
 (0)