我试图分别从所有符号的所有信息中dataframes
。即df_ACC
,df_SBIN
等。将这些dataframes
写入excel
,在单独的sheets
中根据所使用的符号命名工作表。
从以下代码生成的文件只是获取最后一个dataframe
,即JUSTDIAL
。虽然我找不到dataframes
以外的df_name
,而且只有df_JUSTDIAL
而不是start_time = time.time()
#The solution to second problem I listed
path = r"C:\Users\xxx\OneDrive\Data\Fut Data"
opt_fut_excel_file = r'\fo_data_' + str(datetime.date.today()) + ".xlsx"
f_path = path+opt_fut_excel_file
writer = pd.ExcelWriter(f_path, engine='xlsxwriter')
fut_data.to_excel(writer,sheet_name='futures', index=False)
#Please add writer.save() at the point where writing to excel is finished.
symbols = ['ACC','SBIN','PNB','JUSTDIAL']
for symbol in symbols:
print(symbol)
opt_url1 = 'https://www.nseindia.com/marketinfo/companyTracker/mtOptionKeys.jsp?companySymbol='
opt_url3 = '&indexSymbol=NIFTY&series=EQ&instrument=OPTSTK&date=-'
url = opt_url1 + symbol + opt_url3
raw_page = requests.get(url).text
soup = bs(raw_page, "lxml")
if len(raw_page) > 0:
print(symbol + str(len(raw_page)))
table = soup.findAll('table')[1]
test_tab = []
for row in table.findAll('tr'):
test_tab.append(([tr.text for tr in row.findAll('td')]))
# print(len(test_tab))
try:
del test_tab[0]
del test_tab[0]
del test_tab[0]
del test_tab[0]
del test_tab[0]
del test_tab[0]
del test_tab[0]
del test_tab[0]
del test_tab[0]
column_names = test_tab[0]
del test_tab[0]
# df_name = 'df_' + symbol
# print(df_name)
# df_name = pd.DataFrame(test_tab,columns=column_names)
# opt_fut_excel_file = 'fo_data_' + str(datetime.date.today()) + ".xlsx"
# df_name.to_excel(opt_fut_excel_file, sheet_name=symbol)
except:
print("There was an exception in list del with symbol " + symbol)
pass
df_name = 'df_' + symbol
print(df_name)
df_name = pd.DataFrame(test_tab, columns=column_names)
#print(df_name)
#opt_fut_excel_file = 'fo_data_' + str(datetime.date.today()) + ".xlsx"
df_name.to_excel(writer, sheet_name=symbol)
raw_page = 0
#Solution to second problem, this line needs to be there for the file to be saved
writer.save()
print("--- %s seconds ---" % (time.time() - start_time))
这是我的意图。
dataframes
----我认为这个问题不是重复的,因为-----
双重问题如下:
1-为什么上面的代码没有生成具有不同名称的多个dotesting = () => {
const j = Object.keys(this.state.data);
var journalEntries = [];
for (var i = 0; i < j.length; i++){
journalEntries.push(
<div>
<h3>{j[i].fieldData.toString()}</h3>
</div>);
}
console.log(<div>{journalEntries}</div>)
return(<div>{journalEntries}</div>);
}
?
2-已解决 - 为什么在生成最后一张纸时没有创建纸张? @JonClements评论让我得到了答案。我已经更新了问题和代码以反映相同的内容。