-
-
Save sgsg704/4522db2b86099de9666261ce014e8ec3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Parsing datetime | |
#exploring the length of date objects | |
lengths = data["Date"].str.len() | |
lengths.value_counts() | |
data['Date']= pd.to_datetime(data["Date"]) | |
#Creating a collumn of year | |
data['year'] = data.Date.dt.year | |
# function to encode datetime into cyclic parameters. | |
#As I am planning to use this data in a neural network I prefer the months and days in a cyclic continuous feature. | |
def encode(data, col, max_val): | |
data[col + '_sin'] = np.sin(2 * np.pi * data[col]/max_val) | |
data[col + '_cos'] = np.cos(2 * np.pi * data[col]/max_val) | |
return data | |
data['month'] = data.Date.dt.month | |
data = encode(data, 'month', 12) | |
data['day'] = data.Date.dt.day | |
data = encode(data, 'day', 31) | |
data.head() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment