Skip to content

Instantly share code, notes, and snippets.

View trenton3983's full-sized avatar

Trenton J. McKinney trenton3983

View GitHub Profile
@trenton3983
trenton3983 / no_pandas.py
Created September 26, 2020 23:16
read csv, format date, sort by date, add header, write to file, without pandas
with open('test.csv', mode='r+', newline='') as f:
data = list(csv.reader(f))
for i, v in enumerate(data):
v[0] = datetime.strptime(v[0], "%d-%b-%y").date().strftime('%Y-%m-%d')
data[i] = v
data = sorted(data, key=lambda row: datetime.strptime(row[0], '%Y-%m-%d'))
writer = csv.writer(f)
header = ['date', 1, 2, 3, 4, 5]
f.seek(0)
f.truncate()