永远尝试。似乎应该更简单。如何获取具有重复值的长格式df,并将所有重复值组合在一起?我尝试了groupby,但这不是数字数据。试图枢轴转动,但这也不起作用。
import pandas as pd
input = pd.DataFrame( {
"CombinedID" : ["Alice1084", "Alice1084", "Alice1084", "Alice1084", "Alice1084",
"Mallory1085", "Mallory1085", "Mallory1085",
"Bob42", "Bob42", "Bob42", "Bob42"],
"Occupation" : ["Comedian", "Comedian", "Comedian", "Comedian", "Comedian",
"Surgeon", "Surgeon", "Surgeon",
"Philosopher", "Philosopher", "Philosopher", "Philosopher"] } )
output = pd.DataFrame({"CombinedID" : ["Alice1084","Mallory1085","Bob42"],
"Occupation" : ["Comedian", "Surgeon", "Philosopher"]})
print(output)
CombinedID Occupation
0 Alice1084 Comedian
1 Mallory1085 Surgeon
2 Bob42 Philosopher