Foretify / UsefulPython

This is a library that has multiple useful python snippets
Apache License 2.0
0 stars 0 forks source link

Adding date columns to any dataframe #12

Open topowright22 opened 2 years ago

topowright22 commented 2 years ago

We need a method that will take in a datetime object from a dataframe column and create columns for:

Doing so will allow us to analyze our information for patterns such as violent crimes and werewolves attacking citizens.

Here is our starting code:

df['Joined'] = pd.to_datetime(df['Joined']) df['Joined year'] = df['Joined'].dt.year # adding in a feature that's just the year df['Joined month'] = df['Joined'].dt.month # adding in a feature that's just the year df['Day'] = df['Joined'].dt.day # adding in a feature that's just the year print(min(df['Joined']), max(df['Joined'])) df['Joined'].head()