July and August are often when people take a break or go on vacation. But for me, this summer has been super busy, full of writing and improving LernerPython based on feedback I’ve gotten from people around the world. And so, I’m here with some big changes I’m making at LernerPython World Headquarters: 1. AI…
If you want to get better at Pandas, the hard part isn’t finding tutorials. It’s finding problems worth solving. Most exercises hand you a tidy little table of five rows and ask you to sum a column — which teaches you the syntax, but nothing about the job. For the last 3.5 years, I’ve written…
Over my 30+ years teaching Python, I’ve included practice exercises in all of my courses. And when I started to teach Git and Pandas, I made sure to include practice exercises there, too. That’s because there’s no learning without practice. At least, there’s no effective learning. Frustration isn’t fun, but it’s a necessary part of…
You can’t use a list as a Python dict key: Why not? Dicts run “hash” on a key to choose a pair’s storage location. To avoid pairs getting lost, mutable builtins (list, set, dict) cannot be used as dict keys.
A Python Pandas column contains comma-separated values. How can you get the first of those? First, break each string into a list: Then use .str[0] to grab the first element from the resulting list:
Want to check whether a Python Pandas string series only contains digits? Use str.isdigit: This returns a boolean series, with df’s index. You can then convert the digit-containing strings to integers:
Want to retrieve a slice from a string column in your Python Pandas data frame? Use .str.slice:
Want to retrieve from a string column in your Python Pandas data frame? Use .str.get: But wait: You can use [], in place of .get:
Your Python Pandas data frame has a multi-index, and you want to remove one part — not return it to be a regular column? Add drop=True:
Your Python Pandas data frame has a multi-index? Return selected parts to columns with the “level” keyword argument: