Skip to content
Related Articles

Related Articles

Improve Article
Reading rpt files with Pandas
  • Last Updated : 16 May, 2021

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:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :