擅长:python、mysql、java
<p>你提到你正在使用熊猫数据帧。我无法重现你看到的行为:</p>
<pre><code>In [29]: data
Out[29]:
c1 c2 c3
0 4.000000 3.469136 3.678571
1 3.883721 3.296296 3.592593
2 3.365854 2.901235 3.333333
3 3.725000 3.365854 3.607143
4 4.166667 3.875000 4.071429
5 4.000000 3.468354 3.607143
6 3.950000 3.454545 3.821429
7 3.880952 3.987179 4.214286
8 4.166667 4.194805 4.481481
In [30]: data.__class__
Out[30]: pandas.core.frame.DataFrame
In [31]: for index, row in data.iterrows():
for cell in row:
print(str(cell) + ': ' + str(round(cell,1)))
....:
4.0: 4.0
3.4691358: 3.5
3.67857143: 3.7
3.88372093: 3.9
3.2962963: 3.3
3.59259259: 3.6
3.36585366: 3.4
2.90123457: 2.9
3.33333333: 3.3
3.725: 3.7
3.36585366: 3.4
3.60714286: 3.6
4.16666667: 4.2
3.875: 3.9
4.07142857: 4.1
4.0: 4.0
3.46835443: 3.5
3.60714286: 3.6
3.95: 4.0
3.45454545: 3.5
3.82142857: 3.8
3.88095238: 3.9
3.98717949: 4.0
4.21428571: 4.2
4.16666667: 4.2
4.19480519: 4.2
4.48148148: 4.5
</code></pre>
<p>正如Ami正确指出的,不需要迭代矩阵,使用numpy的好处是将单个操作应用于整个系列的项。在</p>