I need to split the columns of a dataframe by numerical, categorical, and datatime formats separately. I use df.select_dtypes(include=['int64', 'float64'])
and it works, but I'm not sure how to separate the datatime columns?
this is the dataset I have used
this is the command I have used to separate the date time column
date = df.select_dtypes(include=['datetime'])
The output I got
please help to solve this.
CodePudding user response:
You can use below to separate the datetime columns however this only works if your column if of the datetime data type -
converted_column = df.select_dtypes(include=['datetime'])
If these columns are not in datetime type then we first need to convert and then extract them -
df['Start date'] = pd.to_datetime(df['Start date'])
df['End date'] = pd.to_datetime(df['End date'])