Font size
WorksheetsPython series
Total questions: 15
Worksheet time: 8mins
Write the output for the following:
import pandas as pd1
s = pd1.Series(5, index=[0, 1, 2, 3])
print(s)
0 5
0 5
1 5
2 5
3 5
dtype: int64
1 5
2 5
2 5
4 5
dtype: int64
0 5
1 5
2 5
3 5
dtype: object
write the output:
import pandas as pd1
s = pd1.Series([1,2,3])
t = pd1.Series([1,2,4])
u=s-t
print (u)
0 1
1 0
2 1
dtype: int64
0 0
1 0
2 1
dtype: int64
0 0
1 0
2 -1
dtype: float64
0 0
1 0
2 -1
dtype: int64
write the output:
import pandas as pd
s=pd.Series([1,2,3,4],index=['a','b','c','d'])
print(s.iloc[2:4])
b 2
c 3
d 4
dtype: int64
b 3
c 4
dtype: int64
c 3
d 4
dtype: int64
none of the above
write the output:
import pandas as pd
s=pd.Series([1,2,3,4],index=['a','b','c','d'])
print(s.loc['b':'d'])
b 2
c 3
d 4
dtype: float64
b 2
c 3
d 4
dtype: object
c 3
d 4
dtype: int64
b 2
c 3
d 4
dtype: int64
Create an empty series S1
S1 = pandas.Series(empty)
S1 = pandas.series(numpy.Nan)
S1 = pandas.Series()
S1 = pandas.Series(null)
To specify data type int 16 for a series object s1 we can write
s1 = pd.Series(data = numpy.array([2,3,4]), dtype = int16)
s1 = pd.Series(data = numpy.array([2,3,4]), dtype = numpy. int16)
s1 = pd.Series(data = numpy.array([2,3,4]), dtype =pandas. int16)
all of the above
Which is the correct Pandas syntax to read in a csv file and assign it to a DataFrame df?
df = read_csv('file.csv')
df = read('file.csv', type = 'csv')
df = pd.read_csv('file.csv')
df = with open('file.csv') as pd.DataFrame
Type the syntax that returns the top 5 rows in DataFrame df with the native Pandas function (not slicing):
(a)
How many rows of data will be retrieved by default from the series if you use tail( ) method ?
2
3
4
5
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)
0 1 2
1 2 3
x y z
None of the above
Sruti wants to create a Series with data 10, 20 , 30. She is confused from the choice given below:
s= pd.Series ( [ 10, 20, 30 ] )
s= pd.Series ( [ 10, 20, 30 ] , [ 0, 1, 2 ] )
s= pd.Series ( index= [ 0, 1, 2 ] , data = [ 10, 20, 30 ] )
All of the above
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 ] ] )
Prints rows with index 1 , 5 and 3
Prints rows at position 1, 5 and 3
Prints rows with data 1,5, 3
Error
In a Series S
1 11
2 22
3 33
4 44
5 55
dtype: int64
del S[2] will delete
22
33
Both 22 and 33
None of the above
If S is a series object , which command should be used to change the name of the Series object?
S.index.name
S.name
S.index
S.columns
Indices of the pandas Series object need not be unique.
True
False
