Recommend me a Python textbook

Status
Not open for further replies.

hongooi

Ars Tribunus Militum
2,244
Subscriptor
Background: I'm a statistician data scientist who works mainly in R, and has done some C and C++ coding (numerical algorithms, not any general-purpose stuff).

I'm looking to learn Python, which seems to be well on the way to taking over the world and in particular the data science world. What's a good text to use?

In terms of writing style, my favourite CS textbook would have to be K&R, so something that has a similar style would be ideal.
 

spiralscratch

Ars Praefectus
3,103
Subscriptor
Top of my head, the only reasons I can think of to not use 3:
- The org is stuck on 2 and requires that all projects be targeted to a specific version.
- Some needed library/extension isn't available for 3.

The migration to 3 has been slow simply due to the sheer size of 2's install base. There was also often some recoding required to make projects compatible with 3's changes.
 

Tuco

Ars Scholae Palatinae
696
I haven't found a python book like K&R. I am not a data scientist but you may want to look at https://pandas.pydata.org/. Pandas is a very powerful especially for data analysis. I bought https://automatetheboringstuff.com/ which was good to learn some of the basics and was able to get going pretty quickly. I am currently been doing https://www.udemy.com/data-analysis-with-pandas which is not a book unfortunately, but have been very useful learning a lot of the features in Pandas.
 

bonester

Seniorius Lurkius
1
Thanks guys. I actually don't mind paying money, especially for a physical book.

Aside on Python 3: what's the current status of the 3-vs-2 debate? Last I checked, a lot of scientific programming users were still on Python 2 but this was some years back.

Most of the version 3 code is mostly backwards compatible, just more structured (i.e. print function needing parenthesis). Version 2 has a better selection of third party libraries.
Its usually easier to convert a project from 3 to 2 than upgrade from 2 to 3, so might want to consider learning 3.

Consider also whether all you need is their awesome tutorial and documentation: https://www.python.org/doc/. It looks like there is a link to download it, maybe print it all out and bind it together into your own book?

This here is also very helpful: https://www.python.org/dev/peps/pep-0008/
 

GohanIYIan

Ars Legatus Legionis
10,196
Aside on Python 3: what's the current status of the 3-vs-2 debate? Last I checked, a lot of scientific programming users were still on Python 2 but this was some years back.

There's a pretty hard push for 3 specifically from a lot of the big scientific libraries. They're saying they'll stop supporting 2 entirely in 2020 and may stop adding new features to the python2 version of their libraries even earlier.
 

hanser

Ars Legatus Legionis
43,847
Subscriptor++
I haven't found a python book like K&R. I am not a data scientist but you may want to look at https://pandas.pydata.org/. Pandas is a very powerful especially for data analysis. I bought https://automatetheboringstuff.com/ which was good to learn some of the basics and was able to get going pretty quickly. I am currently been doing https://www.udemy.com/data-analysis-with-pandas which is not a book unfortunately, but have been very useful learning a lot of the features in Pandas.
If you use K&R to learn C in the last 20 years, you learned C wrong.
 

hanser

Ars Legatus Legionis
43,847
Subscriptor++
Aside on Python 3: what's the current status of the 3-vs-2 debate? Last I checked, a lot of scientific programming users were still on Python 2 but this was some years back.
There's a pretty hard push for 3 specifically from a lot of the big scientific libraries. They're saying they'll stop supporting 2 entirely in 2020 and may stop adding new features to the python2 version of their libraries even earlier.
As a OSS library developer: good. It's time for organizations to start upgrading software more often.

"Can you add <feature or bugfix> to <deprecated version>, too? We're stuck on .NET 4.0".
"No."

If you enable the bad behavior, there's no incentive to update. Turns out, if you update incrementally, it's really not so bad.
 

MarkLT1

Ars Tribunus Militum
1,615
Subscriptor
I do engineering code, and data science work on a regular basis. I moved from primarily C++ to Python about 4-5 years ago (I still write much of my simulation code in C++, but usually wrap it in Python via Cython or Boost::python).

Re: a book- I dont know of any good ones myself (outside of "Two Scoops of Django" if you want to use Django which is a Python-based web framework). Some people like "Learning Python The Hard Way", but I haven not personally used it.

As for Python 2 vs Python 3, since Numpy and Pandas (which as a data scientist are probably more important to learn in-depth than the Python core itself) are Python 3 compatible, the only thing holding me back to 2 was Mayavi (A 3D visualization tool). Now that there is a Python 3 version of Mayavi, I have moved 100% over to Python 3. At this point if you are learning for data processing work, I'd recommend diving into Python 3 as just about everything has now been ported over (and likely everything you'll need for the short-to-mid-term horizon).
 

StarSeeker

Ars Legatus Legionis
50,836
Subscriptor
I posted about this in a thread of it's own, but in a Web Pen Testing course the organization I work for is sending me the instructor STRONGLY recommended learning Python if you were at all serious about this sort of thing. Sadly the Python course is another class so I'm going to have to pick up my Python training on my own. I've looked at several of the books mentioned in this thread.
 

Verno

Ars Tribunus Militum
1,706
Subscriptor
Python Crash Course is pretty solid, good foundation for most aspects of Python 3 and lots of little exercises throughout.

Think Like a Computer Scientist is good stuff.

Automate the Boring Stuff with Python is another good one but its more a dabblers book and doesn't reinforce concepts as much.

I don't recommend the "Learn Python the Hard Way" books, his style of "just do this, I'll explain it later" is very frustrating and there is more to programming than just syntax & repetition. I feel like the book generally teaches people to be pretty poor programmers due to little emphasis on problem solving or creative thinking. Too mechanical for my taste.
 

Ento

Seniorius Lurkius
3
Since you have prior experience with development, a short book that writes about Python might be what you are looking for.

However, if you are looking for something in depth "Learning Python, 5th Edition" by Mark Lutz is an excellent book. Furthermore, there is a book called "Fluent Python" by Luciano Ramalho, I have read good things about this book but have never read it myself.
 
Dive into Python 3 has been a good read for a lot of junior devs I've worked with. Working through the python koans (https://github.com/gregmalcolm/python_koans) is a great way to pick up language features if you like learning hands on. It's a full test suite that has a bunch of broken stuff, and through modifying code to get tests to pass, you'll learn most language features. Greg also has a solid video from PyOhio 2012 up: https://www.youtube.com/watch?v=M64aoqgVsMM. I've found it also helps if you're not familiar with writing tests or TDD at all.


As far as 3vs2, the debate is almost dead. The story is consistently use 3 unless you can't. 3 is more stable, faster, and has strong library support at this point, especially in the data science realm. That being said, if you're just getting started and focusing on data science problems, get started with Anaconda.
 
Status
Not open for further replies.