I have this code:
if len(self.my_df)==865:
with pd.set_option("display.max_rows", None, "display.max_columns", None):
print(self.my_df)
According to Pretty-print an entire Pandas Series / DataFrame, that should be the correct syntax - and yet that line crashes with:
File "myfile.py", line 1132, in my_function
with pd.set_option("display.max_rows", None, "display.max_columns", None):
AttributeError: __enter__
Why is this happening?
CodePudding user response:
If you notice in the post you linked, in the post you linked, they're using pd.option_context, but you're using pd.set_option. with statements call methods on the object they're passed such as __enter__ and __exit__, but pd.set_option doesn't return an object that has those methods, while pd.option_context does. That's why you're seeing that error.
So just change your code to this:
if len(self.my_df)==865:
with pd.option_context("display.max_rows", None, "display.max_columns", None):
print(self.my_df)
