0
0
Pandasdata~20 mins

Importing Pandas conventions - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pandas Import Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this code importing pandas?
Consider the following code snippet importing pandas and creating a DataFrame. What will be the output when printing df.head()?
Pandas
import pandas as pd

data = {'Name': ['Anna', 'Bob', 'Cara'], 'Age': [28, 34, 29]}
df = pd.DataFrame(data)
print(df.head())
A
Name Age
0 Anna 28
1 Bob 34
2 Cara 29
B
Name  Age
Anna  28
Bob   34
Cara  29
C
   Name  Age
1  Anna   28
2   Bob   34
3  Cara   29
D
   Name  Age
0  Anna   28
1   Bob   34
2  Cara   29
Attempts:
2 left
💡 Hint
Remember that df.head() shows the first 5 rows with index and columns.
data_output
intermediate
1:30remaining
What is the shape of the DataFrame after importing pandas and creating it?
Given this code, what is the shape (rows, columns) of the DataFrame df?
Pandas
import pandas as pd

data = {'City': ['NY', 'LA', 'Chicago', 'Houston'], 'Population': [8.4, 4.0, 2.7, 2.3]}
df = pd.DataFrame(data)
print(df.shape)
A(4, 2)
B(2, 4)
C(3, 2)
D(4, 1)
Attempts:
2 left
💡 Hint
Shape shows (number of rows, number of columns).
🔧 Debug
advanced
1:00remaining
Which option causes an error when importing pandas?
Which of the following import statements will cause an error?
Aimport pandas
Bfrom pandas import DataFrame
Cimport panda as pd
Dimport pandas as pd
Attempts:
2 left
💡 Hint
Check the spelling of the library name.
🧠 Conceptual
advanced
1:30remaining
Why do we use import pandas as pd instead of just import pandas?
What is the main reason for importing pandas with an alias like pd?
ATo shorten the code and make it easier to type pandas functions.
BBecause pandas cannot be imported without an alias.
CTo avoid conflicts with other libraries named pandas.
DTo automatically load all pandas functions into the global namespace.
Attempts:
2 left
💡 Hint
Think about typing convenience and code readability.
🚀 Application
expert
1:30remaining
What is the output of this code using pandas import conventions?
Given the code below, what will be printed?
Pandas
import pandas as pd

s = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
print(s['b'])
A10
B20
Cb
DKeyError
Attempts:
2 left
💡 Hint
Accessing a Series by index label returns the value at that label.