Pandas dataframe ရှိ သီးခြားဆဲလ်တစ်ခု၏တန်ဖိုးကို မည်သို့သတ်မှတ်မည်နည်း။
pandas DataFrame အတွင်းရှိ သီးခြားဆဲလ်တစ်ခု၏တန်ဖိုးကို သတ်မှတ်ရန် အောက်ပါအခြေခံ syntax ကို သင်အသုံးပြုနိုင်သည်-
#set value at row index 0 and column 'col_name' to be 99 df. at [0, ' col_name '] = 99
အောက်ဖော်ပြပါနမူနာများသည် အောက်ပါ pandas DataFrame နှင့် လက်တွေ့တွင် ဤ syntax ကိုမည်သို့အသုံးပြုရမည်ကို ပြသသည် ။
import pandas as pd #createDataFrame df = pd. DataFrame ({' points ': [25, 12, 15, 14, 19, 23, 25, 29], ' assists ': [5, 7, 7, 9, 12, 9, 9, 4], ' rebounds ': [11, 8, 10, 6, 6, 5, 9, 12]}) #view DataFrame df points assists rebounds 0 25 5 11 1 12 7 8 2 15 7 10 3 14 9 6 4 19 12 6 5 23 9 5 6 25 9 9 7 29 4 12
ဥပမာ 1- Pandas ရှိ ဆဲလ်တစ်ခု၏တန်ဖိုးကို သတ်မှတ်ပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် “ points” ကော်လံ၏ 3rd အညွှန်းအနေအထား၏တန်ဖိုးကို 99 သို့ သတ်မှတ်နည်းကို ပြသည်-
#set value in 3rd index position and 'points' column to be 99 df. at [3, ' points '] = 99 #view updated DataFrame df points assists rebounds 0 25 5 11 1 12 7 8 2 15 7 10 3 99 9 6 4 19 12 6 5 23 9 5 6 25 9 9 7 29 4 12
“ points” ကော်လံ၏ 3rd အညွှန်းအနေအထားရှိ တန်ဖိုးကို ပြောင်းလဲပြီး DataFrame ရှိ အခြားတန်ဖိုးများအားလုံး တူညီနေမည်ကို သတိပြုပါ။
ဥပမာ 2- Pandas ရှိ ဆဲလ်များစွာ၏ တန်ဖိုးကို သတ်မှတ်ပါ။
အောက်ပါကုဒ်သည် အပိုင်းအခြားတစ်ခုအတွင်း ဆဲလ်များစွာ၏တန်ဖိုးကို တစ်ပြိုင်နက်သတ်မှတ်နည်းကို ပြသသည်-
#set values in index positions 0 to 3 in 'points' column to be 99 df. at [0:3, ' points '] = 99 #view updated DataFrame df points assists rebounds 0 99 5 11 1 99 7 8 2 99 7 10 3 99 9 6 4 19 12 6 5 23 9 5 6 25 9 9 7 29 4 12
ဥပမာ 3- Pandas တွင် Values Conditionally သတ်မှတ်ပါ။
အမှတ်များ ကော်လံရှိ တန်ဖိုးသည် 20 ထက် ကြီး ပါက၊ အောက်ဖော်ပြပါ ကုဒ်သည် “ rebounds” ကော်လံရှိ တန်ဖိုးများကို 99 သို့ မည်သို့သတ်မှတ်ရမည်ကို ပြသသည်-
#set values in 'rebounds' column to be 99 if value in points column is greater than 20
df. loc [df[' points ']>20, [' rebounds ']] = 99
#view updated DataFrame
df
points assists rebounds
0 25 5 99
1 12 7 8
2 15 7 10
3 14 9 6
4 19 12 6
5 23 9 99
6 25 9 99
7 29 4 99
အမှတ်များ ကော်လံရှိ တန်ဖိုးသည် 20 ထက် ပိုနေပါက ပြန်လှန်ကော်လံရှိ တန်ဖိုးတစ်ခုစီကို 99 သို့ ပြောင်းထားကြောင်း သတိပြုပါ။
အခြားတန်ဖိုးများအားလုံး အတူတူပင်ဖြစ်ပါသည်။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် ပန်ဒါများတွင် အခြားဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
Pandas DataFrame မှဆဲလ်တန်ဖိုးကိုဘယ်လိုရယူမလဲ။
Pandas DataFrame ၏ပထမတန်းကိုဘယ်လိုရယူမလဲ။
Pandas DataFrame မှ ပထမဆုံး ကော်လံကို ဘယ်လိုရယူမလဲ။
Pandas တွင်တန်ဖိုးနှင့်ကိုက်ညီသောကော်လံ၏အညွှန်းကိန်းကိုဘယ်လိုရယူမလဲ။