Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (160 points)
edited by
Could anyone tell me how to extract multiple rows from each patient in a dataset?

1 Answer

0 votes
ago by (1.9k points)

In a data set, you can use the criteria based on a patient identifier column to filter the data and retrieve several rows for each patient. Here's a step-by-step approach:

Use Pandas if your dataset is in tabular form, such as an Excel or CSV file:


 

import pandas as pd

# Load the dataset

df = pd.read_csv('patients_data.csv')

# Example: Extract rows for specific patients

patient_ids = [101, 102, 103]  # List of patient IDs you want to extract

filtered_rows = df[df['patient_id'].isin(patient_ids)]

print(filtered_rows)

31k questions

32.9k answers

507 comments

693 users

...