Contents:
- Programs
- Theory Question
Practice Program
1.Write python code to create a Series object using the python sequence [4,6,8,10]. Assume that pandas is imported as alias name pd.
2.Write code to create a Series object using the python sequence(11,21,31,41). Assume that pandas is imported as alias name pd
3.Write a python program to create a Series object using a dictionary that stores the item name and its price of your grocery list.
maggie 10
salt 25
mustard oil 150
turmeric 25
4.Write a program to create a series object using an ndarray that has 10 number in the range of 20 to 25
5.Consider the series object listed below, Write python code to the amount section 'A' as 7500 and for section 'c' and 'd' as 6000. print the changed object.
A | 6700 |
B | 5000 |
C | 4800 |
D | 8700 |
6.A series object data consists of around 2500 rows of data. write a program to print the following details.
- First 100 rows of the data
- Last 5 rows of data
7.Number of students in class 11 and 12 in 2 streams ("Science","Humanities") are stored in a series object, write code to find total number of students in each stream combining both the class.Take any data you want in series object.
8.srPop store the population details of four states in india and srIncome stores the total income reported in previous year in each city. Calculate income per capita for each of these cities.
population data:
delhi=10927986
mumbai=12691836
kolkata=46132392
chennai=4328956
Total income data:
delhi=75467963145698
mumbai=78423694528478
kolkata=4789657893214
chennai=9845637852496
9.Series objects temp1, temp2, temp3, temp4 store the temperature of days of week1, week2, week3, week4 respectively. Write a script to
a. print average temperature per week
b. print average temperature of entire month
10.Write a python program that stores the sales of 5 fast moving items of a store for each month in 12 Series objects, i.e. s1 Series object store sales of these 5 items in 1st month, s2 stores the sales of these 5 items in the 2nd month and so on, consider the following table of data where each row is a series object:
Series Object | item1 | item2 | item3 | item4 | item5 |
s1 | 4578 | 658 | 4753 | 452 | 1256 |
s2 | 4568 | 6158 | 753 | 4252 | 156 |
s3 | 3578 | 6581 | 4713 | 4152 | 5256 |
s4 | 1578 | 258 | 753 | 4152 | 1856 |
s5 | 1278 | 6158 | 4153 | 432 | 156 |
s6 | 1278 | 6158 | 4153 | 432 | 156 |
s7 | 1278 | 6158 | 4153 | 432 | 156 |
s8 | 1278 | 6158 | 4153 | 432 | 156 |
s9 | 1278 | 6158 | 4153 | 432 | 156 |
s10 | 1278 | 6158 | 4153 | 432 | 156 |
s11 | 1278 | 6158 | 4153 | 432 | 156 |
s12 | 1278 | 6158 | 4153 | 432 | 156 |
The program should display the summary sales report like this:
- Total yearly sales, item-wise(should display sum of items' sales over the month)
- Maximum sales of items made: (name of items that was sold the maximum in whole year)
- Maximum sales of individual items
- Maximum sales of item 1 made: (month in which that items sold the maximum)
- Maximum sales of item 2 made: (month in which that items sold the maximum)
- Maximum sales of item 3 made: (month in which that items sold the maximum)
- Maximum sales of item 4 made: (month in which that items sold the maximum)
- Maximum sales of item 5 made: (month in which that items sold the maximum)
11.Three series object store the marksof 10 students in three terms. Roll numbers of students from the index of these Series object. The Three Series objects have the same indexes.
Calculate the total weighted marks obtained by students as per following formula:
Final Marks=25% Term 1 + 25% Terms 2 + 50% Terms 3
SOLUTION(to above question)
Assignment Question:
1.What is a Series and how is it different from a 1-D array, a list and a dictionary?
2.Create the following Series and do the specified operations:
a) EngAlph, having 26 elements with the alphabets as values and default index values.
b) Vowels, having 5 elements with index labels ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’ and all the five values set to zero. Check if it is an empty series.
c) Friends, from a dictionary having roll numbers of five of your friends as data and their first name as keys.
d) MTseries, an empty Series. Check if it is an empty series.
e) MonthDays, from a numpy array having the number of days in the 12 months of a year. The labels should be the month numbers from 1 to 12.
3.Using the Series created in Question 2, write commands for the following:
a) Set all the values of Vowels to 10 and display the Series.
b) Divide all values of Vowels by 2 and display the Series.
c) Create another series Vowels1 having 5 elements with index labels ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’ having values [2,5,6,3,8] respectively.
d) Add Vowels and Vowels1 and assign the result to Vowels3.
e) Subtract, Multiply and Divide Vowels by Vowels1.
f) Alter the labels of Vowels1 to [‘A’, ‘E’, ‘I’, ‘O’, ‘U’].
4.Using the Series created in Question 2, write commands for the following:
a) Find the dimensions, size and values of the Series EngAlph, Vowels, Friends, MTseries, MonthDays.
b) Rename the Series MTseries as SeriesEmpty.
c) Name the index of the Series MonthDays as monthno and that of Series Friends as Fname.
d) Display the 3rd and 2nd value of the Series Friends, in that order.
e) Display the alphabets ‘e’ to ‘p’ from the Series EngAlph.
f) Display the first 10 values in the Series EngAlph.
g) Display the last 10 values in the Series EngAlph.
h) Display the MTseries
5.Using the Series created in Question 2, write commands for the following:
a) Display the names of the months 3 through 7 from the Series MonthDays.
b) Display the Series MonthDays in reverse order.