-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Test long string formatting in to_string and to_html #1852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is not a bug, but a matter of how repr works, the values inside are as expected. pandas truncates columns in repr to 50 characters. This can be controlled with >>> print dfg.aggregate(lambda x: ', '.join(x.values)).to_string() |
Indeed, pandas tries to prevent flooding the screen in the console. I wonder if adding something like |
OK, yes, the value is there. But df.to_string() does not retrieve it, it stops at the truncation -- I guess it calls repr and go from there? Same for df.to_html() |
Only In [16]: print dfg.aggregate(lambda x: ', '.join(x.values)).to_string()
b
a
a1 b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b
a2 b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b In [19]: print dfg.aggregate(lambda x: ', '.join(x.values)).to_html()
|
Hmm, I'm on version 0.8.1 and it does truncate for to_string() and to_html() But anyway, Lodagro's pandas.set_printoptions works, so problem solved :) Thanks all. |
@lodagro I'm going to reopen this and change the title so we add a test on the to_string and to_html behavior |
i assume you want to check that |
I guess that makes the most sense |
@lodagro keep this open? |
@jreback this issue moved away from the original question. Idea was to keep it open and make sure that In [4]: from pandas import *
In [5]: cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:df = DataFrame({'a':['a1']*100+['a2']*100, 'b':['b']*200})
:dfg = df.groupby(['a'])
:dfg.aggregate(len) ## this gives right answer, every entry is of length 100
:dfg.aggregate(lambda x: ', '.join(x.values))
:--
Out[5]:
b
a
a1 b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b...
a2 b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b...
In [6]: print dfg.aggregate(lambda x: ', '.join(x.values)).to_string()
b
a
a1 b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b...
a2 b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b...
In [7]: print dfg.aggregate(lambda x: ', '.join(x.values)).to_html()
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>b</th>
</tr>
<tr>
<th>a</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<th>a1</th>
<td> b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b...</td>
</tr>
<tr>
<th>a2</th>
<td> b, b, b, b, b, b, b, b, b, b, b, b, b, b, b, b...</td>
</tr>
</tbody>
</table>
In [8]: |
I think this will go toward solving this (maybe need some additional options), #5012 reopening and moving to 0.14: thanks....always welcome a PR! |
Closing as this is working as expected (and a matter of the repr, as noted above) |
Start with a data frame -- large-ish number of rows
It works fine if the string is not very long, eg start with
df = DataFrame({'a':['a1']_10+['a2']_10, 'b':['b']*20)
The text was updated successfully, but these errors were encountered: