程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python time series data resampling

編輯:Python

python time series data Resampling

List of articles

  • Downsampling
  • L sampling


꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ
Resampling : It refers to the process of changing time series data from one frequency to another .
Resampling can be divided into

Downsampling : High frequency to low frequency .

L sampling : Low frequency to high frequency .

Missing values will be generated after L sampling . In contrast, downsampling is more commonly used .


Downsampling

import pandas as pd
import numpy as np
# Create daily data 100 strip 
data1 = pd.DataFrame(np.random.uniform(10, 50, (100, 1)), index=pd.date_range('20220101', periods=100), columns=["value"])
print(data1)


Downsampling , To 10 Daily data sum

data2 = data1.resample('10D').sum()
print(data2)


Downsampling , Convert to monthly data And sum up

data3 = data1.resample('M').sum()
print(data3)


L sampling

After L sampling, it is necessary to use asfreq() Method , Only in this way can the data after L sampling be converted to DataFrame Format , All the newly added data are displayed as null values .

First prepare a set of data .

data4 = pd.DataFrame(np.random.randint(1000,4000,size=(4,4)),index=pd.date_range('1/1/2022', periods=4, freq='W-WED'), columns=[" Beijing "," Shanghai "," Guangzhou "," Shenzhen "])
print(data4)


print(data4.resample('D').asfreq())


꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ꧔ꦿ
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved