0

enter image description here

I have a problem with plotting this time series of the S&P500.

First I sorted the pandas DataFrame in ascending order by the date and then I used the Seaborn lineplot, which supposedly works fine with plotting time series. But in all examples I saw on the internet as well as in the documentation of seaborn this error did not occur. Here, as you can see, the y-axis is not consistent in that it is ascending as it goes up. I tried to fix/set the y-axis but then the plot vanished completely..

I am relatively new to plotting with seaborn and could't resolve the issue on my own. Maybe it is just a silly error I am doing but can anyone please help me setting the y axis right, I'd appreciate that! The y-Axis should start somewhere in the early 3000s and go up to 4000. How is that to be done?

  • 2
    Your data are strings, not floats. – BigBen Jan 04 '23 at 14:52
  • 2
    Does this answer your question? [Matplotlib y axis values are not ordered](https://stackoverflow.com/questions/48062499/matplotlib-y-axis-values-are-not-ordered) – dm2 Jan 04 '23 at 14:53
  • thank you very much! I am now trying to convert the Price-column in the dataframe to float from string but I am getting error messages... – Student_1899 Jan 04 '23 at 15:04
  • sp500['Price'] = sp500['Price'].astype(int) sp500["Price"] = pd.to_numeric(sp500["Price"], downcast="float") These two do not work. In the first one it said 'cannot convert string into a float' although this is what I want – Student_1899 Jan 04 '23 at 15:05
  • thanks again! i was able to resolve the issue regarding the conversion of the data types. I appreciate your tip! :) – Student_1899 Jan 04 '23 at 15:45

0 Answers0