0% found this document useful (0 votes)
6 views3 pages

Python Part 2

The document contains code snippets for creating and manipulating a Pandas Series object representing the number of days in each month, including adding, updating, and changing the index. It also includes a program to display a bar chart of the number of students in different groups with specified colors and axis titles. The output of the operations on the Series and the bar chart is also indicated.

Uploaded by

j2492618
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Python Part 2

The document contains code snippets for creating and manipulating a Pandas Series object representing the number of days in each month, including adding, updating, and changing the index. It also includes a program to display a bar chart of the number of students in different groups with specified colors and axis titles. The output of the operations on the Series and the bar chart is also indicated.

Uploaded by

j2492618
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q21) Write the code to create the series “SerObj” and answer the questions

followed
Jan 31
Feb 29
Mar 31
Apr 30
I. Write the code to add one row ‘May’=31
II. Write the code to update Feb to 29
III. Write the code to change index to 1,2,3,4,5 in place of Jan, Feb, Mar,
Apr and May
IV. Write a code to print a month name having number od days less than
31
V. Write the output:
(a) print(SerObj<30)
(b)print(SerObj+3)
Ans)
import pandas as pd
S={"Jan":31,"Feb":28,"Mar":31,"Apr":30}
SerObj=pd.Series(S)
print(SerObj)
print("\n")
SerObj['May']=31
print(SerObj)
print("\n")
SerObj['Feb']=29
print(SerObj)
print("\n")
SerObj.index=[1,2,3,4,5]
print(SerObj)
print("\n")
SerObj[SerObj<31]
print(SerObj)
print("\n")
print(SerObj<30)
print("\n")
print(SerObj+3)

28
Output)

29
Q22) Write a program to display a bar chart of number of students
I. Use different colour for each bar
II. Title for X axis should be “Groups” and Title for the Y axis should be
“Number of Students”

Ans)
import matplotlib.pyplot as plt
Groups=['I','II','III','IV']
Strenght=[38,30,45,49]
plt.bar(Groups,Strenght,color=['r','g','b','c'])
plt.xlabel("Groups")
plt.ylabel("Number of Students")
plt.show()

Output)

30

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy