11

working on pandas describe function. simple enough code:

df['Revenue'].describe()

output is :

enter image description here

perfect. my issue is i want to be able to save this data as either a png or a table so that i can place in a single page. this is for my EDA (exploratory data analysis) i have 6 main charts or information that i want to evaluate on each feature. each chart will be a seperate png file. i will then combine into one pdf file. i iterate over 300 + features so doing one at a time is not an option especially seeing as it is done monthly.

if you know of a way to save this table as a png or other similar file format that would be great. thanks for the look

  • Are you specifically asking how to turn raw text into a PNG? – TankorSmash Jan 08 '18 at 22:03
  • So basically, save a pandas dataframe as an image (PNG specifically) for reporting-purposes. Is that your question? If so, does [this](https://stackoverflow.com/questions/35634238/how-to-save-a-pandas-dataframe-table-as-a-png) help? – Jarad Jan 08 '18 at 22:10

1 Answers1

18

Saving as a csv or xlsx file

You may use to_csv("filename.csv") or to_excel("filename.xlsx") methods to save the file in a comma separated format and then manipulate/format it in Excel however you want. Example:

df['Revenue'].describe().to_csv("my_description.csv")

Saving as a png file

As mentioned in the comments, this post explains how to save pandas dataframe to png file via matplot lib. In your case, this should work:


    import matplotlib.pyplot as plt
    from pandas.plotting import table

    desc = df['Revenue'].describe()

    #create a subplot without frame
    plot = plt.subplot(111, frame_on=False)

    #remove axis
    plot.xaxis.set_visible(False) 
    plot.yaxis.set_visible(False) 

    #create the table plot and position it in the upper left corner
    table(plot, desc,loc='upper right')

    #save the plot as a png file
    plt.savefig('desc_plot.png')
Zoe
  • 27,060
  • 21
  • 118
  • 148
Hrant Davtyan
  • 476
  • 4
  • 13