AttributeError: 'Dataset' object has no attribute 'pop'

I keep receiving this error, with whatever i try and do to a dataset dictionary that i downloaded from hugging face. I want to remove certain features from the dictionary and just keep a few. (base_prompt, best_answer)

features_kept = [‘base_prompt’, ‘best_answer’]
test_set_new = {key: value for key, value in test_reloaded.items() if key in features_kept}

second error:
AttributeError: ‘Dataset’ object has no attribute ‘pop’

code:
prompt_removed = test_reloaded.pop(‘base_prompt’)
answer_removed = test_reloaded.pop(‘best_answer’)

I can seem to figure out how to solve?

Any help would be much appreciated. Thank you.

Hello there :wave:

To remove features in a Dataset you need to use the .remove_columns() method. Doc here.

1 Like

Thank you so much! I’ve actually just found a hugging face video aswell!

For anyone, who wants to learn this and other things relating to changing datasetDicts hugging face have made a great video. Hope this helps.

Slice and dice a dataset by hugging face :YouTube

if the link doesn’t work.