0
0
Data Analysis Pythondata~10 mins

Reading HTML tables in Data Analysis Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read all tables from the given URL.

Data Analysis Python
import pandas as pd
url = 'https://example.com/tables.html'
tables = pd.read_html([1])
Drag options to blanks, or click blank then click option'
Aurl
Bpd.read_html
C'url'
Dtables
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the URL as a string literal instead of the variable.
Passing the function name instead of the URL.
2fill in blank
medium

Complete the code to read only the first table from the URL.

Data Analysis Python
import pandas as pd
url = 'https://example.com/tables.html'
table = pd.read_html(url)[[1]]
Drag options to blanks, or click blank then click option'
Amatch
B1
C0
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using parameters like match or index inside pd.read_html.
Using a string like '0' instead of the integer 0.
3fill in blank
hard

Fix the error in the code to read tables from the URL.

Data Analysis Python
import pandas as pd
url = 'https://example.com/tables.html'
tables = pd.read_html([1])
Drag options to blanks, or click blank then click option'
Atables
B'url'
Cpd.read_html
Durl
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the string 'url' instead of the variable url.
Passing the function name instead of the URL.
4fill in blank
hard

Fill both blanks to create a dictionary of table lengths for tables with more than 3 rows.

Data Analysis Python
import pandas as pd
url = 'https://example.com/tables.html'
tables = pd.read_html(url)
lengths = {i: len(tables[[1]]) for i in range(len(tables)) if len(tables[[2]]) > 3}
Drag options to blanks, or click blank then click option'
Ai
B0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using fixed indices like 0 or 1 instead of the loop variable.
Using different indices in the two places causing mismatch.
5fill in blank
hard

Fill all three blanks to create a dictionary of table indices and their row counts for tables with more than 2 columns.

Data Analysis Python
import pandas as pd
url = 'https://example.com/tables.html'
tables = pd.read_html(url)
table_info = { [1]: len(tables[[2]]) for [3] in range(len(tables)) if len(tables[[3]].columns) > 2 }
Drag options to blanks, or click blank then click option'
Ai
Dlen(tables)
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables or fixed numbers instead of i.
Using len(tables) as a key which is invalid.