Generalize processing legends in a CSV file