File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed
core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 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 >
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 >
Original file line number Diff line number Diff 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+
163186Creates a [ ` DataFrame ` ] ( DataFrame.md ) from an [ ` Iterable ` ] ( https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-iterable/ ) of objects:
164187
165188<!-- -FUN readDataFrameFromObject-->
You can’t perform that action at this time.
0 commit comments