0

I have a csv file given in seconds formatted like so:

0
1
0
0
0
0
1

My question is how do I use a for loop to convert the data in the csv file(seconds) to minutes and hours and write it back to the same csv file in a different column. Here is what I have so far:

data[]
input_file = open("geiger.csv", "r")
for line in input_file:
    data.append(int(line))
    #Here needs to be modulus of data in sec to get minutes and hours
    #writing back to csv file

I am not sure what to do for the commented sections. Any help is appreciated. Thanks!

njzk2
  • 38,969
  • 7
  • 69
  • 107
  • Can you be more specific? Which part are you struggling with, exactly? – AMC Feb 26 '20 at 23:29
  • Divide by `3600` to get hours, divide the remainder by `60` to get minutes, and the final remainder is seconds. – Barmar Feb 26 '20 at 23:32
  • For writing it to the csv file, use a second file handler `output_file = open(r"formattedData.csv", "w+")`. Then get `minutes` by dividing the line (seconds) by 60. Get `hours` by dividing the minutes by 60. Use the output_file file handler to write to the new file with commas like so: `output_file.write(line.strip() + ", " + str(minutes) + ", " + str(hours) +"\n")` – Jamin Feb 26 '20 at 23:40

0 Answers0