tushare获取股票数据excel
时间: 2023-12-04 14:05:16 浏览: 81
作为AI语言模型,我无法在本地提供tushare获取股票数据excel的代码。不过,你可以在tushare官方文档中查看如何使用tushare获取股票数据并将其保存为excel文件。以下是一个简单的示例:
```python
import tushare as ts
# 获取股票数据
data = ts.get_hist_data('600036', start='2021-01-01', end='2021-12-31')
# 将数据保存为excel文件
data.to_excel('600036.xlsx')
```
这个例子用tushare库获取了中国平安(股票代码为600036)从2021年1月1日到2021年12月31日的历史数据,并将其保存为名为“600036.xlsx”的excel文件。你可以根据自己的需要调整代码中的股票代码和日期范围。
相关问题
tushare数据python导出excel
您好!非常感谢您对ChitGPT的使用。关于您的问题,您可以通过以下代码使用tushare库将数据导出为Excel文件:
``` python
import tushare as ts
import pandas as pd
# 获取股票数据
df = ts.get_hist_data('600519',start='2021-01-01',end='2021-12-31')
# 将数据写入Excel文件
df.to_excel('stock_data.xlsx')
```
这里我们通过tushare获取了茅台股票(股票代码为600519)从2021年1月1日到2021年12月31日的历史交易数据,并将数据写入名为“stock_data.xlsx”的Excel文件中。
希望这个回答能够帮到您,如还有其他问题,请继续提问。
从tushare网站获取000893股票的数据,积分只有2100的情况下,并保存在Excel中的代码是
以下是从tushare网站获取000893股票数据,并保存在Excel中的Python代码:
```python
import tushare as ts
# 设置token
ts.set_token('你的token')
# 初始化pro接口
pro = ts.pro_api()
# 获取000893股票的历史数据
df = pro.daily(ts_code='000893.SZ')
# 保存数据至Excel
df.to_excel('000893.xlsx', index=False)
```
请注意,你需要将代码中的`你的token`替换为你在tushare网站上申请的token,才能正常运行代码。此外,你还需要安装`tushare`库和`pandas`库,如果没有安装,可以使用以下命令进行安装:
```
pip install tushare pandas
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)