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
Copy file name to clipboardExpand all lines: docs/StardustDocs/topics/DataColumn.md
+1-123Lines changed: 1 addition & 123 deletions
Original file line number
Diff line number
Diff line change
@@ -35,127 +35,5 @@ Special case of [`ValueColumn`](#valuecolumn) that stores another [`DataFrame`](
35
35
36
36
[`DataFrame`](DataFrame.md) stored in [`FrameColumn`](DataColumn.md#framecolumn) may have different schemas.
37
37
38
-
[`FrameColumn`](DataColumn.md#framecolumn) may appear after [reading](read.md) from JSON or other hierarchical data structures, or after grouping operations such as [groupBy](groupBy.md) or [pivot](pivot.md).
39
-
40
-
## Column accessors
41
-
42
-
`ColumnAccessors` are used for [typed data access](columnAccessorsApi.md) in [`DataFrame`](DataFrame.md). `ColumnAccessor` stores column [`name`](#properties) (for top-level columns) or column path (for nested columns), has type argument that corresponds to [`type`](#properties) of thep column, but it doesn't contain any actual data.
43
-
44
-
<!---FUN columnAccessorsUsage-->
45
-
46
-
```kotlin
47
-
val age by column<Int>()
48
-
49
-
// Access fourth cell in the "age" column of dataframe `df`.
50
-
// This expression returns `Int` because variable `age` has `ColumnAccessor<Int>` type.
51
-
// If dataframe `df` has no column "age" or column "age" has type which is incompatible with `Int`,
52
-
// runtime exception will be thrown.
53
-
df[age][3] +5
54
-
55
-
// Access first cell in the "age" column of dataframe `df`.
56
-
df[0][age] *2
57
-
58
-
// Returns new dataframe sorted by age column (ascending)
59
-
df.sortBy(age)
60
-
61
-
// Returns new dataframe with the column "year of birth" added
62
-
df.add("year of birth") { 2021- age }
63
-
64
-
// Returns new dataframe containing only rows with age > 30
65
-
df.filter { age >30 }
66
-
```
67
-
68
-
<!---END-->
69
-
70
-
[Column accessors](DataColumn.md#column-accessors) are created by [property delegate](https://kotlinlang.org/docs/delegated-properties.html)`column`. Column [`type`](DataColumn.md#properties) should be passed as type argument, column [`name`](DataColumn.md#properties) will be taken from the variable name.
71
-
72
-
<!---FUN createColumnAccessor-->
73
-
74
-
```kotlin
75
-
val name by column<String>()
76
-
```
77
-
78
-
<!---END-->
79
-
80
-
To assign column name explicitly, pass it as an argument.
81
-
82
-
<!---FUN createColumnAccessorRenamed-->
83
-
84
-
```kotlin
85
-
val accessor by column<String>("complex column name")
86
-
```
87
-
88
-
<!---END-->
89
-
90
-
You can also create column accessors for [ColumnGroups](DataColumn.md#columngroup) and [FrameColumns](DataColumn.md#framecolumn)
91
-
92
-
<!---FUN createGroupOrFrameColumnAccessor-->
93
-
94
-
```kotlin
95
-
val columns by columnGroup()
96
-
val frames by frameColumn()
97
-
```
98
-
99
-
<!---END-->
100
-
101
-
To reference nested columns inside [ColumnGroups](DataColumn.md#columngroup), invoke `column<T>()` on accessor to parent [`ColumnGroup`](#columngroup):
102
-
103
-
<!---FUN createDeepColumnAccessor-->
104
-
105
-
```kotlin
106
-
val name by columnGroup()
107
-
val firstName by name.column<String>()
108
-
```
109
-
110
-
<!---END-->
111
-
112
-
You can also create virtual accessor that doesn't point to a real column but computes some expression on every data access:
113
-
114
-
<!---FUN columnAccessorComputed-->
115
-
<tabs>
116
-
<tabtitle="Properties">
117
-
118
-
```kotlin
119
-
val fullName by column(df) { name.firstName +""+ name.lastName }
120
-
121
-
df[fullName]
122
-
```
123
-
124
-
</tab>
125
-
<tabtitle="Strings">
126
-
127
-
```kotlin
128
-
val fullName by column { "name"["firstName"]<String>() +""+"name"["lastName"]<String>() }
129
-
130
-
df[fullName]
131
-
```
132
-
133
-
</tab></tabs>
134
-
<!---END-->
135
-
136
-
If expression depends only on one column, you can also use `map`:
To convert [`ColumnAccessor`](columnAccessorsApi.md) into [`DataColumn`](DataColumn.md) add values using `withValues` function:
151
-
152
-
<!---FUN columnAccessorToColumn-->
153
-
154
-
```kotlin
155
-
val age by column<Int>()
156
-
val ageCol1 = age.withValues(15, 20)
157
-
val ageCol2 = age.withValues(1..10)
158
-
```
159
-
160
-
<!---END-->
38
+
[`FrameColumn`](DataColumn.md#framecolumn) may appear after [reading](read.md) from JSON or other hierarchical data structures, or after grouping operations such as [groupBy](groupBy.md) or [pivot](pivot.md).
0 commit comments