query และ isin สำหรับตัวกรองที่อ่านง่าย
กรองค่าจำนวนมากให้อ่านเข้าใจง่าย
query และ isin สำหรับตัวกรองที่อ่านง่าย เป็นบทเรียน Data Science Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Data Science Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
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. ✅
คำถามที่พบบ่อย
บทเรียน “query และ isin สำหรับตัวกรองที่อ่านง่าย” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “query และ isin สำหรับตัวกรองที่อ่านง่าย” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Data Science Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “query และ isin สำหรับตัวกรองที่อ่านง่าย”
กรองค่าจำนวนมากให้อ่านเข้าใจง่าย คุณปฏิบัติ Data Science Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Data Science Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Data Science Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “query และ isin สำหรับตัวกรองที่อ่านง่าย” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Data Science Academy นี้ได้ไหม
ได้ บทเรียน Data Science Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- เลือกคอลัมน์ด้วยชื่อ
- กรองแถวด้วยเงื่อนไข
- รวมตัวกรองด้วย AND และ OR
- query และ isin สำหรับตัวกรองที่อ่านง่าย