1

I have created a where condition with python.

filter = data['Ueber'] > 2.3
data[filter]

Here you can see my dataset.

   Saison  Spieltag            Heimteam  ... Ueber  Unter  UeberUnter
0    1819         3      Bayern München  ...  1.30   3.48       Ueber
1    1819         3       Werder Bremen  ...  1.75   2.12       Unter
2    1819         3         SC Freiburg  ...  2.20   1.69       Ueber
3    1819         3       VfL Wolfsburg  ...  2.17   1.71       Ueber
4    1819         3  Fortuna Düsseldorf  ...  1.46   2.71       Ueber

Unfortunately, my greater than condition is not working. What's the problem?

Thanks

12
  • Hallo. Have you checked the datatypes already? What colum type is Über? For me it worked, when I imported your data with read_csv and letting it figure out the types itself. I really suspect, that there is something wrong with the types in your dataframe, but on the other hand, if it was string, an exception should be raised. Commented Aug 10, 2019 at 10:52
  • Datatype is decimal or number. Commented Aug 10, 2019 at 10:55
  • what does data.dtypes say? Commented Aug 10, 2019 at 10:57
  • Sorry, it is float64. Commented Aug 10, 2019 at 10:59
  • 1
    You absolutly right. Of course, there is no data greater than 2,3, Thanks it works. Commented Aug 10, 2019 at 11:19

1 Answer 1

1

Just for the sake of clarity, if you have really floats into your column, which you want into conditional check then it should work.

Example DataFrame:

>>> df = pd.DataFrame({'num': [-12.5, 60.0, 50.0, -25.10, 50.0, 51.0, 71.0]} , dtype=float)

>>> df
    num
0 -12.5
1  60.0
2  50.0
3 -25.1
4  50.0
5  51.0
6  71.0

Conditional check to compare..

>>> df['num'] > 50.0
0    False
1     True
2    False
3    False
4    False
5     True
6     True
Name: num, dtype: bool

Result:

>>> df [ df['num'] > 50.0 ]
    num
1  60.0
5  51.0
6  71.0
Sign up to request clarification or add additional context in comments.

Comments