2

I have two DataFrames (1) fruit, and (2) market. Both have three rows denoted 0,1,2 and only one column with no header.

print fruit
0   apple
1   pear
2   melon

print market
0   apple
1   pear
2   melon

I would like to to print the index in integers and tried below but have hard time in

print market.iloc[np.where(fruit[0] == market)].index
Int64Index([0], dtype='int64')

print market.iloc[np.where(fruit[0] == market)].index.tolist
<bound method Int64Index.tolist of Int64Index([0], dtype='int64')>

print market.iloc[np.where(fruit[0] == market)].index.values
[0]

print market.iloc[np.where(fruit[0] == market)].index.get_values
<bound method Int64Index.get_values of Int64Index([0], dtype='int64')>

What should I do to print 0 only without the brackets? Goal: 0

5
  • 1
    Err, what do you want to do really? These look like series to me. Commented Aug 29, 2017 at 22:02
  • typo nosec_db.iloc[np.where(nosec_tmplt[0] == nosec_db)].index.tolist() Commented Aug 29, 2017 at 22:10
  • What I as trying to do is: find out which index of market is matching fruit[0] hence apple. And then print that index as an integer, not a list. Thanks! Commented Aug 29, 2017 at 22:45
  • Oh. found the answer. Was a very simple one. Thanks all for the help! Commented Aug 29, 2017 at 23:52
  • print int(market.iloc[np.where(fruit[0] == market)].index.values) 0 Commented Aug 29, 2017 at 23:52

1 Answer 1

1

Would this work?

print(list(market.index)[0])
print(list(fruit.index)[0])
Sign up to request clarification or add additional context in comments.

1 Comment

Hi unfortunately no. I do want the condition to find the index from market which matches fruit[0]. Thanks for the input though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.