I would like to draw a scatter plot with x and y axis with x axes grouped. x axis will be three types(e.g. h, o, c), which is identifiable by ID column. y axis will have mean values per each ID.
Here's sample data:
id sum mean color type
0 109 2852 5.301115 r h
1 110 3162 5.877323 r h
2 111 1997 3.711896 b o
Y axis will be "mean" column value and X axis will be grouped "id" value. When I run my code below, it generates an error:
File "pandas\index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas\index.c:4279)
File "pandas\src\hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13742)
File "pandas\src\hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13696)
KeyError: 'type'
Here'e my code:
df.set_index('type', inplace=True)
...
col = df['type'].map({'h':'r', 'o':'b', 'c':'y'})
ax = df.plot.scatter(x='type', y='mean', c=col)

ax = df.plot.scatter(x='type', y='mean', c=col)