Home > Net >  ValueError: Missing column provided to 'parse_dates': 'Time'
ValueError: Missing column provided to 'parse_dates': 'Time'

Time:12-31

image of parse_dates error

As is hopefully clear from the image i've inserted, I'm running into an issue when I attempt to parse_dates. The first read_csv is done without, and the .head shows that there is clearly a Date and Time column. But when I attempt to parse them, I'm getting a missing column 'Time' error. I don't understand why this is happening. thank you

CodePudding user response:

After doing some testing, I stand corrected about my previous comment.
The correct command is simply:

df = pd.read_csv(file_name, parse_dates=['Date', 'Time'])

Note the differences between your line and this line, don't use an embedded list Which yields a dataframe like the following:

Date    Time    Open    High    Low Close   Volume
0   2022-10-07  2022-12-30 16:52:00 0.9746  0.9746  0.9735  0.9744  290
1   2022-10-07  2022-12-30 16:54:00 0.9749  0.9749  0.9744  0.9743  285
2   2022-10-07  2022-12-30 16:55:00 0.9760  0.9760  0.9755  0.9754  279
3   2022-10-07  2022-12-30 16:56:00 0.9772  0.9772  0.9762  0.9760  295

where the dataframe columns take the form:

0   Date    4 non-null      datetime64[ns]
 1   Time    4 non-null      datetime64[ns]
 2   Open    4 non-null      float64       
 3   High    4 non-null      float64       
 4   Low     4 non-null      float64       
 5   Close   4 non-null      float64       
 6   Volume  4 non-null      int64      

CodePudding user response:

there was a space in front of Time.

  • Related