0

I have a data frame that has a quantity column and I need to check if the data was inputted correctly. If there's a number that was inputted with decimals I receive de data frame with de quantity column as a float and not as an integer, but I need to print out the index of the rows that were inputted with decimals.

For example

data = {'quantity':  [2.00, 1.00, 3.00, 4.55, 5.00, 6.22]
        }

testdf = pd.DataFrame(data)

I need to print out the index of the rows that contain the decimal values that are not .00

2 Answers2

0

You can compare the values to the rounded versions of the values and use boolean masking to select only those rows

testdf[testdf['quantity']!=testdf['quantity'].round()]\
.index\
.tolist()

[3, 5]
G. Anderson
  • 5,815
  • 2
  • 14
  • 21
0

One possibility is to use the modulo operator, as in this example, and then extract the indexes that satisfy the condition to a list:

print(testdf[(testdf.quantity % 1) != 0].index.tolist())

[3, 5]
fortune_pickle
  • 141
  • 2
  • 8