我可以創建一個recarray並通過名稱來訪問它的成員:如何訪問numpy recarray的字段#k?
import numpy as np
n = 20
x = np.recarray((n,), dtype=[('x',int),('y',float),('label',object)])
x.x[:] = range(n)
x.y[:] = np.arange(n)*0.08
x.label[:] = ['%d bottles of beer on the wall' % i for i in range(n)]
,我可以通過行索引訪問數據,或者遍歷行:
>>> print x[3]
(3, 0.24, '3 bottles of beer on the wall')
但我怎麼能遍歷在領域或得到k
th字段在recarray?
嗯。我將從'numpy.recarray'切換到'pandas.DataFrame'。 –