XII IP Practical List - Anand
XII IP Practical List - Anand
1) #code
import pandas as pd
Output:
marks 45
dtype: int64
marks 95
dtype: int64
2) #code
import pandas as pd
for i, j in salesman.iteritems():
print(j)
Output:
0 Ham
1 Burr
2 George
3 Seabury
Name: Name, dtype: object
0 43
1 38
2 53
3 47
Name: Sales, dtype: int64
3) #code
import pandas as pd
Output:
4) #code
import pandas as pd
Output:
Batsman ODI
0 Virat Kohli 2245
1 Ajinkya Rehane 2165
2 Rohit Sharma 2080
3 Shikhar Dhawan 1957
4 Hardik Pandya 1856
5) #code
import pandas as pd
d1 = {'a': 100, 'b': 200, 'c': 300, 'd': 400, 'e': 800}
s1 = pd.Series(d1)
print(s1)
Output:
a 100
b 200
c 300
d 400
e 800
dtype: int64
6) #code
import pandas as pd
Output:
ENGLISH 75
HINDI 78
MATHS 82
SCIENCE 86
dtype: int64
7) #code
import pandas as pd
Output:
Term1 45
Term2 65
Term3 24
Term4 89
dtype: int64
8. Write a program in Python Pandas to create the following DataFrame batsman from a
Dictionary:
Perform the following operations on the DataFrame: 1)Add both the scores of a
batsman and assign them to column “Total” 2)Display the highest score in both
Score1 and Score2 of the DataFrame.
8) #code
import pandas as pd
batsman_dict = {'B_NO': [1, 2, 3, 4], 'Name': ['Sunil Pillai', 'Gaurav Sharma', 'Piyush Goel',
'Kartik Thakur'],
'Score1': [90, 65, 70, 80], 'Score2': [80, 45, 90, 76]}
batsman = pd.DataFrame(batsman_dict)
print(batsman, end='\n\n')
batsman['Total'] = batsman['Score1'] + batsman['Score2']
print(batsman, batsman[['Score1', 'Score2']].max(), sep='\n\n')
Output:
Score1 90
Score2 90
dtype: int64
9) #code
import pandas as pd
Output:
PB1 90
PB2 80
dtype: int64
Write commands to :
i. Add a new column ‘Winner’ to the Dataframe
ii. Add a new row with values ( s5, 5, Handball, 20)
10) #code
import pandas as pd
Output:
11. Write a Python code to create the following DataFrame Library using Python Pandas.
Give index as ‘B1’, ‘B2’, ‘B3’, ‘B4’
(i) Display Item Number and Name whose price is less than 150.
(ii) Display the top two and bottom two rows.
(iii) Display the DataFrame.
11) #code
import pandas as pd
Output:
ItemNo ItemName Price
B1 I99 Sugar 100
B2 I10 Tea 150
B3 I50 Coffee 200
B4 I60 Green Tea 250
ItemNo ItemName
B1 I99 Sugar
12. The number of bed sheets manufactured by a factory during five consecutive weeks is
given below.
12) #code
import matplotlib.pyplot as plt
Output:
13. The number of students in 7 different classes is given below. Represent this data on
the bar graph.
13) #code
import matplotlib.pyplot as plt
14. Consider the following graph. Write the code to plot it.
14) #code
import matplotlib.pyplot as plt
a = ['1', '2', '3', '4', '5']
b = [10, 31, 16, 12, 20]
plt.plot(a, b, marker='o', color='c')
plt.grid(axis='y')
plt.show()
Output:
15. Consider the following graph. Write the code to plot it.
15) #code
import matplotlib.pyplot as plt
Output:
16. Write a Python program to display a bar chart of the number of students in a school.
Use different colours for each bar.
Sample data: Class: I,II,III,IV,V,VI,VII,VIII,IX,X Strength:
38,30,45,49,37,53,48,44,36,46
16) #code
import matplotlib.pyplot as plt
a = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X']
b = [38, 30, 45, 49, 37, 53, 48, 44, 36, 46]
plt.bar(a, b, color=['g', 'r', 'b', 'y', 'c', 'm', 'k', 'olive', 'brown', 'silver'])
plt.title('Students per Class')
plt.xlabel('Class')
plt.ylabel('Number of Students')
plt.show()
Output:
17. Write a Python program to plot the given bar graph to depict the popularity of various
programming languages. Label the graph with x-axis, y-axis, y-ticks and title. Data :
Programming languages: Python, C++, Java, Perl, Scala, Lisp Usage= 10,8,6,4,2,1
17) #code
import matplotlib.pyplot as plt
Output:
18. Consider the following data of a medical store and plot the data on the line chart:
18) #code
import matplotlib.pyplot as plt
Output:
19. Plot following data on line chart:
19) #code
import matplotlib.pyplot as plt
Output:
20. Observe the following data and plot data according to the given instructions:
1. Create a bar chart to display data of Virat Kohli & Rohit Sharma.
● Customise the chart in this manner
● Use different widths
● Use different colours to represent different years' score
● Display appropriate titles for axis and chart
● Show legends
20) #code
import matplotlib.pyplot as plt
import numpy as np
barWidth = 0.25
batsmen = ['Virat Kohli', 'Steve Smith', 'Babar Azam', 'Rohit Sharma', 'Kane Williamson', 'Jos
Butler']
y2017 = [2501, 2340, 1750, 1463, 1256, 1125]
y2018 = [1855, 2250, 2147, 1985, 1785, 1853]
y2019 = [2203, 2003, 1896, 1854, 1874, 1769]
y2020 = [1223, 1153, 1008, 1638, 1974, 1436]
Virat_Kohli = [2501, 1855, 2203, 1223]
Rohit_Sharma = [1463, 1985, 1854, 1638]
years = np.arange(2017, 2021)
Output:
21. Draw the histogram based on the Production of Wheat in different Years
Year:2000,2002,2004,2006,2008,2010,2012,2014,2016,2018
Production':4,6,7,15,24,2,19,5,16,4
21) #code
import matplotlib.pyplot as plt
prod = [4, 6, 7, 15, 24, 2, 19, 5, 16, 4]
plt.hist(prod, bins=20)
plt.title('Production')
plt.show()
Output: