You can sort the first and second columns so that a,b and b,a are treated as the same in groupby.
Now, since the sort() is deprecated, we can use numpy sort and re-create a new dataframe.
Assuming the following csv_file:
column1,column2,salary
a,b,1
c,b,3
b,a,10
b,c,30
d,e,99
We can do it as follows:
import pandas as pd
import numpy as np
df = pd.read_csv("csvfile.csv",)
print("Original:\n ",df.head())
print ("\nGrouped sum:\n")
print ((pd.concat([pd.DataFrame(np.sort(df[df.columns[:2]], axis=1), columns=df.columns[:2]),\
df["salary"]], axis=1)).reset_index(drop=True, inplace=False).groupby\
(["column1", "column2"]).sum())
The output is shown below:
Original:
column1 column2 salary
0 a b 1
1 c b 3
2 b a 10
3 b c 30
4 d e 99
Grouped sum:
salary
column1 column2
a b 11
b c 33
d e 99