tickers = "GNA.BO PDMJEPAPER.BO MEGH.BO REFEX.BO GULPOLY.BO TRIVENI.BO TCI.BO NUCLEUS.BO
SHILPAMED.BO JUBILANT6.BO TITANBIO.BO INDOBORAX.BO POLYPLEX.BO MAZDALTD.BO KSE.BO RAJGLOWIR.BO
MANORG.BO TATAMETALI.BO HIL.BO BAJAJST.BO TINPLATE.BO SESHAPAPER.BO DECCANCE.BO GESHIP.BO
ESTER.BO DIAMINESQ.BO DENORA.BO UNICK.BO LASA.BO APLLTD.BO BESGALASM.BO KPRMILL.BO
INSECTICID.BO SAREGAMA.BO WELCORP.BO KRITIIND.BO PRECWIRE.BO UNIDT.BO RACLGEAR.BO FINOLEXIND.BO
CEATLTD.BO NATPEROX.BO BEPL.BO KNRCON.BO DAAWAT.BO DCBBANK.BO FIEMIND.BO VOLTAMP.BO ZENTEC.BO K
EC.BO NAVINFLUOR.BO BALAJITELE.BO INDNIPPON.BO GMDCLTD.BO POLYMED.BO VIKRAMTH.BO SEAMECLTD.BO
IPCALAB.BO PLASTIBLEN.BO ICIL.BO JBCHEPHARM.BO TRANSPEK.BO PHILIPCARB.BO FERMENTA.BO
DHARAMSI.BO INDIANHUME.BO HFCL.BO METROGLOBL.BO OAL.BO PRICOLLTD.BO HGS.BO RTSPOWR.BO TIGLOB.BO
MIRZAINT.BO HMVL.BO CGVAK.BO DHPIND.BO WPIL.BO MALLCOM.BO VIJSOLX.BO RUBFILA.BO ASAHISONG.BO
HINDCOMPOS.BO CONTROLPR.BO EVERESTIND.BO PIXXTRANS.BO APCL.BO LGBBROSLTD.BO AMRUTANJAN.BO
GSFC.BO PNBHOUSING.BO RVNL.BO IRCON.BO HATHWAY.BO MAHSEAMLES.BO GMRINFRA.BO AMBIKCO.BO CCL.BO
MINDAIND.BO RAMCOIND.BO TNPETRO.BO PCJEWELLER.BO AHLEAST.BO SHARDA.BO ",
import yfinance as yf
import pandas as pd
tickerlist = tickers
df_list = list()
for tick in tickerlist:
data = yf.download(tick, period='1d', threads='true')
data.drop(['Open','High','Low','Volume','Adj Close'], inplace=True, axis=1)
data = data.copy()
data['ticker'] = tick
df_list.append(data)
df = pd.concat(df_list)
df = df.T
# save to csv
df.to_csv('ticker.csv', header=True, index=True)
print(df_list)
生成的csv文件有[1行x 105列]]生成的文件映像我不想对它进行转置因为我想在之后的列之间进行计算这会让它变得更困难?
对于长格式的数据收集,我认为很容易准备一个空数据帧,按顺序获取股票数据,并将其添加到空数据帧中。
import yfinance as yf
import pandas as pd
tickers = "GNA.BO PDMJEPAPER.BO MEGH.BO REFEX.BO GULPOLY.BO TRIVENI.BO TCI.BO NUCLEUS.BO"
tickerlist = tickers.split(' ')
df_list = pd.DataFrame()
for tick in tickerlist:
data = yf.download(tick, period='1d', threads='true')['Close'].to_frame()
data['ticker'] = tick
data.reset_index(inplace=True)
df_list = df_list.append(data, ignore_index=True)
print(df_list)
Date Close ticker
0 2021-08-10 680.500000 GNA.BO
1 2021-08-10 41.650002 PDMJEPAPER.BO
2 2021-08-10 130.000000 REFEX.BO
3 2021-08-10 246.699997 GULPOLY.BO
4 2021-08-10 165.500000 TRIVENI.BO
5 2021-08-10 428.450012 TCI.BO
6 2021-08-10 680.000000 NUCLEUS.BO