# convertTo

> For the complete documentation index, see [llms.txt](https://kotlin.github.io/dataframe/llms.txt).

[Converts](convert.html) all columns in the [DataFrame](dataframe.html) to match a given schema [Schema](schema.html).

API reference: [convertTo](https://kotlin.github.io/dataframe/api-docs/core/org.jetbrains.kotlinx.dataframe.api/convert-to.html)

```KOTLIN
convertTo<Schema>(excessiveColumns = ExcessiveColumns.Keep)
```

Related operations: [Adjust schema](adjustschema.html), [convert](convert.html)

> **Tip:**
> This page is for the `DataFrame<*>.convertTo<Schema>()` operation.
>
>
>
> If you were looking for [DataColumn&lt;*&gt;.convertTo&lt;ValueType&gt;()](convert.html), see [convert](convert.html).

Conversion to match the target schema is done mostly automatically; DataFrame knows how to convert between many types (see [convert](convert.html) for details and the supported types).

However, if you have a custom type in your target schema, or the automatic conversion fails, you can provide a custom converter, parser, or filler for it. These have priority over the automatic ones.

Customization DSL:

* `convert<A>.with { it.toB() }` * Provides `convertTo<>()` with the knowledge of how to convert `A` to `B`

* `parser { YourType.fromString(it) }` * Provides `convertTo<>()` with the knowledge of how to parse strings/chars into `YourType` * Shortcut for `convert<String>().with { YourType.fromString(it) }` * Chars are treated as strings unless you explicitly specify `convert<Char>().with { YourType.fromChar(it) }`

* `fill { some cols }.with { rowExpression }` * Makes `convertTo<>()` fill missing (or existing) columns from the target schema with values computed by the given row expression

```KOTLIN
class MyType(val value: Int)

@DataSchema
class MySchema(val a: MyType, val b: MyType, val c: Int)
```

```KOTLIN
val df: AnyFrame = dataFrameOf(
    "a" to columnOf(1, 2, 3),
    "b" to columnOf("1", "2", "3"),
)
df.convertTo<MySchema> {
    // providing the converter: Int -> MyType, so column `a` can be converted
    convert<Int>().with { MyType(it) }
    // providing the parser: String -> MyType, so column `b` can be converted
    parser { MyType(it.toInt()) }
    // providing the filler for `c`, as it's missing in `df`
    fill { c }.with { a.value + b.value }
}
```

