Rows နှင့် Columns ဖယ်ရှားခြင်း
Data ထဲမှာ analysis အတွက်မလိုတဲ့ column တွေ၊ test row တွေ၊ duplicate-looking temporary fields တွေ ပါနေရင် .drop() နဲ့ဖယ်နိုင်ပါတယ်။ Column ဖယ်တဲ့အခါ axis=1 သုံးပြီး row ဖယ်တဲ့အခါ index ကိုသုံးပါတယ်။
python
import pandas as pd
df = pd.DataFrame({
"Name": ["Alice", "Bob", "Charlie"],
"Age": [25, 30, 35],
"City": ["New York", "Paris", "London"],
"TempNote": ["ok", "check", "old"]
})
clean_df = df.drop("TempNote", axis=1)
without_first_row = clean_df.drop(0, axis=0)
print(clean_df)
print("
After dropping first row:")
print(without_first_row)df.drop("TempNote", axis=1) က column ကိုဖယ်တာပါ။ clean_df.drop(0, axis=0) က index 0 ရှိတဲ့ row ကိုဖယ်တာပါ။ Drop လုပ်ပြီး DataFrame အသစ်ကို variable အသစ်ထဲသိမ်းထားတာကြောင့် original df ကိုမထိပါ။
You should see
Name Age City 0 Alice 25 New York 1 Bob 30 Paris 2 Charlie 35 London After dropping first row: Name Age City 1 Bob 30 Paris 2 Charlie 35 LondonInfo
Original DataFrame ကိုတန်းပြောင်းချင်ရင် inplace=True သုံးနိုင်ပေမယ့် beginner အတွက် variable အသစ်ထဲသိမ်းတာ ပိုလုံခြုံပါတယ်။ Mistake ဖြစ်ရင် original data ပြန်ရှိနေပါသေးတယ်။