working script to extract data and create new .csv