You are on page 1of 2

21/04/2022 -

*
Input -
import numpy as np
import pandas as pd
a1 = np.tile([5, 4], 3)
s1 = pd.Series(a1)
print(s1)
Output -
0 5
1 4
2 5
3 4
4 5
5 4
Input -
s2 = pd.Series({'XII A': 30, 'XII B': 40, 'XII C': 35})
print(s2)
Output -

Input -
s3 = pd.Series([5, 10, 15, 20], index = ["qtr1", "qtr2", "qtr3", "qtr4"])
print(s3)
Output -

Q. WAP to create a series containing the value as 200 medals recieved for the year
2020, 2021 and 2022.
Input -
s4 = pd.Series(200, index = [2020, 2021, 2022])
print(s4)
Output -
Q. WAP to create a series containing the value as 200 medals recieved for the years
2020 - 2030.
Input -
s5 = pd.Series(200, index = range(2020, 2031))
print(s5)
* Adding NaN (not a number) to a clause.
# you can fill the missing data with NaN value you can use the numpy module np. NaN
to specify the missing values.
Input -
s6 = pd.Series([2000, np.NaN, 3000])
print(s6)
Output -
0 2000
1 NaN
2 3000

Q. WAP to make a series to show the charity contribution of 12th standard.


Input -
s7 = pd.Series([5000, np.NaN, 0, np.NaN, 7000, 200], index = ["XII A", "XII
B", "XII C", "XII D", "XII E", "XII F"])
print(s7)
Q. WAP to create a series for numbers ranging between 1 to 15 with an interval gap
of 3 and the index as A, B, C and D.
Input -
s8 = pd.Series(range(1,15,3), index = [x for x in "ABCDEFG"])
print(s8)
Q. WAP to create a series having following data
i. A python list named section storing section name A, B, C and D
ii. Another list named contri storing values 6000, 5000, 7000, 8000
The series should store contribution amount as values and sections as index.
Input -
section = ["A", "B", "C", "D"]
contri = [6000, 5000, 7000, 8000]
s9 = pd.Series(contri, index = section, dtype = np.float 64)
print(s9)
# specifying data type along with data and index -
eg. a = np.arange(9,13)
s1 = pd.Series(index = a, data = a*2)
print(s1)
Output -
9 18
10 20
11 22
12 24
Q. Find the output.
Input-
L1 = [9, 10, 11, 12]
s2 = pd.Series(data = (2*L1))
print(s2)
Output -
0 9
1 10
2 11
3 12
4 9
5 10
6 11
7 12
# Note that in the output the list [9, 10 , 11, 12] has been repeated twice
instead.
Q. WAP to create two list section and contri section storing ABCDE and contri
storing values 6000, 7000, 8000, 9000, nil
kindly create a series having data type float 32
Input -
section = ["A", "B", "C", "D", "E"]
contri = [6000, 7000, 8000, 9000, np.NaN]
s3 = pd.Series(contri, index = section, dtype = np.float 32)
print(s3)

You might also like