0
0
Data Analysis Pythondata~10 mins

Sample() for random rows in Data Analysis Python - Interactive Code Practice

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

Complete the code to select 3 random rows from the DataFrame df.

Data Analysis Python
random_rows = df.[1](3)
Drag options to blanks, or click blank then click option'
Asort
Bhead
Ctail
Dsample
Attempts:
3 left
💡 Hint
Common Mistakes
Using head() or tail() which select fixed rows, not random ones.
Using sort() which orders rows but does not sample.
2fill in blank
medium

Complete the code to select 20% random rows from the DataFrame df.

Data Analysis Python
random_rows = df.sample(frac=[1])
Drag options to blanks, or click blank then click option'
A0.2
B2
C0.02
D20
Attempts:
3 left
💡 Hint
Common Mistakes
Using 20 instead of 0.2, which causes an error.
Using 2 which is greater than 1 and invalid for fraction.
3fill in blank
hard

Fix the error in the code to select 5 random rows without replacement from df.

Data Analysis Python
random_rows = df.sample(n=5, replace=[1])
Drag options to blanks, or click blank then click option'
ANone
BTrue
CFalse
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting replace=True causes repeated rows.
Using None or 0 which are invalid for replace.
4fill in blank
hard

Fill both blanks to select 4 random rows with a fixed random seed for reproducibility.

Data Analysis Python
random_rows = df.sample(n=[1], random_state=[2])
Drag options to blanks, or click blank then click option'
A4
B42
C5
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using random_state=0 which is valid but less common than 42.
Mixing up n and random_state values.
5fill in blank
hard

Fill all three blanks to create a dictionary of word lengths for words longer than 3 letters.

Data Analysis Python
lengths = {word: [1] for word in words if len(word) [2] [3]
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C3
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of len(word) for the value.
Using < or == instead of > in the condition.