Important Pandas program for class 12 Term 1 Very important Exam point of view you must do
1 Write a program to generate a series of the first 10 numbers.
import pandas as pddef Ser_1to10():s = pd.Series(range(1,11))print(s)Ser_1to10()
Out put
2 Write a program to generate a series of float numbers from 21.0 to 30.0 with an increment of 1.5 each.
import pandas as pdimport numpy as npdef fl_ser():n = np.arange(21,32,1.5)s = pd.Series(n)print(s)fl_ser()
3 Write a program to generate a series using a dictionary to represent month number and month names.
import pandas as pddef Ser_dic():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)Ser_dic()
4 Write a program to generate a series of 5 elements of multiples of 7 starting with 35 with index multiply by 3.
import pandas as pdimport numpy as npdef Ser_mul7():a = 35n = np.arange(a,a*2,7)s = pd.Series(index=n*3,data=n)print(s)Ser_mul7()
5 Write a program to generate a series of marks of 10 students. Give grace marks up to 5 of those who are having <33 marks and print the new list of the marks.
import pandas as pddef Ser_stumarks():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+5print("New List is:")print(s[s>=33])Ser_stumarks()
6 Write a program to generate a series of these numbers: 33,55,65,29,19,23. Find the sum of those values which ends with 3 or 5.
import pandas as pdlist = [33,55,65,29,19,23]ser = pd.Series(list)val_sum = 0sum5 = sum(ser[ser % 10 == 5])sum3 = sum(ser[ser % 10 == 3])print(sum3+sum5)
Output is
176
7 Write a program to generate a series of 10 numbers. Change the value of all the elements to 21 those values are multiples of 4.
import pandas as pdnumbers = []# Generating a seriesfor i in range(1,11):val = int(input("Enter a number :"))numbers.append(val)ser = pd.Series(numbers)# Changing the values of multiple of four and assigning them a value 21ser[ser % 4 == 0] = 21print(ser)
8 Write a program to generate a series of 10 numbers starting with 41 and with the increment of 3. Now add 7 all odd values and reprint the updated series.
import pandas as pds = pd.Series(range(14,71,3))print(s)s[s % 2 != 0] = s + 7print(s)
9 Write a program to generate a series of 10 numbers with scalar value 33.
import pandas as pdprint(pd.Series(33,range(1,11)))
show output of this program
10 Write a program to generate series S1 with prime numbers between 1 to 25 and S2 with factorial numbers between 1 to 25.
import pandas as pdimport maths1 = pd.Series(x for x in range(1,25)if all(x % y != 0 for y in range(2, x)))s2 = pd.Series([math.factorial(n)for n in range(25)])print("Prime Number series:")print(s1)print("Factorial series:")print(s2)Do question no 11 to 14 in your Copy send me your code with output....
11 Write a program to swap the values of series to modify the contents of the series that the values which are multiples of 5 with the value present at the position in the array.
12 Write a program to demonstrate the use of common series attributes. Generate any series of your choice.
13 Write a program to generate a series and print the top 3 elements using the head function.
14 Write a program to generate a series and print the bottom 3 elements using the tail function
Important Python program for Series attributes
0 Comments