Error: `raise ValueError( ValueError: Missing column provided to 'parse_dates': 'Date'

I am using a .csv with two columns. The first has dates and the second has temperatures. I would like to plot it with dates on the x-axis and temperatures on the y-axis.

I used this command:

dataset = pandas.read_csv('/home/UbuntuUser/Desktop/mesurements.csv', 
          usecols=[1], engine='python', skipfooter=3, index_col=['Date'],
          parse_dates=['Date'])

but I got the error:

Error: raise ValueError(
ValueError: Missing column provided to 'parse_dates': 'Date'

Any ideas why? From searching, I found this suggestion, that does not help me.

Update:

Part of the code is from here:

import numpy as np
import matplotlib.pyplot as plt
from scipy.fftpack import fft, ifft
import pandas as pd

# Import csv file
df = pd.read_csv('rsam_2016-17_fft_test.csv', index_col=['DateTime'], parse_dates=['DateTime'])
print(df.head())

#plot data
plt.figure(figsize=(12,4))
df.plot(linestyle = '', marker = '*', color='r')
plt.savefig('rsam_2016_2017_snippetforfft.jpg')
plt.show()

Source

Topic csv pandas python

Category Data Science


The problem is that you are setting the Date column as index the same time you are parsing it. Once it is set as the index, this is not a column anymore (but the index) so the parse_dates does not find any column name Date

Try this:

dataset = pandas.read_csv('/home/UbuntuUser/Desktop/mesurements.csv', 
          engine='python', skipfooter=3,
          parse_dates=['Date'])

dataset.set_index('Date', inplace = True)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.