I am working with a pandas dataframe consisting of "recipients" on the y axis and "donors" on the x.
Donor1 Donor2 Donor3 Donor4 Donor5 Donor6
Recipient1 0 4 1 4 7 6
Recipient2 6 0 9 8 5 8
Recipient3 5 3 5 0 9 3
Recipient4 9 2 1 8 0 5
Recipient5 4 5 5 9 4 2
Recipient6 5 4 2 8 5 6
The maxValueIndex code
maxValueIndex = df_test_bid.idxmax(axis = 1)
print(str(maxValueIndex))
produces: (index of max value in that row)
Recipient1 Donor5
Recipient2 Donor3
Recipient3 Donor5
Recipient4 Donor1
Recipient5 Donor4
Recipient6 Donor4
dtype: object
How can I convert each recipient/donor pair into a single string? In other words, how can I iterate through each recipient/donor pair?
Trying to iterate with a for loop only gets me the donors.
source https://stackoverflow.com/questions/71991781/how-to-convert-pandas-dataframe-max-index-values-into-string
Comments
Post a Comment