I need to extract table information from pdf file, it contains the header and subheader. I used python tabula package and it gives me something like this:
| Header | unnanmed1 | unnamed2 |
|---|---|---|
| subheader1 | subheader2 | subheader3 |
| A | nan | nan |
| 1 | aaa | bbb |
| 2 | ccc | ddd |
| 3 | eee | fff |
| B | nan | nan |
| 4 | ggg | hhh |
| 5 | iii | jjj |
| 6 | kkk | lll |
import pandas as pd
import numpy as np
NaN = np.nan
df = pd.DataFrame({
'Header': ['subheader1', 'A', 1, 2, 3, 'B', 4, 5, 6],
'unnanmed1': ['subheader2', NaN, 'aaa', 'ccc', 'eee', NaN,
'ggg', 'iii', 'kkk'],
'unnamed2': ['subheader3', NaN, 'bbb', 'ddd', 'fff', NaN,
'hhh', 'jjj', 'lll'],
})
so, what I need to get is to get this result:
| Header | subheader1 | subheader2 | subheader3 |
|---|---|---|---|
| A | 1 | aaa | bbb |
| A | 2 | ccc | ddd |
| A | 3 | eee | fff |
| B | 4 | ggg | hhh |
| B | 5 | iii | jjj |
| B | 6 | kkk | lll |
I consider using map to do so, but still do not have a very clear clue. Thank you very much.