← Back to Pandas Course | Chapter 3: DataFrame Basics | Lesson 4 of 7

Columns Select करना

Square brackets एक column (एक Series) या कई columns (एक छोटा DataFrame) pick करते हैं।
Syntax
python
df["column"]
df[["column1", "column2"]]

Columns Select करना

df["name"] एक Series return करता है, जबकि एक list के साथ df[["name", "age"]] एक DataFrame return करता है। Attribute access df.name simple names के लिए काम करता है लेकिन spaces वाले या methods से clash करने वाले names के लिए नहीं। Bracket access safest form है।

Note: Double brackets एक column के लिए भी एक DataFrame return करते हैं।

उदाहरण: Selecting columns

python
import pandas as pd

df = pd.DataFrame({"name": ["Ann", "Bob"], "age": [28, 35], "city": ["Oslo", "Rome"]})
print(type(df["age"]).__name__)
print(type(df[["age"]]).__name__)
print(df[["name", "city"]])

# Output:
# Series
# DataFrame
#   name  city
# 0  Ann  Oslo
# 1  Bob  Rome
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. कई columns के लिए double brackets भूल जाना
  2. spaces वाले names पर dot access इस्तेमाल करना
  3. एक column misspell करना और KeyError पाना
चैप्टर सारांश
  • एक label एक Series return करता है
  • labels की एक list एक DataFrame return करती है
  • Bracket access safest है
  • Dot access की limits हैं
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.