Python Basic, Numpy, Panda-Mcq - Key
Python Basic, Numpy, Panda-Mcq - Key
y=8
z = lambda x: x * y
print z (6)
A. 48
B. 14
C. 64
D. None of the above
import re
sentence = 'horses are fast'
regex = re.compile('(?P<animal>w+) (?P<verb>w+) (?P<adjective>w+)')
matched = re.search(regex, sentence)
print(matched.groupdict())
A. {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
B. (‘horses’, ‘are’, ‘fast’)
C. ‘horses are fast’
D. ‘are’
print 9//2
A. 4.5
B. 4.0
C. 4
D. Error
A. ||
B. |
C. //
D. /
A. dlroW olleH
B. Hello Worl
C. d
D. Error
A. List
B. Dictionary
C. Tuple
D. Array
def myfunc(a):
a=a+2
a=a*2
return a
print myfunc(2)
A. 8
B. 16
C. Indentation Error
D. Runtime Error
A. 0.333333
B. 0.33
C. 0.333333: -2
D. Error
10.What is the output of the following program?
i=0
while i < 3:
print i
i += 1
else:
print 0
A. 01230
B. 0120
C. 012
D. Error
import numpy as np
np.zeros((2,2))
import numpy as np
e = np.array([(1,2,3), (4,5,6)])
print(e)
e.reshape(3,2)
## Horitzontal Stack
import numpy as np
f = np.array([1,2,3])
g = np.array([4,5,6])
A. Horizontal Append: [4 5 6 1 2 3]
B. Horizontal Append: [1 2 3 4 5 6]
C. Horizontal Append: [1 2 3]
D. All the above
x = np.array([1,2,3], dtype=np.complex128)
x.itemsize
A. 16
B. 61
C. 6
D. Error
f = np.array([1,2])
g = np.array([4,5])
np.dot(f, g)
A. 31
B. 12
C. 14
D. Error
h = [[1,2],[3,4]]
i = [[5,6],[7,8]]
np.matmul(h, i)
import numpy np
np.arange(1, 11)
import numpy as np
y = x [[0,1,2], [0,1,0]]
print y
A. [5 4 1]
B. [1 4 5]
C. [4 1 5]
D. Error
import numpy as np
print np.var([1,2,3,4])
A. 1.25
B. 1
C. 1.0
D. Error
21.What is the output of the following program?
import pandas as pd
s = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])
print s[0]
A. 1
B. 0
C. 2
D. Error
import pandas as pd
import numpy as np
df = pd.DataFrame(index=[0,1,2,3,4,5],columns=['one','two'])
A. 0
B. nan
C. error
D. All the above
import pandas as pd
print pd.Timestamp('2017-03-01')
A. 2017-03-01 00:00
B. 2017-03-01 00:00:00
C. 2017-03-01 00:01
D. All the above
import pandas as pd
import numpy as np
print cat.ordered
A. True
B. False
C. Error
D. All the above
25.What is the output of the following program?
import pandas as pd
A. I am any
B. I any
C. any
D. Error
A. Structured ndarray
B. Series
C. DataFrame
D. All of the Mentioned
27.Which of the following takes a dict of dicts or a dict of array-like sequences and returns a
DataFrame ?
A. DataFrame.from_items
B. DataFrame.from_records
C. DataFrame.from_dict
D. All of the Mentioned
A. A DataFrame is like a fixed-size dict in that you can get and set values by index label
B. Series can be be passed into most NumPy methods expecting an ndarray
C. A key difference between Series and ndarray is that operations between Series
automatically align the data based on label
D. None of the Mentioned
A. True
B. False
A. a python dict
B. a ndarray
C. a scalar value
D. all of the Mentioned