0
import pandas as pd
from string import ascii_letters as al
from random import choice

data = [[''.join([choice(al) for x in range(100)]),'2']] #generating 100 long string of charachter


label = ['text', 'number']

x = pd.DataFrame.from_records(data=data,columns=label)

print(x)

If you print x, you will see pandas Dataframe shortens value by adding "...".

0  ZguBjqdVeKzyzcaBZeufeRCIEDQJRYeinDRWSaLDbrezZN...      2

Is there a way in pandas to see long words in full? By making larger "cell size" or something. Would appreciate your help. I have already tried something with set.option, however no results...

using:

with pd.option_context('display.max_colwidth', -1):
    x = pd.DataFrame.from_records(data=a,columns=b)
    print(x)

I get whole word, but the number column is then being placed in other row. It's not printable at all. I am looking something like merge cell option in excel.

Thank you.

EDITED:

Solution is:

with pd.option_context('display.height',-1, 'max_colwidth', -1):


    x = pd.DataFrame.from_records(data=a,columns=b)

    print(x.to_string())
    a = input()
Makaroniiii
  • 348
  • 3
  • 16

1 Answers1

1

From the documentation:

display.max_colwidth sets the maximum width of columns. Cells of this length or longer will be truncated with an ellipsis.

pd.set_option('max_colwidth', 40)
Steven Laan
  • 190
  • 10