Page 41 - Informatics_Practices_Fliipbook_Class12
P. 41
c. myDict = {"Samir":1,"Manisha":2,"Dhara":3,"Shreya":4,"Kusum":5}
friends = pd.Series(myDict)
print(friends)
d. import pandas as pd
# Creating an empty Series
MTseries = pd.Series()
# Checking if the Series is empty
isEmpty = MTseries.empty
# Printing the result
print("Is the Series empty? ", isEmpty)
e. import numpy as np
import pandas as pd
MonthDays = np.array([31,28,31,30,31,30,31,31,30,31,30,31])
month = pd.Series(MonthDays,index=np.arange(1,13))
print(month)
3. Using the Series created in Question 2, write commands for the following:
a. Set all the values of Vowels to 10 and display the Series.
b. Divide all values of Vowels by 2 and display the Series.
c. Create another series Vowels1 having 5 elements with index labels 'a', 'e', 'i', 'o' and 'u' having values [2,5,6,3,8]
respectively.
d. Add Vowels and Vowels1 and assign the result to Vowels3.
e. Subtract, Multiply and Divide Vowels by Vowels1.
f. Alter the labels of Vowels1 to ['A', 'E', 'I', 'O', 'U'].
Ans. a. import pandas as pd
vowels = pd.Series(0,index=['a','e','i','o','u'])
vowels.iloc[0:5] =10
print(vowels)
vowels.loc['a':'u']=10
print(vowels)
b. vowels = vowels / 2
c. vowels1 = pd.Series([2,5,6,3,8],index=['a','e','i','o','u'])
d. vowels3 = vowels + vowels1
e. vowels3 = vowels - vowels1
vowels3 = vowels * vowels1
vowels3 = vowels / vowels1
f. vowels1.index = ['A','E','I','O','U']
4. Using the Series created in Question 2, write commands for the following:
a. Find the dimensions, size and values of the Series EngAlph, Vowels, Friends, MTseries, MonthDays.
b. Rename the Series MTseries as SeriesEmpty.
c. Name the index of the Series MonthDays as monthno and that of Series Friends as Fname.
d. Display the 3rd and 2nd value of the Series Notes Friends, in that order.
e. Display the alphabets 'e' to 'p' from the Series EngAlph.
f. Display the first 10 values in the Series EngAlph.
g. Display the last 10 values in the Series EngAlph.
h. Display the MTseries.
Data Handling using Pandas 27

