If a label is not present, loc raises a KeyError. Make sure the labels exist in your DataFrame.