0% found this document useful (0 votes)
48 views10 pages

A) Index B) Column C) Columns D) Colindex

The document contains a series of questions and answers related to the Pandas library in Python, specifically focusing on DataFrames and Series. It covers topics such as creating DataFrames, indexing, and various methods and attributes associated with these data structures. The questions are designed to test knowledge of Pandas functionalities and best practices.

Uploaded by

manishmcamba2013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views10 pages

A) Index B) Column C) Columns D) Colindex

The document contains a series of questions and answers related to the Pandas library in Python, specifically focusing on DataFrames and Series. It covers topics such as creating DataFrames, indexing, and various methods and attributes associated with these data structures. The questions are designed to test knowledge of Pandas functionalities and best practices.

Uploaded by

manishmcamba2013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Q1.

Which of the following is used to give user defined column index in


DataFrame?
a) index
b) column
c) columns
d) colindex
Q2 The following code create a dataframe named ‘D1’ with ___________
columns.
import pandas as pd

dicts = [{‘a’:10, ‘b’:20}, {‘a’:5, ‘b’:10, ‘c’:20}]

D1 = pd.DataFrame(dicts)

a) 1
b) 2
c) 3
d) 4
Q3. We can add a new row to a DataFrame using the _____________
method

a) rloc[ ]
b) loc[ ]
c) irloc[ ]
d) None of the above
Q4. In Pandas _______________ is used to store data in multiple columns.

a) Series
b) DataFrame
c) Both of the above
d) None of the above

Q5. The following code create a dataframe named ‘D1’ with ______ rows.
import pandas as pd
LoD = [{'a':10, 'b':20}, {'a':5, 'b':10, 'c':20}]

D1 = pd.DataFrame(LoD)

a) 0
b) 1
c) 2
d) 3
Q6. In given code dataframe ‘D1’ has ________ rows and _______ columns

import pandas as pd
LoD = [{‘a’:10, ‘b’:20}, {‘a’:5, ‘b’:10, ‘c’:20},{‘a’:7, ‘d’:10, ‘e’:20}]
D1 = pd.DataFrame(LoD)

a) 3, 3
b) 3, 4
c) 3, 5
d) None of the above
Q7. The following code create a dataframe named ‘D1’ with
_______________ columns.

import pandas as pd
D1 = pd.DataFrame([1,2,3] )

a) 1
b) 2
c) 3
d) 4
Q8. Which of the following function is used to create DataFrame?

a) DataFrame( )
b) NewFrame( )
c) CreateDataFrame( )
d) None of the Above
Q9. Which of the following statements is false?
a) Dataframe is size mutable
b) Dataframe is value mutable
c) Dataframe is immutable
d) Dataframe is capable of holding multiple type of data
Q10. When we create DataFrame from List of Dictionaries, then dictionary
keys will become _______
a) Column labels
b) Row labels
c) Both of the above
d) None of the above
Q11. When we create DataFrame from List of Dictionaries, then number of
columns in DataFrame is equal to the _______

a) maximum number of keys in first dictionary of the list


b) maximum number of different keys in all dictionaries of the list
c) maximum number of dictionaries in the list
d) None of the above
Q12. A _______________ is a two-dimensional labelled data structure .

a) DataFrame
b) Series
c) List
d) None of the above
Q13. In DataFrame, by default new column added as the _____________
column
a) First (Left Side)
b) Second
c) Last (Right Side)
d) Any where in dataframe

Q14. In the following statement, if column ‘Rollno’ already exists in the


DataFrame ‘D1’ then the assignment statement will __________
D1['Rollno'] = [1,2,3] #There are only three rows in DataFrame D1
a) Return error
b) Replace the already existing values.
c) Add new column
d) None of the above
Q15. We can create DataFrame from _____

a) Numpy arrays
b) List of Dictionaries
c) Dictionary of Lists
d) All of the above
Q16. In Pandas _______________ is used to store data in multiple columns.
a) Series
b) DataFrame
c) Both of the above
d) None of the above
Q17. _____________ data Structure has both a row and column index.

a) List
b) Series
c) DataFrame
d) None of the above
Q18. DF1.loc[ ] method is used to ______ . (Here# DF1 is a DataFrame )

a) Add new row in a DataFrame ‘DF1’


b) To change the data values of a row to a particular value
c) Both of the above
d) None of the above
Q19. Which library is to be imported for creating DataFrame?

a) Python
b) DataFrame
c) Pandas
d) Random

Q20. ________ index takes user defined label as index.


a) Positional Index
b) Valued Index
c) Labelled Index
d) Sliced Index

Q21. Which of the following is correct way of assigning a


labelled index to series?

a) s=pd.Series(index=range(5,10),[22,33,44,56,78])
b) s=pd.Series(index=range(5,10),dt=[22,33,44,56,78])
c) s=pd.Series({22,33,44,56,78},index=range(6,10))
d) s=pd.Series([22,33,44,56,78],index=range(5,10))

Q22. Which of the following attribute gives the following


output – (4,) for following data frame?
0 23
1 25
2 28
4 30

a) s.shape()
b) s.index
c) s.shape
d) s.size

Q23. What will be the output of following code:


import pandas as pd

s=pd.Series([11,12,13,14,15,16])

s[1:4] = 20

s=list(s)

print(s)

Select the correct output:

a) [11, 20, 20, 20, 15, 16]


b) [20, 20, 20, 20, 15, 16]
c) [20, 12, 13, 20, 15, 16]
d) [11, 20, 13, 20, 15, 16]

Q24. Ms. Hetvee wants to check whether series is empty


or not. But she is confused to how to do the same, help
her to select the correct method out of the following?

a) s.empty()
b) s.empty
c) s.isempty
d) s.None

Q25. Mr. Smit is trying to access 3rd element from series


named s using positional index. Suggest him the correct
statements from given statements:

a) s(2)
b) s{2}
c) s[2]
d) s[II]

Q26 Select the correct option to get the index preview in


reverse order

a) s[-1::1]
b) s[-1:1:1]
c) s[::-1]
d) s[::]

Q27 Which of the following statement is fales with


respect to accessing series elements through slicing?

a) It can be used as same as numpy or list slicing


b) It requires slicing start and end parameters
c) The values of last positional index is included
d) The series must be created with a sequence to access using slicing

Q28. Ms. Priya is a python developer and she created a


series using the following code, but she missed some of
the lines given as blank. Fill that blanks and help her to
complete the code:
import pandas as pd

import ________ as np
s1=pd.Series([3,4,_____,44,67])

print(s1)

Output:

0 3
1 4
2 NaN
3 44
4 67

a) numPy, no.None
b) numpy,np.nan
c) numpy,np.NaN
d) umPy,np.NaN

Q29. Select the correct statement to assign a new name


MySeries to a series object named 's'

a) s.Name(‘MySeries’)
b) s.name=’MySeries’
c) s(‘MySeries’)
d) s.Name=’MySeries’

Q30. Series attributes are also known as series


____________

a) Methods
b) Events
c) Properties
d) Characteristics

Q31. Mr. Asutosh has created a series with object s1 and


assigned a name the index as ‘states’. Which of the
following statement should he use to print the index of
series by assigned name?

a) s1.Index.Name
b) s1.index.name
c) s1.Name
d) s1.index

Q32. Which of the following is the correct statement to


access index 3rd and 5th values using positional index for
series s?

a) s[3,5]
b) s[[3,5]]
c) s[(3,5)]
d) s([3,5])

Q33. The head function returns how many elements by


default from the series?

a) 2
b) 3
c) 4
d) 5

Q34. The by default indexing is

a) Positional Index
b) Valued Index
c) Labelled Index
d) Sliced Index

Q35. Which of the following function of series is used to


return first ‘n’ elements from series?

a) s.head()
b) s.tail()
c) s.top()
d) s.on()

Q36. Which of the following attribute is used check


whether a series contains NaN value or not?

a) s.NaN
b) s.None
c) s.hasnans
d) s.nan
Q37. Ms. Anita wants to print only list of values from the
series. She should use which of the following attribute?

a) s.value
b) s.values
c) s.val
d) s.eval

Q38. Mr. Sidhhart wants to define the index explicitely for


a series named s. Which of the following statement(s)
is/are correct?
Statement 1:
s.index=[‘1st’, ’2nd’, ’3rd’, ’4th’]

Statement 2:
s.index(‘1st’, ’2nd’, ’3rd’, ’4th’)

a) Only Statement 1 is Correct


b) Only Statement 2 is Correct
c) Both statements are correct
d) None of these statements are correct

Q39. Which of the following attribute is used to returns


the total number of rows?

a) countAll
b) size
c) shape
d) ndim

Q40. To get the transpose of a dataframe D1, you can


write__________

a) D1.T
b) D1.Transpose
c) D1.swap
d) All of the above
CHECK YOURSELF

1 c 11 b 21 d 31 b
2 c 12 a 22 c 32 b
3 b 13 c 23 a 33 d
4 b 14 b 24 b 34 a
5 c 15 d 25 c 35 a
6 c 16 b 26 c 36 c
7 a 17 c 27 d 37 b
8 a 18 c 28 c 38 a
9 c 19 c 29 b 39 c
10 a 20 c 30 c 40 a

You might also like