Home > Net >  I can't read date without time from CSV using pandas
I can't read date without time from CSV using pandas

Time:11-17

I have this dataframe:

forecasts
Out[15]: 
             timestamp         1            2          
0  2022-11-08 12:12:15         5679.658691  5400.217773  
1  2022-11-08 12:38:49         5679.658691  5400.217773  
2  2022-11-09 11:05:53         5863.616699  5619.101562  
3  2022-11-10 10:46:27         6047.025391  5714.026367  
4  2022-11-11 11:59:29         6147.197754  5750.312988  
5  2022-11-12 11:56:45         6008.574707  5775.820312  

And I'm trying to get the forecasts on a specific date without including the hour:

forecasts = forecasts[forecasts['timestamp'] == pd.Timestamp(str(2022)   '-'   str(11)   '-'   str(11))]

to read this date:

2022-11-11 11:59:29

But I receive an empty dataframe. How can I fix that?

CodePudding user response:

you can use:

forecasts = forecasts[forecasts['timestamp'].dt.strftime('%Y-%m-%d') == '2022-11-11']
#or
forecasts = forecasts[forecasts['timestamp'].dt.strftime('%Y-%m-%d') == (str(2022)   '-'   str(11)   '-'   str(11))]

  • Related