Nested Queries / Comparing Multiple Datasets Efficiently In Pandas
I am using Pandas (first time) to determine whether personnel meet prerequisites when it comes to course attendance. The code below returns the desired results however I am sure th
Solution 1:
pivoted = df.groupby(['Name', df.CourseName.str.split().str[0]]) \
.CourseId.size().gt(0).unstack(fill_value=False)
pivoted
matches = pivoted.query('Engineering & Mathematics & ~Physics')
matches
df.query('Name in @matches.index')
Solution 2:
Use query
to type more natural math relationships :
df.query('CourseId == "P12" or CourseId != "P99"')
Post a Comment for "Nested Queries / Comparing Multiple Datasets Efficiently In Pandas"