Как можно сделать поворот в пандах? Я не могу обойти ошибку «повторяющиеся записи». Вход и выход должны выглядеть так, как показано ниже.
import pandas as pd
input = pd.DataFrame({'measure': ['length','length','length','weight','weight','weight','sex','sex','sex'],
'species': [10, 10, 10, 10, 10, 10, 10, 10, 10],
'value': [1, 2, 3, 13, 45, 123, 0, 1, 1],
'set': [3, 3, 3, 3, 3, 3, 3, 3, 3]})
output = pd.DataFrame({'set': [3,3,3],
'species': [10, 10, 10],
'length': [1, 2, 3],
'weight': [13, 45, 123],
'sex': [0, 1, 1]})
test = input.pivot(index='set',columns='measure', values='value')
print(test)