def to_image(self, path): """ Save the profiler result as image :param self: :param path: :return: """ path_css = os.path.dirname(os.path.abspath(__file__)) css = path_css + "//..//css//styles.css" imgkit.from_string(self.html, path, css=css) print_html("<img src='" + path + "'>")
def table_image(self, path, limit=10): """ :param self: :param limit: :param path: :return: """ # imgkit.from_url('http://google.com', 'out.jpg') path_css = os.path.dirname(os.path.abspath(__file__)) css = path_css + "//..//css//styles.css" imgkit.from_string(self.table_html(limit=limit, full=True), path, css=css) print_html("<img src='" + path + "'>")
def _load_css(): """ Try to load the css for templates :return: """ try: if __IPYTHON__: path = os.path.dirname(os.path.abspath(__file__)) url = path + "//css//styles.css" styles = open(url, "r", encoding="utf8").read() s = '<style>%s</style>' % styles print_html(s) except NameError: pass
def table(self, limit=100, columns=None): try: __IPYTHON__ result = self.table_html(limit=limit, columns=columns) return print_html(result) except NameError: self.show()
def table(self, limit=100, columns=None, title=None): try: if __IPYTHON__ and DataFrame.output is "html": result = self.table_html(title=title, limit=limit, columns=columns) return print_html(result) else: self.show() except NameError: self.show()
def run(self, df, columns, buckets=40, infer=False, relative_error=1): """ Return dataframe statistical information in HTML Format :param df: Dataframe to be analyzed :param columns: Columns to be analized :param buckets: Number of buckets calculated to print the histogram :param infer: infer data type :param relative_error: Relative Error for quantile discretizer calculation :return: """ columns = parse_columns(df, columns) output = Profiler.to_json(df, columns, buckets, infer, relative_error) # Load jinja path = os.path.dirname(os.path.abspath(__file__)) template_loader = jinja2.FileSystemLoader(searchpath=path + "//templates") template_env = jinja2.Environment(loader=template_loader, autoescape=True) # Render template # Create the profiler info header html = "" general_template = template_env.get_template("general_info.html") html = html + general_template.render(data=output) template = template_env.get_template("one_column.html") # Create every column stats for col_name in columns: hist_pic = None col = output["columns"][col_name] if "hist" in col: if col["column_dtype"] == "date": hist_year = plot_hist({col_name: col["hist"]["years"]}, "base64", "years") hist_month = plot_hist({col_name: col["hist"]["months"]}, "base64", "months") hist_weekday = plot_hist( {col_name: col["hist"]["weekdays"]}, "base64", "weekdays") hist_hour = plot_hist({col_name: col["hist"]["hours"]}, "base64", "hours") hist_minute = plot_hist({col_name: col["hist"]["minutes"]}, "base64", "minutes") hist_pic = { "hist_years": hist_year, "hist_months": hist_month, "hist_weekdays": hist_weekday, "hist_hours": hist_hour, "hist_minutes": hist_minute } else: hist = plot_hist({col_name: col["hist"]}, output="base64") hist_pic = {"hist_pic": hist} if "frequency" in col: freq_pic = plot_freq({col_name: col["frequency"]}, output="base64") else: freq_pic = None html = html + template.render( data=col, freq_pic=freq_pic, **hist_pic) html = html + df.table_html(10) # Display HTML print_html(html) # send to queue if self.queue_url is not None: self.to_queue(output) # JSON # Save in case we want to output to a json file self.json = output # Save file in json format write_json(output, self.path) # Save in case we want to output to a html file self.html = html