Drop and Replacing NaN values

I am an Industrial Engineer utilizing the power of python to gain deeper insights in data.
I am currently learning Deep learning with TensorFlow
Search for a command to run...

I am an Industrial Engineer utilizing the power of python to gain deeper insights in data.
I am currently learning Deep learning with TensorFlow
No comments yet. Be the first to comment.
I recently built an interactive A3 process improvement app using Claude Sonnet 4 - and here's the interesting part: the app itself uses Claude's API to analyze completed A3 documents. It's essentially Claude helping to build a tool that leverages Cla...

Comparing Mistral 7B vs. LLaMA-2 7B using HuggingFace

Implementing a RAG model

This took a bit of time to get the certificate, but circling back to follow up on a previous accomplishment — I officially completed an AI/ML Apprenticeship! [U.S. Department of Labor apprenticeship completion certificate for the AI/ML Fundamentals P...
A time-series forecasting and anomaly-detection tool

In a previous post I talked about the need for replacing NaN values in my data in preparation for some machine learning models. Some other methods that I have used include dropping or filling them in with something else.
Sometimes the easiest thing to do is drop the values, if my data is large enough.
Dropping the rows or dropping the columns
# Drop rows with NaN values
df_cleaned = df.dropna()
# Drop columns with NaN values in-place
df.dropna(axis=1, inplace=True)
I had a couple datasets that were small and I did not want to drop the rows of data.
Instead I utilized the .fillna() function to replace the NaN value with a number. Maybe replacing it with 0, or replacing it with the column mean. Another option is using interpolation. Options depend on what makes sense for the dataset.
# Replace NaN values with column mean
df_filled = df.fillna(df.mean())
# Replace NaN values with zero
df_filled = df.fillna(0)