I'm trying to backtest a simple strategy of mine and the first step is to retrieve historical data from yfinance. However, whenver I run this, I can't see the contents of hist. Instead, it just has this outputthis output
# import all the libraries
import nsetools as ns
import pandas as pd
import numpy
from datetime import datetime
import yfinance as yf
import matplotlib.pyplot as plot
plot.style.use('classic')
a = input("Enter the ticker name you wish to apply strategy to")
ticker = yf.Ticker(a)
hist = ticker.history(period="1mo", interval="5m")
hist
I really just want to see the historical prices against the time but can't get the dataframe to appear. I would appreciate any input on this.
Related
i have the following quastion-
What can you tell about the relationship between time and speed? Is there a best time of day to connect? Has it changed throughout the years?
this is my dataframedataframe
my columns
data
does any one have any suggestion on how i would aprouch this question ?
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
df = pd.read_csv('/Users/dimagoroh/Desktop/data_vis/big_file.csv', low_memory=False)
sns.lmplot(x="hours",y="speed",data=df)
im trying to do a plot but get this error i think i need to manipulate the hour column to a diffrent data type right now it is set as object
Please post the error you get. From the data I think you need to pass x="hour" and not x="hours". Also try
df.hour = pd.to_datetime(df.hour)
I'm trying to plot a figure on Python but I get a KeyError. I can't read the column "Cost per Genome" for some reason.
Here is my code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv("Sequencing_Cost_Data_Table_Aug2021 - Data Table.csv") #The data can be found here: https://docs.google.com/spreadsheets/d/1auLPEnAp0aI__zIyK9fKBAkLpwQpOFBx9qOWgJoh0xY/edit#gid=729639239
fig = plt.figure()
plt.plot(data["Date"],data["Cost per Genome"])
It looks like either you have interpreted the data wrong into the Dataframe, of made an error with the plot. Read this. It might help you further: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
P.S. I couldn't acces your spreadsheet. It was request only
Not sure how to resolve this error
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import nba_api
from nba_api.stats.endpoints import leagueleaders
stats = leagueleaders.LeagueLeaders(season='2017-18')
df17 = stats.get_data_frames()
df17.head()
'list' object has no attribute 'head'
Based on the error, it looks like the API you're using is giving you the data in the form of a standard list object, not as a pandas data frame. You'll need to wrap the data inside the list obtained from the API inside a pandas data frame.
I am currently trying to extract stock prices from a list of stock codes contained on a csv file by using pandas and yfinance.
I have 145 companies I need to do this for, is there a way of doing it? As I have tried over a period of 5 days without success.
I just need to know if its possible and what would you recommend to achieve this.
yfinance.Ticker(ticker).history(start=start_date) gets you the data that you desire.
if you have a giant csv, with a field "ticker", you can create a pandas dataframe with the below:
import pandas as pd
import yfinance
def read_create_giant_df(file_in):
df = pd.read_csv(file_in)
out = []
for item in df["ticker"]:
ticker_df = yfinance.Ticker(item).history(start="1930-01-01")
ticker_df["ticker"] = item
out.append(ticker_df)
return pd.concat(out)
below code should work , if any module missing use command to install it .
pip install yfinance
pip install yahoofinancials
Run below code to get the data for Amazon-AMZN
import pandas as pd
import yfinance as yf
from yahoofinancials import YahooFinancials
amzn_df = yf.download('AMZN',
start='2019-01-01',
end='2019-12-31',
progress=False)
amzn_df.head()
I want to pull ticker data from the all the sp500 stocks from yahoo.
I saved the sp500 ticker symbols into a list from a local csv file that I made.
When when I run the following code, I get the:
ValueError 'Index contains duplicate entries, cannot reshape'
However, I noticed that this problem doesn't seem to occur with shorter stock lists but can't figure why; some help would be fully appreciated.
import pandas as pd
import numpy as np
from pandas_datareader import data
from statsmodels.tsa.stattools import coint
import matplotlib.pyplot as plt
from pyfinance.ols import PandasRollingOLS
sp500=pd.read_csv('sp500 stocks list.csv')
sp500_list=[]
for i in sp500:
sp500_list.append(i)
dataframe=data.DataReader(sp500_list, 'yahoo',start='2020/01/01')
print(dataframe)
I have tried dataframe = dataframe.drop_duplicates(sp500_list) however i still gives me the same ValueError