WellAlly Logo
WellAlly康心伴
Development

Forecasting Your 'Focus Hours': A Python Tutorial with Prophet and Your To-Do List

Turn your task history into a predictive tool. This guide shows you how to use Python, Pandas, and Facebook Prophet to analyze your to-do list data and forecast your most productive days, helping you schedule deep work effectively.

W
2025-12-11
10 min read

Ever feel like some days you can conquer the world, checking off tasks left and right, while other days you can barely muster the energy to reply to an email? What if you could predict those "focus hours" in advance? For developers, timing is everything. Scheduling a complex refactoring session during a productivity slump can lead to frustration and bugs. Conversely, knowing when you're likely to be in "the zone" can be a game-changer.

In this tutorial, we'll build a personal productivity forecast. We'll export our completed tasks from a to-do list manager (we'll use Todoist as an example), clean and process the data with the powerful Pandas library, and then use Facebook's Prophet to predict our future productivity cycles.

This isn't just an abstract data science exercise; it's about turning your own historical data into a practical tool for better time management and more effective work. Whether you're a seasoned data scientist or a developer curious about machine learning, this guide will provide you with a tangible and useful project.

Understanding the Problem

The core challenge is to identify patterns in our task completion history. Are we more productive in the morning or afternoon? Do we get more done at the beginning of the week or the end? Are there larger, seasonal trends to our productivity? Answering these questions from raw data can be difficult.

This is where time-series forecasting comes in. By treating our completed tasks as a sequence of data points over time, we can model trends and seasonality. Facebook Prophet is particularly well-suited for this because it's designed to handle "human-scale" seasonalities like day-of-the-week and time-of-year patterns, and it's robust to missing data and outliers, which are common in real-world personal data.

Our approach is to quantify our productivity by counting the number of tasks completed each day. We'll then feed this time-series data into Prophet to forecast future daily task completions.

Prerequisites

Before we begin, make sure you have the following:

  • Python Environment: Python 3.6 or later.
  • Jupyter Notebook or Google Colab: Ideal for this kind of exploratory data analysis.
  • Required Libraries: You'll need pandas, fbprophet, and matplotlib. You can install them using pip:
    code
    pip install pandas fbprophet matplotlib
    
    Code collapsed
    Note: fbprophet has a dependency on pystan, which may require a C++ compiler. Follow the installation instructions for your specific operating system if you encounter issues.
  • To-Do List Data: An exported CSV file of your completed tasks. We'll cover how to get this from Todoist.

Step 1: Exporting and Loading Your Data

First, we need to get our hands on our task data. Many to-do list apps offer a way to export your data.

Exporting from Todoist

  1. Log in to the Todoist web app.
  2. Click on your profile picture in the top-right corner and go to Settings.
  3. Navigate to the Account tab.
  4. Scroll down to the "Export account data" section and click Create export.
  5. You'll receive an email with a link to download your data as a ZIP file. Inside, you'll find a CSV file for your tasks.

Note: Some services like Todoist also offer official Google Sheets integrations or third-party tools that can export to CSV or JSON.

Loading the Data with Pandas

Once you have your CSV file, we can load it into a Pandas DataFrame.

code
#
src/data_loading.py
import pandas as pd

# Load the dataset
# Make sure to replace 'your_todoist_export.csv' with the actual file name
try:
    df = pd.read_csv('your_todoist_export.csv')
    print("File loaded successfully!")
    print(df.head())
except FileNotFoundError:
    print("Error: Make sure the CSV file is in the same directory or provide the full path.")

# Expected output: A preview of the first few rows of your Todoist data.
Code collapsed

How it works: We're using the read_csv function from Pandas to load our task data into a DataFrame, which is essentially a table. We've wrapped it in a try-except block to handle the case where the file isn't found.

Step 2: Data Cleaning and Preparation

Now that our data is loaded, we need to prepare it for Prophet. The library has a specific requirement for the column names: the date column must be named ds and the value we want to forecast must be y.

What we're doing

We'll convert the 'Date' column to a proper datetime format, count the number of tasks completed per day, and rename the columns to ds and y.

Implementation

code
# src/data_processing.py
import pandas as pd

# Assuming 'df' is the DataFrame from the previous step
# Filter for completed tasks if your export includes incomplete ones
# The column name for the completion date might vary, inspect your CSV file.
# Common names are 'Date Completed', 'Completed Date', etc.
df_completed = df[df['Date Completed'].notna()].copy()

# Convert the date column to datetime objects
df_completed['ds'] = pd.to_datetime(df_completed['Date Completed'])

# Group by date and count the number of tasks
daily_tasks = df_completed.groupby(df_completed['ds'].dt.date).size().reset_index(name='y')

# Rename the date column to 'ds' for Prophet
daily_tasks.rename(columns={'index': 'ds'}, inplace=True)

# Convert the 'ds' column back to datetime objects after grouping
daily_tasks['ds'] = pd.to_datetime(daily_tasks['ds'])


print(daily_tasks.head())
# Expected output: A DataFrame with two columns: 'ds' (the date) and 'y' (the number of tasks completed on that day).
Code collapsed

How it works

  1. Filtering: We first ensure we're only looking at completed tasks.
  2. Date Conversion: We use pd.to_datetime to convert the date strings into a format Pandas can understand and work with.
  3. Aggregation: We use groupby to group all tasks by their completion date and size() to count how many tasks fall into each group.
  4. Renaming: Finally, we rename the columns to ds and y to meet Prophet's requirements.

Step 3: Building and Training the Forecast Model

With our data properly formatted, we can now build our forecasting model. This is where the magic of Prophet happens.

What we're doing

We will initialize a Prophet model, fit it to our historical task data, and create a "future" DataFrame to hold our predictions.

Implementation

code
# src/model_training.py
from prophet import Prophet

# Initialize the Prophet model
model = Prophet()

# Fit the model to our data
model.fit(daily_tasks)

# Create a DataFrame for future predictions (e.g., for the next 90 days)
future = model.make_future_dataframe(periods=90)

print(future.tail())

# Expected output: A DataFrame with a 'ds' column extending 90 days into the future.
Code collapsed

How it works

  1. Initialization: We create an instance of the Prophet class.
  2. Fitting: The fit method is where the model learns the trends, seasonalities, and any holiday effects from our data.
  3. Future DataFrame: The make_future_dataframe method creates a new DataFrame with a 'ds' column that includes our historical dates plus the number of future periods we specify.

Step 4: Making and Visualizing the Forecast

Now for the exciting part: generating and visualizing our forecast.

What we're doing

We'll use our trained model to predict the values for our "future" DataFrame and then use Prophet's built-in plotting capabilities to visualize the results.

Implementation

code
# src/forecasting.py

# Make predictions
forecast = model.predict(future)

# Print the last few forecasted values
print(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail())

# Plot the forecast
fig1 = model.plot(forecast)

# Plot the forecast components (trend, weekly, and yearly seasonality)
fig2 = model.plot_components(forecast)

# Expected output: A table with forecasted values and two plots.
# The first plot shows the historical data, the forecast, and the uncertainty interval.
# The second plot breaks down the forecast into its trend and seasonal components.
Code collapsed

How it works

The predict method takes our future DataFrame and adds several new columns, most importantly:

  • yhat: The forecasted value.
  • yhat_lower and yhat_upper: The lower and upper bounds of the uncertainty interval.

Prophet's plotting functions provide a quick and insightful way to view our results. The components plot is particularly useful for understanding the drivers of our productivity. You might discover a strong weekly pattern (e.g., high productivity on Mondays, dipping on Fridays) or a yearly trend.

Putting It All Together: Interpreting Your "Focus Hours"

The "Forecast" plot gives you a general idea of your productivity trajectory. The blue shaded area represents the uncertainty – the model is less confident about predictions further into the future.

The real gold is in the "Components" plot:

  • Trend: This shows the overall direction of your productivity. Are you generally getting more done over time, or is there a downward trend?
  • Weekly: This is where you can spot your "focus hours" within a week. If the graph peaks on Tuesday and Wednesday, those are likely your best days for tackling challenging tasks.
  • Yearly: This component reveals longer-term patterns. You might be more productive in the fall and less so during the summer, for example.

By looking at the weekly seasonality plot, you can strategically plan your work week. If your forecast shows a dip in productivity on Fridays, maybe that's a good day for administrative tasks, meetings, or planning, rather than intensive coding.

Alternative Approaches

While Prophet is excellent for its ease of use and interpretability, other time-series models could be used:

  • ARIMA/SARIMA: These are more traditional statistical models that can be very powerful but often require more expertise to tune.
  • LSTM (Long Short-Term Memory) Networks: A type of recurrent neural network that can capture complex patterns in sequential data. This is generally overkill for this type of problem but is a powerful tool for more complex time-series tasks.

For most personal productivity forecasting, Prophet offers the best balance of simplicity and power.

Conclusion

We've successfully turned a simple CSV export from a to-do list into a personalized productivity forecast. You now have a data-driven way to understand your work patterns and schedule your tasks more intelligently.

Your next steps could be:

  • Experiment with different timeframes: Forecast for a full year or just the next month.
  • Add holidays: Prophet allows you to account for the effect of holidays on your productivity.
  • Incorporate more data: If you use a time-tracking app, you could forecast hours spent on specific projects.

Resources

#

Article Tags

pythondatasciencemachinelearningproductivitytutorial
W

WellAlly's core development team, comprised of healthcare professionals, software engineers, and UX designers committed to revolutionizing digital health management.

Expertise

Healthcare TechnologySoftware DevelopmentUser ExperienceAI & Machine Learning

Found this article helpful?

Try KangXinBan and start your health management journey

© 2024 康心伴 WellAlly · Professional Health Management