# How exactly do I go about extracting features from timestamps for machine learning? [closed]

My dataset has a timestamp column with the following format: 06/24/18 0:56 How exactly do I convert this information into features that can be used for classification algorithms like logistic regression?

## closed as too broad by Mark.F, oW_♦, Esmailian, Ethan, Siong Thye GohMar 20 at 1:16

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

A common approach for time-series classification problems is to divide the continuous stream of data into samples of a certain duration.

This is called sliding window segmentation.

You don't really use timestamps as features because they wouldn't be useful during the classification of unseen data. Imagine training a model with data obtained in 2018, and trying to classify data for 2019. The information is not on the dates but in the values of the other features!

• Nice answer but I think he's looking for more basic help than that! – I_Play_With_Data Mar 19 at 15:50

Welcome to the site! You will get better answers if you post the language you are working in, but I'll assume python. One of the most basic things you're going to need is to break it down into components. So, let's say your column in the pandas dataframe is named "client_date". You could use:

# Convert the date to something python understands
df['client_date'] = pd.to_datetime(df['client_date'])
# Get a year
df['client_year'] = df['client_date'].dt.year
# Get a month
df['client_year'] = df['client_date'].dt.month


I think you get the idea and that will help get you started for the rest of your research. Good luck!

• Thank you so much for your response. I'd love it if you could address another silly doubt of mine. Converting the date to the python format worked perfectly fine. However, while trying to extract the month/year, I get the following error: return object.__getattribute__(self, name) AttributeError: 'Series' object has no attribute 'month' – Apollo Mar 19 at 20:15
• @Apollo I apologize, there was an error in my original answer. Please try the above code again. Note the addition of "dt" , as in df['client_year'] = df['client_date'].dt.year – I_Play_With_Data Mar 19 at 20:32
• @Apollo Also, if my answer has helped you in some way, I'd appreciate the upvote and marking my answer as the chosen solution. – I_Play_With_Data Mar 19 at 20:32
• Upvotes will turn public once my reputation crosses 15. Thanks again! – Apollo Mar 19 at 20:47