Series Programs
Series Programs
Solution :
import pandas as pd
def Ser_1to10():
s = pd.Series(range(1,11))
print(s)
Ser_1to10()
Output
Program 2 : Write a program to generate a series of float numbers from 21.0 to 30.0 with an increment
of 1.5 each.
Solution :
import numpy as np
import pandas as pd
def serExp():
n = np.arange(21.0, 32.0, 1.5)
s = pd.Series(n)
print(s)
serExp()
Program 3 : Write a Program to generate a Series using a dictionary to represent month number and
month Name.
Sol :
import pandas as pd
def serDict():
di = { 1: "January", 2 : "February", 3: "March", 4 : "April", 5 : "May", 6 : "June", 7 : "July", 8 : "August",
9 : "September",
10: "October", 11 : "November", 12 : "December"}
s = pd.Series(di)
print(s)
serDict()
Output:
Program 4 : Write a program to generate a series of 5 elements of multiples of 7 starting with 35 with
index multiply by 3.
Sol :
import pandas as pd
import numpy as np
def ser_mul7():
a = 35
n = np.arange(a, a*2, 7)
s = pd.Series(index = n*3, data = n)
print(s)
ser_mul7()
Output
Program 5 :Write a program to generate a series of marks of 10 students. Give grace marks upto 5 of
those who are having <33 marks and print the new list of the marks.
Solution :
import pandas as pd
def ser_marks():
std_marks=[]
for i in range(1,11):
m = int (input("Enter the Marks : "))
std_marks.append(m)
s = pd.Series(index = range(1201, 1211), data = std_marks)
s[s<33] = s+5
print("\nOld List is : \n",s)
print("New list is : ")
print(s[s>=33])
ser_marks()
Input Output
Program 6: Write a program to generate series of 10 numbers starting from 41 and with increment of
3 now add 4 to all odd values and subtract 3 to all even numbers. Reprint updated series.
Solution :
import pandas as pd
s = pd.Series(range(41, 71, 3))
print(s)
s[s%2 !=0]= s+4
s[s%2 == 0] = s-3
print(s)
Program 7 : Write a Program to Generate S1 with prime numbers between 1 to 25 and S2 with factorial
numbers between 1 to 25.