wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python series

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Write the output for the following:

import pandas as pd1

s = pd1.Series(5, index=[0, 1, 2, 3])

print(s)

a)

0 5

b)

0 5

1 5

2 5

3 5

dtype: int64

c)

1 5

2 5

2 5

4 5

dtype: int64

d)

0 5

1 5

2 5

3 5

dtype: object

2.

write the output:

import pandas as pd1

s = pd1.Series([1,2,3])

t = pd1.Series([1,2,4])

u=s-t

print (u)

a)

0 1

1 0

2 1

dtype: int64

b)

0 0

1 0

2 1

dtype: int64

c)

0 0

1 0

2 -1

dtype: float64

d)

0 0

1 0

2 -1

dtype: int64

3.

write the output:

import pandas as pd

s=pd.Series([1,2,3,4],index=['a','b','c','d'])

print(s.iloc[2:4])

a)

b 2

c 3

d 4

dtype: int64

b)

b 3

c 4

dtype: int64

c)

c 3

d 4

dtype: int64

d)

none of the above

4.

write the output:

import pandas as pd

s=pd.Series([1,2,3,4],index=['a','b','c','d'])

print(s.loc['b':'d'])

a)

b 2

c 3

d 4

dtype: float64

b)

b 2

c 3

d 4

dtype: object

c)

c 3

d 4

dtype: int64

d)

b 2

c 3

d 4

dtype: int64

5.

Create an empty series S1

a)

S1 = pandas.Series(empty)

b)

S1 = pandas.series(numpy.Nan)

c)

S1 = pandas.Series()

d)

S1 = pandas.Series(null)

6.

To specify data type int 16 for a series object s1 we can write

a)

s1 = pd.Series(data = numpy.array([2,3,4]), dtype = int16)

b)

s1 = pd.Series(data = numpy.array([2,3,4]), dtype = numpy. int16)

c)

s1 = pd.Series(data = numpy.array([2,3,4]), dtype =pandas. int16)

d)

all of the above

7.

Which is the correct Pandas syntax to read in a csv file and assign it to a DataFrame df?

a)

df = read_csv('file.csv')

b)

df = read('file.csv', type = 'csv')

c)

df = pd.read_csv('file.csv')

d)

df = with open('file.csv') as pd.DataFrame

8.

Type the syntax that returns the top 5 rows in DataFrame df with the native Pandas function (not slicing):

(a)  

9.

How many rows of data will be retrieved by default from the series if you use tail( ) method ?

a)

2

b)

3

c)

4

d)

5

10.

What will be the index of the following series?

import pandas as pd

import numpy as np

info = {'x' : 0., 'y' : 1., 'z' : 2.}

a = pd.Series(info)

print (a)

a)

0 1 2

b)

1 2 3

c)

x y z

d)

None of the above

11.

Sruti wants to create a Series with data 10, 20 , 30. She is confused from the choice given below:

a)

s= pd.Series ( [ 10, 20, 30 ] )

b)

s= pd.Series ( [ 10, 20, 30 ] , [ 0, 1, 2 ] )

c)

s= pd.Series ( index= [ 0, 1, 2 ] , data = [ 10, 20, 30 ] )

d)

All of the above

12.

Write the output of the following?

import pandas as pd

s=pd.Series( [ 10,20,30,40,50] ,index=[1,2,3,4,5])

print ( s [ [ 1, 5, 3 ] ] )

a)

Prints rows with index 1 , 5 and 3

b)

Prints rows at position 1, 5 and 3

c)

Prints rows with data 1,5, 3

d)

Error

13.

In a Series S

1 11

2 22

3 33

4 44

5 55

dtype: int64

del S[2] will delete

a)

22

b)

33

c)

Both 22 and 33

d)

None of the above

14.

If S is a series object , which command should be used to change the name of the Series object?

a)

S.index.name

b)

S.name

c)

S.index

d)

S.columns

15.

Indices of the pandas Series object need not be unique.

a)

True

b)

False