英文:
want to change the value of variable using list in loop python
问题
以下是翻译好的代码部分:
symbols = ["NIFTY", "ITC", "BBC", ....etc]
from tvDatafeed import TvDatafeed, Interval
tv = TvDatafeed()
tv = TvDatafeed(username, password, chromedriver_path=None)
tv = TvDatafeed(auto_login=true)
nifty_data = tv.get_hist(symbol='NIFTY', exchange='NSE', interval=Interval.in_1_hour, n_bars=1)
print(nifty_index_data)
#result will be like this in pandas>>>>>>>
| datetime | symbol | open | high | low | close | volume |
| --- | --- | --- | --- | --- | --- | --- |
| 2023-07-20 08:45:00 | NSE:NIFTY | 19943.15 | 19991.85 | 19935.45 | 19987.05 | 60215122.0 |
There is around 1060 stocks/symbols and we have to run script again-again to scrap different data for different symbols like this \>\>\>
# nifty
nifty_data = tv.get_hist(symbol='NIFTY', exchange='NSE', interval=Interval.in_1_hour, n_bars=1)
# ITC
ITC_data = tv.get_hist(symbol='ITC', exchange='NSE', interval=Interval.in_1_hour, n_bars=1)
# RELIANCE
RELIANCE_data = tv.get_hist(symbol='RELIANC', exchange='NSE', interval=Interval.in_1_hour, n_bars=1)
print(nifty_data)
print(ITC_data)
print(RELIANCE_data)
#this will return 3 different tables
#i need data in 1 datafame
需要注意的是,代码中的库和变量名没有进行中文翻译,因为您要求只翻译代码部分,不要有其他内容。
英文:
symbols = ["NIFTY", "ITC", "BBC", ....etc]
from tvDatafeed import TvDatafeed, Interval
tv = TvDatafeed()
tv = TvDatafeed(username, password, chromedriver_path=None)
tv = TvDatafeed(auto_login=true)
nifty_data = tv.get_hist(symbol='NIFTY',exchange='NSE',interval=Interval.in_1_hour,n_bars=1)
print(nifty_index_data)
#result will be like this in pandas>>>>>>>
datetime | symbol | open | high | low | close | volume |
---|---|---|---|---|---|---|
2023-07-20 08:45:00 | NSE:NIFTY | 19943.15 | 19991.85 | 19935.45 | 19987.05 | 60215122.0 |
There is around 1060 stocks/symbols and we have to run script again-again to scrap different data for different symbols like this >>>
# nifty
nifty_data = tv.get_hist(symbol='NIFTY',exchange='NSE',interval=Interval.in_1_hour,n_bars=1)
# ITC
ITC_data = tv.get_hist(symbol='ITC',exchange='NSE',interval=Interval.in_1_hour,n_bars=1)
# RELIANCE
RELIANCE_data = tv.get_hist(symbol='RELIANC',exchange='NSE',interval=Interval.in_1_hour,n_bars=1)
print(nifty_data)
print(ITC_data)
print(RELIANCE_data)
#this will return 3 different tables
#i need data in 1 datafame
I need all symbol data in one data frame like this>>>
datetime | symbol | open | high | low | close | volume |
---|---|---|---|---|---|---|
2023-07-20 03:45:00 | NSE:BORORENEW | 474.50 | 485.00 | 473.45 | 483.75 | 89517.0 |
2023-07-20 03:45:00 | NSE:NIFTY | 19841.15 | 19844.00 | 19784.55 | 19813.35 | 19934954.0 |
AND I ALSO DONT WAN'T TO RUN SCRIPT AGAIN-AGAIN BY CHANGING SYMBOL NAME
PLESE HELP THIS IS MY FIRST INTERVIEW PRESENTATION
**LIBARRY THAT I USED>>>TVDATAFEED **
答案1
得分: 1
以下是翻译好的部分:
import pandas as pd
symbols = ["NIFTY", "ITC", "RELIANC"]
result = pd.concat([tv.get_hist(symbol=symbol, exchange='NSE', interval=Interval.in_1_hour, n_bars=1) for symbol in symbols])
英文:
Something like this should work:
import pandas as pd
symbols = ["NIFTY", "ITC", "RELIANC"]
result = pd.concat([tv.get_hist(symbol=symbol,exchange='NSE',interval=Interval.in_1_hour,n_bars=1) for symbol in symbols])
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论