0
0
Data Analysis Pythondata~15 mins

Reading HTML tables in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Reading HTML tables
📖 Scenario: Imagine you found a webpage that shows a table of daily temperatures for a week. You want to get this data into your program to analyze it easily.
🎯 Goal: You will write a program that reads the temperature table from an HTML string and shows it as a table you can work with.
📋 What You'll Learn
Use the pandas library to read HTML tables
Extract the first table from the HTML content
Store the table in a variable called temperature_table
Print the temperature_table to see the data
💡 Why This Matters
🌍 Real World
Websites often show data in tables. Being able to read these tables lets you collect and analyze data easily without manual copying.
💼 Career
Data analysts and scientists frequently extract data from web pages. Knowing how to read HTML tables with pandas is a useful skill for data gathering and cleaning.
Progress0 / 4 steps
1
Create the HTML string with the temperature table
Create a variable called html_data and set it to this exact HTML string containing a table with days and temperatures:
<table>
  <tr><th>Day</th><th>Temperature</th></tr>
  <tr><td>Monday</td><td>20</td></tr>
  <tr><td>Tuesday</td><td>22</td></tr>
  <tr><td>Wednesday</td><td>19</td></tr>
  <tr><td>Thursday</td><td>23</td></tr>
  <tr><td>Friday</td><td>21</td></tr>
</table>
Data Analysis Python
Need a hint?

Use triple quotes ''' to create a multi-line string for the HTML table.

2
Import pandas library
Write a line to import the pandas library using the alias pd.
Data Analysis Python
Need a hint?

Use the syntax import pandas as pd to import pandas with the short name pd.

3
Read the HTML table into a DataFrame
Use pd.read_html with the variable html_data to read the tables. Store the first table in a variable called temperature_table.
Data Analysis Python
Need a hint?

Use pd.read_html(html_data) to get a list of tables, then select the first with [0].

4
Print the temperature table
Write a line to print the variable temperature_table to see the table data.
Data Analysis Python
Need a hint?

Use print(temperature_table) to show the table.