清理你的時間序列資料

使用 Python 視覺化時間序列資料

Thomas Vincent

Head of Data Science, Getty Images

CO2 濃度時間序列

夏威夷茂納羅亞觀測站每週 CO2 濃度量測的節錄。

datastamp    co2                   
1958-03-29  316.1
1958-04-05  317.3
1958-04-12  317.6
...
...
2001-12-15  371.2
2001-12-22  371.3
2001-12-29  371.5
使用 Python 視覺化時間序列資料

找出 DataFrame 中的遺漏值

print(df.isnull())
datestamp   co2
1958-03-29  False
1958-04-05  False
1958-04-12  False
print(df.notnull())
datestamp    co2
1958-03-29   True
1958-04-05   True
1958-04-12   True
...
使用 Python 視覺化時間序列資料

計算 DataFrame 中的遺漏值數量

print(df.isnull().sum())
datestamp     0
co2          59
dtype: int64
使用 Python 視覺化時間序列資料

替換 DataFrame 中的遺漏值

print(df)
...
5  1958-05-03  316.9
6  1958-05-10    NaN
7  1958-05-17  317.5
...
df = df.fillna(method='bfill')
print(df)
...
5  1958-05-03  316.9
6  1958-05-10  317.5
7  1958-05-17  317.5
...
使用 Python 視覺化時間序列資料

一起來練習吧!

使用 Python 視覺化時間序列資料

Preparing Video For Download...