code to reformat from python to sql