バグ?もしそうなら、回避策はありますか?パンダ別のタイムスタンプ値と1つのdfのヌル日時値の置換
df1['DecisionDate'].head()
Out[238]:
ID
RED 2017-02-13 00:00:00
GREEN 2016-07-29 00:00:00
ORANGE 2017-01-26 00:00:00
PURPLE 2016-10-31 00:00:00
YELLOW NaT
Name: DecisionDate, dtype: datetime64[ns]
をそして、この:
for ID in df2.index:
df1.ix[ID,'DecisionDate'] = df2.ix[ID,'DecisionDate']
を私はこの
TypeError: long() argument must be a string or a number, not 'Timestamp'
を取得:今、私はこれを行うにしようとした場合
df2['DecisionDate']
Out[239]:
YELLOW 2014-04-05 00:00:00
Name: DecisionDate, dtype: datetime64[ns]
私には、以下の持っています
何を試しても、pd.NaT
をタイムスタンプ値に置き換えることはできません。
両方のデータフレームの値はすべてタイムスタンプです。 df2観測値はdf1観測値のサブセットであるため、df2.indexのすべての値はdf1.indexにあります。
私は簡単なことを見落としていますか?それともバグですか?
ご協力いただきありがとうございます。
編集
完全なトレースバックがあります。私はこれを読んで良いじゃないけど、多分それは診断に役立ちます:
File "C:\Users\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 141, in __setitem__
def _slice(self, obj, axis=0, kind=None):
File "C:\Users\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 533, in _setitem_with_indexer
File "C:\Users\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 473, in setter
value = getattr(value, 'values', value).ravel()
File "C:\Users\Anaconda2\lib\site-packages\pandas\core\internals.py", line 3168, in setitem
File "C:\Users\Anaconda2\lib\site-packages\pandas\core\internals.py", line 3056, in apply
align_copy = False
File "C:\Users\Anaconda2\lib\site-packages\pandas\core\internals.py", line 668, in setitem
def _replace_single(self, *args, **kwargs):
File "C:\Users\Anaconda2\lib\site-packages\pandas\core\internals.py", line 2265, in _try_coerce_args
Parameters
TypeError: long() argument must be a string or a number, not 'Timestamp'
私は複製できません。 Python、Pandas、OSなどのバージョンは? –
Windows 7. Python 2.7.13。スパイダー3.1.4パンダ0.20.2。 – Windstorm1981
私はSpyder以外のすべてにマッチしています。実行するために直接コピー/ペーストできるサンプルデータを作成することをお勧めします。 IEは 'read_csv'、' read_fwf'、または 'DataFrame'の直接構築の呼び出しです。ここを参照してください:https://stackoverflow.com/questions/43945424/python-pandas-multiply-dataframe-by-weights-that -vary-with-vectorize/43947807#43947807 –