0

I have a data Frame df enter image description here so i converted it to date time using pandas, stock_data['Date'] = pd.to_datetime(stock_data['Date'],unit='s')

enter image description here

but when i'm plotting this, i get this.... enter image description here

I think this is not a right format for date and time so, i tried converting this to time stamp.

df['date'] = pd.DatetimeIndex(df.Date).asi8
but then also no luck how do i fix this?

4
  • You need to show the line where you imported the dataframe (df). I suspect that is where your date/time parsing is happening with pandas. Commented May 26, 2022 at 16:27
  • hey thanks for the reply, can you please check the question i've added the initial steps Commented May 26, 2022 at 16:35
  • 1
    Did you try this plt.scatter(df['Date'], df["C"], marker = "^", color = "green", label = "Close Price");? Commented May 26, 2022 at 16:40
  • @yashaswavarshney answered you. What in buy, show. Commented May 27, 2022 at 8:22

1 Answer 1

1

In my opinion, there are two solutions.

1.I downloaded the data from yfinance and specifically reset the indexes to turn the 'Datetime' indexes into a column. And I draw a scatter, specifying a list of indexes. Possible that you have these indexes and have buy?

import matplotlib.pyplot as plt
import yfinance as yf

df = yf.download(tickers='AAPL', period="3d", interval="15m")
df = df.reset_index()

plt.scatter(df['Datetime'].values[[7, 55, 70]], df['Close'].values[[7, 55, 70]], color='magenta')
plt.plot(df['Datetime'].values, df['Close'].values)
plt.legend(['stock', 'point'])
plt.show()

2.And also try to specify indexes in plt.plot, when drawing line, something like this:

plt.plot(df['C'].index, df['C'])

Perhaps because of this, such a picture turns out that the scatter appears somewhere at the beginning of the indexes.

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.