I have a list of dictionaries. for example
data =[{'col1
:‘foo1’,col2’:‘bar1’}, {‘col1:'foo2',col2':'bar2'},...,{'col1
:‘foon’,col2’:‘barn’}]’
how can I convert this array into a huggingface dataset object?
I think the easiest way would be datasets.Dataset.from_pandas(pd.DataFrame(data=data))
.
6 Likes
Thank you very much @beneyal ! It worked!
2 Likes
from datasets import Dataset
my_dict = {"a": [1, 2, 3]}
dataset = Dataset.from_dict(my_dict)
2 Likes
If your dataset is a list of dicts, then Dataset.from_list()
is made for this:
from datasets import Dataset
data = [{'col1':'foo1','col2':'bar1'}, {'col1':'foo2','col2':'bar2'},...,{'col1':'foon','col2':'barn'}]
dataset = Dataset.from_list(data)