How to use stargazer on Pandas DataFrame object?
Clash Royale CLAN TAG#URR8PPP
How to use stargazer on Pandas DataFrame object?
I am new to python and I am trying to use stargazer using rpy2 to generate the latex table for a pandas Data Frame object. I can do this but the output in the jupyter notebook is not usable in latex as it has a lot of tabs and unnecessary spacing. I tried to use rmagic but it did not work. I do not know how to proceed.
import pandas as pd
import numpy as np
from rpy2.robjects.packages import importr
from rpy2.robjects import pandas2ri
utils = importr('utils')
df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
utils.install_packages('stargazer')
stargazer = importr('stargazer')
stargazer.stargazer(pandas2ri.py2ri_pandasdataframe(df))
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I was doing this the hardest way. One could simply use df.to_latex().
– BIM
Aug 7 at 20:36