DataFrame
我要覆蓋與另一列的一個切片。熊貓的熊貓(v0.8.0)的高級索引分配
在下面的代碼拋出列出的錯誤。
什麼將是實現這一目標的有效替代的方法?
df = DataFrame({'a' : range(0,7),
'b' : np.random.randn(7),
'c' : np.random.randn(7),
'd' : np.random.randn(7),
'e' : np.random.randn(7),
'f' : np.random.randn(7),
'g' : np.random.randn(7)})
# overwrite cols
df.ix[:,'b':'d'] = df.ix[:, 'e':'g']
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pandas\core\indexing.py", line 68, in __setitem__
self._setitem_with_indexer(indexer, value)
File "C:\Python27\lib\site-packages\pandas\core\indexing.py", line 98, in _setitem_with_indexer
raise ValueError('Setting mixed-type DataFrames with '
ValueError: Setting mixed-type DataFrames with array/DataFrame pieces not yet supported
編輯
而作爲置換的,我怎麼可能還指定行的子集來設置
df.ix[df['a'] < 3, 'b':'d'] = df.ix[df['a'] < 3, 'e':'g']
col_range函數是一個好主意,因爲我仍然要在列中指定切片。作爲一個置換,我怎麼能指定分配中的行的子集(上面編輯的問題)。 – brendan 2012-07-17 09:24:29
用行切片的額外信息更新了答案。 – ely 2012-07-17 12:25:09
感謝您的更新 - 儘管當我嘗試df.ix [my_rows,col_range(df,'b','d')] = df.ix [my_rows,'e':'g'] .value時,會引發ValueError也。 – brendan 2012-07-18 09:53:43