Skip to content
Advertisement

How can I group by two columns interchangeably?

How can I group by two columns interchangeably?

For example, if I have this table

image with two columns of variables

and I want to get

image with 3 columns of desired variables

However, I get this instead when I use

JavaScript

The resulting table

The entries (rows) that have the same names but exchanged are considered to be new entries, but i want to treat them the same way, can you please tell me a way to do this?

Advertisement

Answer

Example with shorter DataFrame:

JavaScript

Prints:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement