Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- filepath = 'amazon-meta.txt'
- id = 1
- limit = 15001
- csv_data = []
- with open(filepath, mode='r') as file:
- line = file.readline()
- while id < limit:
- if 'group' in line and 'Book' in line:
- while 'cutomer' not in line:
- line = file.readline()
- while 'cutomer' in line:
- data = line[line.find('cutomer:') + len('cutomer:'):line.rfind('votes')].strip().replace('rating:', '').replace(' ', '', 2).replace(' ', ',', 1)
- data_as_list = data.split(',')
- csv_data.append([str(id), data_as_list[0], data_as_list[1]])
- line = file.readline()
- id += 1
- line = file.readline()
- with open('books.csv', mode='w', newline='') as file:
- writer = csv.writer(file)
- writer.writerows(csv_data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement