Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Filling Null Values | Analyzing the Data
Pandas First Steps

book
Challenge: Filling Null Values

To handle null values while retaining each row of the DataFrame, we can utilize the fillna() method. This allows us to populate each empty cell with a specific value (like a string or number) rather than eliminating it.

To replace null values with the number 0, the fillna() method is used:

python
import pandas as pd
df = pd.read_csv(file.csv)
new_df = df.fillna(0)
Task

Swipe to start coding

You are given a DataFrame named wine_data.

  • Replace null values with the string 'no'.

Solution

import pandas as pd

wine_data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a43d24b6-df61-4e11-9c90-5b36552b3437/wine_with_nan.csv')

# Write your code below
wine_data = wine_data.fillna('no')

# Testing the result
print(wine_data.info())
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 9
import pandas as pd

wine_data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a43d24b6-df61-4e11-9c90-5b36552b3437/wine_with_nan.csv')

# Write your code below
wine_data = ___

# Testing the result
print(wine_data.info())

Ask AI

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt