Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.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
季节性分解&x27;s resid函数删除Python中的列名_Python_Pandas_Time Series_Data Science_Series - Fatal编程技术网

季节性分解&x27;s resid函数删除Python中的列名

季节性分解&x27;s resid函数删除Python中的列名,python,pandas,time-series,data-science,series,Python,Pandas,Time Series,Data Science,Series,在下面的代码中,我试图在一个变量残差上实现Dickey Fuller的测试,这是一个系列。 我不知道为什么它会删除函数test\u stationarity()中需要的“total\u case”列标签。 这是indexedataset\u logScale的样子 total_cases date 2020-01-30 0.000000 2020-01-31 0.000000 2020-02-01 0.000000 2020-02-0

在下面的代码中,我试图在一个变量
残差
上实现Dickey Fuller的测试,这是一个系列。
我不知道为什么它会删除函数
test\u stationarity()
中需要的“total\u case”列标签。 这是
indexedataset\u logScale
的样子

total_cases
date                   
2020-01-30     0.000000
2020-01-31     0.000000
2020-02-01     0.000000
2020-02-02     0.693147
2020-02-03     0.693147
...                 ...
2020-06-13    12.641074
2020-06-14    12.678953
2020-06-15    12.714167
2020-06-16    12.745751
2020-06-17    12.777236

[139 rows x 1 columns]
date
2020-02-02    0.188993
2020-02-03    0.049152
2020-02-04    0.284231
2020-02-05    0.126681
2020-02-06    0.022418
                ...   
2020-06-10    0.012442
2020-06-11    0.009722
2020-06-12   -0.036078
2020-06-13   -0.016174
2020-06-14    0.001704
Name: resid, Length: 133, dtype: float64
这是分解的日志数据的样子

total_cases
date                   
2020-01-30     0.000000
2020-01-31     0.000000
2020-02-01     0.000000
2020-02-02     0.693147
2020-02-03     0.693147
...                 ...
2020-06-13    12.641074
2020-06-14    12.678953
2020-06-15    12.714167
2020-06-16    12.745751
2020-06-17    12.777236

[139 rows x 1 columns]
date
2020-02-02    0.188993
2020-02-03    0.049152
2020-02-04    0.284231
2020-02-05    0.126681
2020-02-06    0.022418
                ...   
2020-06-10    0.012442
2020-06-11    0.009722
2020-06-12   -0.036078
2020-06-13   -0.016174
2020-06-14    0.001704
Name: resid, Length: 133, dtype: float64
它给出了这个错误

Result of Dickey-Fuller Test: 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/anaconda3/envs/covid/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_value(self, series, key)
   4410             try:
-> 4411                 return libindex.get_value_at(s, key)
   4412             except IndexError:

pandas/_libs/index.pyx in pandas._libs.index.get_value_at()

pandas/_libs/index.pyx in pandas._libs.index.get_value_at()

pandas/_libs/util.pxd in pandas._libs.util.get_value_at()

pandas/_libs/util.pxd in pandas._libs.util.validate_indexer()

TypeError: 'str' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
~/anaconda3/envs/covid/lib/python3.8/site-packages/pandas/core/indexes/datetimes.py in get_value(self, series, key)
    650         try:
--> 651             value = Index.get_value(self, series, key)
    652         except KeyError:

~/anaconda3/envs/covid/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_value(self, series, key)
   4418                 else:
-> 4419                     raise e1
   4420             except Exception:

~/anaconda3/envs/covid/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_value(self, series, key)
   4404         try:
-> 4405             return self._engine.get_value(s, k, tz=getattr(series.dtype, "tz", None))
   4406         except KeyError as e1:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine._date_check_type()

KeyError: 'total_cases'

During handling of the above exception, another exception occurred:

ParserError                               Traceback (most recent call last)
pandas/_libs/tslibs/conversion.pyx in pandas._libs.tslibs.conversion.convert_str_to_tsobject()

pandas/_libs/tslibs/parsing.pyx in pandas._libs.tslibs.parsing.parse_datetime_string()

~/anaconda3/envs/covid/lib/python3.8/site-packages/dateutil/parser/_parser.py in parse(timestr, parserinfo, **kwargs)
   1373     else:
-> 1374         return DEFAULTPARSER.parse(timestr, **kwargs)
   1375 

~/anaconda3/envs/covid/lib/python3.8/site-packages/dateutil/parser/_parser.py in parse(self, timestr, default, ignoretz, tzinfos, **kwargs)
    648         if res is None:
--> 649             raise ParserError("Unknown string format: %s", timestr)
    650 

ParserError: Unknown string format: total_cases

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
~/anaconda3/envs/covid/lib/python3.8/site-packages/pandas/core/indexes/datetimes.py in get_value(self, series, key)
    659             try:
--> 660                 return self.get_value_maybe_box(series, key)
    661             except (TypeError, ValueError, KeyError):

~/anaconda3/envs/covid/lib/python3.8/site-packages/pandas/core/indexes/datetimes.py in get_value_maybe_box(self, series, key)
    674         elif not isinstance(key, Timestamp):
--> 675             key = Timestamp(key)
    676         values = self._engine.get_value(com.values_from_object(series), key, tz=self.tz)

pandas/_libs/tslibs/timestamps.pyx in pandas._libs.tslibs.timestamps.Timestamp.__new__()

pandas/_libs/tslibs/conversion.pyx in pandas._libs.tslibs.conversion.convert_to_tsobject()

pandas/_libs/tslibs/conversion.pyx in pandas._libs.tslibs.conversion.convert_str_to_tsobject()

ValueError: could not convert string to Timestamp

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
 in 
     27 decomposedLogData = residual
     28 decomposedLogData.dropna(inplace=True)
---> 29 test_stationarity(decomposedLogData)
     30 # print(decomposition.resid)

 in test_stationarity(timeseries)
     17     #Perform Dickey-Fuller test:
     18     print('Result of Dickey-Fuller Test: ')
---> 19     dftest = adfuller(timeseries['total_cases'],autolag='AIC')
     20     dfoutput = pd.Series(dftest[0:4], index=['Test Statistic', 'p-value', '#Lags Used', 'Number of Observations Used'])
     21     for key,value in dftest[4].items():

~/anaconda3/envs/covid/lib/python3.8/site-packages/pandas/core/series.py in __getitem__(self, key)
    869         key = com.apply_if_callable(key, self)
    870         try:
--> 871             result = self.index.get_value(self, key)
    872 
    873             if not is_scalar(result):

~/anaconda3/envs/covid/lib/python3.8/site-packages/pandas/core/indexes/datetimes.py in get_value(self, series, key)
    660                 return self.get_value_maybe_box(series, key)
    661             except (TypeError, ValueError, KeyError):
--> 662                 raise KeyError(key)
    663         else:
    664             return com.maybe_box(self, value, series, key)

KeyError: 'total_cases'
我知道我遗漏了一件小事。

残差是串联的。 将it信息转换为df,并将列名更改为“乘客”。它起作用了

restrival=restrival.to_frame()restrival.columns=['Passengers']