0% found this document useful (0 votes)
17 views3 pages

Series Assign2

The document contains questions related to Pandas Series operations. It covers topics like creating Series from NumPy arrays, accessing Series elements using indexes, applying arithmetic, logical and comparison operations on Series, modifying Series values and checking properties of Series like empty.

Uploaded by

ipshitanegi7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Series Assign2

The document contains questions related to Pandas Series operations. It covers topics like creating Series from NumPy arrays, accessing Series elements using indexes, applying arithmetic, logical and comparison operations on Series, modifying Series values and checking properties of Series like empty.

Uploaded by

ipshitanegi7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Series Assignment-2

Q1 Write the output of the following:


a) import pandas as pd
L1=[1,"A",21]
S1 = pd.Series (data=2*L1)
print(S1)

b) import numpy as num


import pandas as pd
arr=num.array([1,7,21])
S1 = pd.Series(arr)
print(S1)

c) import numpy as num


import pandas as pd
arr=num.array ([1,7,21])
S1 = pd.Series (arr, index = (77,777))
print(S1)

d) import numpy as num


import pandas as pd
arr=num.array([31,47,121])
S1 = pd.Series(arr, index = (7,77,777))
print(S1[777])

e) import numpy as num


import pandas as pd
arr=num.array([31,47,121])
S1 = pd.Series(arr)
print(S1[0])

f) import pandas as pd
L1 = list("My name is Ravi Kumar")
S1 = pd.Series(L1)
print(S1 [0])

g) import pandas as pd
S1 = pd.Series([3 1, 28, 31, 30, 31], index = ["Jan", "Feb", "Mar", "Apr", "May"])
print(S1[ “Jan"])

h) import pandas as pd
S1=pd.Series ([31,28,31,30,31], index =["Jan", "Feb", "Mar","Apr","May"] )
print("_________”)
print(S1 [1:3])
print(“_________”)
print(S1 [:5])
print(“_________”)
print(S1 [3:3])
print(“_________”)
print(S1["Jan" : "May"] )

i) import pandas as pd
S1 = pd.Series([31, 28, 31, 30, 31], index = "Jan", "Feb", "May", "Apr", "May")
print(S1[‘May’])

j) import pandas as pd
S1 pd.Series([31, 28, 31, 30, 31], index = [Jan", "Feb", "Mar", "Apr", "May"])
print(S1[ [0, 2, 4] ])

k) import pandas as pd
S1 = pd.Series ([2, 5, 7, 10])
print(S1 + 2)
print(S1 *2)
print(S1 ** 2)
print(S1 - 2)
print(S1 > 2)

l) import pandas as pd
S1 = pd.Series([2, 5, 7, 10])
S2 = pd.Series ([1, 3, 5, 7])
print(S1 + S2)

m) import pandas as pd
S1 = pd.Series ([3, 1, 12, 17], index = ("a", "b","c","d"))
S2 = pd.Series ([4, 5, 6, 7], index = ("a","b","e","f") )
print(S1*S2)

n) import pandas as pd
S1 = pd.Series ([3, 1, 12, 17], index = ["a", "b", "c", "d"] )
S2 = pd.Series ([4, 5, 6, 7], index= ["a", “b", "e”, “f”+ )
print(S1.mul(S2, fill_value = 0))

o) import pandas as pd
S1= pd.Series([31, 28, 31, 30, 31], index = ["Jan'", "Feb", "Mar", "Apr","May"])
print(S1 [0 : 2] * 2)

Q2. Which property of series returns all the index value?


Q3. Which property of series returns the number of elements in the series?
Q4. Give an example of creating series from NumPy array.
Q5. Write a program to modify the value 5000 to 7000 in the following Series "S1":

Q6. Which property of Series help to check whether a Series is empty or not?
Explain with example.
Ans. empty property : This property returns True if the Series is empty otherwise
return False.
import pandas as pd OUTPUT:
S1 = pd.Series() True
print(S1.empty)

Q7. Fill in the blanks in the given code:


import pandas as pd
______ = ________.Series ([1, 2, 3, 4, 5])
print(S1)

Q8. Fill in the blank of given code, if the output is 71.


import pandas as pd
S1 = pd.Series([10, 20, 30, 40, 71,50])
print(S1 [ ____ ])

Q9. Complete the code to get the required output :


import ____ as pd OUTPUT:
_____= pd.Series([31, 28, 31], index = ["Jan","Feb", "Mar"]) 28
print(S1 *“_____”+)

Q10. Explain any two properties/attributes of Pandas Series.


Ans. Two properties/attributes of Pandas Series are:
1. size : It returns the number of values in the Series Object.
2. values: It returns the list of the values in the series.

Q11. Explain any three methods of Pandas Series.


Ans. Three methods of Pandas Series are:
1) head(n):This function returns the first n members of the series. If the value for n is
not
passed, then by default n takes 5 and the first five members are displayed.
2) tail( n):This function returns the last n members of the series. If the value for n is
not
3) count():This function returns the number of non-NaN values in the Series.

_____________

You might also like