Mark rows whose ticker and date appear more than once with duplicated(subset=…, keep=…), look at conflicting copies, and keep one row per ticker and date with drop_duplicates.
After this lesson, you can find conflicting closes in a price file and keep one close per ticker and date.
How do I mark repeated rows?
.duplicated() marks a row True when it repeats an earlier row, and subset=["ticker", "date"] compares only those columns, so it also finds two different closes for the same stock and day. In six made-up vendor records, row 4 repeats row 3 exactly, and row 2 gives AAA a second close on 3 March, 102.4 against 102.0.
The records are in arrival order, with closes in kronor. keep="first", the default, leaves the first copy unmarked, keep="last" the last one, and keep=False marks every copy, which shows both sides of a conflict.
The pair that identifies a record depends on the file, and a file with one close per trading venue needs the venue in the pair too.
How do I keep one row per ticker and date?
.drop_duplicates(subset=pair, keep="last") keeps one row per ticker and date, the last to arrive, which suits a vendor whose later records correct earlier ones. AAA keeps 102.4 on 3 March, and checking .duplicated(subset=pair).any() on the result gives False.
ignore_index=True numbers the remaining rows from 0. A conflict without a rule for the right copy belongs in a review, and a backtest uses the record available when the trading decision was made.
The following box keeps the last copy of each pair and checks the result.