I have a data Frame df
so i converted it to date time using pandas,
stock_data['Date'] = pd.to_datetime(stock_data['Date'],unit='s')
but when i'm plotting this, i get this....
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?
CodePudding user response:
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.