I am doing the following operation:
import pandas as pd
something = [[1, "p", 2], [3, "t", 5], [6, "u", 10], [1, "p", 2], [4, "l", 9], [1, "t", 2], [3, "t", 5], [6, "c", 10], [1, "p", 2], [4, "l", 9]]
test = pd.DataFrame(something)
print(test)
test = test.drop_duplicates()
test.columns = ['id', 'state', 'level']
test = test.sort_values(by=['id'], ascending=True)
test_unique = test["id"].unique()
print(test[test["id"] == 1])
The output is the following:
0 1 2
0 1 p 2
1 3 t 5
2 6 u 10
3 1 p 2
4 4 l 9
5 1 t 2
6 3 t 5
7 6 c 10
8 1 p 2
9 4 l 9
#this after dropping duplicates
id state level
0 1 p 2
5 1 t 2
What I want to do is to combine these two rows with the same id and produce one output as 1 p-t 2. Here, the column names will be the same id, state and level. How can this be accomplished?