如何打印此数据框

时间:2017-02-19 22:44:36

标签: python pandas

我有这个数据框。我想迭代行并打印出前三列。但这并不奏效。 KeyError: '0'

for index, row in df.iterrows():
    print row['0'], row['1'], row['2']


                     0         1         2         3         4
1       Libor Rates (USD)    Latest    Wk ago      High       Low
2         Libor Overnight   0.68611   0.68667   0.69544   0.36790
3            Libor 1 Week   0.71889   0.71611   0.72428   0.39070
4           Libor 1 Month   0.78056   0.77056   0.78056   0.42830
5           Libor 2 Month   0.85833   0.84000   0.85833   0.51420
6           Libor 3 Month   1.05650   1.03372   1.05650   0.61820
7           Libor 6 Month   1.36378   1.33489   1.36378   0.86790
8            Libor 1 Year   1.74511   1.69400   1.74511   1.13975

1 个答案:

答案 0 :(得分:1)

KeyError是因为您正在使用row['0']它应该是row[0](而不是int)

for index, row in df.iterrows():
    print row[0], row[1], row[2]