Hey ChatGPT, Automate These Tasks Using Python

Using AI to plot graphs, send emails/messages, and do web scraping in a few seconds.

The PyCoach
Geek Culture
Published in
6 min readDec 9, 2022

--

Image via Shutterstock under license to Frank Andrade

Recently ChatGPT was released. This is an AI chatbot developed by OpenAI that specializes in dialogue. Its goal is to make AI systems more natural to interact with, but it can also help you when writing code.

You can make ChatGPT your coding assistant or even go beyond that!

I’ve been playing with ChatGPT a bit over the past few days. Here are some tasks I gave ChatGPT ordered by difficulty (spoiler alert: I was amazed at the results)

Task #1: Plot a linear regression

If you want to plot a linear regression, you can simply tell ChatGPT:

plot a linear regression with Python using matplotlib

We can be very specific by telling ChatGPT the library it should use, otherwise, it’ll choose itself.

Here’s the Python code created by ChatGPT (with comments included!)

import matplotlib.pyplot as plt
import numpy as np

# Generate some random data
x = np.random.rand(100)
y = x + np.random.normal(0, 0.1, size=100)

# Fit a linear regression to the data
m, b = np.polyfit(x, y, 1)

# Plot the data and the fitted line
plt.plot(x, y, 'o')
plt.plot(x, m*x + b, '-')
plt.show()

And here’s the output.

This was an easy one, so let’s try something a bit more difficult.

Task #2: Send a message on WhatsApp with pywhatkit

I was curious to see if ChatGPT could help us with third-party libraries such as pywhatkit. This library allows us to send messages using Whatsapp.

send a message on Whatsapp using Python and pywhatkit

--

--

The PyCoach
Geek Culture

My ChatGPT Course - ChatGPT Unleashed: Master GPT-4 & Prompt Engineering: bit.ly/chatgpt-pycoach