avatarJosep Ferrer

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

5631

Abstract

tGPT chat. ChatGPT explaining the basics commands of the Geopandas library with its corresponding examples.</figcaption></figure><p id="947e"><b>The craziest part? <i>I can even ask for some code I can use right away.</i></b></p><blockquote id="172f"><p>Give some code I can use right now using Geopandas</p></blockquote><p id="b71b">ChatGPT answered me with the following code. To use it, it gave me the sample dataset as well. (contained in this <a href="https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_populated_places.zip">link</a>)</p><div id="8f24"><pre><span class="hljs-keyword">import</span> geopandas <span class="hljs-keyword">as</span> gpd <span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt

<span class="hljs-comment"># Read the shapefile into a GeoDataFrame</span> gdf = gpd.read_file(<span class="hljs-string">'path/to/ne_110m_populated_places.shp'</span>)

<span class="hljs-comment"># Select rows where the 'POP_MAX' column is greater than 10000</span> selected_rows = gdf[gdf[<span class="hljs-string">'POP_MAX'</span>] > <span class="hljs-number">10000</span>]

<span class="hljs-comment"># Plot the selected rows on a map</span> selected_rows.plot(color=<span class="hljs-string">'red'</span>)

<span class="hljs-comment"># Show the map</span> plt.show()</pre></div><p id="aa8e">Just following it withou changing a single letter, it worked!! <b>Crazy, huh?</b></p><figure id="d7a3"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*nceum8Isn1RZ06Szny-YRg.png"><figcaption>Screenshot of a Jupyter Notebook testing the sample code that ChatGPT gave me to use Geopandas.</figcaption></figure><h1 id="8c37">#4. Ask ChatGPT to code for you</h1><p id="d3a9">The best part of ChatGPT is that <i>it has plenty of ideas and knowledge.</i><b> This is why we can even ask it to facilitate some already working python code </b>— just as during the previous example.</p><blockquote id="4f6f"><p>Code me how to scrape the ChatGPT website</p></blockquote><p id="b81d">And ChatGPT answers right away:</p><blockquote id="4f70"><p>To scrape the ChatGPT webpage, you can use the Python library <code>BeautifulSoup</code> along with the <code>requests</code> library to fetch the HTML content of the webpage and parse it. Here is some example code that demonstrates how you can do this:</p></blockquote><div id="36f2"><pre><span class="hljs-keyword">import</span> requests <span class="hljs-keyword">from</span> bs4 <span class="hljs-keyword">import</span> BeautifulSoup <span class="hljs-comment"># Fetch the HTML content of the webpage</span> url = <span class="hljs-string">'https://openai.com/blog/chatgpt/'</span> response = requests.get(url) html = response.text <span class="hljs-comment"># Parse the HTML content</span> soup = BeautifulSoup(html, <span class="hljs-string">'html.parser'</span>) <span class="hljs-comment"># Find all the paragraphs in the HTML</span> paragraphs = soup.find_all(<span class="hljs-string">'p'</span>) <span class="hljs-comment"># Print the text of the paragraphs</span> <span class="hljs-keyword">for</span> p <span class="hljs-keyword">in</span> paragraphs: <span class="hljs-built_in">print</span>(p.text)</pre></div><p id="88de">Just copying once again the previous code on my jupyter notebook, it works!</p><figure id="77d5"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*19sr03JOZjAqDTb1UMIjpQ.png"><figcaption>Screenshot of a Jupyter Notebook testing the sample code that ChatGPT gave me to parse its own website.</figcaption></figure><p id="d4e1">I can even ask to send ChatGPT how to send an automatic email to my google account. The following code was provided by ChatGPT.</p><div id="64c3"><pre><span class="hljs-keyword">import</span> smtplib <span class="hljs-comment"># Set up the SMTP server</span> server = smtplib.SMTP(<span class="hljs-string">'smtp.gmail.com'</span>, <span class="hljs-number">587</span>) server.starttls() server.login(<span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'your-password'</span>) <span class="hljs-comment"># Send the email</span> to = <span class="hljs-string">'[email protected]'</span> subject = <span class="hljs-string">'Test Email'</span> body = <span class="hljs-string">'This is a test email sent from Python.'</span> msg = <span class="hljs-string">f'Subject: <span class="hljs-subst">{subject}</span>\n\n<span class="hljs-subst">{body}</span>'</span> server.sendmail(<span class="hljs-string">'[email protected]'</span>, to, msg) <span class="hljs-comment"># Disconnect from the server</span> server.quit()</pre></div><p id="be48">Copying it and executing it in my Jupyter Notebook… <i>voilà! </i>I just received the corresponding email right away!</p><figure id="7164"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*NoHqXTx83OjwDdDxUkAxRw.png"><figcaption>Screenshot of my gmail account to check that I have received the automated mail generated by Python.</figcaption></figure><p id="8b0d"><b>Cool!!! Isn’t it?? You can just ask whatever you want — your imagination is your only limit.</b></p><h1 id="a9e7">#5. Get help with your code</h1><p id="e629">The last but not least thing you can do with ChatGPT is to debug your code. If you are having trouble with your Python code, you can ask ChatGPT for help with debugging. It can suggest possible solutions or strategies for troubleshooting your code.</p><p id="9652">Just imagine I want to compute the fibonacci serie. However, I defined the following function that does not work properly:</p>

Options

<div id="1371"><pre><span class="hljs-keyword">def</span> <span class="hljs-title function_">fibonacci_of</span>(<span class="hljs-params">n</span>): <span class="hljs-keyword">if</span> n <span class="hljs-keyword">in</span> {<span class="hljs-number">0</span>, <span class="hljs-number">1</span>}: <span class="hljs-comment"># Base case</span> <span class="hljs-keyword">return</span> n <span class="hljs-keyword">return</span> fibonacci_of(n) + fibonacci_of(n) <span class="hljs-comment"># Recursive case</span></pre></div><p id="b89e">I can ask ChatGPT:</p><blockquote id="5c3c"><p>Does this function computes the fibonacci serie? [Insert function here]</p></blockquote><p id="f4bc">And ChatGPT answers me that the function is incorrect and corrects it to me:</p><figure id="448d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*Fls18fT7wQdpwS-joA9i1Q.png"><figcaption>Screenshot of ChatGPT. It corrects my fibonacci function to correctly return the fibonacci series.</figcaption></figure><p id="6e6b">You can even ask ChatGPT to correct your code so it follows the Pep-8 style code.</p><blockquote id="ca36"><p>Convert the following code to Pep-8 [Insert code here]</p></blockquote><p id="867f">As you can observe in the following image, ChatGPT not only corrects my code but explains step by step how to adjust it to fulfill Pep-8.</p><figure id="bb00"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*UyoSdJJFTwe4OKv-KIXcvA.png"><figcaption>Screenshot of ChatGPT. Adjusting my code to fullfil the Pep-8 style guide.</figcaption></figure><p id="0621">You can try to challenge ChatGPT with more complex questions!</p><h1 id="4591">Main Conclusions</h1><p id="b01a"><b>ChatGPT is here to help you learn Python in a more interactive and personalized way.</b> It can offer guidance, explanations, and suggestions as you work on programming exercises and projects.</p><p id="a8f8"><i>This is why you can take advantage of ChatGPT knowledge — and get all its resources to help you further understand Python and its various libraries and frameworks.</i></p><p id="737e">Let me know if ChatGPT surprises you with some other good features. I will read you in the comments! :D</p><p id="8bed"><i>Do you want to try the new AI autonomous model — AutoGPT?</i></p><p id="2f51"><b>Just give a look at the following article!</b></p><div id="c932" class="link-block"> <a href="https://readmedium.com/autogpt-unleashed-the-autonomous-ai-agent-revolution-chat-gpt-ai-artificial-intelligence-productivity-19ad5b71c436"> <div> <div> <h2>AutoGPT Unleashed — The Autonomous AI Agent Revolution</h2> <div><h3>Discover the Next-Generation AI System Designed to Perform Tasks Without Human Intervention</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*AcqWHnUN4bjsKV-4-5BTOg.png)"></div> </div> </div> </a> </div><p id="306e"><b>Data always has a better idea — trust it.</b></p><p id="bf53">You can suscribe to my <a href="https://medium.com/subscribe/@rfeers"><b>Medium Newsletter</b></a><b> to stay tuned and receive my content</b>. <i>I promise it will be unique!</i></p><p id="3d44">If you are not a full Medium member yet, <b>just check it out <a href="https://medium.com/@rfeers/membership">here</a> to support me and many other writers. </b><i>It really helps </i>:D</p><p id="a5fb">Some other nice medium related articles you should go check out! :D</p><div id="5727" class="link-block"> <a href="https://readmedium.com/6-chatgpt-mind-blowing-extensions-to-use-it-anywhere-db6638640ec7"> <div> <div> <h2>6 ChatGPT mind-blowing extensions to use it anywhere</h2> <div><h3>And how to make make ChatGPT our daily assistant using them</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*qDHxdjf90F2FFOL6NvdTBw.png)"></div> </div> </div> </a> </div><div id="f076" class="link-block"> <a href="https://readmedium.com/using-chatgpt-to-learn-sql-53067465076e"> <div> <div> <h2>Using ChatGPT to learn SQL</h2> <div><h3>And how to use this amazing tool to enhance our SQL skills</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*hEgFw1yxm3UdBEh4)"></div> </div> </div> </a> </div><div id="8e93" class="link-block"> <a href="https://markwschaefer.medium.com/20-entertaining-uses-of-chatgpt-you-never-knew-were-possible-3bc2644d4507"> <div> <div> <h2>20 Entertaining Uses of ChatGPT You Never Knew Were Possible</h2> <div><h3>Our RISE community has been on fire, exploring the breathtaking possibilities of ChatGPT. The uses of ChatGPT are…</h3></div> <div><p>markwschaefer.medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*IPZF1hcDWwpPqOz2vL7NxQ.png)"></div> </div> </div> </a> </div></article></body>

Having a personal Python Teacher using ChatGPT

And how to take advantage of this amazing tool to enhance our Python skills

Self-made picture

ChatGPT can do many cool things. One of them is writing code. You only need to give the right instruction and ChatGPT will do the job for you.

If you want to learn Python, ChatGPT is a great resource to get started. It can help you find the perfect library you need to use, solve any coding questions you might have or even code for you!

In this article, I will outline how you can use ChatGPT to learn Python and become proficient in this valuable language.

Let’s figure it out together!👇🏻

First things first, so… what’s exactly ChatGPT?

ChatGPT defines itself as a large language model trained by OpenAI. It is capable of generating human-like text based on the input it receives and can be used to answer questions and engage in conversations with people.

So basically, we can take advantage of its knowledge — and its capacity to tell us anything in a very simple and human way — to learn python and improve our current skills.

#1. Practice writing Python code

You can ask ChatGPT to give you coding challenges and then write the code to solve them. This will help you get hands-on experience with the language and improve your coding skills.

For instance, I can ask ChatGPT:

Can you give me some problems to solve in Python?

ChatGPT gives us 5 different problems to be solved, as you can observe in the following image:

Screenshot of the ChatGPT chat. It gives me some problems to test my python.

You can try to solve them and check the answer using ChatGPT as well. I coded the following code to answer the first problem:

def max_num(x): 
    return max(x)

And ChatGPT told me my answer is alright, as you can observe in the following screenshot.

Screenshot of the ChatGPT chat. It validates my code.

Or I can rather ask for the solutions right away and try to understand them — or ask ChatGPT to further explain them to me.

Screenshot of the ChatGPT chat. ChatGPT giving the answers to the problems it gave me earlier to test my Python.

#2. Understand some Python-specific concepts

If you are struggling with a particular concept or syntax in Python, you can ask ChatGPT to explain it to you in more detail. This can be a helpful way to get a better understanding of how the language works.

For instance, I can ask about the list element in Python.

What’s a list in Python?

And ChatGPT will generate a complete and easy-to-understand answer explaining the list concept and using samples to further simplify it.

Screenshot of the ChatGPT chat. ChatGPT explaining what’s a list.

You can try asking any command you are unfamiliar with! Give it a chance :)

#3. Learn about Python libraries and framework

Python has a large number of libraries and frameworks that can be used for various tasks, such as web development, data analysis, and machine learning. ChatGPT can help you learn about these tools and how to use them in your own projects.

Just imagine I want to create some good-looking interactive map in Python.

What libraries should I use to create an interactive map in Python?

Screenshot of the ChatGPT chat. ChatGPT explaining what libaries to use for creating an interactive map plot.

As you can observe, ChatGPT recommened me four of them. But I can still ask for more detailed explanations:

Screenshot of the ChatGPT chat. ChatGPT explaining the basics of the Geopandas library.

I can even ask for the basic commands or some more specific actions to perform.

Screenshot of the ChatGPT chat. ChatGPT explaining the basics commands of the Geopandas library with its corresponding examples.

The craziest part? I can even ask for some code I can use right away.

Give some code I can use right now using Geopandas

ChatGPT answered me with the following code. To use it, it gave me the sample dataset as well. (contained in this link)

import geopandas as gpd
import matplotlib.pyplot as plt

# Read the shapefile into a GeoDataFrame
gdf = gpd.read_file('path/to/ne_110m_populated_places.shp')

# Select rows where the 'POP_MAX' column is greater than 10000
selected_rows = gdf[gdf['POP_MAX'] > 10000]

# Plot the selected rows on a map
selected_rows.plot(color='red')

# Show the map
plt.show()

Just following it withou changing a single letter, it worked!! Crazy, huh?

Screenshot of a Jupyter Notebook testing the sample code that ChatGPT gave me to use Geopandas.

#4. Ask ChatGPT to code for you

The best part of ChatGPT is that it has plenty of ideas and knowledge. This is why we can even ask it to facilitate some already working python code — just as during the previous example.

Code me how to scrape the ChatGPT website

And ChatGPT answers right away:

To scrape the ChatGPT webpage, you can use the Python library BeautifulSoup along with the requests library to fetch the HTML content of the webpage and parse it. Here is some example code that demonstrates how you can do this:

import requests
from bs4 import BeautifulSoup
# Fetch the HTML content of the webpage
url = 'https://openai.com/blog/chatgpt/'
response = requests.get(url)
html = response.text
# Parse the HTML content
soup = BeautifulSoup(html, 'html.parser')
# Find all the paragraphs in the HTML
paragraphs = soup.find_all('p')
# Print the text of the paragraphs
for p in paragraphs:
 print(p.text)

Just copying once again the previous code on my jupyter notebook, it works!

Screenshot of a Jupyter Notebook testing the sample code that ChatGPT gave me to parse its own website.

I can even ask to send ChatGPT how to send an automatic email to my google account. The following code was provided by ChatGPT.

import smtplib
# Set up the SMTP server
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('[email protected]', 'your-password')
# Send the email
to = '[email protected]'
subject = 'Test Email'
body = 'This is a test email sent from Python.'
msg = f'Subject: {subject}\n\n{body}'
server.sendmail('[email protected]', to, msg)
# Disconnect from the server
server.quit()

Copying it and executing it in my Jupyter Notebook… voilà! I just received the corresponding email right away!

Screenshot of my gmail account to check that I have received the automated mail generated by Python.

Cool!!! Isn’t it?? You can just ask whatever you want — your imagination is your only limit.

#5. Get help with your code

The last but not least thing you can do with ChatGPT is to debug your code. If you are having trouble with your Python code, you can ask ChatGPT for help with debugging. It can suggest possible solutions or strategies for troubleshooting your code.

Just imagine I want to compute the fibonacci serie. However, I defined the following function that does not work properly:

def fibonacci_of(n):
  if n in {0, 1}:  # Base case
    return n
  return fibonacci_of(n) + fibonacci_of(n)  # Recursive case

I can ask ChatGPT:

Does this function computes the fibonacci serie? [Insert function here]

And ChatGPT answers me that the function is incorrect and corrects it to me:

Screenshot of ChatGPT. It corrects my fibonacci function to correctly return the fibonacci series.

You can even ask ChatGPT to correct your code so it follows the Pep-8 style code.

Convert the following code to Pep-8 [Insert code here]

As you can observe in the following image, ChatGPT not only corrects my code but explains step by step how to adjust it to fulfill Pep-8.

Screenshot of ChatGPT. Adjusting my code to fullfil the Pep-8 style guide.

You can try to challenge ChatGPT with more complex questions!

Main Conclusions

ChatGPT is here to help you learn Python in a more interactive and personalized way. It can offer guidance, explanations, and suggestions as you work on programming exercises and projects.

This is why you can take advantage of ChatGPT knowledge — and get all its resources to help you further understand Python and its various libraries and frameworks.

Let me know if ChatGPT surprises you with some other good features. I will read you in the comments! :D

Do you want to try the new AI autonomous model — AutoGPT?

Just give a look at the following article!

Data always has a better idea — trust it.

You can suscribe to my Medium Newsletter to stay tuned and receive my content. I promise it will be unique!

If you are not a full Medium member yet, just check it out here to support me and many other writers. It really helps :D

Some other nice medium related articles you should go check out! :D

Data Science
ChatGPT
Programming
Python
Artificial Intelligence
Recommended from ReadMedium