2021年3月19日星期五

Python pandas to remove header and footer records if detected before converting to dataframe

I am trying to clean my data before processing it. Below is a sample of my data in .txt file format

Input

20210320  Name|email|age|books|return-date  yuzu|yuzu@gmail.com|23|2020-09-23  apple|apple@gmail.com|27|2021-01-34  Total generated records: 2 rows   Exported on 2021-03-20  

Output - will be converted to dataframe by splitting with |

Name|email|age|books|return-date  yuzu|yuzu@gmail.com|23|2020-09-23  apple|apple@gmail.com|27|2021-01-34  

How do i remove the header and footer records using python? As i will be processing multiple files and the header and footer might not always appear, the codes need to be able to detect and remove if it is in the text file.

Any help is appreciated!

https://stackoverflow.com/questions/66717318/python-pandas-to-remove-header-and-footer-records-if-detected-before-converting March 20, 2021 at 09:00AM

没有评论:

发表评论