I have tried searching other posts on here, but can't seem to solve this problem. I have a CSV file in which Year, Crash_Month, Crash_Day and Crash_Time are all seperate columns in the CSV 'data_dict'. I am trying to solve the below question. How would I go about this? I have tried to use a data frame, and pandas convert to datetime, but I'm not sure if this is the right approach. Many thanks
Here's the data frame I'm trying to assign datetime to
year month day time
0 2000 1 1 4:30:59
1 2000 1 1 0:07:35
2 2000 1 1 4:51:37
3 2000 1 1 4:27:56
4 2000 1 1 2:16:31
5 2000 1 1 0:37:21
6 2000 1 1 0:52:57
7 2000 1 1 3:35:14
8 2000 1 1 2:41:58
9 2000 1 1 3:43:02
10 2000 1 1 3:49:19
11 2000 1 1 3:03:55
12 2000 1 1 4:46:01
13 2000 1 1 1:07:24
14 2000 1 1 8:29:04
15 2000 1 1 6:35:21
16 2000 1 1 6:06:25
17 2000 1 1 7:10:13
18 2000 1 1 10:57:24
19 2000 1 1 7:54:38
So far, I have coded this.
import pandas as pd
df = pd.DataFrame({'year': (data_dict['Year']),
'month': (data_dict['Crash_Month']),
'day': (data_dict['Crash_Day']),
'time': (data_dict['Crash_Time'])})
date=pd.to_datetime(df[["year", "month", "day", "time"]],format='%YYYY%mm%dd, %HH%MM%SS')
print(date)
day_of_week = {0 : 'Monday',
1: 'Tuesday',
2: 'Wednesday',
3: 'Thursday',
4: 'Friday',
5: 'Saturday',
6: 'Sunday'}
month_season= {1: 'Summer',
2: 'Summer',
3: 'Autumn',
4: 'Autumn',
5: 'Autumn',
6: 'Winter',
7: 'Winter',
8: 'Winter',
9: 'Spring',
10: 'Spring',
11: 'Spring',
12: 'Summer'}