I have the date and time in a cell. Where all the dates with time are merged together. I want to split that and get the output of the first date and time, as expected output below in Excel
Current output :
28/Sep/2020 08:29/Sep/2020 13:32
28/Sep/2020 11:129/Sep/2020 13:19
30/Sep/2020 08:01/Oct/2020 12:29
Expected output:
28/Sep/2020 08:29
28/Sep/2020 11:12
30/Sep/2020 08:01
=LEFT(A1,FIND(" ",A1)+5)
=LEFT(A1,FIND("!",SUBSTITUTE(A1,"/","!",3))-1)
28/Sep/2020 11:129/Sep/2020 13:19
Number 9 is mistakenly entered it?
Related
I paste the following in excel, half of them are not recognized as date in excel.
Have already tried text to columns, adding 0 to them. I think exhausted all online techniques.
My target is to convert them all this to this format yyyy-mm-dd hh:mm:ss
9/25/19 19:17
12/5/19 14:28
11/4/19 16:46
3/20/19 14:12
1/2/20 21:15
3/20/19 19:24
3/14/19 20:03
12/29/19 20:24
3/18/19 10:20
3/9/19 11:03
12/16/19 16:01
12/21/19 19:31
12/17/19 11:41
10/12/19 17:09
3/25/19 14:01
11/20/19 21:02
8/28/19 19:00
3/14/19 20:00
3/29/19 1:39
8/30/19 22:04
3/10/19 20:02
11/20/19 8:37
9/15/19 19:19
3/20/19 17:12
8/26/19 11:03
8/30/19 22:16
7/31/19 14:53
3/25/19 20:14
1/26/20 10:24
3/29/19 1:12
6/27/19 10:06
10/15/19 14:05
12/28/19 10:58
10/23/19 13:58
8/25/19 16:07
3/27/19 16:28
3/23/19 11:26
3/24/19 11:13
3/18/19 10:11
3/25/19 13:39
3/26/19 16:35
3/27/19 21:11
11/27/19 13:23
The data sample uses the MDY order. If Excel doesn't recognize half of these as dates, your regional settings use the DMY order.
Instead of pasting the data into Excel, put it into a text file and then open the text file with Excel. That will launch the Text Import Wizard.
Keep Delimited selected and click Next
In Step 2, click Space and click Next. Date and time will now be split into two columns.
In Step 3 of 3, select the first column and click the Date radio button and set the drop-down to MDY.
Click Finish and the data will be in your worksheet as dates.
You can now use formulas to bring the time and date back together by adding the cells, =A1+B1 - and then use formatting to display the date/time values any way you want.
I'm working on generating a report by month and I'm going to create Graph based on the month values.
Consider I'm having 1000+ records in my excel sheet and there is a column called created_date which is containing the values like 11/1/2019 1:34:00 AM. I'm looking for a function or any solution to convert the created_date value to 11 or 11/2019 so I can generate a chart by Month.
Note: I'm using the online version of Microsoft Excel for this operation.
For Example - I have attached some records below.
Created_date
11/1/2019 1:34
11/1/2019 0:10
10/31/2019 19:31
10/31/2019 8:32
10/31/2019 3:59
10/31/2019 0:06
10/29/2019 23:48
10/29/2019 23:37
10/29/2019 22:35
10/29/2019 22:33
10/29/2019 22:26
10/29/2019 19:15
10/25/2019 20:44
10/25/2019 3:36
10/5/2019 3:25
10/5/2019 1:52
10/3/2019 0:40
10/2/2019 19:23
10/1/2019 3:56
9/27/2019 4:23
9/27/2019 0:19
9/25/2019 0:46
9/24/2019 22:22
9/24/2019 22:20
9/24/2019 17:12
9/20/2019 20:21
Assume your data is in cell A1, input the formula into cell B1 =TEXT(A1,"mm/yyyy"). This wil give you output of 11/2019. If you only want a 2 digit month, change the formula to =TEXT(A1,"mm"). You can then reference your chart to this new column.
I have a DataFrame With This Column :
Mi_Meteo['Time_Instant'].head():
0 2013/11/14 17:00
1 2013/11/14 18:00
2 2013/11/14 19:00
3 2013/11/14 20:00
4 2013/11/14 21:00
Name: Time_Instant, dtype: object
After Doing Some Inspection This is What I realised :
Mi_Meteo['Time_Instant'].value_counts():
2013/12/09 02:00 33
2013/12/01 22:00 33
2013/12/11 10:00 33
2013/12/05 09:00 33
.
.
.
.
2013/11/16 02:00 21
2013/11/07 10:00 11
2013/11/17 22:00 11
DateTIme 3
So I striped it:
Mi_Meteo['Time_Instant'] = Mi_Meteo['Time_Instant'].str.rstrip('DateTIme')# Cause Otherwise I would get this Error When Converting : 'Unknown string format'
And Then I tried To Convert it :
Mi_Meteo['Time_Instant'] = pd.to_datetime(Mi_Meteo['Time_Instant'])
But I Get This Error:
String does not contain a date.
Any Suggestion Would Be Much Appreciated , Thank U all.
A bit late, why don't you use this:
Mi_Meteo['Time_Instant'] = pd.to_datetime(Mi_Meteo['Time_Instant'], errors='coerce')
In the pandas.to_datetime document a description of the 'errors' parameter:
errors{‘ignore’, ‘raise’, ‘coerce’}, default ‘raise’ If ‘raise’, then
invalid parsing will raise an exception.
If ‘coerce’, then invalid parsing will be set as NaT.
If ‘ignore’, then invalid parsing will return the input.
I got the same error - it turns out that two of my dates were empty: ' '.
To find the row index of the problematic dates I used the following list comprehension:
badRows = [n for n,x in enumerate(df['DATE'].tolist()) if x.strip() in ['']]
This returned a list, containing the indices of the rows in the 'DATE' column that were causing the problems:
[745672, 745673]
Can then delete these rows in place:
df.drop(df.index[badRows],inplace=True)
I'm having trouble reproducing your error, so I cannot be sure if this will fix the issue you have. If not then please try to provide a minimum sample of code/data that reproduces your error.
This is what I tried to reproduce your situation:
lzt = ['2013/11/16 02:00 ',
'2013/11/07 10:00 ',
'2013/11/17 22:00 ',
'DateTIme',
'DateTIme',
'DateTIme']
ser = pd.Series(lzt)
ser = ser.str.rstrip('DateTIme')
ser = pd.to_datetime(ser)
But as I said I got no error, so either we have a different version of pandas or there's something else wrong with your data. Using rstrip leave some blank string data:
0 2013/11/16 02:00
1 2013/11/07 10:00
2 2013/11/17 22:00
3
4
5
which for me gives NaT (not a time) when I run pd.to_datetime on it:
Out[34]:
0 2013-11-16 02:00:00
1 2013-11-07 10:00:00
2 2013-11-17 22:00:00
3 NaT
4 NaT
5 NaT
dtype: datetime64[ns]
I'd say it's better practice to remove the unwanted rows all together:
ser = ser[ser != 'DateTIme']
Out[39]:
0 2013-11-16 02:00:00
1 2013-11-07 10:00:00
2 2013-11-17 22:00:00
dtype: datetime64[ns]
See if that works, otherwise please give enough information to reproduce the error.
There are two possible solutions to this:
Either you can make the error disappear by using coerce in errors argument of pd.to_datetime() as follows:Mi_Meteo['Time_Instant'] = pd.to_datetime(Mi_Meteo['Time_Instant'], errors='coerce')
Or if you are interested to know which dates have the unparsable values, you can search for them by converting each value at a time as follows. Ths will work regardless of the type or format of the wrong value:
dates = []
wrong_dates = []
for i in Mi_Meteo['Time_Instant'],unique():
try:
date = pd.to_datetime(i)
dates.append(i)
except:
wrong_dates.append(i)
In the wrong_dates list you will have all the wrong values while in dates, all the right values
Please could anyone kindly help. Thanking you in advance. My problem is as the following:
I have thousands lines of data with two clusters of time. One is in sheet1, for example, random times from 16pm to 20pm or 4 hours or 240 minutes, I would like to give value to them i.e. 1 to 241
(column B)
A B
17:19
17:19
17:19
18:06
18:06
18:06
16:30
16:30
16:30
I have a second sheet which will give values to sheet1 column B, the content of sheet2 is:
16:00 1
16:01 2
16:02 3
.
.
.
17:19 80
17:20 81
17:21 82
.
.
.
18:06 127
18:07 128
18:08 129
.
.
.
16:30 31
16:31 32
16:32 33
.
.
.
19:58 239
19:59 240
20:00 241
I tried to use VLOOKUP, hour, minute to get values for sheet1 B, using sheet2 but I am still unsuccessful (I kept getting false value from comparing two columns containing times) e.g. in sheet1 column B, say B2 I have
=IFERROR(VLOOKUP($B2,'sheet2'!$A:$B,2,FALSE),"")
My solution did not work. if possible I should get sheet1 filled in like
A B
17:19 80
17:19 80
17:19 80
18:06 127
18:06 127
18:06 127
16:30 31
16:30 31
16:30 31
You can use an excel formula like this:
B2: =(HOUR(A2)*60)+MINUTE(A2)+1
This is just calculating the number of minutes after midnight. If you wanted to start at say, 16:00, you would just modify it like this:
Set a value somewhere that is the START time... In this example I have "$E$4" set to 16:00
=(HOUR(A3-$E$4)*60)+MINUTE(A3)+1
You could put your start time on another sheet or anywhere.
Of course you can always add the If statement to deal with empty rows:
=IF(A2="","",(HOUR(A3-$E$4)*60)+MINUTE(A3)+1)
In the example, note in the screenshot in column A, the formatting is TIME for row 2, and General for rows 3 & 4. The formula will work for either.
edit:added IF statement & description of screenshot.
EDIT AFTER COMMENT: Modified formula to add 1 minute.
I finally, found a correct answer
=(HOUR(A2)-16)*60+MINUTE(A2)+1
so 16:00 will give 1, 16:30 will give 31, 17:19 will give 80 and so on, 20:00 will give 241.
Thanks for trying to help, PJ Rosenburg. Indeed I was on right track in using hour and minute, BUT I do not even need to use VLOOKUP.
EXCEL - 1st row example; clocked IN at 08:20 - clocked OUT at 17:03
What I want to do is basically in 8:00-8:59 - if row 1 was between them times then output a 1, if not, then output a 0
Any help is greatly appreciated
Assuming 08:00-08:59 is in cell J1, then you can put this formula into J2:
=IF(AND($A2>=VALUE(LEFT(J$1,FIND("-",J$1)-1)),$A2<=VALUE(RIGHT(J$1,LEN(J$1)-FIND("-",J$1)))),1,0)
Storing the time parameters as text forces the use of the VALUE function. Shifting everything down a row and putting the start of the hour in row 1 and the end of the hour in row 2 so it looks like this:
08:00 09:00 10:00 11:00 12:00
Clock1 C1 Clock2 C2 Clock3 C3 Clock4 C4 08:59 09:59 10:59 11:59 12:59
08:20 I 17:03 X
10:20 I 16:03 X
08:00 I 18:00 O
10:11 I 17:00 O
Would change the formula to:
=IF(AND($A3>=J$1,$A3<=J$2),1,0)