Skip to content
Advertisement

How to find which doctor a patient is using, when only given a list of doctor’s patients? (code improvement request) [closed]

I need to create a dataframe which lists all patients and their matching doctors.

I have a txt file with doctor/patient records organized in the following format:

JavaScript

And a list of all unique patients.

To do this, I imported the txt file into a doctorsDF dataframe, separated by a colon. I also created a patientsDF dataframe with 2 columns: ‘Patients’ filled from the patient list, and ‘Doctors’ column empty.

I then ran the following:

JavaScript

This worked fine, and now all patients are matched with the doctors, but the method seems clumsy. Is there any function that can more cleanly achieve the result? Thanks!

(First StackOverflow post here. Sorry if this is a newb question!)

Advertisement

Answer

If you use Pandas, try:

JavaScript

Output:

JavaScript

How to search:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement