故障排除"值错误:索引日期无效"? [英] Troubleshooting" ValueError: Index Date Invalid"?
问题描述
我正在使用 IDLE 学习 Python 3.7.4.我收到一条错误消息,指出索引日期无效.
I'm learning Python 3.7.4 using IDLE. I am receiving an error saying index date invalid.
我已经成功地使用了我用日期和格式格式化的 excel 文件.单个列 (A-C) 中的数据,但这是一个 csv 文件,所有数据都在一个列中,用逗号分隔.在格式化数据的格式中,我将使用以下...
I've had success using excel files that i've formatted with dates & data in individual col's (A-C) but this is a csv file with all the data in one col separated by commas. In the format with the data formatted i would use the below...
ANTM = pd.read_csv(r'C:\..\ANTM_stock'.csv', parse_dates= True, index_col=0)
我很确定 parse_dates=True, index_col=0 表示查看第一个 col &将它们解释为日期.这工作正常.
I'm pretty sure the parse_dates=True, index_col=0 is indicating look at the first col & interpret them as dates. This works fine.
#Markowitz efficient frontier
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pandas_datareader.data as web
companies = ['WMT','FB']
df = pd.read_csv(r'C:\...\Walmart_FB_2014_2017.csv', index_col='Date')
df.head()
我希望看到包含一些数据的表格,但收到以下错误.
I expected to see a table with some data instead i received the error below.
ValueError: Index Date invalid
以下是数据样本(全部在Col A中)
Below is a sample of the data (It is all in Col A)
推荐答案
@xzcvb33 你的代码对我来说运行良好.如果您尝试读取 csv 而不指定索引列 df = pd.read_csv("...2017.csv") 然后将索引设置为Date" df.set_index("Date") 会发生什么?– 汤姆昨天
@xzcvb33 Your code runs fine for me. What happens if you try and read the csv without specifying the index column df = pd.read_csv("...2017.csv") and then setting the index to be "Date" df.set_index("Date")? – Tom yesterday
这篇关于故障排除"值错误:索引日期无效"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!