-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
to_html function fail when max_rows is specified #8273
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
Can you write up some short example code that will reproduce the issue? Preferably code that's simple and self-contained enough that people can just copy-paste into a Python console to see the issue for themselves. |
Of course: import pandas as pd |
Hmmm, I think the fix for this one is actually a little bit more complicated than you've outlined (although you're definitely right to have noticed that The bug you've found only occurs when Here's some extra test code if people want to compare the import pandas as pd
import numpy as np
df = pd.DataFrame({'a': np.arange(10), 'b': np.random.randn(10)})
print(df.to_html(max_rows=3))
print(df.to_html(index=False, max_rows=3))
# Hierarchical index cases
cols = pd.MultiIndex.from_tuples([('a', 'x'), ('a', 'y'), ('b', 'x'), ('b', 'y')])
index = pd.MultiIndex.from_arrays([
[1, 1, 1, 1, 1, 2, 2, 2, 2, 2],
['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'bar']
])
df2 = pd.DataFrame(np.random.randn(10, 4), columns=cols, index=index)
print(df2)
print(df2.to_html(max_rows=3))
print(df2.to_html(index=False, max_rows=3)) |
closing as stale. pls reopen if still an issue. |
The error is:
list index out of range
Exception Location: /home/pietro/lod4statenv/local/lib/python2.7/site-packages/pandas/core/format.py in _write_body, line 923
In order to fix it I have replaced line 922 from:
for i in range(len(self.frame)):
to:
for i in range(min(len(self.frame), self.max_rows)):
The text was updated successfully, but these errors were encountered: