I know this can be done with pivot
, I just don't know how. When I tried, I got too many rows with many nan
values. I have a number of objects identified by their x
and y
coordinates. I want to get one row for each such object, as in this example:
input = pd.DataFrame.from_dict({'dim_name':['height', 'height', 'width', 'width'], 'dim_val': [1, 2, 10, 20], 'x': [0.1, 0.2, 0.1, 0.2],
'y':[0.6, 0.7, 0.6, 0.7]})
output = pd.DataFrame.from_dict({'x':[0.1, 0.2], 'y': [0.6, 0.7], 'height': [1, 2], 'width':[10, 20]})
How do I do this in pandas?