Completed
Pandas Series & DataFrame Challenge
Questions From This Challenge
Q1output1 mark
What will be the output of the following Python code?
import pandas as pd s = pd.Series([12, 24, 36], index=['A', 'B', 'C']) print(s['B'])
Correct output:
24Q2output1 mark
What will be the output of the following Python code?
import pandas as pd s = pd.Series([10, 20, 30, 40], index=['w', 'x', 'y', 'z']) print(s[1:3])
Correct output:
x 20
y 30
dtype: int64Q3mcq1 mark
Which statement correctly creates a Pandas Series from a dictionary?
pd.Series(['A':10, 'B':20])
pd.Series({'A':10, 'B':20}) ✓
pd.Series(('A':10, 'B':20))
pd.Series({'A','B':10,'C':20})
Q4output1 mark
What will be the output of the following Python code?
import pandas as pd s = pd.Series(8, index=['P', 'Q', 'R']) print(s['Q'] + s['R'])
Correct output:
16Q5output1 mark
What will be the output of the following Python code?
import pandas as pd s = pd.Series([5, 10, 15, 20]) print(s.head(2)) print(s.tail(1))
Correct output:
0 5
1 10
dtype: int64
3 20
dtype: int64Q6output1 mark
What will be the output of the following Python code?
import pandas as pd s = pd.Series([10, 20, 30], index=['a', 'b', 'c']) s['b'] = s['b'] + 5 print(s['b'])
Correct output:
25Q7mcq1 mark
Consider the following Series: import pandas as pd s = pd.Series([4, 8, 12, 16], index=['A', 'B', 'C', 'D']) What will be the output of the following statement? print(s['B':'D'].sum())
20
28
36 ✓
40
Q8mcq1 mark
Which of the following correctly creates a DataFrame from a list of dictionaries?
pd.DataFrame([{'Name':'A', 'Marks':80}, {'Name':'B', 'Marks':90}]) ✓
pd.DataFrame({'Name':'A', 'Marks':80}, {'Name':'B', 'Marks':90})
pd.DataFrame(('Name':'A', 'Marks':80), ('Name':'B', 'Marks':90))
pd.DataFrame(['Name':'A', 'Marks':80], ['Name':'B', 'Marks':90])
Q9output1 mark
What will be the output of the following Python code?
import pandas as pd
df = pd.DataFrame({
'Name': ['A', 'B', 'C'],
'Marks': [72, 45, 88]
})
print(df['Marks'][1])
Correct output:
45Q10mcq1 mark
Consider the following DataFrame: import pandas as pd df = pd.DataFrame({ 'Name': ['A', 'B', 'C', 'D'], 'Marks': [35, 65, 48, 82] }) print(df[df['Marks'] >= 50]['Name']) What will be printed?
A and C
B and D ✓
A and B
C and D
Q11mcq1 mark
What will be the result of the following operation? import pandas as pd df = pd.DataFrame({ 'Name': ['A', 'B'], 'Marks': [70, 80] }) df['Grade'] = ['B', 'A']
A new row named Grade is created
A new column named Grade is created ✓
The Marks column is replaced
An error occurs because new columns cannot be added
Q12mcq1 mark
Consider the following DataFrame: import pandas as pd df = pd.DataFrame({ 'Name': ['A', 'B', 'C'], 'Marks': [60, 70, 80], 'Grade': ['B', 'A', 'A'] }) df.drop('Grade', axis=1, inplace=True) Which columns remain in the DataFrame?
Name and Grade
Marks and Grade
Name and Marks ✓
Only Name
Q13output1 mark
What will be the output of the following Python code?
import pandas as pd
df = pd.DataFrame({
'Name': ['A', 'B'],
'Marks': [75, 85]
})
df.rename(columns={'Marks':'Score'}, inplace=True)
print(df.columns[1])
Correct output:
ScoreQ14mcq1 mark
Consider the following DataFrame: import pandas as pd df = pd.DataFrame({ 'Name': ['A', 'B', 'C'], 'Marks': [55, 75, 65] }, index=['S1', 'S2', 'S3']) What value will be obtained from the following statement? print(df.loc['S2', 'Marks'])
55
65
75 ✓
S2
Q15mcq1 mark
A DataFrame named df contains student records and is stored in a CSV file named students.csv. Which statement correctly exports the DataFrame to a CSV file named result.csv?
df.read_csv('result.csv')
pd.read_csv(df, 'result.csv')
df.to_csv('result.csv') ✓
pd.to_csv(df, 'result.csv')