Manipulate data efficiently in Python | Other SQL Question