Invoke “groupby” with two categorical columns in Python Pandas, and get a two-part multi-index: Turn into a data frame with unstack: The post Pandas groupby with two columns: Reshape results with unstack appeared first on LernerPython.
A “groupby” call in Python Pandas is normally sorted by index. But if you’re grouping by month name, April will come before January. Pass “sort=False”, and the index will reflect […] The post Pandas groupby with sort=False: Keep groups in order of appearance appeared first on LernerPython.
The simplest grouping in Python Pandas is groupby: For example: Returns a series whose index is the unique values from passenger_count. The post Pandas groupby basics: Aggregating a numeric column by category appeared first on LernerPython.
You can remove NaN from a Python Pandas data frame with dropna, but be careful: It removes rows with even one NaN, which can be overkill. Pass “thresh” to allow […] The post Pandas dropna with thresh: Drop only rows with too many NaN values appeared first on LernerPython.
Coming to Python Pandas from NumPy? You’ll reach for np.isnan: Unfortunately, this works. Better, use s.isna (or s.isnull). But the best way to drop NaN? Use dropna: The post Pandas dropna: The best way to remove NaN values from a series appeared first on LernerPython.
I’m a big fan of exercises, which is why the LernerPython platform includes hundreds of them — all using my in-browser practice system, which handles Python, Pandas, and Git, along […] The post New on the LernerPython practice system: A visual debugger appeared first on LernerPython.
PyArrow dtypes in Python Pandas are nullable (with pd.NA): s is: 0 101 2 30dtype: int64[pyarrow] The dtype is int64, but allows nulls. (Use np.nan? It’s turned into pd.NA.) The post PyArrow dtypes in pandas: Nullable integers with pd.NA appeared first on LernerPython.
You have a Python Pandas series with ints + NaN. You don’t want float forced on you. Solution: Use the “extension” type Int64 (note Initial Caps) and pd.NA: s is: […] The post Pandas nullable integers: Keeping ints with Int64 and pd.NA appeared first on LernerPython.
Some of the most satisfying work I do happens one on one. You arrive with a real problem from your real job — code that will not behave, an architecture […] The post Get Python help, one on one: my coaching sessions appeared first on LernerPython.
Some of the most satisfying work I do happens one on one. You arrive with a real problem from your real job — code that will not behave, an architecture […] The post Get Python help, one on one: my coaching sessions appeared first on LernerPython.
Missing data? NumPy calls it nan. Python Pandas displays it as NaN. But: Pandas doesn’t define pd.nan or pd.NaN. NumPy removed np.NaN in version 2.0. So you have to refer […] The post NaN in Pandas: Why you need np.nan, not pd.NaN appeared first on LernerPython.
Missing data in Python Pandas? We use nan (“not a number”), which comes from NumPy. np.nan is a float, but not a normal one: The post np.nan in Pandas: Why missing values break comparisons appeared first on LernerPython.
What is a “callable” in Python? Typically, a function or class. But really, it’s anything with __call__ defined: The “callable” builtin basically returns True if it finds __call__. The post Python callables: Any object that defines __call__ appeared first on LernerPython.
If you invoke +=, Python can use __add__. MyClass implements __add__ (calling print for debugging): m1 now refers to a new object, and its repr is: MyClass instance, vars(self)={‘x’: 30} The post Python += calls __add__ and rebinds to a new object appeared first on LernerPython.
How does the “in” operator work in Python? – If an object defines __contains__, then its (boolean) result is returned (coerced to bool).– If not, then Python iterates over it […] The post Python in operator: How __contains__ speeds up membership tests appeared first on LernerPython.
I really enjoy reading e-mail newsletters. They’re clever, informative, and funny, and provide me with lots of food for thought — as well as professional information that is crucial to […] The post Newsprint: Turning e-mail newsletters into a personal PDF appeared first on LernerPython.
In Python, we use “or” for conditions. | is bitwise (not boolean) “or”: x | y # 15, or 0b1111 | runs __or__. On dicts, | combines. The post Python | operator: Bitwise or and dict merging with __or__ appeared first on LernerPython.
The % in Python, on numbers, is modulo: But str uses __mod__ for interpolation: Same operator, same magic method — but totally different. The post Python `__mod__`: Modulo for numbers, interpolation for str appeared first on LernerPython.
Just as + in Python invokes __add__, other operators invoke other magic methods: • – is __sub__• * is __mul__• / is __truediv__• // is __floordiv__• % is __mod__• ** is __pow__ Your methods can […] The post Python operator overloading: The arithmetic magic methods appeared first on LernerPython.
I've been using Claude Code several hours a day for months, and I'm having a blast. But an agent does what you tell it, not what you meant — which is why validating your results now matters more than the results themselves. The post Claude Code always produces something. That’s the hard part. appeared first on LernerPython.
Read at the source
Your visit, your choice.
Optional Google Analytics helps us understand visits. Microsoft Clarity records masked interactions to improve the site. Optional tools stay off unless you choose them. Privacy details.