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

    หากต้องการแสดงไตรมาส (Quarter) ของวันที่จากออบเจ็กต์ PeriodIndex สามารถใช้คุณสมบัติ PeriodIndex.quarter ได้ ขั้นตอนการทำงาน 1. นำเข้าไลบรารีที่จำเป็น import pandas as pd 2. สร้างออบเจ็กต์ PeriodIndex periodIndex = pd.PeriodIndex( [2021-09-25 07:30:35, 2019-10-30 04:15:45, 2021-07-15 02:

  2. Python Pandas - ดึงวินาทีจากออบเจ็กต์ PeriodIndex

    หากต้องการดึงส่วนของวินาทีจากออบเจ็กต์ PeriodIndex สามารถใช้คุณสมบัติ PeriodIndex.second ได้ โดยต้องตั้งความถี่ (freq) เป็นวินาที (S) ขั้นตอนการทำงาน 1. นำเข้าไลบรารีที่จำเป็น import pandas as pd 2. สร้างออบเจ็กต์ PeriodIndex ด้วยความถี่เป็นวินาที periodIndex = pd.PeriodIndex( [2021-09-25 07:

  3. Python Pandas - ดึงสัปดาห์ของปีจากออบเจ็กต์ PeriodIndex

    หากต้องการดึงสัปดาห์ของปีจากออบเจ็กต์ PeriodIndex สามารถใช้คุณสมบัติ PeriodIndex.week ได้ ขั้นตอนการทำงาน 1. นำเข้าไลบรารีที่จำเป็น import pandas as pd 2. สร้างออบเจ็กต์ PeriodIndex periodIndex = pd.PeriodIndex( [2021-09-25 07:30:35, 2019-10-30 04:15:45, 2021-07-15 02:55:15, 2022-06-25

  4. Python Pandas - ดึงวันในสัปดาห์จากออบเจ็กต์ PeriodIndex

    หากต้องการดึงวันในสัปดาห์จากออบเจ็กต์ PeriodIndex สามารถใช้คุณสมบัติ PeriodIndex.weekday ได้ ขั้นตอนการทำงาน 1. นำเข้าไลบรารีที่จำเป็น import pandas as pd 2. สร้างออบเจ็กต์ PeriodIndex PeriodIndex เป็น ndarray ที่ไม่สามารถเปลี่ยนแปลงได้ (immutable) ซึ่งเก็บค่าลำดับ (ordinal values) ที่บ่งชี้ช่วงเ

  5. Python Pandas - ดึงปี (Year) จาก PeriodIndex Object

    เพื่อดึงปี (year) จาก PeriodIndex object ให้ใช้คุณสมบัติ PeriodIndex.year ขั้นตอนตัวอย่าง import pandas as pd # สร้าง PeriodIndex object (freq=T = รายนาที) periodIndex = pd.PeriodIndex( [2021-09-25 07:30:35, 2019-10-30 04:15:45, 2021-07-15 02:55:15, 2022-06-25 09:40:55], freq=T ) print(Pe

  6. Python Pandas PeriodIndex - แปลง PeriodArray เป็นความถี่ที่ระบุ

    เพื่อแปลง PeriodArray เป็นความถี่ที่ระบุ ให้ใช้เมธอด periodIndex.asfreq() ขั้นตอนตัวอย่าง import pandas as pd # สร้าง PeriodIndex object (freq=Y = รายปี) periodIndex = pd.PeriodIndex( [2021-09-25 07:30:35, 2019-10-30 04:15:45, 2020-07-15 02:55:15, 2022-06-25 09:40:55], freq=Y ) print(Peri

  7. Python Pandas - แปลง PeriodIndex Object เป็น Timestamp

    เพื่อแปลง PeriodIndex object เป็น Timestamp ให้ใช้เมธอด PeriodIndex.to_timestamp() ขั้นตอนตัวอย่าง import pandas as pd # สร้าง PeriodIndex object (freq=Y = รายปี) periodIndex = pd.PeriodIndex( [2021-09-25 07:30:35, 2019-10-30 04:15:45, 2020-07-15 02:55:15, 2022-06-25 09:40:55], freq=Y ) p

  8. Python Pandas - จัดรูปแบบการแสดงสตริงของ PeriodIndex Object

    เพื่อจัดรูปแบบการแสดงสตริง (string representation) ของ PeriodIndex object ให้ใช้เมธอด periodIndex.strftime() ระบุตัวกำหนดรูปแบบ (format specifiers) เป็นอาร์กิวเมนต์ ขั้นตอนตัวอย่าง import pandas as pd # สร้าง PeriodIndex object (freq=Y = รายปี) periodIndex = pd.PeriodIndex( [2021-09-25 07:30:3

  9. Python Pandas - แปลง PeriodIndex Object เป็น Timestamp และตั้งค่าความถี่

    เพื่อแปลง PeriodIndex object เป็น Timestamp ให้ใช้เมธอด PeriodIndex.to_timestamp() ตั้งค่าความถี่ด้วยพารามิเตอร์ freq ขั้นตอนตัวอย่าง import pandas as pd # สร้าง PeriodIndex object (freq=Y = รายปี) periodIndex = pd.PeriodIndex( [2021-09-25 07:30:35, 2019-10-30 04:15:45, 2020-07-15 02:55:15, 20

  10. Python Pandas - สร้าง DateOffset และเพิ่มวันที่

    เพื่อสร้าง DateOffset และเพิ่มวันที่ใน Pandas ให้ใช้เมธอด DateOffset() ระบุค่าเพิ่มเป็นอาร์กิวเมนต์ ขั้นตอนตัวอย่าง from pandas.tseries.offsets import DateOffset import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021-09-11 02:30:55) print(Timestamp...\n, timestamp) # DateOffset เพิ่ม

  11. Python Pandas - คืนค่าความถี่ (Frequency) ที่ใช้กับ DateOffset Object เป็นสตริง

    เพื่อคืนค่าความถี่ (frequency) ที่ใช้กับ DateOffset object เป็นสตริง ให้ใช้คุณสมบัติ offset.freqstr ใน Pandas ขั้นตอนตัวอย่าง from pandas.tseries.offsets import DateOffset import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021-08-30 02:30:55) print(Timestamp...\n, timestamp) # สร้าง

  12. Python Pandas - คืนค่าจุดกึ่งกลาง (Midpoint) ของ Interval

    เพื่อคืนค่าจุดกึ่งกลาง (midpoint) ของ Interval (ช่วง) ให้ใช้คุณสมบัติ interval.mid ขั้นตอนตัวอย่าง import pandas as pd # สร้างช่วงเปิดทั้งสองข้าง interval = pd.Interval(5, 20, closed=neither) print(Interval...\n, interval) print(\nความยาวช่วง...\n, interval.length) print(\nขอบซ้าย...\n, interval.

  13. Python Pandas - ตรวจสอบว่า Interval เปิดทางด้านซ้าย (Open Left) หรือไม่

    เพื่อตรวจสอบว่า Interval (ช่วง) เปิดทางด้านซ้าย (open left) หรือไม่ ให้ใช้คุณสมบัติ interval.open_left หลักการ ช่วงเปิด (open interval) ตั้งค่าด้วย closed=neither ไม่รวมจุดปลายทั้งสองข้าง เช่น (0, 5) หมายถึง 0 < x < 5 ขั้นตอนตัวอย่าง import pandas as pd # สร้างช่วงเปิดทั้งสองข้าง interval =

  14. Python Pandas - ตรวจสอบว่า Interval เปิดทางด้านขวา (Open Right) หรือไม่

    เพื่อตรวจสอบว่า Interval (ช่วง) เปิดทางด้านขวา (open right) หรือไม่ ให้ใช้คุณสมบัติ interval.open_right หลักการ ช่วงเปิด (open interval) ตั้งค่าด้วย closed=neither ไม่รวมจุดปลายทั้งสองข้าง เช่น ช่วง (0, 5) หมายถึง 0 < x < 5 ขั้นตอนตัวอย่าง import pandas as pd # สร้างช่วงเปิดทั้งสองข้าง inte

  15. Python Pandas - ตรวจสอบว่าสอง Interval Object ทับซ้อนกันหรือไม่

    เพื่อตรวจสอบว่าสองออบเจกต์ Interval (ช่วง) ทับซ้อนกันหรือไม่ ให้ใช้เมธอด overlaps() หลักการ ช่วงสองช่วงทับซ้อนกันหากแบ่งปันจุดร่วม รวมถึงปลายปิด ช่วงที่มีเพียงปลายเปิดร่วมกันไม่ถือว่าทับซ้อน ขั้นตอนตัวอย่าง import pandas as pd # สร้างสอง Interval objects (ค่าเริ่มต้น closed=right คือ เปิดซ้าย ปิด

  16. Python Pandas - ตรวจสอบว่าสอง Interval Object ที่มีปลายปิดร่วมกันทับซ้อนหรือไม่

    เพื่อตรวจสอบว่าสองออบเจกต์ Interval (ช่วง) ที่มีปลายปิด (closed endpoints) ร่วมกันทับซ้อน (overlap) หรือไม่ ให้ใช้เมธอด overlaps() หลักการ ช่วงสองช่วงทับซ้อนกันหากแบ่งปันจุดร่วม รวมถึงปลายปิด ช่วงที่มีเพียงปลายเปิดร่วมกันไม่ถือว่าทับซ้อน ขั้นตอนตัวอย่าง import pandas as pd # สร้างสอง Interval obj

  17. Python Pandas - คืนค่าจำนวนแนนอวินาที (Nanoseconds) ใน DateOffset Object

    เพื่อคืนค่าจำนวนแนนอวินาที (nanoseconds) ใน DateOffset object ให้ใช้คุณสมบัติ offset.nanos ใน Pandas ขั้นตอนตัวอย่าง from pandas.tseries.frequencies import to_offset import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021-08-30 03:08:02.000045) print(Timestamp...\n, timestamp) # สร้าง

  18. Python Pandas - คืนค่าความถี่ (Frequency) ที่ใช้กับ DateOffset Object

    เพื่อคืนค่าความถี่ (frequency) ที่ใช้กับ DateOffset object ให้ใช้คุณสมบัติ offset.freqstr ใน Pandas ขั้นตอนตัวอย่าง from pandas.tseries.frequencies import to_offset import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021-09-26 03:25:02.000045) print(Timestamp...\n, timestamp) # สร้าง

  19. Python Pandas - คืนค่าชื่อความถี่ (Frequency Name) ที่ใช้กับ Offset Object

    เพื่อคืนค่าชื่อความถี่ (frequency name) ที่ใช้กับ offset object ให้ใช้คุณสมบัติ offset.name ใน Pandas ขั้นตอนตัวอย่าง from pandas.tseries.frequencies import to_offset import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021-09-26 03:25:02.000045) print(Timestamp...\n, timestamp) # สร้า

  20. Python Pandas - ตรวจสอบว่า DateOffset ถูกปรับปกติ (Normalized) หรือไม่

    เพื่อตรวจสอบว่า DateOffset ถูกปรับปกติ (normalized) หรือไม่ ให้ใช้คุณสมบัติ offset.normalize ใน Pandas ขั้นตอนตัวอย่าง from pandas.tseries.offsets import DateOffset import pandas as pd # สร้าง Timestamp timestamp = pd.Timestamp(2021-09-26 03:25:02.000045) print(Timestamp...\n, timestamp) # สร้าง

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:403/451  20-คอมพิวเตอร์/Page Goto:1 397 398 399 400 401 402 403 404 405 406 407 408 409