python time series data Resampling
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)
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())