pandas
提供通过行和列索引列表查找的能力,
In [49]: index = ['a', 'b', 'c', 'd']
In [50]: columns = ['one', 'two', 'three', 'four']
In [51]: M = pandas.DataFrame(np.random.randn(4,4), index=index, columns=columns)
In [52]: M
Out[52]:
one two three four
a -0.785841 -0.538572 0.376594 1.316647
b 0.530288 -0.975547 1.063946 -1.049940
c -0.794447 -0.886721 1.794326 -0.714834
d -0.158371 0.069357 -1.003039 -0.807431
In [53]: M.lookup(index, columns) # diagonal entries
Out[53]: array([-0.78584142, -0.97554698, 1.79432641, -0.8074308 ])
我想使用相同的索引方法来设置M
元素。我怎样才能做到这一点?