Practical Assignment – I
Q1. Write a program to create a Series object Se1 using a dictionary
that stores the number of students in each section of class 12 of
your school.
Code-
Output-
Q2. Write and display the answers of both the Boolean indexing
statements:
Q3. To generate a series Se2 of 6 numbers with scalar value 56
having index values [a, b, c, d, e, f].
Code-
Output-
Q4. Use and display (in interactive mode) the working of all
attributes
of Series Se2 (of question no 3) and print the top 3 elements using
the
head function and last 4 elements using the tail function.
Ans-
Attributes of Series are as follows-
Q5. Create two series S1 having values [2,3,4,5], index [a, b, c, d]
and S2 values [6,7,8,9], index [a, x, c, z] respectively. Perform
mathematical operations using operators [S1+S2, S2-S1, S1*S2,
S2/S1] and methods [add (), sub (), mul (), div ()].
Code-
Operations on operands -
Using methods-
Q6. To create a Data Frame from List of Dictionaries having at least
6 rows and 4 columns. [Take your six friend’s marks in four
subjects(column), friend name (row index)]
Code-
Output-
Q7. To create a Data Frame df from Dictionary of Series having at
least 6 rows (six cities ‘name) and 4 columns (temperature on Mon,
Tue, Wed, Thu days of first week of June.
Code-
Output-
Q8. To add a new Column ‘Sun’ with proper data to Data Frame df.
Ans-
Q9. Display the total temperature of all cities as column name
‘T_temp’ by adding temperature of all five days.
Q10. To add a new Row having ‘Dehradun’ index with data-to-Data
Frame df.
Q11. To delete a range of rows 2 to 4 from Data Frame df.
Q12. To delete a range of columns 1 to 3 from Data Frame df.
Q13. To delete any 2 random Rows (i.e. not continuous) from a
Data Frame df.
Q14. To delete any 2 random Columns (i.e. not continuous) from a
Data Frame df.
Q15. To rename the top two Row Labels as ‘City-1’,’City-2’and
third and fourth Column Labels as ‘Day-3’,’Day-4’ of Data Frame
df.
Q16. Use and display (in interactive mode) the working of all
attributes of Data Frames on the pandas objects that you have
created in question-6.
Importing/Exporting Data between CSV files and Data
Frames:
Q1-Write a program to read data from a CSV file (empl.csv or
empl.txt) and create a Data Frame from it. The Data Frame should
not use the file's column headers; instead, it should assign default
column numbers as 0, 1, 2, ....
Csv-
Code-
Output-
Q 2- Write a program to store the df_12 Data Frame (from the
previous question) into a file named emp.csv, using the pipe
character (|) as the separator.
Code-
Output- #Saved in emp.csv
Data Visualization (Matplotlib Programs):
Q (1) Plot following data on line chart:
Day Monday Tuesday Wednesda Thursday Friday
y
Income 510 350 475 580 600
Apply following customization to the line chart:
1. Write a title for the chart “The Weekly Income Report”.
2. Write the appropriate titles of both the axes.
3. Write code to Display legends.
4. Display red color for the line.
5. Use the line style – dashed
6. Display diamond style markers on data points
Code-
Output-
Q (2) A Himalayan restaurant has recorded the following data into
their register for their income by Drinks and Food. Plot them on the
line chart.
Day Monday Tuesday Wednesda Thursday Friday
y
Drinks 450 560 400 605 580
Food 490 600 425 610 625
Apply following customization to the line chart:
1.Write a title for the chart “The Weekly Restaurant Orders”.
2.Write the appropriate titles of both the axes.
3.Write code to Display legends.
4.Display your choice of colors for both the lines drinks and food.
5.Use the line style – dotted for drinks and dashdot for food.
6. Display plus markers on drinks and x markers of food.
Code-
Output-
Q (3) A survey gathers height and weight of 100 participants
and recorded the
participants' ages as:
ages= [ 1, 1,2,3,5, 7,8,9, 10, 10,11,13,13, 15, 16,17,18, 19,20, 21,
21,23, 24, 24, 24, 25,25, 25, 25,26, 26, 26, 27, 27, 27,27, 27, 29,
30, 30, 30,30, 31,33, 34, 34, 34, 35, 36, 36, 37, 37, 37, 38, 38, 39,
40,40, 41, 41,42, 43,45,45, 46,46, 46, 47,48, 48, 49, 50, 51, 51, 52,
52, 53, 54, 55, 56,57,58, 60, 61, 63,65, 66, 68, 70, 72, 74, 75,77,81,
83, 84,87,89, 90, 91]
Write a program to plot a histogram from above data with 20 bins.
Write a title for the chart “Participants' Ages Histogram”.
Code-
Output-
Q (4) Write a Python program to show strength of different
sections in a class using BAR CHART.
Sample data:
Group: A, B, C, D, E and Strength: 50, 48, 46, 51, 55
Apply following customization to the chart:
1.Use different colors for each bar.
2.Title for x axis should be ‘Sections’ and title for y axis should be
‘Strength’.
3.Ensure the title of chart is ‘Section wise Strength’ and grid line
must be shown.
Code-
Output-