Home > database >  pandas set_option max_colwidth not working as intended
pandas set_option max_colwidth not working as intended

Time:09-02

This is my code

import pandas as pd
pd.set_option('max_colwidth', 1)
pd.DataFrame({1: ['1' * 1000] * 10000000})

When run in a jupyter notebook it still displays all the character in the row. I want the 1's to be truncated, but it isn't working no matter how hard I try. This is very frustrating, how can this be fixed?

Edit: Doesn't work with any number or setting

import pandas as pd
pd.set_option('max_colwidth', 5)
pd.set_option('max_seq_items', 5)
pd.DataFrame({1: ['1' * 1000] * 10000000})

CodePudding user response:

I personally do the following and never had any issue.

pd.options.display.max_colwidth = X

Also just tested the number needs to be at least 4 to work properly.

I'm using pandas 1.4.3 btw.

enter image description here

CodePudding user response:

This is working for me if I want to display max_colwidth (min is 4) and max_rows = 5 in jupyter notebook.

import pandas as pd
pd.set_option("max_colwidth", 4, "display.max_rows", 5)
pd.DataFrame({1: ['1' * 1000] * 10000000})

enter image description here

  • Related