1

all.

I'd like to get 'ID' column value and print them for each row. Currently my code is returning row index + 'ID' column value.

Here's an output:

ID= 0 109 Name: id, dtype: int64 coordinate: [ 75.
20.19276294 2903. ] label: 1

Here's my code:

for i in range(len(X)):
   print ("ID=", df['ID'].loc[[i]], "coordinate:" , X[i], "label:", labels[i])

If I print 'ID' column, stored values look like this:

print(df['ID'])

0      109
1      110
2      111 

I only want 'ID' values to be printed out, here's what I expect.

ID: 109 coordinate: [ 75. 20.19276294 2903. ] label: 1

1
  • .values on the column should do the job Commented Aug 29, 2017 at 14:44

1 Answer 1

1

Just remove the array from the loc function:

for i in range(len(X)):
    print ("ID=", df['ID'].loc[i], "coordinate:" , X[i], "label:", labels[i])

And you should consider using iloc instead of loc since loc is label based and iloc is integer based (row number).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.