python - 在 python 代码中获取属性错误
解决方案
Date 列已经是索引列,不是吗?如果您想尝试,您可以重置索引列并再次设置它。你会得到同样的结果。
但是,如果要修改 Date 列,可以通过重置索引列、修改它,然后将其设置回索引来完成。
import pandas as pd
import pandas_datareader as web
df = web.DataReader('^BSESN', data_source='yahoo', start='2015-07-16', end='2020-07-16')
df.reset_index(level=0, inplace=True)
# If you want to modify your index column, you can do it here.
df['Date'] = pd.to_datetime(df.Date, format='%Y-%m-%d')
df.index = df['Date']
df.drop('Date', axis=1, inplace=True)
df
推荐阅读
- sql - SQL 对 DB2 中的两个不同列进行排序
- php - 在 SELECT 语句中插入变量
- sql - Excel VBA 中的 SQL 查询以从 Access 中提取信息
- angular - Angular 7:发布请求总是发送一个空正文
- java - 在函数内的随机线上添加切入点
- sql-server - 消息 102,级别 15,状态 1,第 1 行 ',' 附近的语法不正确
- bash - 如何在 Bash 脚本中使用 sed 更改字符串
- alexa - 两个 Alexa 技能可以具有相同的调用名称吗?
- alexa - Alexa - 在调用技能内部路由后立即使用插槽
- python - 如何在没有换行符的情况下编写数组的最终索引?