-1

My input:

df.query('date == 2009')[df['id'] == 35988].index[0]

The error raised:

C:\Anaconda\lib\site-packages\ipykernel_launcher.py:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index. "Entry point for launching an IPython kernel.

The output:

11136

How to avoid an error, keeping given output?

ZF007
  • 3,708
  • 8
  • 29
  • 48
AlexR
  • 9
  • 1
  • 6
  • Possible duplicate of https://stackoverflow.com/questions/51055788/userwarning-boolean-series-key-will-be-reindexed-to-match-dataframe-index –  Feb 12 '19 at 15:18

1 Answers1

1

Without example data, I can't test these potential solutions, but maybe one or both will work for you.

Option 1: include both conditions in DatFrame.query:

df.query('date == 2009 & id == 35988').index[0]

Option 2: reverse the order of the two queries with something like this:

df[df['id'] == 35988].query('date == 2009').index[0]
Peter Leimbigler
  • 10,775
  • 1
  • 23
  • 37