Ask Your Question
2

In pandas, what is the method to eliminate identical values that appear in the same row within two columns of a dataframe? How can the remaining values be stored in a new dataframe without altering the original dataframe?

asked 2022-05-10 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-11-25 05:00:00 +0000

lakamha gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-10 11:00:00 +0000

Seen: 21 times

Last updated: Nov 25 '21