Pandas dataframe တွင် ကော်လံများစွာကို ထည့်သွင်းနည်း


Pandas DataFrame တွင် ကော်လံအများအပြားကို ထည့်သွင်းရန် အောက်ပါနည်းလမ်းများကို သင်အသုံးပြုနိုင်ပါသည်။

နည်းလမ်း 1- တန်ဖိုးတစ်ခုစီပါရှိသော ကော်လံများစွာကို ထည့်ပါ။

 df[[' new1 ', ' new2 ', ' new3 ']] = pd. DataFrame ([[ 4 , ' hey ', np. nan ]], index=df. index )

နည်းလမ်း 2- တန်ဖိုးများစွာပါရှိသော တစ်ခုစီတွင် ကော်လံများစွာကို ထည့်ပါ။

 df[' new1 '] = [1, 5, 5, 4, 3, 6]
df[' new2 '] = ['hi', 'hey', 'hey', 'hey', 'hello', 'yo']
df[' new3 '] = [12, 4, 4, 3, 6, 7]

အောက်ပါနမူနာများသည် အောက်ပါ pandas DataFrame ဖြင့် နည်းလမ်းတစ်ခုစီကို အသုံးပြုနည်းကို ပြသသည်-

 import pandas as pd
import numpy as np

#createDataFrame
df = pd. DataFrame ({' team ': ['A', 'B', 'C', 'D', 'E', 'F'],
                   ' points ': [18, 22, 19, 14, 14, 11],
                   ' assists ': [5, 7, 7, 9, 12, 9]})

#view DataFrame
df

        team points assists
0 to 18 5
1 B 22 7
2 C 19 7
3 D 14 9
4 E 14 12
5 F 11 9

နည်းလမ်း 1- တန်ဖိုးတစ်ခုစီပါရှိသော ကော်လံများစွာကို ထည့်ပါ။

အောက်ပါကုဒ်သည် ကော်လံအသစ်သုံးခုကို pandas DataFrame တွင် ကော်လံအသစ်တစ်ခုစီတွင် တန်ဖိုးတစ်ခုသာပါရှိသည်ကို ပြသသည်-

 #add three new columns to DataFrame
df[[' new1 ', ' new2 ', ' new3 ']] = pd. DataFrame ([[ 4 , ' hey ', np. nan ]], index=df. index )

#view updated DataFrame
df

        team points assists new1 new2 new3
0 A 18 5 4 hey NaN
1 B 22 7 4 hey NaN
2 C 19 7 4 hey NaN
3 D 14 9 4 hey NaN
4 E 14 12 4 hey NaN
5 F 11 9 4 hey NaN

အသစ် 1အသစ် 2 နှင့် new3 ကော်လံအသစ်သုံးခုကို DataFrame တွင်ထည့်သွင်းထားကြောင်း သတိပြုပါ။

ကော်လံအသစ်တစ်ခုစီတွင် သီးခြားတန်ဖိုးတစ်ခုသာ ပါဝင်ကြောင်းကိုလည်း သတိပြုပါ။

နည်းလမ်း 2- တန်ဖိုးများစွာပါရှိသော တစ်ခုစီတွင် ကော်လံများစွာကို ထည့်ပါ။

အောက်ပါကုဒ်သည် ကော်လံအသစ်သုံးခုကို pandas DataFrame တွင် မည်သို့ထည့်ရမည်ကို ကော်လံအသစ်တစ်ခုစီတွင် တန်ဖိုးများစွာပါရှိသည်-

 #add three new columns to DataFrame
df[' new1 '] = [1, 5, 5, 4, 3, 6]
df[' new2 '] = ['hi', 'hey', 'hey', 'hey', 'hello', 'yo']
df[' new3 '] = [12, 4, 4, 3, 6, 7]

#view updated DataFrame
df

	team points assists new1 new2 new3
0 A 18 5 1 hi 12
1 B 22 7 5 hey 4
2 C 19 7 5 hey 4
3 D 14 9 4 hey 3
4 E 14 12 3 hello 6
5 F 11 9 6 yo 7

အသစ် 1အသစ် 2 နှင့် new3 ကော်လံအသစ်သုံးခုကို DataFrame တွင်ထည့်သွင်းထားကြောင်း သတိပြုပါ။

ကော်လံအသစ်တစ်ခုစီတွင် တန်ဖိုးများစွာပါရှိသည်ကိုလည်း သတိပြုပါ။

ထပ်လောင်းအရင်းအမြစ်များ

အောက်ဖော်ပြပါ သင်ခန်းစာများသည် ပန်ဒါများတွင် အခြားဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-

Pandas ရှိ ကော်လံများစွာဖြင့် စီနည်း
Pandas တွင် ကော်လံရှိမရှိ စစ်ဆေးနည်း
Pandas တွင် ကော်လံအမည်ပြောင်းနည်း

မှတ်ချက်တစ်ခုထည့်ပါ။

သင့် email လိပ်စာကို ဖော်ပြမည် မဟုတ်ပါ။ လိုအပ်သော ကွက်လပ်များကို * ဖြင့်မှတ်သားထားသည်