Q. Create the following Series and do the specified operations:


a) EngAlph, having 26 elements with the alphabets as values and default index values.

b) Vowels, having 5 elements with index labels ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’ and all the five values set to zero. Check if it is an empty series.

c) Friends, from a dictionary having roll numbers of five of your friends as data and their first name as keys.

d) MTseries, an empty Series. Check if it is an empty series.

e) MonthDays, from a numpy array having the number of days in the 12 months of a year. The labels should be the month numbers from 1 to 12.



Answer :-

a =

import pandas as pd
alph =[chr(i) for i in range(65,91)]
engAlph = pd.Series(alph)
print(engAlph)
Output :-

0     A
1     B
2     C
3     D
4     E
5     F
6     G
7     H
8     I
9     J
10    K
11    L
12    M
13    N
14    O
15    P
16    Q
17    R
18    S
19    T
20    U
21    V
22    W
23    X
24    Y
25    Z
dtype: object
>>> 

b =
import pandas as pd
vowels = pd.Series([1,2,3,4,5],index=list('aeiou'))
print(vowels)
vowels[vowels!='not zero']=0 #
print(vowels)
print()
print('is empty',vowels.empty)
Output :-

a    1
e    2
i    3
o    4
u    5
dtype: int64
a    0
e    0
i    0
o    0
u    0
dtype: int64

is empty False
>>> 

c =
import pandas as pd
di={'data':[1,2,3,4,5],'first name':['Path','Walla','Python','Portal','Express']}
friends = pd.Series(di)
print(friends)
Output :-

data                                 [1, 2, 3, 4, 5]
first name    [Path, Walla, Python, Portal, Express]
dtype: object
>>> 

d =
import pandas as pd
MTseries = pd.Series()
print(['Series is not empty','Series is empty'][MTseries.empty])
Output :-

Series is empty
>>> 

e =
import pandas as pd
import numpy as np
array1 = np.array([31,28,31,30,31,30,31,31,30,31,30,31])
MonthDays = pd.Series(array1,index=[1,2,3,4,5,6,7,8,9,10,11,12])
print(MonthDays)

Output :-

1     31
2     28
3     31
4     30
5     31
6     30
7     31
8     31
9     30
10    31
11    30
12    31
dtype: int32

>>> 


10 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post