Iam working with a project that is converting invoice PDFs to excels and comparing values between two different columns, but iam having trouble with something when comparing values,what iam doing is using .loc function to search for the values of a list in a specific column
This is the code to compare if a value on list is in values column and add to a different DF
difference = df_bank.loc[df_bank['value'].isin(list_difference)]
This is the bank_df:
Date Name Value
0 25/02/2022 Lorem C 0.0
1 02/03/2022 Ipsum C 100.0
2 02/03/2022 Lorem Ipsum * 16.9
3 02/03/2022 Lorem C 2454.0
4 02/03/2022 Ipsum 3732.0
This is the list_difference:
[0.0, 16.9, 2454.0, 3732.0]
But for some reason the difference is only:
Date Name Value
0 25/02/2022 Lorem C 0.0
3 02/03/2022 Lorem C 2454.0
4 02/03/2022 Ipsum 3732.0
It doesn't get the value 16.9 for example, even though it is on bank_df
CodePudding user response:
Convert the column to a float.
df_bank['Value'] = df_bank['Value'].astype(float)
CodePudding user response:
It's possible that you're encountering rounding issues, so 16.9
could be really 16.90000001 or something like that.
Maybe you should try:
list_difference = np.array(list_difference).round(2)
difference = df_bank.loc[df_bank['Value'].round(2).isin(list_difference)]