Issue
I would like to delete "- 01" , "- 02", "- 03",etc. in the Hours column and then concatenate date and Hours column as a DateTime. Could you please help me?
Thanks in advance
Solution
df['new_date'] = df['date'].astype(str) + ' ' + df['Volume'].astype(str).replace(r'\s-\s\d+$','', regex=True)
df['new_date'] = pd.to_datetime(df['new_date'])
This creates a new column. You could also replace the date column and drop the hours if you'd prefer.
Output:
0 2022-01-03 00:00:00
1 2022-01-04 01:00:00
2 2022-01-05 02:00:00
3 2022-01-06 03:00:00
4 2022-01-07 04:00:00
5 2022-01-10 05:00:00
6 2022-01-11 06:00:00
7 2022-01-12 07:00:00
8 2022-01-13 08:00:00
9 2022-01-14 09:00:00
Name: new_date, dtype: datetime64[ns]
Answered By - shullaw
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.