I got 3 dfs, I want to write a function, take these 3 dfs as input, these 3 dfs are cb_list, cb_info, and cb_data, I first want to check whether the unqiue values in cb_list column called order_book_id is the same as the unique values in cb_info column called order_book_id, if yes, print yes, if no, print how many number of values are not the same, and print the unmatched values, then do the same thing between cb_list and cb_data
时间: 2024-04-07 08:33:05 浏览: 10
To compare the unique values in the "order_book_id" column between the three DataFrames `cb_list`, `cb_info`, and `cb_data`, you can use the following function:
```python
def compare_order_book_ids(cb_list, cb_info, cb_data):
list_order_book_ids = set(cb_list['order_book_id'].unique())
info_order_book_ids = set(cb_info['order_book_id'].unique())
data_order_book_ids = set(cb_data['order_book_id'].unique())
if list_order_book_ids == info_order_book_ids:
print("Yes")
else:
mismatched_values = list_order_book_ids.symmetric_difference(info_order_book_ids)
print(f"{len(mismatched_values)} values are not the same.")
print("Unmatched values:", mismatched_values)
if list_order_book_ids == data_order_book_ids:
print("Yes")
else:
mismatched_values = list_order_book_ids.symmetric_difference(data_order_book_ids)
print(f"{len(mismatched_values)} values are not the same.")
print("Unmatched values:", mismatched_values)
```
You can call this function by passing your three DataFrames as arguments:
```python
compare_order_book_ids(cb_list, cb_info, cb_data)
```
This function will compare the unique values in the "order_book_id" column between `cb_list` and `cb_info`, and then between `cb_list` and `cb_data`. It will print "Yes" if all the unique values match, or else it will print the number of unmatched values along with the unmatched values themselves.