Skip to content

Instantly share code, notes, and snippets.

@comtom
Created November 28, 2017 23:25
Show Gist options
  • Select an option

  • Save comtom/28d8a7ba8df0436f3136691a819183b1 to your computer and use it in GitHub Desktop.

Select an option

Save comtom/28d8a7ba8df0436f3136691a819183b1 to your computer and use it in GitHub Desktop.
import time
import datetime
with open('file1.csv', 'w') as output:
with open('combined_data_1.txt', 'r') as f:
currentMovieID = 0
for line in f:
line = line.strip()
if (line[len(line) - 1] == ":"):
currentMovieID = int(line[0: len(line) - 1])
else:
(userID, rating, rating_date) = line.split(',')
rating_date = int(time.mktime(datetime.datetime.strptime(rating_date, "%Y-%m-%d").timetuple()))
output.write('%s,%s,%s,%s\n' % (currentMovieID, userID, rating_date, rating))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment