I want to use Pandas to store values about my cars. I can view the information in a coordinate system like setup with the Pivot command, but only one kind of info per Pivot. I also want to be able to get the values fast, like with a class (cars.[x][y].x_goal). How do I do this? Or is there a better way to store coordinat system information like this? This is what I have tried. The print(result) at the end does not work.
import pandas as pd
cars = pd.DataFrame({'x': [1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4],
'y': [1, 2, 3, 4, 1, 3, 1, 2, 3, 1, 2, 3],
'x_goal': [55, 5, 4, 10, 2, 2, 3, 31, 33, 41, 42, 34],
'y_goal': [3, 1, 10, 2, 12, 31, 3, 13, 4, 4, 4, 18]})
print('x_goal')
print(cars.pivot('x','y','x_goal').values)
[[55. 5. 4. 10.]
[ 2. nan 2. nan]
[ 3. 31. 33. nan]
[41. 42. 34. nan]]
print('y_goal')
print(cars.pivot('x','y','y_goal').values)
[[ 3. 1. 10. 2.]
[12. nan 31. nan]
[ 3. 13. 4. nan]
[ 4. 4. 18. nan]]
print('x_goal at 2,3')
df_filt = cars[cars['x'] == 2 & cars['y'] == 3]
result = df_filt.get_value(df_filt.index[0],'VALUE')
print(result)