最近系统更新后原先安装的TensorFlow和jupyter notebook都没了
1.Anaconda的下载
C:\Users\liqin\anaconda3
2. create a new virtual Python environment
conda create -n tensorflow python=3.8 -y
type command: conda info --envs
4. install tensorflow
conda activate tensorflow
pip install tensorflow
5. ipykernel
pip install ipykernel
To make the new tensorflow environment visible within Jupyter, run the following code:ts11_pmdarima_edgecolor_bokeh plotly_Prophet_Fourier_VAR_endog exog_Granger causality_IRF_Garch vola_layout.xaxis.rangebreaks-优快云博客
python -m ipykernel install --name tensorflow --display-name "tensorflow"
python -m ipykernel install --name tensorflow --display-name "tensorflow"
6. conda install jupyter notebook
conda install jupyter notebook
Put all jupyter notebook together
OR you can copy a shortcut from other jupyter notebook then rename:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)
C:\Users\liqin\anaconda3\python.exe C:\Users\liqin\anaconda3\cwp.py C:\Users\liqin\anaconda3\envs\tensorflow C:\Users\liqin\anaconda3\envs\tensorflow\python.exe C:\Users\liqin\anaconda3\envs\tensorflow\Scripts\jupyter-notebook-script.py %USERPROFILE%
C:\Users\liqin\anaconda3\python.exe C:\Users\liqin\anaconda3\cwp.py C:\Users\liqin\anaconda3\envs\tensorflow C:\Users\liqin\anaconda3\envs\tensorflow\python.exe C:\Users\liqin\anaconda3\envs\tensorflow\Scripts\jupyter-notebook-script.py %USERPROFILE%
Show Line Numbers
7.update pip if you need
python -m pip install -U pip
8.python -m pip install -U matplotlib
python -m pip install -U matplotlib
9. pip install plotly
pip install plotly
10. pip install pandas_datareader
pip install pandas_datareader
11. pip install yfinance
pip install yfinance
虽然正确安装了但是Jupyter不能用
import yfinance as yf
logger.error(f"Failed to get screener data for '{self._body.get('query', "query not set")}' reason: {e}") ^ SyntaxError: invalid syntax
conda install conda-forge::yfinance
链接问题
再次运行
conda install conda-forge::yfinance
stack Ticker in the MultiIndex for dropping Ticker columns
import yfinance as yf
stock_symbol='ADTN' #ADTRAN Inc
start_date='2008-02-15'
new_start_date = pd.to_datetime('2007-04-18')
new_end_date = '2008-04-16'
df = yf.download( stock_symbol, start=new_start_date, end=new_end_date)
df
小细节出现了Ticker这一行
vs
按level=0堆叠就是按Price进行堆叠
import yfinance as yf
stock_symbol='ADTN' #ADTRAN Inc
start_date='2008-02-15'
new_start_date = pd.to_datetime('2007-04-18')
new_end_date = '2008-04-16'
df = yf.download( [stock_symbol], start=new_start_date, end=new_end_date)
# Transform the DataFrame: stack the ticker symbols to create a multi-index (Date, Ticker),
# then reset the 'Ticker' level to turn it into a column
df = df.stack(level=1)#.rename_axis(['Date', 'Ticker']).reset_index(level=1)
#df.drop(columns='Ticker', inplace=True)
df
Level(s) to stack from the column axis onto the index axis, defined as one index or label, or a list of indices or labels.
从列轴堆叠到索引轴上的级别,定义为一个索引或标签,或者索引或标签的列表。
按level=1堆叠就是按Ticker进行堆叠
import yfinance as yf
stock_symbol='ADTN' #ADTRAN Inc
start_date='2008-02-15'
new_start_date = pd.to_datetime('2007-04-18')
new_end_date = '2008-04-16'
df = yf.download( [stock_symbol], start=new_start_date, end=new_end_date)
# Transform the DataFrame: stack the ticker symbols to create a multi-index (Date, Ticker),
# then reset the 'Ticker' level to turn it into a column
#df = df.stack(level=1).rename_axis(['Date', 'Ticker']).reset_index(level=1)
#OR
df = df.stack(level=1).reset_index(level=1)
#df.drop(columns='Ticker', inplace=True)
df
import yfinance as yf
stock_symbol='ADTN' #ADTRAN Inc
start_date='2008-02-15'
new_start_date = pd.to_datetime('2007-04-18')
new_end_date = '2008-04-16'
df = yf.download( [stock_symbol], start=new_start_date, end=new_end_date)
# Transform the DataFrame: stack the ticker symbols to create a multi-index (Date, Ticker),
# then reset the 'Ticker' level to turn it into a column
#df = df.stack(level=1).rename_axis(['Date', 'Ticker']).reset_index(level=1)
df = df.stack(level=1).reset_index(level=1)
df.drop(columns='Ticker', inplace=True)
df.columns.name=''###
df
DatetimeIndex to short Date
import yfinance as yf
stock_symbol='ADTN' #ADTRAN Inc
start_date='2008-02-15'
new_start_date = pd.to_datetime('2007-04-18')
new_end_date = '2008-04-16'
df = yf.download( [stock_symbol], start=new_start_date, end=new_end_date)
# Transform the DataFrame: stack the ticker symbols to create a multi-index (Date, Ticker),
# then reset the 'Ticker' level to turn it into a column
#df = df.stack(level=1).rename_axis(['Date', 'Ticker']).reset_index(level=1)
df = df.stack(level=1).reset_index(level=1)
df.drop(columns='Ticker', inplace=True)
df.columns.name=''
#df['Date'] = df['Date'].dt.strftime('%Y-%m-%d')
df.index=df.index.strftime('%Y-%m-%d')
df
不对,我们需要让dae保持为DateTimeIndex
import yfinance as yf
stock_symbol='ADTN' #ADTRAN Inc
start_date='2008-02-15'
new_start_date = pd.to_datetime('2007-04-18')
new_end_date = '2008-04-16'
df = yf.download( [stock_symbol], start=new_start_date, end=new_end_date)
# Transform the DataFrame: stack the ticker symbols to create a multi-index (Date, Ticker),
# then reset the 'Ticker' level to turn it into a column
#df = df.stack(level=1).rename_axis(['Date', 'Ticker']).reset_index(level=1)
df = df.stack(level=1).reset_index(level=1)
df.drop(columns='Ticker', inplace=True)
df.columns.name=''
#df['Date'] = df['Date'].dt.strftime('%Y-%m-%d')
#df.index=df.index.strftime('%Y-%m-%d')
df.index=pd.to_datetime(df.index.date)
df
multi_level_index: bool : Default is True
Optional. Always return a MultiIndex DataFrame? Default is True
import yfinance as yf
stock_symbol='ADTN' #ADTRAN Inc
start_date='2008-02-15'
new_start_date = pd.to_datetime('2007-04-18')
new_end_date = '2008-04-16'
df = yf.download( [stock_symbol], start=new_start_date, end=new_end_date, multi_level_index=False)
df