Last active
March 11, 2020 05:58
-
-
Save witoong623/86960cb33253613e15cd5a8d86b413fb to your computer and use it in GitHub Desktop.
This file contains 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 | |
csvfiles = { | |
'ACRU': 'ACRU.csv', | |
'ANLI': 'ANLI.csv', | |
'BBUA': 'BBUA.csv' | |
} | |
data = {} | |
for key, filename in csvfiles.items(): | |
with open('ACRU.csv', newline='') as csvfile: | |
measure_values = csv.reader(csvfile, delimiter=',') | |
first = True | |
for row in measure_values: | |
if first: | |
first = False | |
continue | |
year, month, day, time, rain = row | |
if data.get(f'{year}-{month}-{day}') is None: | |
data[f'{year}-{month}-{day}'] = [] | |
row.append(key) | |
data[f'{year}-{month}-{day}'].append(row) | |
for key, day_data in data.items(): | |
with open(f'output/{key}.csv', 'w', newline='') as f: | |
writer = csv.writer(f, delimiter=',') | |
# header | |
writer.writerow(['year','month','day','time','rain', 'station']) | |
for row in day_data: | |
writer.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment