I can't access dataframe fields

Markos markos at c2o.pro.br
Sat Feb 15 19:50:24 EST 2020


Hi all,

I created the following data frame (updated_distance_matrix)

      P1            P2            P4            P5           (P3, P6)
P1 0,000000 0,244307 0,367696 0,341760 0
P2 0.234307 0.000000 0.194165 0.1443178 0
P4 0.366969 0.194165 0.000000 0.284253 0
P5 0.341760 0.1443178 0.284253 0.000000 0
(P3, P6) 0.000000 0.000000 0.000000 0.000000 0

I can change the fields of columns and rows P1-P5 without problems.

But when I try to access the fields of the row, or column, (P3, P6)

print (updated_distance_matrix_df.loc [clusters [i], last_cluster])

the message appears:

KeyError: 'the label [P3, P6] is not in the [index]'

If I change find the "loc" by "at" method appears the error:

print (updated_distance_matrix_df.at [clusters [i], last_cluster])

TypeError: unhashable type: 'list'

And if you simply leave:

print (updated_distance_matrix_df [clusters [i], last_cluster])

gives the error:

TypeError: unhashable type: 'list'

A last_cluster variable is of type list:

print (last_cluster, type (last_cluster))

['P3', 'P6'] <class 'list'>

And a variable cluster [i] is a string:

print (clusters [i], type (clusters [i]))

P5 <class 'str'>

Any tip?

Thank you,

Markos



More information about the Python-list mailing list