RAS HYE PythonPandasSeries

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Revision Assignment – HYE-Python Pandas-Series (IP-XII)

1 What is the purpose of following statement:


import pandas as pd
s1=pd.Series()
print(s1)

What will be the data type of created object?


2 Write statement for creating following series:
0 2
1 8
2 90
3 11
4 5
dtype: int64
3 Use range() function to create following series:
0 0
1 1
2 2
3 3
dtype: int64
4 Create series with following list values:
[10, 20, 38, 44]
5 Create series with following tuple values:
(10, 20, 38, 44)
6 What will be the output of:
import pandas as pd
s1=pd.Series("INDIA")
7 What will be the output of:
import pandas as pd
s1=pd.Series(["INDIA", "IS MY COUNTRY"])
8 Output?
import pandas as pd
s1=pd.Series(("INDIA", "IS MY COUNTRY"))
9 Output?
import pandas as pd
s1=pd.Series({'I':'INDIA', 'U':'UAE', 'O': 'OMAN'})
print(s1)
Prepared by: Tanu Sarda
10 Write code for series:
10 Dates
20 Oryx
30 Falcon
dtype: object

11 Write code for series:


Fruit Dates
Animal Oryx
Bird Falcon
dtype: object

12 Output?
import pandas as pd
s1=pd.Series(100, index=range(1,10,2))

13 Output?
import pandas as pd
s1=pd.Series(100, index=range(10,50,10))

14 Write code for series:


1 3.0
3 5.0
5 NaN
7 19.0
dtype: float64

15 1 3.0
3 5.0
5 NaN
7 19.0
9 24.0
11 65.0
dtype: float64

output?
s1[3]
s1[2]
s1[1:5]
s1[1:5:2]
s1[:3:2]
s1[1:]
s1[::-1]
s1[1::3]

Prepared by: Tanu Sarda


16 Output?
s1=pd.Series([26, 36, 76, 86, 98, 65], index=range(1,7))
s1[1:7:2]=100

17 1 26
2 100
3 76
4 100
5 98
6 100
dtype: int64
output?
s1.head()
s1.head(3)

18 0 2.0
1 4.0
2 6.0
3 7.0
4 NaN
dtype: float64

Output?
s1+2
s1**2
s1>2
s1[s1>2]

19 Output?
s1=pd.Series([2, 4, 6, 7, np.nan])
s2=pd.Series([1,6,9])
print(s1+s2)

20 Output?
s1=pd.Series([2, 4, 6, 7, np.nan])
s2=pd.Series([1,6,9], index=[2,5,7])
print(s1+s2)

21 0 21.0
1 4.0
2 62.0
3 17.0
4 NaN
5 11.0
dtype: float64

Write code for sorting values in :


Prepared by: Tanu Sarda
i) ascending order
ii) descending order

Prepared by: Tanu Sarda

You might also like