import sqlite3 db = sqlite3.connect(':memory:') db = sqlite3.connect('met_office') # Get a cursor object cursor = db.cursor() print(" Cwmystwyth maximum monthly rainfall values") print(" mm ins") for row in cursor.execute("SELECT s_year , s_month , MAX(rain) FROM cwmystwyth GROUP BY s_month"): y=row[0] m=row[1] rmm = row[2] rins= rmm/25.4 print(" {0:4} {1:2} {2:7.2f} {3:7.2f}".format(y,m,rmm,rins)) db.close()