While appending two dataframes, if we want to raise error in case row labels are duplicate, we shall use which parameter of append() method?
While appending two dataframes, if we want to raise error in case row labels are duplicate, we shall use which parameter of append() method?
Solution
DataFrame.append() has a parameter verify_integrity. When it is set to True, pandas checks the row labels of the combined result and raises a ValueError if any label is duplicated. Its default is False, so duplicate labels are normally allowed.
Option 1: ignore_index controls whether the old labels are discarded and replaced by a fresh 0 to n-1 index. Setting it to False (the default) keeps the old labels and does not check for duplicates.
Options 2 and 3: row_index and in_place are not parameters of append().
ignore_index = True is another way to avoid duplicate labels, but it renumbers the rows instead of raising an error.
Related questions:
2026: 23 May Shift 1
2025: 3 June Shift 2
2025: 15 May Shift 2