6

I have the following df:

import pandas as pd
df = pd.DataFrame({"foo": ["bar", "baz"]})

How do I convert to a Huggingface Dataset?

Vincent Claes
  • 3,960
  • 3
  • 44
  • 62

1 Answers1

10

datasets have an easy way to convert pandas dataframes to hugginface datasets:

from datasets import Dataset
dataset = Dataset.from_pandas(df)

Dataset({
   features: ['foo'],
   num_rows: 2
})

more info here: https://huggingface.co/docs/datasets/main/en/loading#inmemory-data

Vincent Claes
  • 3,960
  • 3
  • 44
  • 62