Skip to content
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

Multilevel indexing with .to_latex() method merges two index columns #2924

Closed
jobingr opened this issue Feb 25, 2013 · 10 comments
Closed

Multilevel indexing with .to_latex() method merges two index columns #2924

jobingr opened this issue Feb 25, 2013 · 10 comments

Comments

@jobingr
Copy link

jobingr commented Feb 25, 2013

using Release 0.10.1
using the .to_latex method on a multilevel frame (specifically using a pivot_table) merges the two index columns so that it does not render correctly in latex. Looks like it is missing the & for blank cells in index. and also an & for the columns. Manually inserted those in output and it fixes problem

@jobingr
Copy link
Author

jobingr commented Feb 25, 2013

PS sorry definitely wrong place for this, but any idea on where to find documentation on .to_latex method. Only info I can find is in docstring and can't figure out how to use it to format numbers and alignments. considering regexes, but I have feeling the functionality is already there, just cant figure it out.

@ghost
Copy link

ghost commented Feb 25, 2013

@jobingr
Copy link
Author

jobingr commented Feb 25, 2013

had look at the formatters can' t figure it out Tried:
form={'colname': round()} as index also tried the formula in quotes. I am missing something? is it a string formatter for the numbers?

@ghost
Copy link

ghost commented Feb 25, 2013

round() calls round and puts the result as the formatter, not what you want.
try round (no parens).

@jobingr
Copy link
Author

jobingr commented Feb 25, 2013

thanks.. any suggestions for currency formatting... no need for symbol, but thousand separators will make it much more readable. Also is there a way to change the default c of the to_latex method to r. can manualy munge the latex output, but I suspect there is already a builtin way of doing this.

@ghost
Copy link

ghost commented Feb 25, 2013

I think python .format() style string formatting does thousands.
The 'c' is hard-coded I believe, so no to the latter. Haven't done latex
in a long time so I'm not sure what 'c' vs. 'r' actually does, but if you need
it maybe others do too, Pull Requests are welcome.

@jobingr
Copy link
Author

jobingr commented Feb 25, 2013

tried:
x=randn(10)
def f(x):
return round(3)
fr = pd.DataFrame(x, columns=['test'])
fr.to_latex(formatters={'test': f})
also tried f with () still error

@jobingr
Copy link
Author

jobingr commented Feb 25, 2013

c makes column centre justified, can use l or r to to left and right. numbers more readable if r justified. that is an easy fix though.

@jobingr
Copy link
Author

jobingr commented Feb 25, 2013

got it figured formatter needs string return
import pandas as pd
x=randn(10)
def f(x):
return str(round(x,3))
fr = pd.DataFrame(x, columns=['test'])
fr.to_latex(formatters={'test': f})
worked
thanks for help

@jobingr
Copy link
Author

jobingr commented Feb 27, 2013

Got split up here for a while... will close this one an re-add the issue with to_latex method on multi indexed frames on its own

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant