How to Convert Float to Int in Pandas

python float to int

While I was working on a data analysis project for a US retail dataset, I needed to convert price columns from float to integer format. The challenge was maintaining data accuracy while removing decimal places. In this article, I will share five practical methods to convert float values to integers in Pandas, based on my … Read more >>

How to Make a Dashed Horizontal Line in Python Matplotlib

How to Make a Dashed Horizontal Line in Python Matplotlib

When I started working with Python data visualization, I often needed to highlight specific thresholds in my plots. Sometimes, a horizontal line was the best way to do it. But instead of a solid line, I wanted a dashed horizontal line to make the chart more readable. At first, it wasn’t obvious how to do … Read more >>

How to Split a List in Python by Comma

python split string by comma

Recently, while working on a data-cleaning project, I needed to split a long list of values separated by commas into individual items. At first, I thought this would be tricky, but Python makes it surprisingly simple. With over 10 years of experience writing Python code, I’ve used this technique countless times for real-world projects. In … Read more >>

Different Ways to Create Strings in Python

creating and storing strings in python

When I first started working with Python more than ten years ago, I quickly realized how important strings were. Almost every project I worked on involved text in some way. I’ve explored many different ways to create strings in Python. Some methods are simple and quick, while others give you more flexibility. In this tutorial, … Read more >>

jQuery Check if Element Has Class

jQuery Check Element Has Class

When working with dynamic web applications, you’ll often need to check whether an HTML element contains a specific CSS class. jQuery provides several powerful methods to accomplish this task efficiently. In this comprehensive guide, we’ll explore all the ways to check if an element has a class using jQuery, complete with practical examples and best … Read more >>

Booleans in Python: True, False and How to Check Them

Python booleans: the Command Prompt showing that the string False evaluates as True

A boolean in Python is a value that is either True or False, and nothing else: Both must be capitalised. Lowercase true is just an undefined name, so it raises a NameError. The trap worth knowing before anything else: bool(“False”) is True, because any non-empty string is truthy. Everything on this page was run on … Read more >>

Remove the Last Character From a String in Python

Python remove the last character from a string: the Command Prompt showing how a zero count empties the string

To remove the last character from a string in Python, slice up to -1: Two traps follow from that. Writing text[:-n] with n as a variable empties the string when n is zero, and rstrip removes more characters than you expect. Both are demonstrated below, on Python 3.12.5. Removing the last character with slicing A … Read more >>

Remove a Character From a String in Python (by Index or Value)

Python remove a character from a string: the Command Prompt showing that str does not support item deletion

To remove a character from a string in Python, you build a new string without it. Which method you want depends on whether you know the position or the character: There is no del and no item assignment. Both raise a TypeError, which is the first thing to understand here. Every result below is a … Read more >>

Reverse a String in Python: Slicing, Loops and Recursion

Python reverse a string: the Command Prompt comparing the speed of slicing, reversed and a manual loop

To reverse a string in Python, slice it with a step of -1: There is no reverse() method on strings, because strings cannot be changed in place. Every approach below builds a new string. All timings and output come from real runs on Python 3.12.5. Reversing a string with slicing The slice takes three numbers, … Read more >>

NumPy sum(): Axis, keepdims, dtype and Sum of Squares

Python NumPy sum: the Command Prompt comparing three ways to compute a sum of squares

np.sum adds up the values in a NumPy array, either all of them or along one axis: The axis argument is what people come for, and the rule is short: the axis you name is the one that disappears from the result. All figures below are real runs on Python 3.12.5, NumPy 2.5.3. Using np.sum … Read more >>