Open In App

Reading rpt files with Pandas

Last Updated : 16 May, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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. 

Example:

Python3




import pandas as pd
  
df = pd.read_fwf('sample.rpt', delimiter='|')
  
display(df)


Output:

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. 

Example:

Python3




import pandas as pd
  
df = pd.read_csv('sample.rpt', delimiter = '|')
  
display(df)


Output:


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads