query e isin para filtros limpos
Filtragem legível para muitos valores.
query e isin para filtros limpos é uma aula grátis de Data Science Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Data Science Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Data Science Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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. ✅
Perguntas Frequentes
A aula “query e isin para filtros limpos” é grátis?
Sim — o texto completo de “query e isin para filtros limpos” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Data Science Academy, atualize para CoddyKit PRO. O curso de Data Science Academy inclui 4 aulas no total.
O que vou aprender em “query e isin para filtros limpos”?
Filtragem legível para muitos valores. Você pratica Data Science Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Data Science Academy?
Nenhuma experiência prévia é necessária. Data Science Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “query e isin para filtros limpos”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Data Science Academy?
Sim. Cada aula de Data Science Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Selecionar colunas pelo nome
- Filtrar linhas com condições
- Combinar filtros com AND e OR
- query e isin para filtros limpos