Q:

Can __repr__ return a dataframe?

Is it possible to make __repr__ in the code below return a dataframe?
The code below will throw 

TypeError: str returned non-string (type DataFrame)

because - I guess - __repr__ has to return a string.
Or should I replace __repr__ with some other magic method?
import pandas as pd

class Query():
    def __init__(self, filename):
        self.df = pd.read_excel(filename)

    def __repr__(self):
        return self.df

if __name__ == '__main__':
    filename = 'some_filename'
    query = Query(filename)
    print(query)

A:

You want __repr__ to return a string, which would be the representation of your dataframe. So, just do:
def __repr__(self):
        return repr(self.df)

