> For the complete documentation index, see [llms.txt](https://docs.zingg.ai/zingg/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zingg.ai/zingg/versions/community-v0.3.3/stepbystep/createtrainingdata/exportlabeleddata.md).

# Exporting labeled data as csv

## Export labeled data from previously labeled Zingg learner pairs and import it to new Zingg instance/model

Labelled data of one model can be exported and used as training data for another model.

Here are the instructions to do this. We are going to use pyspark, which comes with the Apache Spark installation.

To run pyspark,

```
$ $SPARK_HOME/bin/pyspark
```

The pyspark command will open a pyspark shell. We will now read the labeled data from the existing model/labelled rounds. Please run the following commands in the pyspark shell.

## Getting Training data

Let us first read te labelled data into Spark as follows. You will need to pass the appropriate location of the model folder from where you want to copy the training data. Tyically, this is the zinggDir/modelId/trainingData/marked folder. Zingg examples write the model uder ZINGG\_HOME/models//trainingData/marked.

```
labeledData = spark.read.parquet("<fully qualified location of models/modelId>/trainingData/marked")
```

The labeled data above has extra attributes added by Zingg beyond the field definitions in the config json. Let us define these in pyspark.

```
baseCols = ['z_cluster', 'z_zid', 'z_prediction', 'z_score', 'z_source', 'z_isMatch']
```

The following command will filter out all the Zingg added columns. After running, sourceDataColumns will contain the original columns which define the user data.

```
sourceDataColumns =  [c for c in labeledData.columns if c not in  baseCols]
```

But we also need the labels and the clusters assigned to them to utilize the work we did earlier during labelling. The following columns contain that information.

```
additionalTrainingColumns = ['z_cluster','z_isMatch']
```

Let us now build our dataframe with the list of columns needed for training samples in desired sequence.

```
trainingSampleColumns = [*additionalTrainingColumns, *sourceDataColumns]
```

With the trainingSampleColumns in place, let us now select all the required columns from the labeled data. This data will be exported to csv and become our training data.

```
trainingSamples = labeledData.select(trainingSampleColumns)
```

Let us now Save the samples in a single csv file.

```
trainingSamples.coalesce(1).write.csv("<location>")
```

At the above location folder, a file named part\*\*\*.csv will get created. This file contains the labeled data so far.

## Getting Schema

We can generate the schema of this file to feed as part of the trainingSamples schema by the following command. This schema can be used for the trainingSamples schema in the Zingg config file.

```
trainingSamples.schema.jsonValue()
```

While running pyspark, you can view the list of columns or actual labeled data, print columns etc by using the following commands

```
trainingSamples.show()
trainingSamples.columns
print(trainingSampleColumns)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zingg.ai/zingg/versions/community-v0.3.3/stepbystep/createtrainingdata/exportlabeleddata.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
