I don’t think the WeightedRandomSampler creates the error, but your pandas.DataFrame raises a KeyError so you should check how this DataFrame is called and make sure the keys are valid.
PS: it’s better to post code snippets by wrapping them into three backticks ```, which would make debugging easier.