Remove Brackets from Python Strings

How to remove brackets from Python string

Recently, while working on a data-cleaning project, I ran into a problem where my dataset had unnecessary square brackets around values. For example, instead of “New York”, the data looked like “[New York]”. If you’ve ever imported lists or JSON data into Python, you’ve probably seen this happen too. At first glance, it looks small, … Read more >>

Python File Does Not Exist Exception

python file does not exist

When I was working with files in Python, one of the most common errors I faced was the File Does Not Exist exception. If you’ve ever tried to open a file that wasn’t there, you’ve likely seen the dreaded FileNotFoundError. It can be frustrating, especially when you’re building something important like a log processor, a … Read more >>

How to Initialize an Array in Python?

Initialize an Array in Python

A few months back, I built a local app to track paid time off for my 10-person team. HR managed everything in Excel, and someone often missed an update or approved overlapping dates. I opened a Python file and considered how to store employees, PTO balances, and approval statuses. That is where I had to … Read more >>

How to Split a List in Python?

Split a List in Python

Recently, in a Python webinar, someone asked me a question about splitting lists. After researching and testing various methods, I found a few important methods to achieve this task. In this tutorial, I will explain how to split a list in Python with suitable examples and screenshots. Split a List in Python One of the … Read more >>

How to Convert Python String to Double?

python string to double

As a Python developer, working on a project for an e-commerce analytics dashboard the sales where data comes as strings. I needed to convert Python string to double for further calculations like total revenue, average order value, etc. After researching various methods, I found several important methods to accomplish this task. I will share my … Read more >>

Read CSV to Dictionary Using Pandas in Python

pandas csv to dict

Working with CSV files is a common task in data analysis and manipulation. While Pandas DataFrames are great for most operations, sometimes you need to convert your CSV data into a Python dictionary for specific use cases. In my decade-plus experience as a Python developer, I’ve found that knowing how to transform CSV data into … Read more >>

Add Rows To A DataFrame Pandas In Loop

add row to dataframe

Recently, I was working on a data analysis project where I needed to add rows to a pandas DataFrame in a loop. This is a common task when processing data incrementally or building a DataFrame row by row. While pandas is optimized for vectorized operations, there are times when you need to add rows one … Read more >>

Write a List to CSV in Python (Row, Column or Table)

Write a list to CSV in Python: the Command Prompt showing the extra blank lines caused by opening the file without newline

Writing a Python list to CSV takes three lines with the built-in csv module: That newline=”” is not decoration. Leave it out and every row in your file gets a blank line after it, which is the most common complaint about CSV in Python. What shape the data lands in depends on which method you … Read more >>

Iterate Through a Dictionary in Python (keys, values, items)

Iterate through a dictionary in Python: the Command Prompt showing the RuntimeError raised when a dictionary changes size during iteration

To iterate through a dictionary in Python and get both parts, loop over .items(): Looping over the dictionary on its own gives you the keys and nothing else, which is the detail most people trip over first. Below: the four ways to loop, sorting as you go, nested dictionaries, and the RuntimeError that appears when … Read more >>

Get the First Key in a Python Dictionary

python get first element of dict

Recently, I was working on a project where I had to quickly retrieve the first key from a Python dictionary. At first, it sounded simple, but when I dug deeper, I realized that dictionaries don’t behave exactly like Python lists. The challenge was that dictionaries are unordered collections in older versions of Python. But starting … Read more >>