2017-12-09 17 views
0

私は初心者のファンダースユーザーです。データフレームにシリーズを追加できない場合があります

ここに該当します。 これは最初のデータフレームです。

In [9]: df 
Out[9]: 
    importance interval last_read    last_update name trigger 
0   2  NaN  NaN 2017-12-09 00:00:00+09:00 foobar  NaN 

これは追加するレコードです。

In [10]: record = df.iloc[0].copy() 

このレコードを追加するときにエラーはありません。

In [11]: df.append(record) 
Out[11]: 
    importance interval last_read    last_update name trigger 
0   2  NaN  NaN 2017-12-09 00:00:00+09:00 foobar  NaN 
0   2  NaN  NaN 2017-12-09 00:00:00+09:00 foobar  NaN 

レコードのNaN値をintに変更して追加します。エラーは発生しません。

In [12]: record['interval'] = 1 

In [13]: df.append(record) 
Out[13]: 
    importance interval last_read    last_update name trigger 
0   2  NaN  NaN 2017-12-09 00:00:00+09:00 foobar  NaN 
0   2  1  NaN 2017-12-09 00:00:00+09:00 foobar  NaN 

次に、レコードの別のNaN値をpd.Timestampに変更して追加します。 これはエラーが発生します。

In [10]: record 
Out[10]: 
importance        2 
interval        NaN 
last_read       NaN 
last_update 2017-12-09 00:00:00+09:00 
name        foobar 
trigger        NaN 
Name: 0, dtype: object 

In [11]: record['trigger'] = record['last_update'] 

In [12]: record 
Out[12]: 
importance        2 
interval        NaN 
last_read       NaN 
last_update 2017-12-09 00:00:00+09:00 
name        foobar 
trigger  2017-12-09 00:00:00+09:00 
Name: 0, dtype: object 

In [13]: df.append(record) 
--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
<ipython-input-13-7c027f1cbb54> in <module>() 
----> 1 df.append(record) 

~/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in append(self, other, ignore_index, verify_integrity) 
    4545    to_concat = [self, other] 
    4546   return concat(to_concat, ignore_index=ignore_index, 
-> 4547      verify_integrity=verify_integrity) 
    4548 
    4549  def join(self, other, on=None, how='left', lsuffix='', rsuffix='', 

~/anaconda3/lib/python3.6/site-packages/pandas/core/reshape/concat.py in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity, copy) 
    205      verify_integrity=verify_integrity, 
    206      copy=copy) 
--> 207  return op.get_result() 
    208 
    209 

~/anaconda3/lib/python3.6/site-packages/pandas/core/reshape/concat.py in get_result(self) 
    405    new_data = concatenate_block_managers(
    406     mgrs_indexers, self.new_axes, concat_axis=self.axis, 
--> 407     copy=self.copy) 
    408    if not self.copy: 
    409     new_data._consolidate_inplace() 

~/anaconda3/lib/python3.6/site-packages/pandas/core/internals.py in concatenate_block_managers(mgrs_indexers, axes, concat_axis, copy) 
    4830  blocks = [make_block(
    4831   concatenate_join_units(join_units, concat_axis, copy=copy), 
-> 4832   placement=placement) for placement, join_units in concat_plan] 
    4833 
    4834  return BlockManager(blocks, axes) 

~/anaconda3/lib/python3.6/site-packages/pandas/core/internals.py in <listcomp>(.0) 
    4830  blocks = [make_block(
    4831   concatenate_join_units(join_units, concat_axis, copy=copy), 
-> 4832   placement=placement) for placement, join_units in concat_plan] 
    4833 
    4834  return BlockManager(blocks, axes) 

~/anaconda3/lib/python3.6/site-packages/pandas/core/internals.py in concatenate_join_units(join_units, concat_axis, copy) 
    4937  to_concat = [ju.get_reindexed_values(empty_dtype=empty_dtype, 
    4938           upcasted_na=upcasted_na) 
-> 4939     for ju in join_units] 
    4940 
    4941  if len(to_concat) == 1: 

~/anaconda3/lib/python3.6/site-packages/pandas/core/internals.py in <listcomp>(.0) 
    4937  to_concat = [ju.get_reindexed_values(empty_dtype=empty_dtype, 
    4938           upcasted_na=upcasted_na) 
-> 4939     for ju in join_units] 
    4940 
    4941  if len(to_concat) == 1: 

~/anaconda3/lib/python3.6/site-packages/pandas/core/internals.py in get_reindexed_values(self, empty_dtype, upcasted_na) 
    5210      pass 
    5211     else: 
-> 5212      missing_arr = np.empty(self.shape, dtype=empty_dtype) 
    5213      missing_arr.fill(fill_value) 
    5214      return missing_arr 

TypeError: data type not understood 

私のパンダのバージョンは0.20.3
あなたは私にいくつかのアドバイスを与えることができるのですか?

あなたは

答えて

0

してみてくださいありがとうございました。 下記のリンクをご覧ください。

Github Issues #16044

0

あなたは、タイムスタンプの代わりにpd.to_datetime試すことができます。これはバグです

+0

あなたのリプレイをありがとう、私は私の悪いコード例ごめんなさい。私が理解しているように、あなたはpd.to_datetime関数を使ってタイムスタンプを作ることを勧めました。ただし、この場合、タイムスタンプは正常に生成されています。 (他のセルのタイムスタンプ値からコピーされたばかり) –

関連する問題