-1

When I type this:

enter image description here

I get this:

enter image description here

This is a pandas DataFrame with 1M+ rows. How do we solve this?

  • This is basic pandas indexing: please [read the tutorial on Indexing and selecting data](https://pandas.pydata.org/docs/user_guide/indexing.html). In your case, `df[df['symbol']=='SBIN-BL', 'token']`. If you do this a lot (look up rows by 'symbol') column, then make it your index. – smci Apr 21 '22 at 07:36
  • 1
    Also, please state your question in words, not just by reference to screenshots, and please post the code and data as text, not screenshots, then they can't be indexed, serched, retrieved (or even possibly viewed for some users). – smci Apr 21 '22 at 07:37

1 Answers1

0

Use:

out = next(iter(df.loc[df.symbol.eq('SBIN-BL'), 'token']), 'no match')
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • jezrael, this question was a duplicate of both the tutorial and SO questions with almost 3000 upvotes (once we find the desired rows, it's trivial to index the column(s)). Please post your answer on [How do I select rows from a DataFrame based on column values?](https://stackoverflow.com/questions/17071871/how-do-i-select-rows-from-a-dataframe-based-on-column-values/47693145#47693145) and I'll happily upvote it. – smci Apr 21 '22 at 09:38
  • @smci - can you show me when is scalar ouput? Maybe I miss it. – jezrael Apr 21 '22 at 09:39
  • @smci - dupe is for filtering, OP need scalar. I use `next` with `iter` for default value if no match. – jezrael Apr 21 '22 at 09:41
  • e.g. [this answer](https://stackoverflow.com/questions/17071871/how-do-i-select-rows-from-a-dataframe-based-on-column-values/47693145#47693145). Like I said, once we find the desired rows, it's trivial to index the column(s). – smci Apr 21 '22 at 09:41
  • @smci - hmmm, I cannot find any solution what need OP. in this lik get DataFrame, not scalar – jezrael Apr 21 '22 at 09:53