Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫每月第15天重新取样_Python_Pandas_Resampling - Fatal编程技术网

Python 熊猫每月第15天重新取样

Python 熊猫每月第15天重新取样,python,pandas,resampling,Python,Pandas,Resampling,我试图重新采样到每月的值,但关于第15天 我查看了timeseries文档,但只有 月底频率 SM半月末频率(15日和月末) 月初频率 短信半个月开始频率(第一和第十五) 而我只需要第15天 差不多 2000-01-15 8.7 2000-02-15 6.9 2000-03-15 15.8 2000-04-15 12.4 我尝试使用pd.offsets.MonthBegin和MonthOffset,但没有结果按月初的MS累计,然后按loffset参数调整重新采样的时间标签: df1 = df.

我试图重新采样到每月的值,但关于第15天

我查看了timeseries文档,但只有

月底频率 SM半月末频率(15日和月末) 月初频率 短信半个月开始频率(第一和第十五)

而我只需要第15天

差不多

2000-01-15 8.7
2000-02-15 6.9
2000-03-15 15.8
2000-04-15 12.4

我尝试使用pd.offsets.MonthBegin和MonthOffset,但没有结果

按月初的
MS
累计,然后按
loffset
参数调整重新采样的时间标签:

df1 = df.resample('MS', loffset=pd.Timedelta(14, 'd')).sum()
样本:

rng = pd.date_range('2017-04-03', periods=15, freq='5D')
df = pd.DataFrame({'a': range(15)}, index=rng)  
print (df)
             a
2017-04-03   0
2017-04-08   1
2017-04-13   2
2017-04-18   3
2017-04-23   4
2017-04-28   5
2017-05-03   6
2017-05-08   7
2017-05-13   8
2017-05-18   9
2017-05-23  10
2017-05-28  11
2017-06-02  12
2017-06-07  13
2017-06-12  14

df1 = df.resample('MS', loffset=pd.Timedelta(14, 'd')).sum()
print (df1)
             a
2017-04-15  15
2017-05-15  51
2017-06-15  39

df1 = df.resample('SMS').sum()
print (df1)
             a
2017-04-01   3
2017-04-15  12
2017-05-01  21
2017-05-15  30
2017-06-01  39

什么是输入样本数据?您需要聚合数据还是只过滤
15天
df=df[df['date'].dt.day==15]
?例如,每日数据。我正在尝试聚合数据