September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -0,0 +1,22 @@
import csv
from pathlib import Path
from tempfile import NamedTemporaryFile
filepath = Path('data.csv')
temp_file = NamedTemporaryFile('w',
newline='',
delete=False)
with filepath.open() as csv_file, temp_file:
reader = csv.reader(csv_file)
writer = csv.writer(temp_file)
header = next(reader)
writer.writerow(header + ['SUM'])
for row in reader:
row_sum = sum(map(int, row))
writer.writerow(row + [row_sum])
temp_file_path = Path(temp_file.name)
temp_file_path.replace(filepath)

View file

@ -0,0 +1,8 @@
import pandas as pd
filepath = 'data.csv'
df = pd.read_csv(filepath)
rows_sums = df.sum(axis=1)
df['SUM'] = rows_sums
df.to_csv(filepath, index=False)