# Answer column not dictionary it is string when load csv using load\_dataset

**URL:** <https://discuss.huggingface.co/t/answer-column-not-dictionary-it-is-string-when-load-csv-using-load-dataset/37777>\
**Category:** 🤗Datasets\
**Created:** [April 26, 2023, 9:36am UTC](https://discuss.huggingface.co/t/answer-column-not-dictionary-it-is-string-when-load-csv-using-load-dataset/37777 "2023-04-26T09:36:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Indramal](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/indramal/32/61744_2.png) [@Indramal](https://discuss.huggingface.co/u/Indramal)\
**Post date:** [April 26, 2023, 9:36am UTC](https://discuss.huggingface.co/t/answer-column-not-dictionary-it-is-string-when-load-csv-using-load-dataset/37777/1 "2023-04-26T09:36:59Z")

</div>

I have two CSV file for train and validation. When I import those csv using following code, it give string type not dictionary type data for answer.

```auto
from datasets import load_dataset

datafiles = {"train":"/content/tain.csv","validation":"/content/validation.csv"}

raw_datasets = load_dataset('csv',data_files=datafiles)

```

Output:

```auto
DatasetDict({
    train: Dataset({
        features: ['id', 'context', 'question', 'answers'],
        num_rows: 5834
    })
    validation: Dataset({
        features: ['id', 'context', 'question', 'answers'],
        num_rows: 1459
    })
})

```

when I access answers, it is string not dictionary.

`raw_datasets["train"][0]['answers']`

`'{'text': ['Vimy Ridge'], 'answer_start': [51]}'`

Can not access text. `raw_datasets["train"][0]['answers']['text']` give error.

---

<div class="post-metadata">

**Author:** ![lhoestq](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lhoestq/32/52888_2.png) [@lhoestq](https://discuss.huggingface.co/u/lhoestq)\
**Post date:** [May 2, 2023, 12:44pm UTC](https://discuss.huggingface.co/t/answer-column-not-dictionary-it-is-string-when-load-csv-using-load-dataset/37777/2 "2023-05-02T12:44:43Z")

</div>

Hi ! CSV data are not nested: each field can be a string or a number but not nested data.

You can try loading JSON files instead or decoding the nested data using `json.loads` in `map`:

```python
datasets = raw_datasets.map(lambda x: {"answers": json.loads(x["answers"])})

```
