Ivy Professional School
Rating
Learning/Python Data Drill #6

Hospital Patient Visit Analysis

Last updated

Analyze patient visits, treatment costs, insurance discounts, age risk, and department-wise revenue.

PythonIntermediatePandasNumPyHealthcare AnalyticsLambdaGroupBy

Your Objective

Analyze patient visits, treatment costs, insurance discounts, age risk, and department-wise revenue.

The Setup

Your dataset contains patient_visits with visit type, department, consultation fee, medicine cost, and insurance status.

Table Schema

patient_visits
ColumnTypeKey / Notes
patient_idINTUnique patient ID
patient_nameVARCHAR(50)Patient name
ageINTPatient age
departmentVARCHAR(50)Hospital department visited
visit_typeVARCHAR(30)Type of visit
consultation_feeFLOATConsultation fee charged
medicine_costFLOATMedicine cost charged
insurance_coveredVARCHAR(10)Whether insurance is available

Sample Data

patient_visits — 8 rows

patient_idpatient_nameagedepartmentvisit_typeconsultation_feemedicine_costinsurance_covered
301Amit45CardiologyFollow-up12003500Yes
302Neha29DermatologyNew8001200No
303Suresh63OrthopedicsNew15004200Yes
304Kavita52CardiologyEmergency25008500Yes
305Imran34NeurologyNew20005000No
306Ritu41DermatologyFollow-up800900Yes
307Joseph70OrthopedicsEmergency30009500Yes
308Meenal26NeurologyFollow-up18002500No

Your Task

Calculate total treatment cost for each patient. Apply a 20% insurance discount for insured patients. Classify age risk as Senior, Adult, or Young. Identify high-cost patients where final bill is above 8000. Summarize total revenue and patient count by department.

Your output should look like this (partial example):

patient_idpatient_namedepartmenttotal_treatment_costfinal_billage_risk_grouphigh_cost_patient
301AmitCardiology47003760.0AdultNo
302NehaDermatology20002000.0YoungNo
.....................

Python Hint

  • →final_bill depends on insurance_covered, so apply row-wise logic before department aggregation.
Explore Enterprise Solutions