Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carloocchiena/fdc7f497020399a8ed667890fa52d98c to your computer and use it in GitHub Desktop.
Save carloocchiena/fdc7f497020399a8ed667890fa52d98c to your computer and use it in GitHub Desktop.
# Add useful time-based features
df['Hour'] = df.index.hour
df['Day'] = df.index.day
df['Weekday'] = df.index.weekday # Monday=0, Sunday=6
df['Month'] = df.index.month
df['Date'] = df.index.date # useful for grouping by day
plt.figure(figsize=(10, 4))
sns.histplot(df['Value'], bins=50, kde=True)
plt.title('Distribution of values')
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.grid(True)
plt.tight_layout()
plt.show()
plt.figure(figsize=(12, 5))
sns.boxplot(data=df, x='Hour', y='Value')
plt.title('Hourly Distribution of Values')
plt.xlabel('Hour of Day')
plt.ylabel('Value')
plt.grid(True)
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment