I have one ugly text file that looks like this:
2020-06-13
----------------------------------------
|Order |Warehouse|Stock|Price|Vendor|
|--------------------------------------|
|31434 |WA12 |200 |160 |AS12 |
|31435 |WA11 |26 |12 |AS11 |
|31436 |WA13 |202 |161 |AS16 |
----------------------------------------
2020-06-14
----------------------------------------
|Order |Warehouse|Stock|Price|Vendor|
|--------------------------------------|
|31437 |WA12 |200 |160 |AS12 |
|31438 |WA11 |26 |12 |AS11 |
|31439 |WA13 |202 |161 |AS16 |
----------------------------------------
I try to parse it using the read_csv function like so:
df = pd.read_csv(file, sep='|', error_bad_lines=False)
But my dataframe comes out with a lot of notable problems:
First problem, the first dashed lines (before the headers) and I also assume the last dashed lines (the footer) get inserted into the Material column and every other field in that row (Warehouse, Stock, Price, Vendor) is set to NaN
Is there a way to skip these dashed lines:
----------------------------------------?Second problem, is the separator | which shows up before and after the headers. Before Order and after Vendor
|Order |Warehouse|Stock|Price|Vendor|
This make pandas return two NaN headers with empty values inside of them
Third problem is how to ignore this line |--------------------------------------| as well?
Sorry if this question sounds confusing. I'm confused as well if this is the proper way to do it by changing the parameters the read_csv function takes or do I need to normalize/sanitize/clean the file before sending it to the read_csv function by doing some pure python?
Thank you