当index是datetime时,Pandas.DataFrame.dropna不起作用

时间:2017-08-16 17:58:07

标签: python python-2.7 pandas datetime dataframe

我有一个带有日期时间索引的数据框,如下所示:

enter image description here

我想删除所有具有NaN值的行,所以我过去只使用Pandas.DataFrame.dropna删除所有行但是当我将它用于带索引的数据帧时会出现以下错误:

C:\Users\nandhos\Anaconda2\lib\site-packages\pandas\core\frame.pyc in dropna(self, axis, how, thresh, subset, inplace)
   3067                     raise TypeError('must specify how or thresh')
   3068 
-> 3069             result = self.take(mask.nonzero()[0], axis=axis, convert=False)
   3070 
   3071         if inplace:

C:\Users\nandhos\Anaconda2\lib\site-packages\pandas\core\generic.pyc in take(self, indices, axis, convert, is_copy, **kwargs)
   1926         new_data = self._data.take(indices,
   1927                                    axis=self._get_block_manager_axis(axis),
-> 1928                                    convert=True, verify=True)
   1929         result = self._constructor(new_data).__finalize__(self)
   1930 

C:\Users\nandhos\Anaconda2\lib\site-packages\pandas\core\internals.pyc in take(self, indexer, axis, verify, convert)
   4009         new_labels = self.axes[axis].take(indexer)
   4010         return self.reindex_indexer(new_axis=new_labels, indexer=indexer,
-> 4011                                     axis=axis, allow_dups=True)
   4012 
   4013     def merge(self, other, lsuffix='', rsuffix=''):

C:\Users\nandhos\Anaconda2\lib\site-packages\pandas\core\internals.pyc in reindex_indexer(self, new_axis, indexer, axis, fill_value, allow_dups, copy)
   3895             new_blocks = [blk.take_nd(indexer, axis=axis, fill_tuple=(
   3896                 fill_value if fill_value is not None else blk.fill_value,))
-> 3897                 for blk in self.blocks]
   3898 
   3899         new_axes = list(self.axes)

C:\Users\nandhos\Anaconda2\lib\site-packages\pandas\core\internals.pyc in take_nd(self, indexer, axis, new_mgr_locs, fill_tuple)
   1044             fill_value = fill_tuple[0]
   1045             new_values = algos.take_nd(values, indexer, axis=axis,
-> 1046                                        allow_fill=True, fill_value=fill_value)
   1047 
   1048         if new_mgr_locs is None:

C:\Users\nandhos\Anaconda2\lib\site-packages\pandas\core\algorithms.pyc in take_nd(arr, indexer, axis, out, fill_value, mask_info, allow_fill)
   1469     func = _get_take_nd_function(arr.ndim, arr.dtype, out.dtype, axis=axis,
   1470                                  mask_info=mask_info)
-> 1471     func(arr, indexer, out, fill_value)
   1472 
   1473     if flip_order:

pandas\_libs\algos_take_helper.pxi in pandas._libs.algos.take_2d_axis1_float32_float32 (pandas\_libs\algos.c:106602)()

ValueError: Big-endian buffer not supported on little-endian compiler

当索引只是数字时,不会出现该错误,如下所示:

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试使用isfinite()代替:

import numpy as np
df = df[np.isfinite(df['pwv'])]
相关问题