Question
Asked By – Yantraguru
I am struggling with the seemingly very simple thing. I have a pandas data frame containing very long string.
df = pd.DataFrame({'one' : ['one', 'two',
'This is very long string very long string very long string veryvery long string']})
Now when I try to print the same, I do not see the full string I rather see only part of the string.
I tried following options
- using
print(df.iloc[2])
- using
to_html
- using
to_string
- One of the Stack Overflow answers suggested to increase column width by using pandas display option, that did not work either.
- I also did not get how
set_printoptions
would solve this.
Now we will see solution for issue: Print very long string completely in pandas dataframe
Answer
You can use options.display.max_colwidth
to specify you want to see more in the default representation:
In [2]: df
Out[2]:
one
0 one
1 two
2 This is very long string very long string very...
In [3]: pd.options.display.max_colwidth
Out[3]: 50
In [4]: pd.options.display.max_colwidth = 100
In [5]: df
Out[5]:
one
0 one
1 two
2 This is very long string very long string very long string veryvery long string
And indeed, if you just want to inspect the one value, by accessing it (as a scalar, not as a row as df.iloc[2]
does) you also see the full string:
In [7]: df.iloc[2,0] # or df.loc[2,'one']
Out[7]: 'This is very long string very long string very long string veryvery long string'
This question is answered By – joris
This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0