Skip to content

Template for variables in to_latex() #8213

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

Closed
eXcuvator opened this issue Sep 8, 2014 · 3 comments
Closed

Template for variables in to_latex() #8213

eXcuvator opened this issue Sep 8, 2014 · 3 comments

Comments

@eXcuvator
Copy link

Me and several of my colleagues typically create output for variables that have greek letters. Inside pandas, we then call them "epsilon", "sBar" or similar. Right now we have to run a string replace on the output of to_latex() and then manually save it to a file.

It'd be nice to be able to give to_latex() a template such as ['epsilon':'$\epsilon$', 'sBar':'$\bar s$'] and then to_latex() would replace these in the output accordingly.

@onesandzeroes
Copy link
Contributor

The kind of replacements you're describing are already possible using DataFrame.map() with a dictionary:

import pandas as pd
df = pd.DataFrame({'latex_raw': ['sBar', 'epsilon']})
replacements = {'sBar': r'$\bar{s}$', 'epsilon': r'$\epsilon$'}
df['latex_formatted'] = df['latex_raw'].map(replacements)
df
# Output:
  latex_raw latex_formatted
0      sBar       $\bar{s}$
1   epsilon      $\epsilon$

So you should be able to create replaced versions of your columns before doing to_latex(). Is there any particular advantage to duplicating the map() functionality within to_latex(), any examples you can provide of things that aren't easy to do with that approach?

@TomAugspurger
Copy link
Contributor

Or we can lump this in with #3190 when somebody finally gets around to it (I'll possibly take another crack for the next release).

@eXcuvator
Copy link
Author

Since I was mainly referring to label rather than values, I suppose the alternative approach suggested is valid.

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

No branches or pull requests

4 participants