Created
July 15, 2020 16:57
-
-
Save sobernaut/4f87424b5e3441e561e45c8b26864dd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import csv | |
| filename = 'E:/Desai_Jaison_ResearchFiles/From Server/NBI/Panel2.csv' | |
| header = [] | |
| val = {} | |
| with open(filename, 'r') as f: | |
| reader = csv.reader(f) | |
| line_count = 0 | |
| for row in reader: | |
| if line_count == 0: | |
| header = row | |
| line_count += 1 | |
| else: | |
| year = row[9] | |
| year_built = row[166] | |
| nbi_year = row[603] | |
| if year in val: | |
| val[year].append(row) | |
| else: | |
| val[year] = [row] | |
| line_count += 1 | |
| if line_count % 1000000 == 0: | |
| print(line_count) | |
| print("Processed file {} with {} lines".format(filename, line_count)) | |
| all_years = list(val.keys()) | |
| for y in all_years: | |
| f = y + '.csv' | |
| with open('./updated/' + f, 'w', newline='') as csv_file: | |
| writer = csv.writer(csv_file) | |
| data = val[y] | |
| writer.writerow(header) | |
| for d in data: | |
| writer.writerow(d) | |
| print("Written new file {} with {} lines".format(f, len(data))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment