我尝试使用此代码创建一个新的Pandas
DataFrame
组成的行,其中我感兴趣的两列都有值。
sve2_hz = sve2_all[[(sve2_all[' Q l/s'].notnull()) & (sve2_all['Flow_mm/day'].notnull())]]
我也尝试过更换内部支架:
sve2_hz = sve2_all[[sve2_all[' Q l/s'].notnull() & sve2_all['Flow_mm/day'].notnull()]]
但是,Pandas
会引发以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-110-0f3ba1c28b18> in <module>()
----> 1 sve2_hz = sve2_all[[(sve2_all[' Q l/s'].notnull()) & (sve2_all['Flow_mm/day'].notnull())]]
2 print sve2_hz.head()
C:\Users\AppData\Local\Enthought\Canopy32\User\lib\site-packages\pandas\core\frame.pyc in __getitem__(self, key)
1650 if isinstance(key, (Series, np.ndarray, list)):
1651 # either boolean or fancy integer index
-> 1652 return self._getitem_array(key)
1653 elif isinstance(key, DataFrame):
1654 return self._getitem_frame(key)
C:\Users\AppData\Local\Enthought\Canopy32\User\lib\site-packages\pandas\core\frame.pyc in _getitem_array(self, key)
1687 elif len(key) != len(self.index):
1688 raise ValueError('Item wrong length %d instead of %d.' %
-> 1689 (len(key), len(self.index)))
1690 # _check_bool_indexer will throw exception if Series key cannot
1691 # be reindexed to match DataFrame rows
ValueError: Item wrong length 1 instead of 16636.
有人可以解释错误信息的含义吗?特别是注释&#34;系列键无法重新编制索引以匹配DataFrame行&#34;。
答案 0 :(得分:0)
@EdChum提出的解决方案是删除内部括号集:
sve2_all[(sve2_all[' Q l/s'].notnull()) & (sve2_all['Flow_mm/day'].notnull())]