Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to convert strings (which I have in a list) to datetimes.
I tried this:
import datetime
list = [
'12-October-2014-18:30',
'12-October-2014-19:30',
'12-October-2014-20:00',
'12-October-2014-20:30',
'13-October-2014-00:30',
]
for item in list:
item_time = datetime.datetime.strptime(item, "%m-%B-%Y-%H-%M")
print item_time
but I get this error:
ValueError: time data '12-October-2014-18:30' does not match format '%m-%B-%Y-%H-%M'
I dont see the Error, can somebody help please?
There are two things wrong.
for '%m-%B-%Y-%H-%M', your date should be: '12-October-2014-18-30'
In some you have 12th where it should just be 12 and in all of them you have 18:30 but need it to be 18-30
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
import math
import random
possibility_1=0
possibility_2=0
while True:
list = [0, 1]
number_1=random.choice(list)
number_2=random.choice(list)
number_3=random.choice(list)
number_total=str(number_1)+","+str(number_2)+","+str(number_3)
if number_total==(1,1,0) or number_total==(0,0,1):
possibility_1 +=1
if number_total==(1,1,1) or number_total==(0,0,0):
possibility_2 +=1
print(str(number_total)+" possibility_11= "+ str(possibility_1)+" possibility_12= "+ str(possibility_2))
guys the possibility_1 and possibility_2 doesn!t changing. Please help me I want to make a heads or tails code and simulate it then check the possibilities.
Looks like number_total is a string so the output would be "1,1,0" you are comparing with a tuple. This means the if statements will not be invoked.
if number_total=="1,1,0" or number_total=="0,0,1":
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I have a Dataframe called file, but the column 'Time valid (UTC)' has its data values in the following way: '25-10-2017 03:30' which does not conform with datetime index. Now I tried to correct this date by using
file['Time valid (UTC)']=pd.to_datatime(file['Time valid (UTC)'],format='%d-%m-%Y %H:%M')
However, the following errors pops up
file['Time valid (UTC)']=pd.to_datatime(file['Time valid (UTC)'],format='%d-%m-%Y %H:%M') AttributeError: 'module' object has no attribute 'to_datatime'
Any idead about how to fix this or how to set the datetime correctly at once with pd.DatetimeIndex?
You have to correct the function name to pd.to_datetime()
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
Trying to convert str to date ,e.g '2017-8-27'
my code:
from datetime import datetime as dt
import datetime, collections
date = dt.strptime('2017-8-27', '%Y-%-m-%-d')
But I see the following message:
'-' is a bad directive in format '%Y-%-m-%-d'
And don't understand what is incorrect. How can I solve it?
Thanks in advance,
The % should be followed by a format specifier.
The correct format string is '%Y-%m-%d'
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
In Python 2.7, the function bytearray.fromhex(string) gives:
ValueError: non-hexadecimal number found in fromhex() arg at position x
when the string has '16' in it, like in for example:
0200FF001603000E30D03, 0200FF001603004401A03
It's like failing if it was decimal and was '84102' just for having '10', the base, in it.
How can I avoid that error?
There is no problem with 16 existed in the string, the problem is that you try to encode odd length strings - try any valid string with even length and you will see that it is works.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm trying to sort each string inside a list. For example, if I have the list ['bca', 'fed'] then I want my function to return ['abc', 'def'].
Currently trying to do this like so:
lines = [''.join.(sorted(e)) for e in lines]
What's wrong with this syntax?
Just remove the redundant dot (.):
lines = [''.join(sorted(e)) for e in lines]