pythonpandas

Troubleshooting" ValueError: Index Date Invalid"?


I'm learning Python 3.7.4 using IDLE. I am receiving an error saying index date invalid.

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)

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

Below is a sample of the data (It is all in Col A)

Data in CSV File


Solution

  • @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