-1

I had a data in which it has only Date(yyyy-mm-dd) and time(hh.mm). I am getting an error for datetime format does not match.

I want to convert my existing data into standard format using python(Pandas) library.Please give a proper solution for it.

data = btfeeds.GenericCSVData( dataname='2017 BNF.csv',

fromdate=datetime.datetime(2017, 4, 3),
todate=datetime.datetime(2017, 4, 10),

nullvalue=0.0,

dtformat=('%Y-%m-%d'),
tmformat=('%H:%M'),

datetime=0,
time=1,
open=2,
high=3,
low=4,
close=5,
openinterest=-1

) ValueError: time data '2017-01-02T10' does not match format '%Y-%m-%dT%H:%M'

Input(csv) : 2017-01-02,09:08
Expected output:2017-01-02 09:08:00+05:30

meet4288
  • 1
  • 1
  • 2
    Which error? on which input? You need to provide enough details to reproduce your issue to help you and also make your question useful for future readers. – mozway Mar 28 '22 at 07:42
  • Sample input and expected output would help. – Manjunath K Mayya Mar 28 '22 at 08:26
  • Can you edit your question to give some sample code, input, expected output and the exact error message? You have given the error in a comment, but if you could add it, and what produces this error, to the body of your question. See [ask]. – Steve Mar 28 '22 at 09:00

1 Answers1

1

This is because the format you need to ask for does not contain seconds.

  1. correct format: %Y-%m-%dT%H:%M
  2. incorrect format: %Y-%m-%dT%H:%M:S

So this would work:

import datetime as dt
x =  '2017-01-02T09:08'

datetime_object = dt.datetime.strptime(x, '%Y-%m-%dT%H:%M')

print(datetime_object)

And the result (of the print statement) would be this:

2017-01-02 09:08:00
D.L
  • 4,339
  • 5
  • 22
  • 45