0
0
Pandasdata~10 mins

NaN and None in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a pandas DataFrame with a None value.

Pandas
import pandas as pd

data = {'A': [1, 2, [1], 4]}
df = pd.DataFrame(data)
print(df)
Drag options to blanks, or click blank then click option'
A0
BNaN
CNone
D''
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'NaN' as a string instead of the actual NaN value.
Using 0 which is a valid number, not missing data.
2fill in blank
medium

Complete the code to import the correct function to create a NaN value.

Pandas
import pandas as pd
from numpy import [1]

data = {'B': [1, 2, [1], 4]}
df = pd.DataFrame(data)
print(df)
Drag options to blanks, or click blank then click option'
Anan
BNaN
CNaT
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'NaN' with uppercase N which is not the correct import.
Using None which is different from NaN.
3fill in blank
hard

Fix the error in the code to check for NaN values in the DataFrame.

Pandas
import pandas as pd
import numpy as np

df = pd.DataFrame({'C': [1, np.nan, 3]})
print(df.[1]())
Drag options to blanks, or click blank then click option'
Aisnulls
Bisna
Cisnan
Disnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'isnan' which is a numpy function, not a DataFrame method.
Using 'isnulls' which is not a valid method.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

Pandas
words = ['apple', 'bat', 'car', 'door']
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of its length.
Using the word in the condition instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 3.

Pandas
words = ['apple', 'bat', 'car', 'door']
result = { [1]: [2] for word in words if [3] }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 3
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase instead of uppercase for keys.
Using the word itself instead of its length for values.
Incorrect condition for filtering.