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

    การสร้าง IntervalArray จาก tuples ใช้ pd.arrays.IntervalArray.from_tuples() สร้าง IntervalArray จากรายการของ tuples (lower, upper) ขั้นตอน นำเข้า pandas ใช้ from_tuples() สร้าง IntervalArray แสดงผล ดูความยาวและ midpoint ตัวอย่างโค้ด import pandas as pd # สร้าง IntervalArray จาก tuples array = p

  2. Python Pandas - แปลง Timestamp เป็น Period (ทั่วไป)

    การแปลง Timestamp เป็น Period (ตัวอย่างทั่วไป) ใช้เมธอด timestamp.to_period(freq=M) แปลง Timestamp เป็น Period โดยระบุความถี่ ขั้นตอน นำเข้า pandas สร้าง Timestamp จากสตริง ใช้ to_period(freq=M) ตัวอย่างโค้ด import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021-09-14T15:12:34.2618

  3. Python Pandas - แปลง Timestamp เป็น Period ด้วยความถี่รายนาที

    การแปลง Timestamp เป็น Period (ความถี่รายนาที) ใช้เมธอด timestamp.to_period(freq=T) แปลง Timestamp เป็น Period แบบรายนาที ขั้นตอน นำเข้า pandas สร้าง Timestamp ใช้ to_period(freq=T) ตัวอย่างโค้ด import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021, 9, 6, 11, 50, 20, 33) # แสดง T

  4. Python Pandas - แปลง Timestamp เป็น Period ด้วยความถี่รายสัปดาห์

    การแปลง Timestamp เป็น Period (ความถี่รายสัปดาห์) ใช้เมธอด timestamp.to_period(freq=W) แปลง Timestamp เป็น Period แบบรายสัปดาห์ ขั้นตอน นำเข้า pandas สร้าง Timestamp ใช้ to_period(freq=W) ตัวอย่างโค้ด import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021, 9, 18, 11, 50, 20, 33) #

  5. Python Pandas - แปลง Timestamp เป็น Period ด้วยความถี่รายเดือน

    การแปลง Timestamp เป็น Period (ความถี่รายเดือน) ใช้เมธอด timestamp.to_period(freq=M) แปลง Timestamp เป็น Period แบบรายเดือน ขั้นตอน นำเข้า pandas สร้าง Timestamp ใช้ to_period(freq=M) ตัวอย่างโค้ด import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021, 9, 18, 11, 50, 20, 33) # แสด

  6. Python Pandas - ตรวจสอบว่า Index สองชุดมีแอตทริบิวต์และชนิดเหมือนกัน

    การเปรียบเทียบ Index สองชุดว่าเหมือนกันทุกด้าน ใช้เมธอด index1.identical(index2) ตรวจสอบว่า Index ทั้งสองมีค่า ลำดับ dtype และชื่อ (name) เหมือนกันหมด ขั้นตอน นำเข้า pandas สร้าง Index สองชุดที่เหมือนกัน แสดงทั้งสอง Index ใช้ identical() ตรวจสอบ ตัวอย่างโค้ด import pandas as pd # สร้าง Index1 แ

  7. Python Pandas - แปลง Timestamp เป็น Period ด้วยความถี่รายไตรมาส

    การแปลง Timestamp เป็น Period (ความถี่รายไตรมาส) ใช้เมธอด timestamp.to_period(freq=Q) แปลง Timestamp เป็น Period แบบรายไตรมาส ขั้นตอน นำเข้า pandas สร้าง Timestamp ใช้ to_period(freq=Q) ตัวอย่างโค้ด import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021, 9, 18, 11, 50, 20, 33) # แ

  8. Python Pandas - แปลง Timestamp เป็น Period ด้วยความถี่รายชั่วโมง

    การแปลง Timestamp เป็น Period (ความถี่รายชั่วโมง) ใช้เมธอด timestamp.to_period(freq=H) แปลง Timestamp เป็น Period ที่ปัดเศษลงมาที่ชั่วโมง ขั้นตอน นำเข้า pandas สร้าง Timestamp ใช้ to_period(freq=H) ตัวอย่างโค้ด import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021, 9, 18, 11, 50,

  9. Pandas - แปลง Timestamp เป็น native Python datetime object

    การแปลง Pandas Timestamp เป็น Python datetime ใช้เมธอด timestamp.to_pydatetime() แปลง Timestamp ของ Pandas ให้เป็น datetime object มาตรฐานของ Python ขั้นตอน นำเข้า pandas สร้าง Timestamp ใช้ to_pydatetime() ตัวอย่างโค้ด import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021-09-11T1

  10. Python Pandas - ดึงวันที่และเวลาปัจจุบันจาก Timestamp

    การดึงวันที่และเวลาปัจจุบันจาก Timestamp ใช้เมธอด timestamp.today() คืนค่า Timestamp ปัจจุบัน (วันและเวลา) ไม่ขึ้นกับค่า Timestamp เดิม ขั้นตอน นำเข้า pandas และ datetime สร้าง Timestamp ใด ๆ ใช้ today() ตัวอย่างโค้ด import pandas as pd import datetime # สร้าง Timestamp: 10 ตุลาคม 2021 timestam

  11. Python Pandas - แทรกค่า Index ใหม่ที่ตำแหน่งเฉพาะเจาะจง

    การแทรกค่า Index ใหม่ที่ตำแหน่งที่กำหนด ใช้เมธอด index.insert() โดยระบุตำแหน่ง (index) ที่ต้องการแทรก ขั้นตอน นำเข้า pandas สร้าง Index แสดง Index ใช้ insert(ตำแหน่ง, ค่าใหม่) ตัวอย่างโค้ด import pandas as pd # สร้าง Index index = pd.Index([Car, Bike, Airplane, Ship, Truck]) # แสดง Index print

  12. Python Pandas - คืนค่า Proleptic Gregorian Ordinal

    การคืนค่า Proleptic Gregorian Ordinal ใช้เมธอด timestamp.toordinal() คืนค่าลำดับวันตามปฏิทิน Gregorian (1 มกราคม พ.ศ. 1 = วันที่ 1) ขั้นตอน นำเข้า pandas สร้าง Timestamp ใช้ toordinal() ตัวอย่างโค้ด import pandas as pd # สร้าง Timestamp: 18 กันยายน 2021 11:50:20.000033 timestamp = pd.Timestamp(

  13. Python Pandas - แปลง Timestamp เป็น timezone อื่น

    การแปลง timezone ของ Timestamp ใช้เมธอด timestamp.tz_convert() แปลง Timestamp จาก timezone เดิมไปยัง timezone ใหม่ ขั้นตอน นำเข้า pandas สร้าง Timestamp พร้อม timezone ต้นทาง (เช่น US/Eastern) ใช้ tz_convert(timezoneปลายทาง) ตัวอย่างโค้ด import pandas as pd # สร้าง Timestamp พร้อม timezone US/E

  14. Python Pandas - แทรกค่า Index ใหม่ที่ตำแหน่งแรกจากท้าย

    การแทรกค่า Index ใหม่ที่ตำแหน่ง -1 (ตัวแรกจากท้าย) ใช้เมธอด index.insert() โดยระบุตำแหน่ง -1 เพื่อแทรกค่าใหม่ก่อนองค์ประกอบสุดท้าย ขั้นตอน นำเข้า pandas สร้าง Index แสดง Index ใช้ insert(-1, ค่าใหม่) ตัวอย่างโค้ด import pandas as pd # สร้าง Index index = pd.Index([Car, Bike, Airplane, Ship, Tru

  15. Python - ตรวจสอบว่า Pandas Index มีเฉพาะค่า boolean

    การตรวจสอบว่า Index ประกอบด้วยค่า boolean เท่านั้น ใช้เมธอด index.is_boolean() ตรวจสอบว่า Index มีเฉพาะค่า True/False เท่านั้น ขั้นตอน นำเข้า pandas สร้าง Index จากค่า boolean แสดง Index ใช้ is_boolean() ตรวจสอบ ตัวอย่างโค้ด import pandas as pd # สร้าง Index boolean index = pd.Index([True, True

  16. Python Pandas - แปลง naive Timestamp เป็น local time zone

    การเพิ่ม timezone ให้ naive Timestamp ใช้เมธอด timestamp.tz_localize() เพื่อกำหนด timezone ให้กับ Timestamp ที่ไม่มี timezone (naive) ขั้นตอน นำเข้า pandas สร้าง naive Timestamp (ไม่มี timezone) ใช้ tz_localize(tz=timezone) กำหนด timezone ตัวอย่างโค้ด import pandas as pd # สร้าง naive Timestamp

  17. Python Pandas - สร้าง naive UTC datetime จาก POSIX timestamp

    การสร้าง UTC datetime จาก POSIX timestamp ใช้เมธอด timestamp.utcfromtimestamp() สร้าง naive UTC datetime จาก POSIX timestamp (วินาทีนับจาก 1970-01-01) ขั้นตอน นำเข้า pandas สร้าง Timestamp ใด ๆ ใช้ utcfromtimestamp(POSIX) โดยส่ง POSIX timestamp เป็นอาร์กิวเมนต์ ตัวอย่างโค้ด import pandas as pd

  18. Python - ตรวจสอบว่า Pandas Index มีข้อมูล categorical

    การตรวจสอบว่า Index เป็น categorical data ใช้เมธอด index.is_categorical() ตรวจสอบว่า Index เป็น CategoricalIndex หรือไม่ ขั้นตอน นำเข้า pandas สร้าง Index และแปลงเป็น categorical ด้วย astype(category) แสดง Index ใช้ is_categorical() ตรวจสอบ ตัวอย่างโค้ด import pandas as pd # สร้าง Index และแปลง

  19. Python Pandas - สร้าง Timestamp ใหม่แทน UTC วันและเวลา

    การสร้าง Timestamp ใหม่ที่แสดงเวลา UTC ปัจจุบัน ใช้เมธอด timestamp.utcnow() คืนค่า Timestamp ใหม่ที่แสดงวันและเวลา UTC ปัจจุบัน ขั้นตอน นำเข้า pandas สร้าง Timestamp ใด ๆ (พร้อม timezone UTC) ใช้ utcnow() ตัวอย่างโค้ด import pandas as pd # สร้าง Timestamp พร้อม timezone UTC timestamp = pd.Times

  20. Python - ตรวจสอบว่า Pandas Index เป็นชนิด floating

    การตรวจสอบว่า Index เป็นชนิดข้อมูล floating ใช้เมธอด index.is_floating() ตรวจสอบว่า Index มีเฉพาะค่าทศนิยม (float) เท่านั้น ขั้นตอน นำเข้า pandas สร้าง Index แบบทศนิยม แสดง Index ใช้ is_floating() ตรวจสอบ ตัวอย่างโค้ด import pandas as pd # สร้าง Index แบบทศนิยม index = pd.Index([5.7, 6.8, 10.5,

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:378/451  20-คอมพิวเตอร์/Page Goto:1 372 373 374 375 376 377 378 379 380 381 382 383 384