Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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 熊猫:将季度数据转换为月度数据_Python_Pandas_Datetime_Time Series - Fatal编程技术网

Python 熊猫:将季度数据转换为月度数据

Python 熊猫:将季度数据转换为月度数据,python,pandas,datetime,time-series,Python,Pandas,Datetime,Time Series,我有一些季度数据需要转换为月度数据,以便使用其他数据集。数据如下所示: Date Value 1/1/2010 100 4/1/2010 130 7/1/2010 160 Date Value 1/1/2010 100 2/1/2010 110 3/1/2010 120 4/1/2010 130 5/1/2010 140 6/1/2010 150 7/1/2010 160 我需要做的是估算缺失月份的值,使其如下所示: Date Value 1/1/2010 100 4/1/2010 130

我有一些季度数据需要转换为月度数据,以便使用其他数据集。数据如下所示:

Date Value
1/1/2010 100
4/1/2010 130
7/1/2010 160
Date Value
1/1/2010 100
2/1/2010 110
3/1/2010 120
4/1/2010 130
5/1/2010 140
6/1/2010 150
7/1/2010 160
我需要做的是估算缺失月份的值,使其如下所示:

Date Value
1/1/2010 100
4/1/2010 130
7/1/2010 160
Date Value
1/1/2010 100
2/1/2010 110
3/1/2010 120
4/1/2010 130
5/1/2010 140
6/1/2010 150
7/1/2010 160
找不到以前关于如何执行此操作的许多问题。仅相反(每月到每季度)。我反向尝试了其中一种方法,但没有成功:

pd.PeriodIndex(df.Date, freq='M')

在熊猫身上做这件事最简单的方法是什么

您可以使用
重新采样

# convert to period
df['Date'] = pd.to_datetime(df['Date']).dt.to_period('M')

# set Date as index and resample
df.set_index('Date').resample('M').interpolate()
输出:

         Value
Date          
2010-01  100.0
2010-02  110.0
2010-03  120.0
2010-04  130.0
2010-05  140.0
2010-06  150.0
2010-07  160.0