[Tutor] toy program to find standard deviation of 2 columns of a sqlite3 database

Manprit Singh manpritsinghece at gmail.com
Mon Jul 4 01:49:54 EDT 2022


Dear Sir,

My target is still to do this task in pure python. without using an
iterable.
Just shown you using pandas, how easy it is in the last mail . There are
several easy ways also. I will come up with a solution given by Dennis Lee
bieber.


I am exploring other options also, The one using numpy was also explored by
me as given below:

import sqlite3
import numpy as np

conn = sqlite3.connect(":memory:")
cur = conn.cursor()
cur.execute("create table table1(X1, X2)")
lst = [(2, 5),
         (4, 3),
         (5, 2),
         (7, 1)]
cur.executemany("insert into table1 values(?, ?)", lst)
cur.execute("select * from table1")
print(np.std(cur.fetchall(), axis=0))

array([1.80277564, 1.47901995])  which is the right answer

For column names :
col_names= [cur.description[i][0] for i in (0, 1)]
print(col_names)

['X1', 'X2']




My target is still to do this task in pure python. with out using an
iterable


More information about the Tutor mailing list