Chris Conlan

Financial Data Scientist

  • About
  • Blog
    • Business Management
    • Programming with Python
    • Programming with R
    • Automated Trading
    • 3D Technology and Virtual Reality
  • Books
    • The Financial Data Playbook
    • Fast Python
    • Algorithmic Trading with Python
    • The Blender Python API
    • Automated Trading with R
  • Snippets

Learning Python without Library Overload

June 23, 2017 By Chris Conlan 4 Comments

I was just browsing Quora after coming back from dinner, and there were lot of night owls asking “How do I learn XYZ from scratch?”

Naturally, I swooped in to assist with the Python-related questions. Believe it or not, there is a wrong way to learn Python. I have seen many people of many different ages get burnt out on learning Python because they went about it all wrong. The key to learning Python is to do just that, no more, no less.

Learn Python, not Libraries

Python packages can both extend its functionality and modify the way it is written. There are a ton of packages available, and some of them are so large and complex that they require a course of their own. I often see self-educators get hung up on package-specific syntax while trying to learn vanilla Python.

People can get burnt out on Python when they try to learn it in conjunction with packages that alter its syntax and behavior. Thus, for a self-educator’s first few projects, I recommend they avoid complex packages to better familiarize themselves with vanilla Python.

Packages to Avoid While Learning

  • numpy and pandas
  • matplotlib
  • PIL and cv2
  • beautifulsoup, selenium, urllib, and scrapy
  • flask, django, jinja2
  • tkinter, pyqt, pyWX

Packages Encouraged while Learning

  • os, sys, and argparse
  • re
  • json, csv, and pprint
  • datetime and time
  • math, statistics, and random

Case Study

I was once tutoring a Master’s candidate at the University of Virginia how to use Python. She was interested in learning Python to interface with the OpenCV API via the cv2 module. I had recommended her many educational resources from complete beginner texts to advanced OpenCV texts.

After a week of self-teaching, she had not made much progress in learning Python, mainly because she was trying to debug a specific script she found online. The script would read images via OpenCV’s cv2, then use matplotlib to display the images. The script used a strange matplotlib function I had never seen before for displaying the images. So, when she came to me with the error, I had no idea how to fix it. But… I did know how to accomplish the same thing with purely cv2.

All the while, she had learned nothing about Python itself, because she was busy trying to debug a matplotlib function. Obviously, her time would have been much better spent reading the first few chapters of an introductory Python book. I wouldn’t say that this student was unmotivated, rather that she was working a little too hard to fix an archaic and unnecessary matplotlib function.

So, we had to go back to the basics (where we should have started). This was no big deal, but it shined a light on how cavalier attitudes towards learning often do more harm than good.

Conclusion and Project Ideas

Keen readers may have noticed that all of the packages listed as “encouraged” for learning are shipped with vanilla Python. There is a reason for this. The core developers only write and accept highly Pythonic packages for distribution with the base environment.

Don’t be afraid to get your hands dirty with educational projects. Even if they don’t do anything useful or new, they are important to your education in a language where almost everything has been packaged already.

  1. Summary Stats. Read in a csv file supplied to the command line via argparse and os, read the csv file into a list of lists with csv, generate summary statistics with math and statistics, then print a friendly table of summary statistics with pprint or string formatting.
  2. Book Analyzer. Read in Romeo and Juliet as an enormous string using os and with statements, then use re to count occurrences of common words or letters. Print statistics about the frequencies and see if they follow to Zipf’s Law.
  3. Sudoku Checker. Given a 9×9 list of numbers (organized as a list of lists) check if a Sodoku row, column, square, and board are valid. Use random to generate integers for your board. Experiment with slice notation and lists of lists to write efficient code. If you are feeling ambitious, use random and for loops to estimate the probability of a random Sudoku row, column, square, and board being valid under various conditions.

Once you are comfortable with the core tenets of Python, and the Pythonic elements of the syntax, you will have an easy and productive time exploring its best libraries.

Filed Under: Programming with Python

Comments

  1. Fabricio says

    August 16, 2017 at 2:25 pm

    Hi Chris, thank you for the tips! I’ll be sure to take them in consideration while learning Python.
    I’m only beginning, but I do have experience programming from my college days (5~8 years ago), mainly C and C++, but also a bit of Java, Delphi, COBOL. So, a lot of concepts aren’t foreign to me.
    I was never into math and statistics, so I’ll avoid getting into Data Science/Machine Learning until I feel I’m comfortable with several Python projects. What do you recommend as learning steps, from simpler to more complex projects?
    Python (vanilla) -> Web Development -> Games -> Data Science?
    Thanks!

    Reply
    • Chris Conlan says

      August 16, 2017 at 4:29 pm

      Along the lines of the post, I think any of these paths are fine:
      Python (vanilla) -> Web Development -> ???
      Python (vanilla) -> Games -> ???
      Python (vanilla) -> Data Science -> ???

      You’ll end up exploring new packages and learning package-specific syntax to do any of these tasks, so learning one does not necessarily preclude or enable another. Best of luck in your learning!

      Reply
  2. Aditya Patil says

    September 4, 2017 at 6:21 am

    I am a CSE student who has been programming for quite some time(5-7 years, although no professional experience). I don’t know python, but neither am I a newbie to programming. Should I still avoid those libraries, or should I learn stuff as and when needed?

    The only time I have used python was to create a small script for a RESTful API using flask, but I won’t say I learnt anything much as it was hardly even 20-30 lines of code, and I only looked up syntax as needed.

    Reply
    • Chris Conlan says

      September 4, 2017 at 11:22 pm

      Hi Aditya,

      There was some good discussion on Reddit about this article, and a lot of people concluded that this applies most to people who are new to programming in general.

      I say, see how you do. If you are confused, you’ll know how to ratchet it back to get your head around the language.

      Best,
      Chris

      Reply

Leave a Reply Cancel reply

Fast Python: Master the Basics to Write Faster Code

Fast Python: Master the Basics to Write Faster Code

Available for purchase at Amazon.com.

Featured Posts: Python Programming

Pulling All Sorts of Financial Data in Python [Updated for 2021]

When to Use Heap Sort to Speed Up your Python Code

Fastest Way to Flatten a List in Python

Topics

  • 3D Technology and Virtual Reality (8)
  • Automated Trading (9)
  • Business Management (9)
  • Chris Conlan Blog (5)
  • Computer Vision (2)
  • Programming with Python (16)
  • Programming with R (6)
  • Snippets (8)
  • Email
  • LinkedIn
  • RSS
  • YouTube

Copyright © 2022 · Enterprise Pro Theme On Log in