Excel VBA: Compley copy & paste - excel

as many of us, I'm new to VBA. Often I can research the answers to my questions, but I suppose this on is too specific.
I got the following arrangement of data:
<table border=0 cellpadding=0 cellspacing=0 width=491 style='border-collapse:
collapse;table-layout:fixed;width:368pt'>
<col width=107 style='mso-width-source:userset;mso-width-alt:3913;width:80pt'>
<col width=64 span=6 style='width:48pt'>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 width=107 style='height:15.0pt;width:80pt'>Production site</td>
<td class=xl1523206 width=64 style='width:48pt'>Year</td>
<td class=xl1523206 width=64 style='width:48pt'>Part 1</td>
<td class=xl1523206 width=64 style='width:48pt'> Part 2</td>
<td class=xl1523206 width=64 style='width:48pt'>Part 3</td>
<td class=xl1523206 width=64 style='width:48pt'>Part 4</td>
<td class=xl1523206 width=64 style='width:48pt'>Part n</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Site A</td>
<td class=xl1523206 align=right>2017</td>
<td class=xl1523206 align=right>7</td>
<td class=xl1523206 align=right>4</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>5</td>
<td class=xl1523206 align=right>3</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Site A</td>
<td class=xl1523206 align=right>2018</td>
<td class=xl1523206 align=right>8</td>
<td class=xl1523206 align=right>6</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>5</td>
<td class=xl1523206 align=right>3</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Site A</td>
<td class=xl1523206 align=right>2019</td>
<td class=xl1523206 align=right>8</td>
<td class=xl1523206 align=right>6</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>5</td>
<td class=xl1523206 align=right>3</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Site B</td>
<td class=xl1523206 align=right>2017</td>
<td class=xl1523206 align=right>4</td>
<td class=xl1523206 align=right>3</td>
<td class=xl1523206 align=right>1</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>0</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Site B</td>
<td class=xl1523206 align=right>2018</td>
<td class=xl1523206 align=right>7</td>
<td class=xl1523206 align=right>4</td>
<td class=xl1523206 align=right>1</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>0</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Site B</td>
<td class=xl1523206 align=right>2019</td>
<td class=xl1523206 align=right>7</td>
<td class=xl1523206 align=right>4</td>
<td class=xl1523206 align=right>1</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>0</td>
</tr>
<![if supportMisalignedColumns]>
<tr height=0 style='display:none'>
<td width=107 style='width:80pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
</tr>
<![endif]>
</table>
The number of parts, production sites and years is not limited.
Now I need to copy the data and put it into a different structure to be able to work with it.
This is how the data must look like:
<table border=0 cellpadding=0 cellspacing=0 width=491 style='border-collapse:
collapse;table-layout:fixed;width:368pt'>
<col width=107 style='mso-width-source:userset;mso-width-alt:3913;width:80pt'>
<col width=64 span=6 style='width:48pt'>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 width=107 style='height:15.0pt;width:80pt'>Part</td>
<td class=xl1523206 width=64 style='width:48pt'>Production Site</td>
<td class=xl1523206 width=64 style='width:48pt'>2017</td>
<td class=xl1523206 width=64 style='width:48pt'>2018</td>
<td class=xl1523206 width=64 style='width:48pt'>2019</td>
<td class=xl1523206 width=64 style='width:48pt'></td>
<td class=xl1523206 width=64 style='width:48pt'>Year n</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Part 1</td>
<td class=xl1523206 align=right>Site A</td>
<td class=xl1523206 align=right>7</td>
<td class=xl1523206 align=right>4</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>5</td>
<td class=xl1523206 align=right>3</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Part 1</td>
<td class=xl1523206 align=right>Site B</td>
<td class=xl1523206 align=right>8</td>
<td class=xl1523206 align=right>6</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>5</td>
<td class=xl1523206 align=right>3</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Part 1</td>
<td class=xl1523206 align=right>Site n</td>
<td class=xl1523206 align=right>8</td>
<td class=xl1523206 align=right>6</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>5</td>
<td class=xl1523206 align=right>3</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Part 2</td>
<td class=xl1523206 align=right>Site A</td>
<td class=xl1523206 align=right>4</td>
<td class=xl1523206 align=right>3</td>
<td class=xl1523206 align=right>1</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>0</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Part 2</td>
<td class=xl1523206 align=right>Site B</td>
<td class=xl1523206 align=right>7</td>
<td class=xl1523206 align=right>4</td>
<td class=xl1523206 align=right>1</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>0</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl1523206 style='height:15.0pt'>Part 2</td>
<td class=xl1523206 align=right>Site n</td>
<td class=xl1523206 align=right>7</td>
<td class=xl1523206 align=right>4</td>
<td class=xl1523206 align=right>1</td>
<td class=xl1523206 align=right>2</td>
<td class=xl1523206 align=right>0</td>
</tr>
<![if supportMisalignedColumns]>
<tr height=0 style='display:none'>
<td width=107 style='width:80pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
</tr>
<![endif]>
</table>
I suppose I need to do all kind of indexing, looping and so on. Anybody with ideas to get my head around this task? I appreciate any input. Thanks a lot!

This can be done using Powerquery. You are unpivoting Part and pivoting on year.
Load the table using data > from table to import the source, in Excel 2013 use the powerquery add-in tab (free download from microsoft), in the editor window tha opens you then right clicking on columns to pivot/unpivot (or via transform tab) and finally close and load to sheet.

Related

Python multiple if statements for petrol price movement

Situation:
I buy a certain volume of petrol at price X, which is usually sold within a 30 days. During these 30 days, I will need to adjust my petrol station gas price according to average State gas price. If State price goes up by 1.2% from my purchased price, I will set my price to +1% of my purchased price.
Here is an example:
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-wa1i{font-weight:bold;text-align:center;vertical-align:middle}
.tg .tg-7zrl{text-align:left;vertical-align:bottom}
.tg .tg-0lax{text-align:left;vertical-align:top}
</style>
<table class="tg">
<thead>
<tr>
<th class="tg-wa1i">Time</th>
<th class="tg-wa1i">Average state gas price</th>
<th class="tg-wa1i">Av state price change, %</th>
<th class="tg-wa1i">My price change, %</th>
<th class="tg-wa1i">My station gas price</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tg-7zrl">1</td>
<td class="tg-0lax"> 4.231 </td>
<td class="tg-0lax"> - </td>
<td class="tg-0lax"> - </td>
<td class="tg-0lax"> 4.231 </td>
</tr>
<tr>
<td class="tg-7zrl">2</td>
<td class="tg-0lax"> 4.337 </td>
<td class="tg-0lax"> 2.5%</td>
<td class="tg-0lax"> 2.0%</td>
<td class="tg-0lax"> 4.316 </td>
</tr>
<tr>
<td class="tg-7zrl">3</td>
<td class="tg-0lax"> 4.437 </td>
<td class="tg-0lax"> 4.9%</td>
<td class="tg-0lax"> 4.0%</td>
<td class="tg-0lax"> 4.400 </td>
</tr>
<tr>
<td class="tg-7zrl">4</td>
<td class="tg-0lax"> 4.481 </td>
<td class="tg-0lax"> 5.9%</td>
<td class="tg-0lax"> 5.0%</td>
<td class="tg-0lax"> 4.443 </td>
</tr>
<tr>
<td class="tg-7zrl">5</td>
<td class="tg-0lax"> 4.571 </td>
<td class="tg-0lax"> 8.0%</td>
<td class="tg-0lax"> 8.0%</td>
<td class="tg-0lax"> 4.569 </td>
</tr>
<tr>
<td class="tg-7zrl">6</td>
<td class="tg-0lax"> 4.616 </td>
<td class="tg-0lax"> 9.1%</td>
<td class="tg-0lax"> 9.0%</td>
<td class="tg-0lax"> 4.612 </td>
</tr>
<tr>
<td class="tg-7zrl">7</td>
<td class="tg-0lax"> 4.709 </td>
<td class="tg-0lax"> 11.3%</td>
<td class="tg-0lax"> 11.0%</td>
<td class="tg-0lax"> 4.696 </td>
</tr>
<tr>
<td class="tg-7zrl">8</td>
<td class="tg-0lax"> 4.850 </td>
<td class="tg-0lax"> 14.6%</td>
<td class="tg-0lax"> 14.0%</td>
<td class="tg-0lax"> 4.823 </td>
</tr>
</tbody>
</table>
Here is a python code but it is very clunky, and if gas price moves up by 20%, then I have to write my_priceX up to 20 times. Is there a more elegant solution?
my_price1 = last_gas_price["price"]*1.01
my_price2 = last_gas_price["price"]*1.02
my_price3 = last_gas_price["price"]*1.03
my_price4 = last_gas_price["price"]*1.04
my_price5 = last_gas_price["price"]*1.05
if last_gas_price > my_price1:
adj_price(price = my_price1)
if last_gas_price > my_price2:
adj_price(price = my_price2)
if last_gas_price > my_price3:
adj_price(price = my_price3)
if last_gas_price > my_price4:
adj_price(price = my_price4)
if last_gas_price > my_price5:
adj_price(price = my_price5)

Check for vertical scrollbar in html local file

I have a VBA code that opens local HTML files using selenium like that
bot.Get "file:///" & Environ("USERPROFILE") & "\Desktop\OutputHTML.html"
Sometimes I got an error Out of memory as I am trying to take a screen shot for large size of the table (inside the HTML body)
Is it possible to check if there is a vertical scrollbar of the selenium browser and if there is a vertical scrollbar, I need to zoom in till this scrollbar disappears?
This is the code for you to test
Private bot As Selenium.ChromeDriver
Sub Test()
Dim eleTable As Selenium.WebElement, strPath As String, img As Image
Set bot = New Selenium.ChromeDriver
strPath = ThisWorkbook.Path & "\"
bot.Get "file:///" & Environ("USERPROFILE") & "\Desktop\OutputHTML.html"
Set eleTable = Nothing
On Error Resume Next
Set eleTable = bot.FindElementByCss(".table-striped")
On Error GoTo 0
If Not eleTable Is Nothing Then
Set img = eleTable.ScrollIntoView().TakeScreenshot()
img.SaveAs strPath & "Output.png"
Else
Debug.Print "Error In Taking Screenshot"
End If
End Sub
and this is example of the HTML local file
<bdo dir="rtl"><meta http-equiv="Content-Type" content="text/html; charset=windows-1256"/>
<style type="text/css">
th,td{
text-align: center !important;
}
</style>
<table class="table table-striped">
<tr class="">
<th width="5%" style="text-align:center;">م</th>
<th width="15%" style="text-align:center;">التاريخ</th>
<th style="text-align:center;">العملية</th>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>1</td>
<td dir="ltr">2022-02-23</td>
<td style="padding-right:10px;">اعادة فتح ملف )مغلق(</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>2</td>
<td dir="ltr">2022-02-22</td>
<td style="padding-right:10px;">اغلاق ملف</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>3</td>
<td dir="ltr">2022-02-22</td>
<td style="padding-right:10px;">ايصال توريد</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>4</td>
<td dir="ltr">2022-02-14</td>
<td style="padding-right:10px;">اذن صرف</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>5</td>
<td dir="ltr">2022-02-14</td>
<td style="padding-right:10px;">استمارة صــرف</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>6</td>
<td dir="ltr">2022-01-19</td>
<td style="padding-right:10px;">اعادة فتح ملف )مغلق(</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>7</td>
<td dir="ltr">2022-01-18</td>
<td style="padding-right:10px;">اغلاق ملف</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>8</td>
<td dir="ltr">2022-01-18</td>
<td style="padding-right:10px;">ايصال توريد</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>9</td>
<td dir="ltr">2021-12-27</td>
<td style="padding-right:10px;">اعادة فتح ملف )مغلق(</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>10</td>
<td dir="ltr">2021-12-26</td>
<td style="padding-right:10px;">اغلاق ملف</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>11</td>
<td dir="ltr">2021-12-26</td>
<td style="padding-right:10px;">ايصال توريد</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>12</td>
<td dir="ltr">2021-11-22</td>
<td style="padding-right:10px;">اعادة فتح ملف )مغلق(</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>13</td>
<td dir="ltr">2021-11-21</td>
<td style="padding-right:10px;">اغلاق ملف</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>14</td>
<td dir="ltr">2021-11-21</td>
<td style="padding-right:10px;">ايصال توريد</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>15</td>
<td dir="ltr">2021-11-15</td>
<td style="padding-right:10px;">اذن صرف</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>16</td>
<td dir="ltr">2021-11-15</td>
<td style="padding-right:10px;">استمارة صــرف</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>17</td>
<td dir="ltr">2021-10-19</td>
<td style="padding-right:10px;">اعادة فتح ملف )مغلق(</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>18</td>
<td dir="ltr">2021-10-18</td>
<td style="padding-right:10px;">اغلاق ملف</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>19</td>
<td dir="ltr">2021-10-18</td>
<td style="padding-right:10px;">ايصال توريد</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>20</td>
<td dir="ltr">2021-09-15</td>
<td style="padding-right:10px;">اعادة فتح ملف )مغلق(</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>21</td>
<td dir="ltr">2021-09-14</td>
<td style="padding-right:10px;">اغلاق ملف</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>22</td>
<td dir="ltr">2021-09-14</td>
<td style="padding-right:10px;">ايصال توريد</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>23</td>
<td dir="ltr">2021-09-12</td>
<td style="padding-right:10px;">اذن صرف</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>24</td>
<td dir="ltr">2021-09-12</td>
<td style="padding-right:10px;">استمارة صــرف</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>25</td>
<td dir="ltr">2021-09-12</td>
<td style="padding-right:10px;">ايصال توريد</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>26</td>
<td dir="ltr">2021-08-23</td>
<td style="padding-right:10px;">اعادة فتح ملف )مغلق(</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>27</td>
<td dir="ltr">2021-08-22</td>
<td style="padding-right:10px;">اغلاق ملف</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>28</td>
<td dir="ltr">2021-08-22</td>
<td style="padding-right:10px;">ايصال توريد</td>
</tr>
<tr class="resultRowOdd" align="center" style="line-height:25px;">
<td>29</td>
<td dir="ltr">2021-08-02</td>
<td style="padding-right:10px;">اعادة فتح ملف )مغلق(</td>
</tr>
<tr class="resultRowEven" align="center" style="line-height:25px;">
<td>30</td>
<td dir="ltr">2021-08-01</td>
<td style="padding-right:10px;">اغلاق ملف</td>
</tr>
</table>
</html></bdo>
I tried such a line to check the vertical scrollbar
Debug.Print bot.ExecuteScript("return document.documentElement.scrollHeight>document.documentElement.clientHeight;")
But this returns False although there's a scroll bar
I tried this line bot.ExecuteScript "document.body.style.zoom='90%';" to make the zoom out but I got another error Element outside the screenshot

Sort Beautiful soup elements by text value

I've search about this on the internet on how I could do this but it seems to have a different type of question & goal.
So I have this soup right here. You can have a test on this code.
from bs4 import BeautifulSoup
html = '''
<table border="1" cellspacing="0" width="300">
<tbody><tr>
<td width="50%">lesson 1</td>
<td>lesson 7</td>
</tr>
<tr>
<td width="50%">lesson 2</td>
<td>lesson 8</td>
</tr>
<tr>
<td width="50%">lesson 3</td>
<td>lesson 9</td>
</tr>
<tr>
<td width="50%">lesson 4</td>
<td>lesson 10</td>
</tr>
<tr>
<td width="50%">lesson 5</td>
<td>lesson 11</td>
</tr>
<tr>
<td width="50%">lesson 6</td>
<td>lesson 12</td>
</tr>
</tbody></table>
'''
soup = BeautifulSoup(html,"html5lib")#use any parser you want.
for td in soup.find_all("td"):
print(td)# This outputs the not sorted <td> tags
Not sorted <td> tags.
<td width="50%">lesson 1</td>
<td>lesson 7</td>
<td width="50%">lesson 2</td>
<td>lesson 8</td>
<td width="50%">lesson 3</td>
<td>lesson 9</td>
<td width="50%">lesson 4</td>
<td>lesson 10</td>
<td width="50%">lesson 5</td>
<td>lesson 11</td>
<td width="50%">lesson 6</td>
<td>lesson 12</td>
Now you can see on the .text of every <td> tag there is a text for example "lesson 1" , "lesson 7", "lesson 2" and so on... Now what I wanted to have is sort this <td> tags by its text value also by the number. So I'd want to have an output like this.
<td width="50%">lesson 1</td>
<td width="50%">lesson 2</td>
<td width="50%">lesson 3</td>
<td width="50%">lesson 4</td>
<td width="50%">lesson 5</td>
<td width="50%">lesson 6</td>
<td>lesson 7</td>
<td>lesson 8</td>
<td>lesson 9</td>
<td>lesson 10</td>
<td>lesson 11</td>
<td>lesson 12</td>
Thank you so much! I really appreciate your help.
This should do the job and give you a list of the sorted td tags that contain an a tag.
from bs4 import BeautifulSoup
html = '''
<table border="1" cellspacing="0" width="300">
<tbody><tr>
<td width="50%">lesson 1</td>
<td>lesson 7</td>
</tr>
<tr>
<td width="50%">lesson 2</td>
<td>lesson 8</td>
</tr>
<tr>
<td width="50%">lesson 3</td>
<td>lesson 9</td>
</tr>
<tr>
<td width="50%">lesson 4</td>
<td>lesson 10</td>
</tr>
<tr>
<td width="50%">lesson 5</td>
<td>lesson 11</td>
</tr>
<tr>
<td width="50%">lesson 6</td>
<td>lesson 12</td>
</tr>
</tbody></table>
'''
soup = BeautifulSoup(html, 'html.parser')
# Function takes one <td> tag, finds it's child which is an <a> tag
# it then finds the text inside it and then splits it to get the number
# this is then returned to the sorted function as an int
def sort_soup(item):
item = list(item.children)[0].text
data = item.split(" ")
return int(data[1])
out = soup.findAll('td')
out = sorted(out, key= lambda elem: sort_soup(elem))
print(out)

Excel formula to find the nearest values

Is it possible to find the nearest value (+or-) with formula and display the 1st row value & 1st column value in my linked excel table?
Eg:
Search Value is "7,30" (C12; variable can ask for any value on table)
Found row value is "7" (E12 with formula; adressed to A7)
Found column value "4,00%" (E13 with formula; adressed to E1)
"F12" Formula is OK. What can be the formula in "F13" regarding the information on table below?
<head>
<meta http-equiv=Content-Type content="text/html; charset=Windows-1254">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 14">
<link rel=File-List href="SampleT_dosyalar/filelist.xml">
<style id="table-3_9841_Styles">
<!--table
{mso-displayed-decimal-separator:"\,";
mso-displayed-thousand-separator:"\.";}
.xl159841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl659841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:General;
text-align:right;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl669841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl679841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:Fixed;
text-align:general;
vertical-align:bottom;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl689841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:"0\.00\\%";
text-align:general;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl699841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
background:#FFC000;
mso-pattern:black none;
white-space:nowrap;}
.xl709841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:"0\.00\\%";
text-align:general;
vertical-align:bottom;
background:#FFC000;
mso-pattern:black none;
white-space:nowrap;}
.xl719841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:"0\.00\\%";
text-align:general;
vertical-align:bottom;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl729841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:General;
text-align:left;
vertical-align:top;
border:none;
mso-diagonal-up:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:normal;}
.xl739841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:red;
font-size:11.0pt;
font-weight:700;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl749841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:#0070C0;
font-size:11.0pt;
font-weight:700;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl759841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:General;
text-align:center;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl769841
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:162;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
background:#D9D9D9;
mso-pattern:black none;
white-space:nowrap;}
-->
</style>
</head>
<body>
<!--[if !excel]> <![endif]-->
<!--Aşağıdaki bilgiler Microsoft Excel'in Web Sayfası Olarak Yayımlama
sihirbazı tarafından oluşturuldu.-->
<!--Aynı öğe Excel'den yeniden yayımlanırsa, DIV etiketleri arasındaki
bilgilerin tümü değiştirilecek.-->
<!----------------------------->
<!--EXCEL WEB SAYFASI OLARAK YAYIMLA SİHİRBAZI ÇIKTI BAŞLANGICI-->
<!----------------------------->
<div id="table-3_9841" align=center x:publishsource="Excel">
<table border=0 cellpadding=0 cellspacing=0 width=1114 style='border-collapse:
collapse;table-layout:fixed;width:836pt'>
<col class=xl159841 width=26 style='mso-width-source:userset;mso-width-alt:
950;width:20pt'>
<col class=xl159841 width=64 style='width:48pt'>
<col width=64 span=16 style='width:48pt'>
<tr class=xl159841 height=20 style='height:15.0pt'>
<td height=20 class=xl769841 width=26 style='height:15.0pt;width:20pt'> </td>
<td class=xl759841 width=64 style='width:48pt'>A</td>
<td class=xl759841 width=64 style='width:48pt'>B</td>
<td class=xl759841 width=64 style='width:48pt'>C</td>
<td class=xl759841 width=64 style='width:48pt'>D</td>
<td class=xl759841 width=64 style='width:48pt'>E</td>
<td class=xl759841 width=64 style='width:48pt'>F</td>
<td class=xl759841 width=64 style='width:48pt'>H</td>
<td class=xl759841 width=64 style='width:48pt'>I</td>
<td class=xl759841 width=64 style='width:48pt'>J</td>
<td class=xl759841 width=64 style='width:48pt'>K</td>
<td class=xl759841 width=64 style='width:48pt'>L</td>
<td class=xl759841 width=64 style='width:48pt'>M</td>
<td class=xl759841 width=64 style='width:48pt'>N</td>
<td class=xl759841 width=64 style='width:48pt'>O</td>
<td class=xl759841 width=64 style='width:48pt'>P</td>
<td class=xl759841 width=64 style='width:48pt'>Q</td>
<td class=xl759841 width=64 style='width:48pt'>R</td>
</tr>
<tr height=20 style='mso-height-source:userset;height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>1</td>
<td rowspan=2 class=xl729841 width=64 style='width:48pt'><span
style='mso-spacerun:yes'> </span>%<br>
<span style='mso-spacerun:yes'> </span>Price</td>
<td class=xl689841 align=right>1,00%</td>
<td class=xl689841 align=right>2,00%</td>
<td class=xl689841 align=right>3,00%</td>
<td class=xl709841 align=right>4,00%</td>
<td class=xl689841 align=right>5,00%</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>2</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>3</td>
<td class=xl159841 align=right>3</td>
<td class=xl159841 align=right><a name="RANGE!C4:G11">3,03</a></td>
<td class=xl159841 align=right>3,06</td>
<td class=xl159841 align=right>3,095</td>
<td class=xl159841 align=right>3,125</td>
<td class=xl159841 align=right>3,16</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>4</td>
<td class=xl159841 align=right>4</td>
<td class=xl159841 align=right>4,04</td>
<td class=xl159841 align=right>4,08</td>
<td class=xl159841 align=right>4,125</td>
<td class=xl159841 align=right>4,165</td>
<td class=xl159841 align=right>4,21</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>5</td>
<td class=xl159841 align=right>5</td>
<td class=xl159841 align=right>5,05</td>
<td class=xl159841 align=right>5,1</td>
<td class=xl159841 align=right>5,155</td>
<td class=xl159841 align=right>5,21</td>
<td class=xl159841 align=right>5,265</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>6</td>
<td class=xl159841 align=right>6</td>
<td class=xl159841 align=right>6,06</td>
<td class=xl159841 align=right>6,12</td>
<td class=xl159841 align=right>6,185</td>
<td class=xl159841 align=right>6,25</td>
<td class=xl739841 align=right>7,29</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>7</td>
<td class=xl699841 align=right>7</td>
<td class=xl159841 align=right>7,07</td>
<td class=xl159841 align=right>7,145</td>
<td class=xl159841 align=right>7,215</td>
<td class=xl739841 align=right>7,29</td>
<td class=xl159841 align=right>7,37</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>8</td>
<td class=xl159841 align=right>8</td>
<td class=xl159841 align=right>8,08</td>
<td class=xl159841 align=right>8,165</td>
<td class=xl159841 align=right>8,245</td>
<td class=xl159841 align=right>8,335</td>
<td class=xl159841 align=right>8,42</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>9</td>
<td class=xl159841 align=right>9</td>
<td class=xl159841 align=right>9,09</td>
<td class=xl159841 align=right>9,185</td>
<td class=xl159841 align=right>9,28</td>
<td class=xl159841 align=right>9,375</td>
<td class=xl159841 align=right>9,475</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>10</td>
<td class=xl159841 align=right>10</td>
<td class=xl159841 align=right>10,1</td>
<td class=xl159841 align=right>10,205</td>
<td class=xl159841 align=right>10,31</td>
<td class=xl159841 align=right>10,415</td>
<td class=xl159841 align=right>10,525</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>11</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>12</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl659841>Search:</td>
<td class=xl679841 align=right>7,30</td>
<td class=xl659841>Row</td>
<td class=xl669841 align=right>7</td>
<td class=xl159841 colspan=11><span style='mso-spacerun:yes'>
</span>=İNDİS($A:$A;MAK((MİN(MUTLAK(DataRange-$C$12))=MUTLAK(DataRange-$C$12))*SATIR(DataRange)))</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>13</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl659841>Column</td>
<td class=xl719841 align=right style='border-top:none'>5,00%</td>
<td class=xl159841 colspan=11><span style='mso-spacerun:yes'>
</span>=İNDİS($1:$1;1;MAK((MİN(MUTLAK(DataRange-$C$12))=MUTLAK(DataRange-$C$12))*SÜTUN(DataRange)))</td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>14</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>15</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl749841 colspan=10>This formula is OK as row# "7" but is
it possible to display "E7" instead of "F6" as column
title?</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>16</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl749841 colspan=12>Can the formula check row# first to retrieve
the colum title then check for others if no figure is identical in row
"7" line?</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<tr height=20 style='height:15.0pt'>
<td height=20 class=xl759841 style='height:15.0pt'>18</td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
<td class=xl159841></td>
</tr>
<![if supportMisalignedColumns]>
<tr height=0 style='display:none'>
<td width=26 style='width:20pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
</tr>
<![endif]>
</table>
</div>
<!----------------------------->
<!--EXCEL WEB SAYFASI OLARAK YAYIMLA SİHİRBAZI ÇIKTI SONU-->
<!----------------------------->
</body>
</html>
I guess there must be a prettier answer to this, but this worked for me:
In E12 put this:
=ROUNDDOWN(C12,0)
And in E13 put this Array-Formula (need to be entered with Ctrl+Shift+Enter instead of the usual Enter):
=MATCH(MIN(ABS(C12-B3:F10)),ABS(C12-INDIRECT(CONCATENATE("B",E12)):INDIRECT(CONCATENATE("F",E12))),0)
Hope this helps
These formulas must be array-entered:
Row: =INDEX($A:$A,MAX((MIN(ABS(DataRange-$C$12))=ABS(DataRange-$C$12))*ROW(DataRange)))
Column: =INDEX($1:$1,1,MAX((MIN(ABS(DataRange-$C$12))=ABS(DataRange-$C$12))*COLUMN(DataRange)))
EDIT: If there is a possibility of duplicates in the table (two values that are equidistant from the search value, then the following formula will ensure that Column comes from the same row as the row value found.
Row: Formula in C12
Column: =INDEX($1:$1,1,MAX((MIN(ABS(INDEX(DataRange,E12-ROW(DataRange)+1,0)-$C$12))=ABS(INDEX(DataRange,E12-ROW(DataRange)+1,0)-$C$12))*COLUMN(DataRange)))
In your example,
DataRange refers to: =Sheet1!$B$3:$F$10
To array-enter a formula, after entering
the formula into the cell or formula bar, hold down
ctrl+shift while hitting enter. If you did this
correctly, Excel will place braces {...} around the formula.
In E12, the row:
=INDEX(A:A,AGGREGATE(15,6,($B$3:$F$10)/(AGGREGATE(15,6,ABS(C12-$B$3:$F$10),1)=ABS(C12-$B$3:$F$10)),1))
In E13, the column:
=INDEX(1:1,AGGREGATE(15,6,COLUMN($B$3:$F$10)/(AGGREGATE(15,6,ABS(C12-$B$3:$F$10),1)=ABS(C12-$B$3:$F$10)),1))

concat multiple df made from pd.read_html

my title does not make any sense so i am going to give brief about situation
i am scraping data from site which basically table but in this case every row is a table element and also every odd table element is not useful so i am eliminating
so what i want is concatenation of every individual dataframe made up of every even table element using read_html()
below is my code
import pandas as pd
all_table = ["""<table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr height="10px">
<td align="right" colspan="9">
<font color="#D5D5D5">.</font>
</td>
</tr>
<tr height="30px" valign="middle" width="100%">
<td class="size-12" colspan="8" width="100%">
<strong>Shipment Status</strong>
</td>
</tr>
<tr valign="bottom" width="100%">
<td align="center" class="size-10" width="10%">
<strong>Station</strong>
</td>
<td align="center" class="size-10" width="10%">
<strong>Flight No.</strong>
</td>
<td align="center" class="size-10" width="25%">
<strong>Status</strong>
</td>
<td align="center" class="size-10" width="15%">
<strong>Date</strong>
</td>
<td align="center" class="size-10" width="9%">
<strong>Time</strong>
</td>
<td align="center" class="size-10" width="8%">
<strong>Pcs</strong>
</td>
<td align="center" class="size-10" width="8%">
<strong>Wgt</strong>
</td>
<td align="center" class="size-10" width="15%">
<strong>ULD - Battery - Temp</strong>
</td>
</tr>
<tr bgcolor="#F0F0F0" class="result-row">
<td align="center" class="size-10" width="10%">KIX</td>
<td align="center" class="size-10" width="10%">
<center>-</center>
</td>
<td align="center" class="size-10" width="25%">Shipment Received</td>
<td align="center" class="size-10" width="15%">11 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 22:45</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#FFFFFF" class="result-row">
<td align="center" class="size-10" width="10%">KIX</td>
<td align="center" class="size-10" width="10%">
<center>-</center>
</td>
<td align="center" class="size-10" width="25%">Freight On Hand</td>
<td align="center" class="size-10" width="15%">11 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 22:45</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#F0F0F0" class="result-row">
<td align="center" class="size-10" width="10%">KIX</td>
<td align="center" class="size-10" width="10%">SQ0621</td>
<td align="center" class="size-10" width="25%">Flight Departed</td>
<td align="center" class="size-10" width="15%">13 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 17:18</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#FFFFFF" class="result-row">
<td align="center" class="size-10" width="10%">SIN</td>
<td align="center" class="size-10" width="10%">SQ0621</td>
<td align="center" class="size-10" width="25%">Flight Arrived</td>
<td align="center" class="size-10" width="15%">13 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 23:02</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#F0F0F0" class="result-row">
<td align="center" class="size-10" width="10%">SIN</td>
<td align="center" class="size-10" width="10%">SQ0621</td>
<td align="center" class="size-10" width="25%">Flight Arrived</td>
<td align="center" class="size-10" width="15%">13 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 23:02</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#FFFFFF" class="result-row">
<td align="center" class="size-10" width="10%">SIN</td>
<td align="center" class="size-10" width="10%">SQ0621</td>
<td align="center" class="size-10" width="25%">Shipment Checked Into Warehouse</td>
<td align="center" class="size-10" width="15%">14 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 02:57</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#F0F0F0" class="result-row">
<td align="center" class="size-10" width="10%">SIN</td>
<td align="center" class="size-10" width="10%">SQ0422</td>
<td align="center" class="size-10" width="25%">Flight Departed</td>
<td align="center" class="size-10" width="15%">14 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 07:39</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#FFFFFF" class="result-row">
<td align="center" class="size-10" width="10%">BOM</td>
<td align="center" class="size-10" width="10%">SQ0422</td>
<td align="center" class="size-10" width="25%">Flight Arrived</td>
<td align="center" class="size-10" width="15%">14 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 10:12</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#F0F0F0" class="result-row">
<td align="center" class="size-10" width="10%">BOM</td>
<td align="center" class="size-10" width="10%">SQ0422</td>
<td align="center" class="size-10" width="25%">Flight Arrived</td>
<td align="center" class="size-10" width="15%">14 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 10:30</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#FFFFFF" class="result-row">
<td align="center" class="size-10" width="10%">BOM</td>
<td align="center" class="size-10" width="10%">SQ0422</td>
<td align="center" class="size-10" width="25%">Shipment Checked Into Warehouse</td>
<td align="center" class="size-10" width="15%">14 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 14:10</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#F0F0F0" class="result-row">
<td align="center" class="size-10" width="10%">BOM</td>
<td align="center" class="size-10" width="10%">
<center>-</center>
</td>
<td align="center" class="size-10" width="25%">Shipment Ready for Pick-up</td>
<td align="center" class="size-10" width="15%">14 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 14:21</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#FFFFFF" class="result-row">
<td align="center" class="size-10" width="10%">BOM</td>
<td align="center" class="size-10" width="10%">
<center>-</center>
</td>
<td align="center" class="size-10" width="25%">Document Delivered</td>
<td align="center" class="size-10" width="15%">14 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 17:15</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
</table>, <table cellpadding="0" cellspacing="0" cols="8" width="100%">
<tbody><tr bgcolor="#F0F0F0" class="result-row">
<td align="center" class="size-10" width="10%">BOM</td>
<td align="center" class="size-10" width="10%">
<center>-</center>
</td>
<td align="center" class="size-10" width="25%">Shipment Delivered</td>
<td align="center" class="size-10" width="15%">14 Oct 2019</td>
<td align="center" class="size-10" width="9%"> 17:15</td>
<td align="center" class="size-10" width="8%">34</td>
<td align="center" class="size-10" width="8%">411.3</td>
<td align="center" class="size-10" width="15%"></td>
</tr>
</tbody></table>"""]
final_delivary = pd.DataFrame()
a = 0
for i in range(len(all_table)):
print("-"*150)
if a % 2 == 0:
print(a)
# print(all_table[a])
tmp_table = all_table[a]
tmp_df = pd.read_html(str(tmp_table))
print("tmp_df = \n", tmp_df)
print("type of tmp_df = ", type(tmp_df))
print("#"*75)
tmp_df2 = pd.DataFrame(tmp_df[0])
print("tmp_df2 = \n", tmp_df2)
print("type of tmp_df2 = ", type(tmp_df2))
print("#"*75)
print("final_delivary = \n", final_delivary)
print("type of final_delivary = ", type(final_delivary))
pd.concat([final_delivary, tmp_df2], axis=0)
else:
print("nope")
a+=1
print("final_delivary = ", final_delivary)
so i am facing problem while concatenating individual dataframe to main dataframe and result am getting is empty dataframe so please help me with that
Try this
from bs4 import BeautifulSoup as bs
import pandas as pd
all_table = '''
html content
'''
finalDf = pd.DataFrame()
soup = bs(all_table)
tables = soup.findAll("table")
for i,table in enumerate(tables):
if i%2==0:
df = pd.read_html(str(table))
finalDf = pd.concat([finalDf,df[0]])

Resources