Q. Using the Series created in Question 5, 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’].
Answer :-
a)
import pandas as pd vowels = pd.Series([1,2,3,4,5],index=list('aeiou')) print(vowels) print() vowels[vowels!='not ten']=10 # all values changed to '10' print(vowels)
Output :-
a 1
e 2
i 3
o 4
u 5
dtype: int64
a 10
e 10
i 10
o 10
u 10
dtype: int64
e 2
i 3
o 4
u 5
dtype: int64
a 10
e 10
i 10
o 10
u 10
dtype: int64
>>>
b)
import pandas as pd vowels = pd.Series([1,2,3,4,5],index=list('aeiou')) print(vowels) print() vowels[vowels!='not ten']=10 # all values changed to '10' print(vowels) vowels=vowels/2 print(vowels)Output :
a 1
e 2
i 3
o 4
u 5
dtype: int64
a 10
e 10
i 10
o 10
u 10
dtype: int64
a 5.0
e 5.0
i 5.0
o 5.0
u 5.0
dtype: float64
>>>
c)
import pandas as pd vowels = pd.Series([2,5,6,3,8],index=list('aeiou')) print(vowels)Output :-
a 2
e 5
i 6
o 3
u 8
dtype: int64
>>>
d)
import pandas as pd vowels = pd.Series([1,2,3,4,5],index=list('aeiou')) print() vowels[vowels!='not ten']=10 # all values changed to '10' vowels=vowels/2 vowels1 = pd.Series([2,5,6,3,8],index=list('aeiou')) vowels3=vowels1+vowels print(vowels3)Output :
a 7.0
e 10.0
i 11.0
o 8.0
u 13.0
dtype: float64
>>>
e)
import pandas as pd vowels = pd.Series([1,2,3,4,5],index=list('aeiou')) print() vowels[vowels!='not ten']=10 # all values changed to '10' vowels=vowels/2 vowels1 = pd.Series([2,5,6,3,8],index=list('aeiou')) vowels3=vowels1+vowels print(vowels3) Subtract=vowels-vowels1 Multiply=vowels*vowels1 Divide=vowels/vowels1Output :
a 7.0
e 10.0
i 11.0
o 8.0
u 13.0
dtype: float64
>>>
f)
import pandas as pd vowels = pd.Series([1,2,3,4,5],index=list('aeiou')) print() vowels[vowels!='not ten']=10 # all values changed to '10' vowels=vowels/2 vowels1 = pd.Series([2,5,6,3,8],index=list('aeiou')) vowels3=vowels1+vowels print(vowels3) Subtract=vowels-vowels1 Multiply=vowels*vowels1 Divide=vowels/vowels1 vowels1.index= ['A', 'E', 'I', 'O', 'U'] print(vowels1)Output :
a 7.0
e 10.0
i 11.0
o 8.0
u 13.0
dtype: float64
A 2
E 5
I 6
O 3
U 8
dtype: int64
>>>
plz upload outputs too.
ReplyDeleteOk, I have updated it.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )