python - KeyError when data encoded as string -
after struggle plotting code, end following minimal working example:
import pandas import matplotlib.pyplot plt data = { 'foo': ['2', '335', '3'], 'bar': [1, 2, 1], } pandas.dataframe(data).plot.scatter('foo', 'bar') # keyerror plt.show()
which raise keyerror: 'foo'
.
however, if use integers in foo
data instead of strings:
'foo': [2, 335, 3],
i expected scatterplot, without error.
what rationale dataframe behavior ? can understand data must in same format. why raise (very laconic) keyerror in case ?
Comments
Post a Comment