I'm new to pandas, and I'm trying to extract some data from some HTML files.
How to convert multiple HTML tables that looks like this :
PS4
Game Name | Price
GoW | 49.99
FF VII R | 59.99
XBX
Game Name | Price
Gears 5 | 49.99
Forza 5 | 59.99
<table>
<tr colspan="2">
<td>PS4</td>
</tr>
<tr>
<td>Game Name</td>
<td>Price</td>
</tr>
<tr>
<td>GoW</td>
<td>49.99</td>
</tr>
<tr>
<td>FF VII R</td>
<td>59.99</td>
</tr>
</table>
<table>
<tr colspan="2">
<td>XBX</td>
</tr>
<tr>
<td>Game Name</td>
<td>Price</td>
</tr>
<tr>
<td>Gears 5</td>
<td>49.99</td>
</tr>
<tr>
<td>Forza 5</td>
<td>59.99</td>
</tr>
</table>
into a json object like this:
[
{ "Game Name": "Gow", "Price": "49.99", "platform": "PS4"},
{ "Game Name": "FF VII R", "Price": "59.99", "platform": "PS4"},
{ "Game Name": "Gears 5", "Price": "49.99", "platform": "XBX"},
{ "Game Name": "Forza 5", "Price": "59.99", "platform": "XBX"}
]
I tried to load the html file containing the tables with pandas.read_html(path/to/file) and it did return a list of DataFrames but I don't know how to extract the data after that, especially that the platform name is in the header and not as a separate column.
I'm using pandas because I'm extracting those tables from local htm files that contain other forms of tables and HTML code, so I use :
tables = pandas.read_html(file_path, match="Game Name")
to quickly isolate the tables I need with the match parameter based on that column name.