簡體   English   中英

溢出錯誤:Python int 太大,無法在 python 中轉換為 C long 雖然日期被定義為 datetime64[ns]54EB666CDF8931AC

[英]OverflowError: Python int too large to convert to C long in python though date are defined as datetime64[ns] type object

在此處輸入圖像描述

在此處輸入圖像描述

設置頻率時出現溢出錯誤

df_train.index.freq = 'W'.

錯誤:

 OverflowError Traceback (most recent call last) <ipython-input-37-bbb3114abe9d> in <module> ----> 1 df_train.index.freq = 'W' /opt/omniai/software/Miniconda/lib/python3.6/site-packages/pandas/core/indexes/extension.py in fset(self, value) 64 65 def fset(self, value): ---> 66 setattr(self._data, name, value) 67 68 fget.__name__ = name /opt/omniai/software/Miniconda/lib/python3.6/site-packages/pandas/core/arrays/datetimelike.py in freq(self, value) 978 if value is not None: 979 value = frequencies.to_offset(value) --> 980 self._validate_frequency(self, value) 981 982 self._freq = value /opt/omniai/software/Miniconda/lib/python3.6/site-packages/pandas/core/arrays/datetimelike.py in _validate_frequency(cls, index, freq, **kwargs) 1039 try: 1040 on_freq = cls._generate_range( -> 1041 start=index[0], end=None, periods=len(index), freq=freq, **kwargs 1042 ) 1043 if not np.array_equal(index.asi8, on_freq.asi8): /opt/omniai/software/Miniconda/lib/python3.6/site-packages/pandas/core/arrays/datetimes.py in _generate_range(cls, start, end, periods, freq, tz, normalize, ambiguous, nonexistent, closed) 406 end = end.tz_localize(None) 407 # TODO: consider re-implementing _cached_range; GH#17914 --> 408 values, _tz = generate_regular_range(start, end, periods, freq) 409 index = cls._simple_new(values, freq=freq, dtype=tz_to_dtype(_tz)) 410 /opt/omniai/software/Miniconda/lib/python3.6/site-packages/pandas/core/arrays/_ranges.py in generate_regular_range(start, end, periods, freq) 79 xdr = generate_range(start=start, end=end, periods=periods, offset=freq) 80 ---> 81 values = np.array([x.value for x in xdr], dtype=np.int64) 82 83 return values, tz /opt/omniai/software/Miniconda/lib/python3.6/site-packages/pandas/core/arrays/_ranges.py in <listcomp>(.0) 79 xdr = generate_range(start=start, end=end, periods=periods, offset=freq) 80 ---> 81 values = np.array([x.value for x in xdr], dtype=np.int64) 82 83 return values, tz /opt/omniai/software/Miniconda/lib/python3.6/site-packages/pandas/tseries/offsets.py in generate_range(start, end, periods, offset) 2765 2766 if end is None: -> 2767 end = start + (periods - 1) * offset 2768 2769 if start is None: pandas/_libs/tslibs/offsets.pyx in >pandas._libs.tslibs.offsets.BaseOffset.__radd__() pandas/_libs/tslibs/offsets.pyx in >pandas._libs.tslibs.offsets._BaseOffset.__add__() /opt/omniai/software/Miniconda/lib/python3.6/site-packages/pandas/tseries/offsets.py in wrapper(self, other) 109 other = other.tz_localize(None) 110 --> 111 result = func(self, other) 112 113 if self._adjust_dst: /opt/omniai/software/Miniconda/lib/python3.6/site-packages/pandas/tseries/offsets.py in apply(self, other) 1577 k -= 1 1578 -> 1579 return other + timedelta(weeks=k) 1580 1581 @apply_index_wraps pandas/_libs/tslibs/c_timestamp.pyx in >pandas._libs.tslibs.c_timestamp._Timestamp.__add__() OverflowError: Python int too large to convert to C long

您可以嘗試使用適當數量的句點重新索引您的 dataframe

df = df.set_index(pd.date_range('2010-02-05', periods=100, freq='W'))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM