Filter mit AND und OR kombinieren
Mehrere Bedingungen sicher verketten
Filter mit AND und OR kombinieren ist eine kostenlose Data Science Academy-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Data Science Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Data Science Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
One Condition Is Rarely Enough
Real questions stack conditions: adults in Paris, or orders that are late and large. You need to combine filters cleanly. 🧩
Use the Ampersand for AND
To require both conditions, join the two masks with the ampersand. It works element by element across the rows.
df[(df["age"] > 30) & (df["city"] == "Paris")]Use the Pipe for OR
To accept either condition, join the masks with the pipe. A row passes if at least one side is True.
df[(df["city"] == "Paris") | (df["city"] == "Lyon")]Wrap Each Condition in Parentheses
Always put parentheses around each condition. Without them, Python evaluates the operators in the wrong order and raises an error.
df[df["age"] > 30 & df["score"] > 80] # breaksWhy Not and or or?
The plain words and and or work on single True/False values, not on whole Series. For row masks you must use the symbols.
# wrong: df[(df["age"] > 30) and (...)]
# right: use & insteadInvert With the Tilde
The tilde flips a mask, turning True into False. It is the clean way to say not this condition.
df[~(df["city"] == "Paris")] # everyone not in ParisMix AND and OR Carefully
You can blend operators, but parentheses decide the grouping. Make your intent explicit so the logic reads the way you mean it.
df[(df["age"] > 30) & ((c == "Paris") | (c == "Lyon"))]Three or More Conditions
Stacking more masks works the same way. For readability, build them on separate lines, then combine the named masks.
old = df["age"] > 30
top = df["score"] > 80
df[old & top]AND Narrows, OR Widens
Keep the mental model simple: AND shrinks the result toward fewer rows, while OR grows it toward more rows.
Combine Across Columns
Your conditions can touch different columns at once, letting you express rich questions in a single expression.
df[(df["age"] > 30) & (df["active"] == True)]Save Complex Masks
When logic gets dense, give the combined mask a clear name. Future you will thank you for the readable variable.
vip = (df["age"] > 30) & (df["score"] > 80)
df[vip]Quick Check
Pick the expression that filters correctly.
Recap: Combining Filters
Use the ampersand for AND, the pipe for OR, the tilde to invert, and always wrap each condition in parentheses. Complex questions, one clean line. ✅
Häufig gestellte Fragen
Ist die Lektion „Filter mit AND und OR kombinieren“ kostenlos?
Ja — der vollständige Text von „Filter mit AND und OR kombinieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Data Science Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Data Science Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Filter mit AND und OR kombinieren“?
Mehrere Bedingungen sicher verketten Du übst Data Science Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Data Science Academy zu starten?
Keine Vorkenntnisse erforderlich. Data Science Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.
Wie lange dauert die Lektion „Filter mit AND und OR kombinieren“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Data Science Academy-Lektion Code schreiben und ausführen?
Ja. Jede Data Science Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Spalten nach Namen auswählen
- Zeilen mit Bedingungen filtern
- Filter mit AND und OR kombinieren
- query und isin für saubere Filter