Write a pandas program to select rows where score is between 15 and 20 (inclusive) with Practical Example.
Program Logic:
- Create Dictionary say ‘marks‘ which store marks of 5 subjects and score of subject
- Create DataFrame say ‘result‘ using DataFrame method and print DataFrame.
- Select score column of data frame ‘result’ and apply between function on it
- Pass values of score as argument to between function
- Display dataframe ‘result’ using print function
- Exit
Below is implementation code/Source code
Here is a code to print rows having score between 15 and 20(inclusive).
import pandas as pd
marks = { "English" :[67,89,90,55],
"Maths":[55,67,45,56],
"IP":[66,78,89,90],
"Chemistry" :[45,56,67,65],
"Biology":[54,65,76,87],
"score" :[12.6,20,16.7,19]}
result = pd.DataFrame(marks,index=["Athang","Sujata","Sushil","Sumedh"])
print("******************Marksheet****************")
print(result)
print("Rows where score between 15 and 20 (inclusive):")
print(result[result['score'].between(15, 20)])
Output:
***********Marksheet***************
English Maths IP Chemistry Biology score
Athang 67 55 66 45 54 12.6
Sujata 89 67 78 56 65 20.0
Sushil 90 45 89 67 76 16.7
Sumedh 55 56 90 65 87 19.0
Rows where score between 15 and 20 (inclusive):
English Maths IP Chemistry Biology score
Sujata 89 67 78 56 65 20.0
Sushil 90 45 89 67 76 16.7
Sumedh 55 56 90 65 87 19.0
Below is snapshot of executable code with output




You can also check our other pandas programs
Write a pandas program to find sum of each column with lowest mean with Practical Example
Write a Pandas program to create data frame for examination result and display row labels, column labels data types of each column and the dimensions.