Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python
Python
  1. การสร้าง DataFrame จาก List of Dictionaries ใน Pandas Python

    DataFrame สามารถสร้างจาก List of Dictionaries ได้ โดยแต่ละ Dictionary = 1 Row, Keys = Column Names ตัวอย่างโค้ด import pandas as pd my_data = [ {ab: 34}, {mn: 56}, {gh: 78}, {wq: 90}, {az: 123}, {kl: 45} ] my_df = pd.DataFrame(my_data) print(The dataframe created from lis

  2. การเพิ่ม Column ใหม่เข้า DataFrame โดยใช้ Series ใน Pandas Python

    วิธีหนึ่งในการเพิ่ม Column ใหม่คือ สร้าง Series ใหม่ (พร้อม Index ที่ตรงกับ DataFrame) แล้ว Assign ให้ DataFrame ตัวอย่างโค้ด import pandas as pd my_data = { ab: pd.Series([1, 8, 7], index=[a, b, c]), cd: pd.Series([1, 2, 0, 9], index=[a, b, c, d]) } my_df = pd.DataFrame(my_data) print(T

  3. การสร้าง DataFrame จาก Dictionary of Series ใน Pandas Python

    DataFrame สามารถสร้างจาก Dictionary ที่ Value เป็น Series ได้ Key จะกลายเป็น Column Name และ Series Index จะกลายเป็น Row Index ตัวอย่างโค้ด import pandas as pd my_data = { ab: pd.Series([1, 2, 3], index=[a, b, c]), mn: pd.Series([56, 78, 13, 13], index=[a, b, c, d]) } my_df = pd.DataFram

  4. การแสดง Histogram ด้วย Seaborn ใน Python

    Histogram แสดงการกระจายตัวของข้อมูลตัวเลข (Numerical Distribution) โดยแบ่งเป็น Bins และนับความถี่ Seaborn ใช้ distplot() (Deprecated) หรือ histplot() / displot(kind=hist) (แนะนำ) สำหรับ Histogram ตัวอย่างโค้ด (distplot - เก่า) import pandas as pd import seaborn as sb from matplotlib import pyplot

  5. การลบ Column ใน DataFrame ด้วย del Operator ใน Pandas Python

    Keyword del ของ Python ใช้ลบ Column จาก DataFrame ได้โดยตรง (In-place) ไม่คืนค่าอะไร คล้ายการลบ Key จาก Dictionary ตัวอย่างโค้ด import pandas as pd my_data = { ab: pd.Series([1, 8, 7], index=[a, b, c]), cd: pd.Series([1, 2, 0, 9], index=[a, b, c, d]), ef: pd.Series([56, 78, 32], index

  6. การลบ Column ใน DataFrame ด้วย pop() ใน Pandas Python

    Method .pop() ลบ Column จาก DataFrame **และคืนค่า Column ที่ลบออกเป็น Series** เหมือน Dictionary.pop() ตัวอย่างโค้ด import pandas as pd my_data = { ab: pd.Series([1, 8, 7], index=[a, b, c]), cd: pd.Series([1, 2, 0, 9], index=[a, b, c, d]), ef: pd.Series([56, 78, 32], index=[a, b, c]),

  7. การสร้าง Column ใหม่ใน DataFrame จาก Column ที่มีอยู่แล้วใน Pandas

    สามารถสร้าง Column ใหม่ใน DataFrame ได้โดยการคำนวณจาก Column เดิม (Arithmetic, Logic, Functions) ผลลัพธ์จะ Align ตาม Index อัตโนมัติ ตัวอย่างโค้ด import pandas as pd import numpy as np my_data = { ab: pd.Series([1, 8, 7], index=[a, b, c]), cd: pd.Series([1, 2, 0, 9], index=[a, b, c, d]),

  8. การหาค่าเฉลี่ย (Mean) ของ Column ตัวเลขทั้งหมดใน DataFrame Pandas

    Method .mean() บน DataFrame จะคำนวณค่าเฉลี่ยของ **ทุก Column ที่เป็น Numeric** อัตโนมัติ (ข้าม String/Object Columns) ตัวอย่างโค้ด import pandas as pd my_data = { Name: pd.Series([Tom, Jane, Vin, Eve, Will]), Age: pd.Series([45, 67, 89, 12, 23]), value: pd.Series([8.79, 23.24, 31.98,

  9. การหา Resolution ของภาพด้วย scikit-image ใน Python

    Resolution ของภาพ = ขนาดความกว้าง × ความสูง (Width × Height) และจำนวน Channels สามารถดูได้จาก Attribute .shape ของ NumPy Array ที่ได้จาก io.imread() ตัวอย่างโค้ด from skimage import io import matplotlib.pyplot as plt path = puppy.png # ปรับ Path ตามจริง img = io.imread(path) print(Image being r

  10. การดูค่า Pixel ของภาพด้วย scikit-image และ Pandas ใน Python

    การเข้าถึงค่า Pixel ของภาพเป็นขั้นตอนพื้นฐานใน Image Processing ภาพ RGB มี 3 Channels (R,G,B) หรือ 4 Channels (RGBA) เก็บใน 3D Array (Height, Width, Channels) ใช้ flatten() แปลง 3D Array → 1D Array แล้วใส่ DataFrame เพื่อวิเคราะห์/แสดงผล ตัวอย่างโค้ด = 3: # Reshape เป็น (H*W, C) pixels_2d

  11. การหา Contours ของภาพด้วย scikit-image (skimage) ใน Python

    Contour Detection คือการหาขอบเขตของวัตถุในภาพ ใช้ใน Computer Vision, Image Segmentation, Shape Analysis โมดูล skimage.measure มีฟังก์ชัน find_contours() ใช้ Algorithms **Marching Squares** หา Contours ที่ระดับความเข้ม (Level) ที่กำหนด หมายเหตุ: scikit-image (skimage) แยกจาก scikit-learn (sklearn)

  12. การใช้ฟังก์ชัน sort() บน NumPy Arrays ใน Python

    NumPy (Numerical Python) เป็นไลบรารีพื้นฐานสำหรับ Scientific Computing มี ndarray (N-dimensional Array) ที่เร็วและประหยัดหน่วยความจำ ฟังก์ชัน numpy.sort() คืนค่า **Sorted Copy** ของ Array (ไม่แก้ไข Array ต้นฉบับ) ส่วน ndarray.sort() ทำ In-place Sort ไวยากรณ์ numpy.sort(a, axis=-1, kind=None, orde

  13. การสร้าง Classifier ด้วย Decision Tree ใน Python (scikit-learn)

    Decision Tree Classifier เป็นอัลกอริทึม Classification ที่เข้าใจง่าย ใช้โครงสร้าง Tree แบ่งข้อมูลตาม Feature Values จนแต่ละ Leaf มี Class เดียว จุดแข็ง: Interpret ได้ (White Box), รองรับ Numerical/Categorical, ไม่ต้อง Scale Features, จัดการ Non-linear ได้ดี จุดอ่อน: Overfitting ง่าย, Unstable (ข้อม

  14. วิธีหาค่าเฉลี่ย (Mean) ของ Column เฉพาะใน DataFrame Pandas Python

    Mean (ค่าเฉลี่ยเลขคณิต) = ผลรวมค่าทั้งหมด / จำนวนค่า ใช้สรุป Central Tendency ของข้อมูล ใน Pandas ใช้ Method .mean() บน Series หรือ DataFrame ตัวอย่างโค้ด import pandas as pd my_data = { Name: pd.Series([Tom, Jane, Vin, Eve, Will]), Age: pd.Series([45, 67, 89, 12, 23]), value: pd.Ser

  15. วิธีหาค่า Standard Deviation ของ Column เฉพาะใน DataFrame Pandas

    Standard Deviation (SD) วัดการกระจายของข้อมูลจากค่าเฉลี่ย ค่า SD สูง = ข้อมูลกระจายกว้าง, ค่า SD ต่ำ = ข้อมูล 모여กลุ่ม ใน Pandas ใช้ Method .std() บน Series (Column เดียว) หรือ DataFrame (ทุก Column Numeric) ตัวอย่างโค้ด import pandas as pd my_data = { Name: pd.Series([Tom, Jane, Vin, Eve, Wi

  16. การสรุปข้อมูล DataFrame ด้วย describe() ใน Pandas Python

    ฟังก์ชัน describe() ให้สถิติพื้นฐานของ DataFrame ทั้ง Numeric และ Object Columns ได้ในครั้งเดียว ช่วย EDA (Exploratory Data Analysis) ให้รวดเร็ว ตัวอย่างโค้ด import pandas as pd my_data = { Name: pd.Series([Tom, Jane, Vin, Eve, Will]), Age: pd.Series([45, 67, 89, 12, 23]), value: pd.S

  17. การใช้ apply() Row-wise และ Column-wise บน DataFrame ใน Pandas

    ฟังก์ชัน apply() ใน DataFrame ใช้เรียกฟังก์ชันตาม Axis ที่กำหนด: axis=0 (Default): Column-wise - ส่งแต่ละ Column (Series) ให้ฟังก์ชัน axis=1: Row-wise - ส่งแต่ละ Row (Series) ให้ฟังก์ชัน ตัวอย่างโค้ด import pandas as pd import numpy as np my_data = { Age: pd.Series([45, 67, 89, 12, 23]),

  18. วิธีใช้ฟังก์ชันแบบ element-wise กับ DataFrame ใน Python

    เมื่อต้องใช้ฟังก์ชันกับทุกเซลล์ใน DataFrame แบบไม่สามารถ vectorize ได้ ให้ใช้ applymap ซึ่งรับค่าเดี่ยว คืนค่าเดี่ยว ตัวอย่าง import pandas as pd import numpy as np my_df = pd.DataFrame(np.random.randn(5,5), columns=[col_1,col_2,col_3,col_4,col_5]) print(DataFrame ต้นฉบับ:) print(my_df) # คูณทุกค่

  19. การ Preprocess ข้อมูลด้วย scikit-learn ใน Python: ตัวอย่าง Binarizer

    Data Preprocessing เป็นขั้นตอนสำคัญใน ML Pipeline: ทำความสะอาดข้อมูล ลบ Noise จัดการ Missing Values แปลงข้อมูลให้เหมาะสมกับอัลกอริทึม scikit-learn มีโมดูล sklearn.preprocessing สำหรับ Preprocessing หลากหลาย เช่น Scaling, Encoding, Imputation, Discretization, Binarization ตัวอย่าง: Binarizer - แปลง

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:197/451  20-คอมพิวเตอร์/Page Goto:1 191 192 193 194 195 196 197 198 199 200 201 202 203