Skip to content

Instantly share code, notes, and snippets.

@witoong623
Last active March 11, 2020 05:58
Show Gist options
  • Save witoong623/86960cb33253613e15cd5a8d86b413fb to your computer and use it in GitHub Desktop.
Save witoong623/86960cb33253613e15cd5a8d86b413fb to your computer and use it in GitHub Desktop.
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