0

In data frame there is mixed date format on job_start_time , When I am trying to handle using the below code. It is throwing error

'The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()'

Code is

if frame['Date format'] == "MM/DD/YY":
    frame['Job_Start_Time'] = pd.to_datetime(frame['Job_Start_Time'] , format ='%m/%d/%Y %H:%M:%S %p' )
elif frame['Date format'] == "DD/MM/YY":
    frame['Job_Start_Time'] = pd.to_datetime(frame['Job_Start_Time'] , format ='%d/%m/%Y %H:%M:%S %p' )
else:
    frame['Job_Start_Time'] = pd.to_datetime(frame['Job_Start_Time'] , format ='%Y/%m/%d %H:%M:%S %p' )

Is there any way to fix this? Any lead would be appreciated. Thank you

Sample data on dataframe Sample data on dataframe

Taylor
  • 113
  • 1
  • 1
  • 9
  • You can try `np.select` here – jezrael Jan 20 '20 at 08:11
  • @jezrael I tried to do like below, but when mentioning the choices, So the issue is it will execute here, Can you please help here to solve – Taylor Jan 20 '20 at 08:34
  • 1
    conditions = [ frame['Date_format'] == "MM/DD/YY" , frame['Date_format'] == "DD/MM/YY" ] choices = [pd.to_datetime(frame['Job_Start_Time'] , format ='%m/%d/%Y %H:%M:%S %p' ) , pd.to_datetime(frame['Job_Start_Time'] , format ='%d/%m/%Y %H:%M:%S %p' ) ] frame['Job_Start_Time'] = np.select(conditions , choices ) – Taylor Jan 20 '20 at 08:35
  • @jezrael hey bro why did you mark it as duplicate and closed? This is different issue and I am stuck for the last two days on this problem. I have not found any solution then after only I posted on StackOverflow but you closed this – Taylor Jan 20 '20 at 08:48
  • OK, can you give code to question and add error? Also is possible create [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) ? – jezrael Jan 20 '20 at 08:49
  • [Please don't post images of code/data (or links to them)](http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question) – jezrael Jan 20 '20 at 08:54
  • I already added code and error also on the question – Taylor Jan 20 '20 at 08:57

0 Answers0