First I will show you the code. I dont have problems gathering data, but more with presenting them the right way.
#Get date of comments
df["Date"] = df["Date"].dt.date
#Get number of comments mentioning each ticker on each day
dfDay = df.groupby(["Ticker","Date"]).sum().reset_index()
dfDay = dfDay[["Ticker", "Date", "Mentions"]]
dfDay["Date"] = pd.to_datetime(dfDay["Date"])
dfGMEm = dfDay[dfDay["Ticker"]== "GME"]
import yfinance as yf
dfGMEp = yf.download("GME", start="2020-05-01", end="2021-05-15",interval="1d").reset_index()
dfGMEp["CloseAmount"] = dfGMEp["Close"]
dfCombined = pd.concat([dfGMEm, dfGMEp])
import plotly.express as px
fig = px.line(dfCombined, x="Date", y=["Mentions", "Close"], title='GME Erwähnungen',
color_discrete_sequence=["rgb(229, 81, 39)","rgb(118, 213, 232)" ])
fig.update_layout(title="Erwähnungen - Preis"+"</b><br>Aug 2018 - Mai 2021", titlefont=dict(color='rgb(229, 81, 39)', size=20), plot_bgcolor='rgb(32,36,44)', paper_bgcolor='rgb(32,36,44)')
fig.update_xaxes(title_text="",color='white', showgrid=False, tickfont=dict(size=10))
fig.update_yaxes(title_text="Erwähnungen", secondary_y=False, color='white', showgrid=False, titlefont=dict(size=20),gridcolor="rgb(228,49,34)")
fig.update_layout(
legend=dict(
title=dict(text="",font=dict(color='white')),
x=.85, y=1.15,
font=dict(
color='white',
size=15
)
)
)
fig.update_traces(line=dict(width=3))
for i in range(0, len(fig.data)):
fig.data[i].hovertemplate = "<b>%{x}</b><br>$%{y:.0f}<extra></extra>"
fig.show()
The Plot created just shows the mentions count on the Y axis. I want to find a way to get a second Y axis representing the Price of the stock. Does anyone know a way to solve my problem?