Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The method to eliminate identical values that appear in the same row within two columns of a dataframe in pandas is to use the 'drop_duplicates' method.

Assuming a dataframe named 'df', with columns 'column1' and 'column2', the code to eliminate identical values and store the remaining values in a new dataframe ('new_df') is:

new_df = df[['column1', 'column2']].drop_duplicates()

This code selects only the columns 'column1' and 'column2', eliminates the identical values that appear in the same row in these columns and stores the remaining values in the new dataframe 'new_df'. The original dataframe 'df' is not altered by this code.