Reading rpt files with Pandas
In most cases, we usually have a CSV file to load the data from, but there are other formats such as JSON, rpt, TSV, etc. that can be used to store data. Pandas provide us with the utility to load data from them. In this article, we’ll see how we can load data from an rpt file with the use of Pandas.
An RPT file is a report or output file created by Crystal Reports, a program used for business-oriented reporting. It can store data from multiple sources and different types of databases.
File in use: here
Method 1: Reading using read_fwf()
One way to read the rpt file is by simply using the read_fwf method. All you need to do is to pass the file path, and it’ll load the data into a dataframe and define the delimiter for it. That is why it usually becomes essential in the case of rpt files to understand the arrangement of data. After this, you just have to pass the delimiter and file name to the method.
Method 2: Reading using read_csv
Once you know the delimiter, you can also use the read_csv() method to read that file by passing the delimiter in the method. Let’s read the above file using read_csv.