import numpy as np
import pandas as pd
n=5 # Number of students , increase this number
my_id=np.arange(1,n+1) # student id from 1 to n
my_math=np.random.randint(0,100,size=n) # 0 to 100 random mark
my_english=np.random.randint(0,100,size=n)
my_pd=pd.DataFrame(data=[my_id,my_math,my_english]).T # transpose the matrix
my_pd.columns=['ID','MATH','ENG'] # adding columns to DataFrame
#print(my_pd.to_string(index=None))
my_labels=['Fail','Third','Second','First'] # labels
my_pd['my_result'] = pd.cut(x=my_pd['MATH'],
bins=[0,40, 50, 75, 100],
labels=my_labels,right=False)
print(my_pd)
Output ( Output will change as we are using random numbers as data (mark))
ID MATH ENG my_result
0 1 98 54 First
1 2 25 29 Fail
2 3 72 25 Second
3 4 26 7 Fail
4 5 78 79 First
Increase the number of students by changing n=25 to get better distribution of data.
my_pd.plot.scatter(title='Math Vs ID ',x='ID',y='MATH')
my_data=my_pd.groupby(['my_result'])[['ID']].count()
print(my_data)
my_data.plot.pie(title="Result ",y='ID',figsize=(4,4))
my_data.plot.bar(title="Result ",y='ID',figsize=(4,4))



Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.