0

I have a panda dataframe with the following columns: enter image description here

Now I would like to plot out a chart with mpf.plot. But I am getting the following error: enter image description here

How can I avoid the above TypeError Message? I did set the df index with the following command:

dfnew_plot = dfnew_plot.set_index('Date')
2
  • Are you sure Date is already a datetime column? in other words, when you print type(dfnew_plot.index) does it return pandas.core.indexes.datetimes.DatetimeIndex ? Commented Jan 30, 2021 at 11:04
  • Result is pandas.core.indexes.base.Index Commented Jan 30, 2021 at 11:48

1 Answer 1

2

Your index isn't the correct dtype. It needs to be converted using:

dfnew_plot.index = pd.to_datetime(dfnew_plot.index)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for your help. Your solution solves my problem. Question: If I print the df before and after the code dfnew_plot.index = pd.to_datetime(dfnew_plot.index), i do not see any differences? What do I have to learn, to understand the difference?
Your index was a dtype of string or "object" according to pandas. To check the dtype of any Series (column, or index) you can use the dtype attribute. Example: `dfnew_plot.index.dtype'. If the result is "O" or "Object" or anything besides "DateTimeIndex" then your financial plotting library won't work.

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.