12

When I try to use to_string to output a column from a dataframe, it truncates the output of the column.

print gtf_df.ix[:1][['transcript_id','attributes']].to_string(header=False,index=False)

Out: ' CUFF.1.1  gene_id "CUFF.1"; transcript_id "CUFF.1.1"; FPKM '

print gtf_df.ix[:1]['attributes'][0]

Out: 'gene_id "CUFF.1"; transcript_id "CUFF.1.1"; FPKM "1670303.8168650887"; frac "1.000000"; conf_lo "0.000000"; conf_hi "5010911.450595"; cov "9658.694354";'

Any ideas as to how to resolve this problem? Thanks!

piRSquared
  • 285,575
  • 57
  • 475
  • 624
Kunal B.
  • 123
  • 1
  • 1
  • 4
  • What is the type of attributes -- i.e. what do you get back from type(gtf_df['attributes'][0]) -- If it is a string, can you tell us whether removing the quotes and semicolons solves the problem -- i.e. gtf_df.attributes = gtf_df.attributes.replace('\"','').replace(';','') – DanB Aug 17 '12 at 04:54
  • It is a string column. However, your recommended fix did not change anything. The answer presented below works. – Kunal B. Aug 17 '12 at 17:08

2 Answers2

13

Using __repr__ or to_string columns are by default truncated at 50 chars. In versions of Pandas older than 0.13.1, this can be controlled using pandas.set_printoptions():

In [64]: df
Out[64]:
                                                   A    B
a  this is a very long string, longer than the defau  bar
b                                                foo  baz

In [65]: pandas.set_printoptions(max_colwidth=100)

In [66]: df
Out[66]:
                                                                      A    B
a  this is a very long string, longer than the default max_column width  bar
b                                                                   foo  baz

In more recent versions of Pandas, use this instead:

pd.options.display.max_colwidth = 100
Brandon Rhodes
  • 83,755
  • 16
  • 106
  • 147
Wouter Overmeire
  • 65,766
  • 10
  • 63
  • 43
1

Pandas changed how to set this option. Here is the current documentation

pd.set_option('display.max_colwidth', 100)

See the docs for other nice ones like:

pd.set_option('display.max_rows', 999)
neves
  • 33,186
  • 27
  • 159
  • 192