Reputation: 1238
I have the date like below.
7/1 09:00
7/1 12:00
7/1/19 12:00
7/2/19 13:00
7/3 4:00*
And I want to split this date only to get date without the time and year.
7/1
7/1
7/1
7/2
7/3
I m thinking of using lambda function. But I'm not sure how to use this.
order['orderDate'] = train.date.apply(lambda x : x.split).astype('int')
Thank you so much for reading.
Upvotes: 1
Views: 162
Reputation: 27
Depending on your input constraints, if your input is plaintext, consider the regex
re.findall(r'^\d+/\d+', text, flags=re.MULTILINE)
which looks for "digits, a slash, and then more digits, at the start of a line". The flags
is there to tell your regex engine that ^
is the start of every line, not the start of the whole text.
Upvotes: 0
Reputation: 5785
You can use lambda
like this,
order['orderDate'] = train.date.apply(lambda x : '/'.join(x.split('/')[:2]))
Upvotes: 0