0

i have 2 queries in pandas and need to join them together.

b.loc[b['Speed']=='100.0']

b.loc[b['Month']=='2022-01']

I need to join them using & but getting error of unsupported operand type.

tim83
  • 13
  • 6
  • What are the data types of `b['Speed']` and `b['Month']`? You are comparing it with `str` but it should be float and datetime respectively. In That case, you need to compare them accordingly. – Rahul May 05 '22 at 03:30
  • float 64 and period M – tim83 May 05 '22 at 03:32
  • A `float64` value will never equal `'100.0'`. Remember that `100.0` and `'100.0'` are two very, very different values. – Tim Roberts May 05 '22 at 03:38

1 Answers1

0

You are comparing your data having different datatype with comparison value of str, while it should be float 64 and period M respectively as you have mentioned in your comment.

Try to match your comparison with correct data type. try this:

b.loc[(b['Speed'] == 100.0) & (b['Month'] == pd.Period('2022-01'))]
Rahul
  • 10,830
  • 4
  • 53
  • 88