Python code to read and write in csv files