error with time data does not match format - python-3.x

I am having this data and try to convert the string date to datetime format. and I have this time data does not match format error.
Date=stock['Trddt'].values
datetime.datetime.strptime(Date[0], "%y.%m.%d")
and it return this error:
ValueError: time data '2015/11/23' does not match format '%y.%m.%d'

Try datetime.datetime.strptime(Date[0], "%Y/%m/%d").
%y matches years without century, but you have years with century, so you need capital %Y.

Related

Excel - How to convert US date string (dd-mmm-yyyy) to European date

How can date in the US format dd-mmm-yyyy be converted to a date in European format.
When importing text based data with US Dates, some dates will import as a date, some import as a string.
A US date like 11-Jun-2021 is equal to NL format, so it will import as a date.
A US date like 11-Oct-2021 should be converted to 10-okt-2021, but it's imported as a string.
Is there a way to convert this string to a date format?
Found something. It's kinda dirty, but it works:
=IF(C3=0;"";IF(IFERROR(FIND("Oct";C3;1);FALSE);REPLACE(C3;FIND("Oct";C3;1);3;"Okt");IF(IFERROR(FIND("May";C3;1);FALSE);REPLACE(C3;FIND("May";C3;1);3;"Mei");IF(IFERROR(FIND("Mar";C3;1);FALSE);REPLACE(C3;FIND("Mar";C3;1);3;"Mrt");C3))))
This works for me in Italian. A3 contains the original date (only 8 months need to be translated):
=IF(ISNUMBER(A3);A3;1*SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A3;"Jan";"GEN");"May";"MAG");"Jun";"GIU");"Jul";"LUG");"Aug";"AGO");"Sep";"SET");"Oct";"OTT");"Dec";"DIC"))

time data does not match format error in robot framework

I am getting following error for datetime in robotframework:
ValueError: time data '1609-38-90 78:55:36.030000' does not match format '%Y-%m-%d %H:%M:%S.%f'
Below is my code:
${lte_epoch_time} Get Current Date result_format=%Y-%m-%d %H:%M:%S.%f
You have the answer in your question itself. '1609-38-90 78:55:36.030000' is not a valid date format. Month can not be 38 and day 90 and hours 78. You need to clean your data set before any preprocessing

Convert timestamp to date results in time out of range error

I`m trying to convert a timestamp to an ISO8601 datetime-string.
E.g.
timestamp_as_iso8601_date=$(date --iso-8601=ns -d #1606982602015489365)
The timestamp is fairly long, with nanoseconds precision, and when I use the full timestamp it returns the following error:
date: time ‘1606982602015489365’ is out of range
The expected result should be: 2020-12-03T09:03:22,015489300+01:00
When I cut the timestamp to this: 1606982612 the error is gone but I loose information!
Is there any way to convert the timestamp without losing the milliseconds information?
Insert a comma:
date --iso-8601=ns -d #1606982602.015489365

Python 3 Pandas Timestamp Date Parse

I have some time series data from an API request and when I am doing some data wrangling this error pops up below. The data wrangling is just some simple Pandas series math (not shown).
TypeError: unsupported operand type(s) for -: 'str' and 'str'
But when I save the data to a CSV:
elecMeter_df.to_csv('C:\\Python Scripts\\elecMeter_df.csv', sep=',', header=True, index=True, na_rep='N/A')
And then parse the dates on a read_CSV:
elecMeter_dfCSV = pd.read_csv('C:\\Python Scripts\\elecMeter_df.csv', index_col='Date', parse_dates=True)
I do not get the original error described above.. Why is that? Am I getting the error because the time stamp is a string and I need to convert into an integer format?
When I get the error, the index is in this format:
print(elecMeter_df.index)
But when read the CSV file and Parse the date column (No error in the data wrangling processes, the index is in this format: (no Chicago Time zone reference)
print(elecMeter_df.index)
Any help/tips that can be explained to me about time stamps and why this error happens would be greatly appreciated. Utilimetely I am trying to not have to use the read/write CSV process, but if its the only method to not get any errors Ill just stick with that!
Not sure what code you are running to generate that error. However the time stamp probably needs to be converted from a string to a date time. Try using pd.to_datetime, additionally you can specify the format (list of options and meanings are provided below). The example I used for the format is year-month-day hour-minutes.
pd.to_datetime(df['column'], format = %Y-%m-%d %H:%M)
%a Locale’s abbreviated weekday name.
%A Locale’s full weekday name.
%b Locale’s abbreviated month name.
%B Locale’s full month name.
%c Locale’s appropriate date and time representation.
%d Day of the month as a decimal number [01,31].
%f Microsecond as a decimal number [0,999999], zero-padded on the left
%H Hour (24-hour clock) as a decimal number [00,23].
%I Hour (12-hour clock) as a decimal number [01,12].
%j Day of the year as a decimal number [001,366].
%m Month as a decimal number [01,12].
%M Minute as a decimal number [00,59].
%p Locale’s equivalent of either AM or PM.
%S Second as a decimal number [00,61].
%U Week number of the year (Sunday as the first day of the week)
%w Weekday as a decimal number [0(Sunday),6].
%W Week number of the year (Monday as the first day of the week)
%x Locale’s appropriate date representation.
%X Locale’s appropriate time representation.
%y Year without century as a decimal number [00,99].
%Y Year with century as a decimal number.
%z UTC offset in the form +HHMM or -HHMM.
%Z Time zone name (empty string if the object is naive).
%% A literal '%' character.

Cannot convert string to date in R [duplicate]

This question already has answers here:
What are the "standard unambiguous date" formats for string-to-date conversion in R?
(8 answers)
Closed 9 years ago.
I need your help to figure out the following problem-
I am trying to convert a date column from string to actual date format. I have tried using as.Date
However, it is showing an error message:
Error in charToDate(x) :
character string is not in a standard unambiguous format
the date column I have in csv file is like this:
Date
03/17/2003
05/31/2003
09/06/2003
10/18/2003
07/15/2003
09/19/2003
The problem is some of the dates are in string and some are in actual date format. I have tried to format it from excel - didn't work
Tried to copy and paste it to notepad and then import it again - didn't work either.
You need to learn about the help system in R. One brief look at help(as.Date) may have told you about the format argument:
R> dt <- c("03/17/2003", "05/31/2003", "09/06/2003")
R> as.Date(dt, "%m/%d/%Y")
[1] "2003-03-17" "2003-05-31" "2003-09-06"
R>
Edit: These days we also have a helper package that does the format-finding for you:
> dt <- c("03/17/2003", "05/31/2003", "09/06/2003")
> anytime::anydate(dt)
[1] "2003-03-17" "2003-05-31" "2003-09-06"
>
This works for datetimes (using anytime()) and dates.

Resources