Create an Empty Array in Python: [], array and NumPy

Python empty array: Command Prompt showing the empty 2D list multiplication trap and the list comprehension fix

An empty array in Python is almost always just an empty list: prices = []. Python has no built-in array type you have to declare first, so a pair of square brackets is the whole answer for most code: When you need typed numbers or math on whole arrays, the array module and NumPy step … Read more >>

Python New Line: How to Use \n in Strings (With Examples)

Python new line: Command Prompt output comparing the backslash n newline character with a forward slash n and a raw string

In Python, a new line is the \n character. Put it anywhere inside a string and everything after it starts on the next line when you print it: Below I cover the /n mix-up, a Windows path that breaks by itself, joining lists, triple quotes and writing files. The screenshots are real runs on Python … Read more >>

How to Parse a String in Python?

Parse a String in Python

In this tutorial, I will explain how to parse a string in Python. As a data scientist working for a marketing analytics firm in New York, I recently worked on a project analyzing customer reviews to identify trends and insights. I needed to parse these strings and separate the data into structured fields to extract … Read more >>

Convert String to Float with 2 Decimal Places in Python

Convert String to Float with 2 Decimal Places in Python

By default, when you convert a string to a float in Python, it may display many digits after the decimal point. However, in real-world scenarios like financial calculations or reports, you often need to show numbers with exactly two decimal places. In this article, I will explain some Python built-in methods to perform the conversion … Read more >>

Convert Strings to Dates in Python

Converting Strings to Dates in Python

Recently, I worked on a data analysis project for a US retail chain, where I needed to process thousands of sales records. The dates were stored as strings in various formats, which made analysis nearly impossible without proper conversion. The issue is that Python can’t directly perform date calculations on string representations of dates. We … Read more >>

Handle a Python Exception within While a loop

while try

I was building a data processing system for a client that needed to continuously monitor stock prices from an API. The challenge was that network issues, API rate limits, and data format errors kept crashing my while loop. I’ve learned that handling exceptions within while loops is crucial for building robust applications. Without proper exception … Read more >>

Read a Text File as String in Python

python read file to string

I was working on a project where I needed to process large text files containing customer feedback data. I wanted to read the entire file into a single string so I could run text analysis on it. At first, I thought this would be tricky, but Python makes it simple. Over the years, I’ve used … Read more >>

TensorFlow Data Pipelines with tf.data

TensorFlow Data Pipelines tf.data

Building efficient data pipelines is one of the most overlooked aspects of training machine learning models. While we often focus on model architectures and hyperparameters, the flow of data can make or break the performance of a training loop. Feeding data inefficiently into GPUs or TPUs can create bottlenecks, slowing down training and reducing scalability. … Read more >>

How to Use React Frame Component

Use React Frame Component

A few weeks ago, I was working on a React dashboard for a U.S.-based marketing analytics platform. One of the key requirements was to embed third-party widgets, like ad previews and live analytics, without affecting the main app’s styling or scripts. That’s when I turned to the React Frame Component. This nifty tool lets you … Read more >>