✅ This is GPT trick will get you visualize any time series data in a minute! It works for any dataset with dates and numbers.
📌 I’ll put the prompt at the end of this post, save this for later.
The results here we have detailed chart with moving average, highlighted weekends, custom calculated fields, and handling of missing dates.
How it works:
✍️ This is one of an example of how we should structure the prompt with clear instructions to achieve perfect results every time!
When we perform prompt engineering, you should test the changes systematically. It’s tweaking few variables at the time.
Before finalizing this prompt, I asked GPT for slightly more analysis on top of a previous result. If it performed worse, I edited the prompt util it gets right answer and then proceeded to further steps.
A trick I use:
After finalizing the conversation with GPT, ask GPT to summarize the instructions into one prompt. This helps streamline the process and we can keep the prompt as a template for later use.
In summary
✍️ Crafting the perfect prompt is an art. Here’s how to get it right every time:
Start with clear, structured instructions.
Test systematically — tweak a few changes at a time.
Build on what works, refine what doesn’t.
Here’s the prompt:
Bonus!
This is the code generated by ChatGPT with this prompt.
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
file_path = '/mnt/data/06_logins_per_day.csv'
data = pd.read_csv(file_path)
data['date'] = pd.to_datetime(data['date'])
date_range = pd.date_range(start=data['date'].min(), end=data['date'].max())
data = data.set_index('date').reindex(date_range, fill_value=0).reset_index()
data.rename(columns={'index': 'date'}, inplace=True)
data['logins'] = data['logins'].astype(int)
data['7d_moving_avg'] = data['logins'].rolling(window=7).mean()
plt.figure(figsize=(15, 8))
plt.plot(data['date'], data['logins'], label='Daily Logins', color='blue', marker='o')
plt.plot(data['date'], data['7d_moving_avg'], label='7-Day Moving Average', color='orange', linestyle='--')
for i in range(len(data)):
if data['date'][i].weekday() >= 5:
plt.axvspan(data['date'][i], data['date'][i] + pd.Timedelta(days=1), facecolor='grey', alpha=0.3)
for i, txt in enumerate(data['logins']):
plt.annotate(txt, (data['date'][i], data['logins'][i]), textcoords="offset points", xytext=(0,10), ha='center')
above_avg = np.sum(data['logins'] > data['7d_moving_avg'])
below_avg = np.sum(data['logins'] < data['7d_moving_avg'])
plt.legend(title=f"Above Avg: {above_avg} days\nBelow Avg: {below_avg} days")
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d (%a)'))
plt.gca().xaxis.set_major_locator(mdates.DayLocator(interval=1))
plt.xticks(rotation=45)
plt.title('Daily Logins and 7-Day Moving Average')
plt.xlabel('Date')
plt.ylabel('Number of Logins')
plt.grid(True)
plt.tight_layout()
plt.show()
_ Happy hacking ~ 🦾✨