series
series
In Pandas, the head() function is used to display the last few rows of a
Series.
Ans : False
2. The only alias name that can be used with the Pandas library is pd.
Ans False
Ans : True
Ans : b
Q.2 _________ is a series attribute used to check whether a series contains any value
or not:
Ans : a)
a) Import pandas as pd
b) import Pandas as py
c) import pandas as pd
d) import panda as pd
ans: c)
Q.4 To get the number of elements in a Series object, ............... attribute may be
used.
Answer S[2]
Ans : .loc()
implemented and all missing values are filled in with _____by default.
Ans : NaN
Q.9 Write a Pandas program to compare the elements of the two Pandas Series.
Q.10 . Write a Pandas program to convert a dictionary to a Pandas series and do the
following:
(iv) Retrieve and print alternate elements, starting from index ‘b’.
output.
c. Each value has a data label associated with it also called its index.
Q.1. Write python code to create following series which stores employee names as
Meet 50000
Ram 65000
Smita 68500
Rohan 46000
Riddhi 56000
Ans:
import pandas as pd
s=pd.Series([50000,65000,68500,46000,56000],index=name)
OR
import pandas as pd
d1={‘acc’:98,’bst’:95,’eco’:88}
d2={‘acc’:94,’bst’:87,’eco’:79}
d3={‘acc’:89,’bst’:76,’eco’:81}
df=pd.DataFrame([d1,d2,d3],index=[‘Meet’,’Ram’,’Smita’])
print(df)
l1=[10,20,30,40,50]
l2=[89,56,23,45,78]
s1=pd.Series(l1,index=[‘a’,’b’,’c’,’d’,’e’])
s2=pd.Series(l2,index=[‘a’,’b’,’e’,’g’,’k’])
print(s1+s2)
print(s2*2)
print(s1[s1>25])
Q.3 . Create a series with 5 elements, then find and print the square of each even
element
Ans:
Q.4 Write a program to create a series object books using a list that stores the
number of
Note: Assume four books’ names as index are [“Computer World”, “Fun with
print(books)
Note: Assume four furniture names are Table, Sofa, Chair and stool having
40, 2, 45, 26 items respectively and pandas library has been imported as
pd.
import pandas as pd
F1=pd.Series(St)
import pandas as pd
df = pd.DataFrame(data)
print(df)
Line 5: Print(S)
Ans:
Line 5: print(S)
The Python code written below has syntactical errors. Rewrite the correct code and
import pandas as pd
vaccine_qty=pd.Series([10,16,1],index=["Typhoid","Tetanus","Hepatitis"])
cost=pd.Series([200,500,800],index=["Typhoid","Tetanus","Flu"])
print(vaccine_qty + cost)
Hepatitis NaN
Tetanus 516.0
Typhoid 210.0
dtype: float64
(b) seal.index
(c) seal.dtype
(d) seal.hasnans
Q.
import pandas as pd
A=pd.Series(data=[10,13,22,18])
print(A>15)
ans:
Output will be :
0 False
1 False
2 True
3 True
Q. Complete the given Python code to get the required output as: Rajasthan
import _________ as pd
'Gir':'Gujarat'}
print(NP[ ___________ ])
ans:
import pandas as pd
NP = pd.Series( di)
print(NP[ 'Sariska'])
import pandas as pd
print (x*2)
print(y*2)
0 40
1 80
2 180
3 220
dtype: int64
b. Create a Series monthdays in which name of the months are index and
corresponding number of days are data.
import pandas as pd
monthnames=['JAN','FEB','MAR','APRIL','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC']
days=[31,28,31,30,31,30,31,31,30,31,30,31]
print(monthdays)
Find the error and also explain the reason of that error in following code fragment :
print(S2.index)
S2.index = [0, 1, 2, 3, 4, 5]
S2[5] = 220
print(S2)
ans: Length of series is not equal to length of index. There is no row of index 5
Table 350
Chair 200
Sofa 800
Stool 150
I.To display the name of the furniture having rent > 250
Q.
data = {
series = pd.Series(data)
print(series)
Q.
data = {
'Uttar Pradesh': Kanpur,
'Maharashtra': 'Mumbai',
'Bihar': 'Patna',
series = pd.Series(data)
print(series)