Feb-28-2020, 07:06 AM
how do I convert df.info() and df.describe() in to PDF in Python
[split] Python Question
|
||||||||||||||
Feb-28-2020, 07:06 AM
how do I convert df.info() and df.describe() in to PDF in Python
Feb-28-2020, 02:42 PM
one method: use two step process:
first convert dataframe to html using pandas.DataFrame.to_html: https://pandas.pydata.org/pandas-docs/ve..._html.html next convert html file to pdf using pdfkit (if you need to install, use pip install pdfkit )
Feb-29-2020, 05:28 AM
(Feb-28-2020, 02:42 PM)Larz60+ Wrote: one method: use two step process: I have tried like below import pandas as pd df = pd.DataFrame(np.random.random((10,3)), columns = ("col 1", "col 2", "col 3")) df1 =df.to_html(df.info()) pdk.from_file('htm.pdf', df1) it is not working
Feb-29-2020, 11:26 AM
Quote:it is not workingCould you please elaborate.
Feb-29-2020, 07:08 PM
(This post was last modified: Feb-29-2020, 07:09 PM by jefsummers.)
Alternative -
Changing the value of stdout redirects all print (and the prompt part of input) statements to the new file. __stdout__ is the value of stdout when the program starts, so you do want to put it back once you are done with the text file generation.
A working test,here using
buf parameter to get sys.stout from info(),i guess @jefsummers advice would work to.
info.pdf :
How can we extract data frame name ?
I have used below code
But my requirement is : df_name because want to pass the data frame as parameter, please help >>> indicate you work in interactive mode.You want to print the result
Note, I am not sure why would you need the df_name string, nor what df that you pass when calling the function is
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
df_name = pd.DataFrame( data=np.ones([4,4]) )
def get_df_name(df): name =[x for x in globals() if globals()[x] is df][0] return name get_df_name(df_name) output is : 'df_name' But cannot use print(get_df_name(df_name)) also, because need to pass in another function
Mar-26-2020, 04:15 PM
This looks like XY problem. What do you want to do? I doubt you want to get name
df_name , which is str .
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs | ||||||||||||||
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
[split] [split] New to the forum, how to post a question? | karnik | 2 | 1,984 |
Feb-12-2022, 03:45 PM Last Post: deanhystad |
|
[split] question about list comprehension | Armin | 17 | 8,405 |
Jan-29-2020, 04:32 PM Last Post: Clunk_Head |