Home > Enterprise >  How to extract a table from a csv file generated by Database
How to extract a table from a csv file generated by Database

Time:12-12

I have a csv file with the following format that is generated when I converted the table into a csv in Oracle Database. But inside the csv file there are other data as well apart from the table such as some meta data.

I want to select only the table part from this and get it into a pandas dataframe. I can just check the '#' marks and the table header and delete them but it will not be dynamic enough. If the csv file is slightly changed it won't work.

Please help me figure out a way to extract only the table part from this csv file.

CodePudding user response:

There is a comment argument if you read in your file, but each line has to start with the appropriate character or your Metadata will not be treated as comment.

import pandas as pd
df = pd.read_csv('path/to/file.csv', sep=';', comment='#')

CodePudding user response:

.csv file can't have comment. Then you must delete comment-line manualy. Try start checking from end file, and stop if # in LINE and ';' not in LINE

  • Related