Re: Python on background for data analyst track

"A. Jorge Garcia via Edu-sig" <[email protected]> Wed, 1 Mar 2023 17:11:37 +0000 (UTC)
Newsgroups gmane.comp.python.education
Message-ID <[email protected]>
--===============0874171245071524288==
Content-Type: multipart/alternative;
	boundary="----=_Part_1114721_1281213914.1677690697562"

------=_Part_1114721_1281213914.1677690697562
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi Kirby!
Great post. Your students are really lucky to have you as their teacher!
I'm introducing teachers to Jupyter Notebooks at a local math conference ca=
lled LIMACON I attend every March hosted by SUNY @ Old Westbury.
Here's a little blog post about my presentation (speaker #8): http://shadow=
faxrant.blogspot.com=C2=A0
Good job,Al
A. Jorge Garcia=C2=A0Applied Math & CompSciNassau Community College=C2=A0

Sent from the all new AOL app for Android=20
=20
  On Wed, Mar 1, 2023 at 11:52 AM, kirby urner<[email protected]> wrote=
:  =20

As some of us will have experienced, quite a few budding data analysts in t=
raining will come to Python via numpy and pandas, heading towards seaborn a=
nd dash, perhaps from past experience in R or Matlab, perhaps not.=C2=A0=20

They've never yet had a core Python class, but are likely to have one in th=
e near future, if they decide to stay within the Python ecosystem and/or st=
ick with data science.
I've got such a cohort coming my way and thought this time I would develop =
some more explicit background content on Python, the core language, which I=
'm calling "warm-up notebooks" and so far doing in Jupyter.
https://github.com/4dsolutions/clarusway_data_analysis/tree/main/python_war=
m_up
Here are some pedagogical features I incorporate that might be of interest =
to others in a similar position of needing to develop curriculum:

1.=C2=A0 mention numpy and pandas early
There's nothing conceptually that hard about a rectangle of numbers, addres=
sable by row and column.=C2=A0 The mechanisms of installing 3rd party packa=
ges may be addressed.
Introduce range, then why not arange and linspace for compare and contrast =
purposes.=C2=A0=20

I go straight to numpy and pandas in notebook 2.=C2=A0 To see the sequence,=
 see here (home base for the class):
https://github.com/4dsolutions/clarusway_data_analysis/blob/main/DAwPy_S1_(=
Numpy_Arrays)/daily_schedule.ipynb
I'm still adding notebooks.

2.=C2=A0 functions are just another type of object
In exploring the various built-in types, with Python allowing us to make ne=
w types, it becomes useful to see individual functions as instances of the =
function type, where list, tuple, int, str.... function are all built-in ty=
pes.
We don't use keyword class to define a function, but keyword def (or maybe =
lambda).=C2=A0=20

What makes function instances stand out is they're callable.=C2=A0 But so a=
re instances of classes implementing __call__.
[1] def f(x):
=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return x * x =C2=A0# return x times i=
tself
[2] type(f)function
[3] issubclass(type(f), object)True
[4] isinstance(f, type(f))True
3.=C2=A0 Use "composition of functions" to motivate drive a decorator synta=
x intro
I've been doing this for a while now.=C2=A0 Most students will remember com=
position of functions from high school, and if not, it's an easy concept.
def f(x):=C2=A0=C2=A0=C2=A0 return 2 * x
def g(x):=C2=A0=C2=A0=C2=A0 return x**2


print("f after g:", f(g(arg)))
print("g after f:", g(f(arg)))
Output:
f after g: 200
g after f: 400
What's not so easy, an may require active tutoring, is passing a function i=
nto Composer type like this:
# where decorator syntax will come in handy
f =3D Composer(f)g =3D Composer(g)
print("f after g:", (f * g)(arg))
print("g after f:", (g * f)(arg))
Output (same answers):f after g: 200
g after f: 400
In other words, we repurpose the __mul__ operator (*) to become the compose=
 operator, which in LaTeX is usually \circ.
Kirby
_______________________________________________
Edu-sig mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/edu-sig.python.org/
Member address: [email protected]
 =20

------=_Part_1114721_1281213914.1677690697562
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi Kirby!<div><br><div>Great post. Your students are really lucky to have y=
ou as their teacher!</div><div><br></div><div>I'm introducing teachers to J=
upyter Notebooks at a local math conference called LIMACON I attend every M=
arch hosted by SUNY @ Old Westbury.</div><div><br></div><div>Here's a littl=
e blog post about my presentation (speaker #8): http://shadowfaxrant.blogsp=
ot.com&nbsp;</div><div><br></div><div>Good job,</div><div>Al</div><div><br>=
</div><div>A. Jorge Garcia&nbsp;</div><div>Applied Math &amp; CompSci</div>=
<div>Nassau Community College&nbsp;<br><br><div id=3D"ymail_android_signatu=
re"><a id=3D"ymail_android_signature_link" href=3D"https://play.google.com/=
store/apps/details?id=3Dcom.aol.mobile.aolapp">Sent from the all new AOL ap=
p for Android</a></div> <br> <blockquote style=3D"margin: 0 0 20px 0;"> <di=
v style=3D"font-family:Roboto, sans-serif; color:#6D00F6;"> <div>On Wed, Ma=
r 1, 2023 at 11:52 AM, kirby urner</div><div>&lt;[email protected]&gt; =
wrote:</div> </div> <div style=3D"padding: 10px 0 0 20px; margin: 10px 0 0 =
0; border-left: 1px solid #6D00F6;"> <div id=3D"yiv6204215369"><div dir=3D"=
ltr"><div style=3D"font-family:arial, helvetica, sans-serif;font-size:small=
;" class=3D"yiv6204215369gmail_default"><br></div><div style=3D"font-family=
:arial, helvetica, sans-serif;font-size:small;" class=3D"yiv6204215369gmail=
_default"><br></div><div style=3D"font-family:arial, helvetica, sans-serif;=
font-size:small;" class=3D"yiv6204215369gmail_default">As some of us will h=
ave experienced, quite a few budding data analysts in training will come to=
 Python via numpy and pandas, heading towards seaborn and dash, perhaps fro=
m past experience in R or Matlab, perhaps not.&nbsp; <br></div><div style=
=3D"font-family:arial, helvetica, sans-serif;font-size:small;" class=3D"yiv=
6204215369gmail_default"><br></div><div style=3D"font-family:arial, helveti=
ca, sans-serif;font-size:small;" class=3D"yiv6204215369gmail_default">They'=
ve never yet had a core Python class, but are likely to have one in the nea=
r future, if they decide to stay within the Python ecosystem and/or stick w=
ith data science.</div><div style=3D"font-family:arial, helvetica, sans-ser=
if;font-size:small;" class=3D"yiv6204215369gmail_default"><br></div><div st=
yle=3D"font-family:arial, helvetica, sans-serif;font-size:small;" class=3D"=
yiv6204215369gmail_default">I've got such a cohort coming my way and though=
t this time I would develop some more explicit background content on Python=
, the core language, which I'm calling "warm-up notebooks" and so far doing=
 in Jupyter.</div><div style=3D"font-family:arial, helvetica, sans-serif;fo=
nt-size:small;" class=3D"yiv6204215369gmail_default"><br></div><div style=
=3D"font-family:arial, helvetica, sans-serif;font-size:small;" class=3D"yiv=
6204215369gmail_default"><a rel=3D"nofollow noopener noreferrer" target=3D"=
_blank" href=3D"https://github.com/4dsolutions/clarusway_data_analysis/tree=
/main/python_warm_up">https://github.com/4dsolutions/clarusway_data_analysi=
s/tree/main/python_warm_up</a></div><div style=3D"font-family:arial, helvet=
ica, sans-serif;font-size:small;" class=3D"yiv6204215369gmail_default"><br>=
</div><div style=3D"font-family:arial, helvetica, sans-serif;font-size:smal=
l;" class=3D"yiv6204215369gmail_default">Here are some pedagogical features=
 I incorporate that might be of interest to others in a similar position of=
 needing to develop curriculum:<br></div><div style=3D"font-family:arial, h=
elvetica, sans-serif;font-size:small;" class=3D"yiv6204215369gmail_default"=
><br></div><div style=3D"font-family:arial, helvetica, sans-serif;font-size=
:small;" class=3D"yiv6204215369gmail_default">1.&nbsp; mention numpy and pa=
ndas early</div><div style=3D"font-family:arial, helvetica, sans-serif;font=
-size:small;" class=3D"yiv6204215369gmail_default"><br></div><div style=3D"=
font-family:arial, helvetica, sans-serif;font-size:small;" class=3D"yiv6204=
215369gmail_default">There's nothing conceptually that hard about a rectang=
le of numbers, addressable by row and column.&nbsp; The mechanisms of insta=
lling 3rd party packages may be addressed.</div><div style=3D"font-family:a=
rial, helvetica, sans-serif;font-size:small;" class=3D"yiv6204215369gmail_d=
efault"><br></div><div style=3D"font-family:arial, helvetica, sans-serif;fo=
nt-size:small;" class=3D"yiv6204215369gmail_default">Introduce range, then =
why not arange and linspace for compare and contrast purposes.&nbsp; <br></=
div><div style=3D"font-family:arial, helvetica, sans-serif;font-size:small;=
" class=3D"yiv6204215369gmail_default"><br></div><div style=3D"font-family:=
arial, helvetica, sans-serif;font-size:small;" class=3D"yiv6204215369gmail_=
default">I go straight to numpy and pandas in notebook 2.&nbsp; To see the =
sequence, see here (home base for the class):</div><div style=3D"font-famil=
y:arial, helvetica, sans-serif;font-size:small;" class=3D"yiv6204215369gmai=
l_default"><br></div><div style=3D"font-family:arial, helvetica, sans-serif=
;font-size:small;" class=3D"yiv6204215369gmail_default"><a rel=3D"nofollow =
noopener noreferrer" target=3D"_blank" href=3D"https://github.com/4dsolutio=
ns/clarusway_data_analysis/blob/main/DAwPy_S1_(Numpy_Arrays)/daily_schedule=
.ipynb">https://github.com/4dsolutions/clarusway_data_analysis/blob/main/DA=
wPy_S1_(Numpy_Arrays)/daily_schedule.ipynb</a></div><div style=3D"font-fami=
ly:arial, helvetica, sans-serif;font-size:small;" class=3D"yiv6204215369gma=
il_default"><br></div><div style=3D"font-family:arial, helvetica, sans-seri=
f;font-size:small;" class=3D"yiv6204215369gmail_default">I'm still adding n=
otebooks.<br></div><div style=3D"font-family:arial, helvetica, sans-serif;f=
ont-size:small;" class=3D"yiv6204215369gmail_default"><br></div><div style=
=3D"font-family:arial, helvetica, sans-serif;font-size:small;" class=3D"yiv=
6204215369gmail_default">2.&nbsp; functions are just another type of object=
</div><div style=3D"font-family:arial, helvetica, sans-serif;font-size:smal=
l;" class=3D"yiv6204215369gmail_default"><br></div><div style=3D"font-famil=
y:arial, helvetica, sans-serif;font-size:small;" class=3D"yiv6204215369gmai=
l_default">In exploring the various built-in types, with Python allowing us=
 to make new types, it becomes useful to see individual functions as instan=
ces of the function type, where list, tuple, int, str.... function are all =
built-in types.</div><div style=3D"font-family:arial, helvetica, sans-serif=
;font-size:small;" class=3D"yiv6204215369gmail_default"><br></div><div styl=
e=3D"font-family:arial, helvetica, sans-serif;font-size:small;" class=3D"yi=
v6204215369gmail_default">We don't use keyword class to define a function, =
but keyword def (or maybe lambda).&nbsp; <br></div><div style=3D"font-famil=
y:arial, helvetica, sans-serif;font-size:small;" class=3D"yiv6204215369gmai=
l_default"><br></div><div style=3D"font-family:arial, helvetica, sans-serif=
;font-size:small;" class=3D"yiv6204215369gmail_default">What makes function=
 instances stand out is they're callable.&nbsp; But so are instances of cla=
sses implementing __call__.</div><div style=3D"font-size:small;" class=3D"y=
iv6204215369gmail_default"><span style=3D"font-family:monospace;"><br></spa=
n></div><div style=3D"font-size:small;" class=3D"yiv6204215369gmail_default=
"><span style=3D"font-family:monospace;">[1] def f(x):<br>&nbsp; &nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; return x * x &nbsp;# return x times itself</span></div=
><div style=3D"font-size:small;" class=3D"yiv6204215369gmail_default"><span=
 style=3D"font-family:monospace;"><br></span></div><div style=3D"font-size:=
small;" class=3D"yiv6204215369gmail_default"><span style=3D"font-family:mon=
ospace;">[2] type(f)</span></div><div style=3D"font-size:small;" class=3D"y=
iv6204215369gmail_default"><span style=3D"font-family:monospace;">function<=
/span></div><div style=3D"font-size:small;" class=3D"yiv6204215369gmail_def=
ault"><span style=3D"font-family:monospace;"><br></span></div><div style=3D=
"font-size:small;" class=3D"yiv6204215369gmail_default"><span style=3D"font=
-family:monospace;">[3] issubclass(type(f), object)</span></div><div style=
=3D"font-size:small;" class=3D"yiv6204215369gmail_default"><span style=3D"f=
ont-family:monospace;">True</span></div><div style=3D"font-size:small;" cla=
ss=3D"yiv6204215369gmail_default"><span style=3D"font-family:monospace;"><b=
r></span></div><div style=3D"font-size:small;" class=3D"yiv6204215369gmail_=
default"><span style=3D"font-family:monospace;">[4] isinstance(f, type(f))<=
/span></div><div style=3D"font-family:arial, helvetica, sans-serif;font-siz=
e:small;" class=3D"yiv6204215369gmail_default"><span style=3D"font-family:m=
onospace;">True</span></div><div style=3D"font-family:arial, helvetica, san=
s-serif;font-size:small;" class=3D"yiv6204215369gmail_default"><br></div><d=
iv style=3D"font-family:arial, helvetica, sans-serif;font-size:small;" clas=
s=3D"yiv6204215369gmail_default">3.&nbsp; Use "composition of functions" to=
 motivate drive a decorator syntax intro</div><div style=3D"font-family:ari=
al, helvetica, sans-serif;font-size:small;" class=3D"yiv6204215369gmail_def=
ault"><br></div><div style=3D"font-family:arial, helvetica, sans-serif;font=
-size:small;" class=3D"yiv6204215369gmail_default">I've been doing this for=
 a while now.&nbsp; Most students will remember composition of functions fr=
om high school, and if not, it's an easy concept.</div><div style=3D"font-s=
ize:small;" class=3D"yiv6204215369gmail_default"><span style=3D"font-family=
:monospace;"><br></span></div><div style=3D"font-size:small;" class=3D"yiv6=
204215369gmail_default"><span style=3D"font-family:monospace;">def f(x):</s=
pan></div><div style=3D"font-size:small;" class=3D"yiv6204215369gmail_defau=
lt"><span style=3D"font-family:monospace;">&nbsp;&nbsp;&nbsp; return 2 * x<=
/span></div><div style=3D"font-size:small;" class=3D"yiv6204215369gmail_def=
ault"><span style=3D"font-family:monospace;"><br></span></div><div style=3D=
"font-size:small;" class=3D"yiv6204215369gmail_default"><span style=3D"font=
-family:monospace;">def g(x):</span></div><div style=3D"font-family:arial, =
helvetica, sans-serif;font-size:small;" class=3D"yiv6204215369gmail_default=
"><span style=3D"font-family:monospace;">&nbsp;&nbsp;&nbsp; return x**2</sp=
an><br></div><div style=3D"font-family:arial, helvetica, sans-serif;font-si=
ze:small;" class=3D"yiv6204215369gmail_default"><br></div><div style=3D"fon=
t-family:arial, helvetica, sans-serif;font-size:small;" class=3D"yiv6204215=
369gmail_default"><br></div><span style=3D"font-family:monospace;">print("f=
 after g:", f(g(arg)))<br>print("g after f:", g(f(arg)))</span><div style=
=3D"font-size:small;" class=3D"yiv6204215369gmail_default"><span style=3D"f=
ont-family:monospace;"><br></span></div><div style=3D"font-size:small;" cla=
ss=3D"yiv6204215369gmail_default"><span style=3D"font-family:monospace;">Ou=
tput:<br></span></div><div style=3D"font-size:small;" class=3D"yiv620421536=
9gmail_default"><span style=3D"font-family:monospace;">f after g: 200<br>g =
after f: 400</span></div><div style=3D"font-family:arial, helvetica, sans-s=
erif;font-size:small;" class=3D"yiv6204215369gmail_default"><br></div><div =
style=3D"font-family:arial, helvetica, sans-serif;font-size:small;" class=
=3D"yiv6204215369gmail_default">What's not so easy, an may require active t=
utoring, is passing a function into Composer type like this:</div><div styl=
e=3D"font-family:arial, helvetica, sans-serif;font-size:small;" class=3D"yi=
v6204215369gmail_default"><br></div><div style=3D"font-size:small;" class=
=3D"yiv6204215369gmail_default"><span style=3D"font-family:monospace;"># wh=
ere decorator syntax will come in handy<br></span></div><div style=3D"font-=
size:small;" class=3D"yiv6204215369gmail_default"><span style=3D"font-famil=
y:monospace;">f =3D Composer(f)</span></div><div style=3D"font-size:small;"=
 class=3D"yiv6204215369gmail_default"><span style=3D"font-family:monospace;=
">g =3D Composer(g)</span></div><div style=3D"font-size:small;" class=3D"yi=
v6204215369gmail_default"><span style=3D"font-family:monospace;"><br></span=
></div><span style=3D"font-family:monospace;">print("f after g:", (f * g)(a=
rg))<br></span><div><span style=3D"font-family:monospace;">print("g after f=
:", (g * f)(arg))</span></div><div><span style=3D"font-family:monospace;"><=
br></span></div><div><span style=3D"font-family:monospace;">Output<span sty=
le=3D"font-size:small;" class=3D"yiv6204215369gmail_default"> (same answers=
)</span>:</span></div><div><span style=3D"font-family:monospace;">f after g=
: 200<br>g after f: 400</span></div><div style=3D"font-family:arial, helvet=
ica, sans-serif;font-size:small;" class=3D"yiv6204215369gmail_default"><br>=
</div><div style=3D"font-family:arial, helvetica, sans-serif;font-size:smal=
l;" class=3D"yiv6204215369gmail_default">In other words, we repurpose the _=
_mul__ operator (*) to become the compose operator, which in LaTeX is usual=
ly \circ.</div><div style=3D"font-family:arial, helvetica, sans-serif;font-=
size:small;" class=3D"yiv6204215369gmail_default"><br></div><div style=3D"f=
ont-family:arial, helvetica, sans-serif;font-size:small;" class=3D"yiv62042=
15369gmail_default">Kirby</div><div style=3D"font-family:arial, helvetica, =
sans-serif;font-size:small;" class=3D"yiv6204215369gmail_default"><br></div=
></div>
</div>_______________________________________________<br>Edu-sig mailing li=
st -- <a ymailto=3D"mailto:[email protected]" href=3D"mailto:edu-sig@pytho=
n.org">[email protected]</a><br>To unsubscribe send an email to <a ymailto=
=3D"mailto:[email protected]" href=3D"mailto:[email protected]=
g">[email protected]</a><br><a href=3D"https://mail.python.org/mailm=
an3/lists/edu-sig.python.org/" target=3D"_blank">https://mail.python.org/ma=
ilman3/lists/edu-sig.python.org/</a><br>Member address: <a ymailto=3D"mailt=
o:[email protected]" href=3D"mailto:[email protected]">[email protected]</a><b=
r> </div> </blockquote></div></div>
------=_Part_1114721_1281213914.1677690697562--

--===============0874171245071524288==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Edu-sig mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/edu-sig.python.org/
Member address: [email protected]

--===============0874171245071524288==--