0Pricing
Data Science Academy · Lezione

query e isin per filtri puliti

Filtrare in modo leggibile molti valori.

query e isin per filtri puliti è una lezione Data Science Academy gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Data Science Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Data Science Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Toward Cleaner Filters

Long chains of ampersands get hard to read. Two tools, query and isin, make complex filtering far more pleasant. ✨

Filter With a String

The query method lets you describe the filter as plain text, so you skip the repeated df name and bracket noise.

df.query("age > 30")

query Uses Plain and or

Inside query you write natural words like and and or, instead of the symbols you needed in bracket filtering.

df.query("age > 30 and city == 'Paris'")

Reference Python Variables

Pull an outside value into a query string by prefixing it with an at sign. This keeps thresholds out of the literal text.

limit = 30
df.query("age > @limit")

Comparing Two Columns

A big win of query is comparing columns to each other directly, naming both inside the same readable string.

df.query("score > target")

Many Values With isin

To match any value from a list, isin beats chaining many OR conditions. It returns a clean boolean mask.

df[df["city"].isin(["Paris", "Lyon", "Nice"])]

Invert isin to Exclude

Combine the tilde with isin to keep rows that are not in your list, a tidy way to exclude several values at once.

df[~df["city"].isin(["Paris", "Lyon"])]

isin Inside query

You can even call isin from within a query string, blending the two tools for readable multi-value filters.

df.query("city in ['Paris', 'Lyon']")

isin Checks Values, Not Columns

Remember that isin tests each cell against a fixed list of allowed values. It is not meant for comparing one column to another column.

df[df["status"].isin(["open", "pending"])]

query Returns a New DataFrame

Like bracket filtering, query leaves the original untouched and hands back a fresh DataFrame to assign or chain.

result = df.query("age > 30")

Choosing Your Style

Reach for query when logic is long and English-like, and for isin when one column must match many values. Pick whatever reads clearest.

Quick Check

Choose the cleanest tool for the job.

Recap: query and isin

Use query for readable English-like filters with @variables, and isin to match many values at once. Your filters stay clean and clear. ✅

Domande Frequenti

La lezione «query e isin per filtri puliti» è gratuita?

Sì — il testo completo di «query e isin per filtri puliti» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Data Science Academy, passa a CoddyKit PRO. Il corso Data Science Academy include 4 lezioni in totale.

Cosa imparerò in «query e isin per filtri puliti»?

Filtrare in modo leggibile molti valori. Eserciti Data Science Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Data Science Academy?

Non è richiesta alcuna esperienza precedente. Data Science Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «query e isin per filtri puliti»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Data Science Academy?

Sì. Ogni lezione Data Science Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Selezionare le colonne per nome
  2. Filtrare le righe con condizioni
  3. Combinare i filtri con AND e OR
  4. query e isin per filtri puliti
← Torna a Data Science Academy