Selection နှင့် Indexing
DataFrame တစ်ခုလုံးကိုမဟုတ်ဘဲ column တစ်ခု၊ row တစ်ကြောင်း၊ ဒါမှမဟုတ် row/column အစိတ်အပိုင်းတစ်ခုကိုပဲ ရွေးထုတ်ချင်ရင် selection/indexing သုံးပါတယ်။ Pandas မှာ အခြေခံအားဖြင့် [], .loc, .iloc ကိုသိထားရင် အလုပ်အများကြီးပြီးပါတယ်။
df["Column"]— column တစ်ခုရွေးသည်df.loc[label]— label/index name ဖြင့် row ရွေးသည်df.iloc[position]— number position ဖြင့် row ရွေးသည်
python
import pandas as pd
df = pd.DataFrame({
"Name": ["Alice", "Bob", "Charlie"],
"Age": [25, 30, 35],
"City": ["New York", "Paris", "London"]
})
print(df["Name"])
print("
--- First Row ---")
print(df.iloc[0])
print("
--- Name and City only ---")
print(df[["Name", "City"]])df["Name"] က Name column တစ်ခုတည်းကို Series အနေနဲ့ပြန်ပေးပါတယ်။ df.iloc[0] က ပထမဆုံး row ကို position နဲ့ရွေးတာပါ။ Column နှစ်ခုရွေးချင်ရင် df[["Name", "City"]] လို list ထဲမှာ column names ထည့်ရပါတယ်။
You should see
0 Alice 1 Bob 2 Charlie Name: Name, dtype: object --- First Row --- Name Alice Age 25 City New York Name: 0, dtype: object --- Name and City only --- Name City 0 Alice New York 1 Bob Paris 2 Charlie London