พล็อตค่ารวมของข้อมูล

การแสดงภาพข้อมูล Time Series ด้วย Python

Thomas Vincent

Head of Data Science, Getty Images

ค่าเฉลี่ยเคลื่อนที่

  • ในการวิเคราะห์อนุกรมเวลา ค่าเฉลี่ยเคลื่อนที่ใช้ได้หลายวัตถุประสงค์:
    • ลดความผันผวนระยะสั้น
    • กำจัดค่าผิดปกติ
    • เน้นแนวโน้มหรือวัฏจักรระยะยาว
การแสดงภาพข้อมูล Time Series ด้วย Python

โมเดลค่าเฉลี่ยเคลื่อนที่

co2_levels_mean = co2_levels.rolling(window=52).mean()

ax = co2_levels_mean.plot()
ax.set_xlabel("Date")
ax.set_ylabel("The values of my Y axis")
ax.set_title("52 weeks rolling mean of my time series")

plt.show()
การแสดงภาพข้อมูล Time Series ด้วย Python

กราฟค่าเฉลี่ยเคลื่อนที่ของข้อมูล CO2

ค่าเฉลี่ยเคลื่อนที่ของอนุกรมเวลา

การแสดงภาพข้อมูล Time Series ด้วย Python

การคำนวณค่ารวมของอนุกรมเวลา

co2_levels.index
DatetimeIndex(['1958-03-29', '1958-04-05',...],
              dtype='datetime64[ns]', name='datestamp', 
              length=2284, freq=None)
print(co2_levels.index.month)
array([ 3,  4,  4, ..., 12, 12, 12], dtype=int32)
print(co2_levels.index.year)
array([1958, 1958, 1958, ..., 2001,
      2001, 2001], dtype=int32)
การแสดงภาพข้อมูล Time Series ด้วย Python

การพล็อตค่ารวมของอนุกรมเวลา

index_month = co2_levels.index.month
co2_levels_by_month = co2_levels.groupby(index_month).mean()
co2_levels_by_month.plot()

plt.show()
การแสดงภาพข้อมูล Time Series ด้วย Python

การพล็อตค่ารวมของอนุกรมเวลา

ค่ารวมรายเดือนของข้อมูลระดับ CO2

การแสดงภาพข้อมูล Time Series ด้วย Python

มาฝึกกันเถอะ!

การแสดงภาพข้อมูล Time Series ด้วย Python

Preparing Video For Download...