2

The following data is able to be plot using matplotlib but not after converting into a Pandas Series. How can it be plotted using pandas?

Without pandas

scores = [Decimal('3.7989'),
 Decimal('4.7989'),
 Decimal('5.7989'),
 Decimal('6.7989'),
 Decimal('7.7989')]

 timestamps = [datetime.datetime(2013, 11, 12, 21, 21, 52),
 datetime.datetime(2013, 11, 12, 21, 21, 8),
 datetime.datetime(2013, 11, 12, 21, 21, 1),
 datetime.datetime(2013, 11, 12, 21, 20, 1),
 datetime.datetime(2013, 11, 12, 21, 19, 33)]

 plt.plot(timestamps,score)

enter image description here

Using pandas

ts = pd.Series(scores, index=timestamps)
ts.plot()

We get the error: TypeError: Series has object dtype and cannot be converted: no numeric data to plot

1
  • Huh. Did you accept the answer without voting for it as useful? Commented Nov 21, 2014 at 19:46

1 Answer 1

1

Try taking away the Decimal type:

ts = pd.Series([float(x) for x in scores], index=timestamps)

or

ts = pd.Series(scores, index=timestamps, dtype='float64')

Pandas only supports float and integer as numeric types, Use anything else, and it becomes an "object."

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.