Python Programming MCQs
Pandas Series
1. What is a Pandas Series?
(A) One-dimensional labelled array
(B) Two-dimensional labelled array
(C) Three-dimensional labelled array
(D) None of the above
2. How do you access a value from a Pandas Series?
(A) series[index]
(B) series.index[value]
(C) series.values[index]
(D) series.data[index]
3. How do you sort a Pandas Series?
(A) series.index()
(B) series.sort_values()
(C) series.ascending()
(D) series.descending()
4. How do you create a Pandas Series?
(A) import pandas as pd
s = pd.Series([1, 2, 3, 4, 5])
(B) import pandas as pd
s = pd.Series(data=[1, 2, 3, 4, 5])
(C) import pandas as pd
s = pd.Series(index=['a', 'b', 'c', 'd', 'e'], data=[1, 2, 3, 4, 5])
(D) All of the above
5. Which of the following is a valid way to create a slice from Pandas Series "s"?
(A) s[:3]
(B) s[2:]
(C) s[1:4]
(D) All of the above
6. How can you find the sum of a Pandas Series (assuming all elements are numbers) ?
(A) series.sum()
(B) series.mean()
(C) series.std()
(D) None of the above.
7. How can you plot a Pandas Series as a line graph?
(A) series.plot(kind=’pie’)
(B) series.plot(kind='line')
(C) series.plot(kind='bar')
(D) None of the above.
8. Predict output of following python pandas code:
import pandas as pdseries1 = pd.Series([1, 2, 3, 5, 8, 10])print(series1[1]+series1[3])
(A) 7
(B) 4
(C) 5
(D) 13
9. How can you check if a Pandas Series has any NaN values?
(A) Check the Series' dtype.
(B) Use the isna() method.
(C) Use the notnull() method.
(D) Check the Series' length.
10. Predict output of following python code:
import pandas as pdseries1 = pd.Series([3, 2, 4])print(series1-1)
(A) Syntax error
(B) 1
(C) -2
(D)
0 21 12 3dtype: int64
ANSWERS: Python Pandas Series MCQs:
1. (A) One-dimensional labelled array
2. (A)
series[index]
3. (B)
series.sort_values()
4. (D)
All of the above
5. (D)
All of the above
6. (A)
series.sum()
7. (B)
series.plot(kind='line')
8. (A)
7
9. (B)
Use the isna() method
10. (D)
0 2
1 1
2 3
dtype: int64
No comments:
Post a Comment