Skip to content

Instantly share code, notes, and snippets.

@chris1610
chris1610 / pretty_print_df.py
Last active February 12, 2022 20:42
custom pretty print descriptor for a pandas dataframe
@pd.api.extensions.register_dataframe_accessor("pt")
# Performs formatting on a dataframe
# Usage: df.pt.pretty()
class Pretty:
def __init__(self, pandas_obj):
self._validate(pandas_obj)
self._obj = pandas_obj
@staticmethod
@chris1610
chris1610 / Ipython-pandas-tips-and-tricks.ipynb
Last active October 18, 2016 15:57
Ipython Notebook from pbpython.com
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chris1610
chris1610 / pdf-report.py
Created February 16, 2015 22:29
PDF Report Generation - pbpython.com
"""
Generate PDF reports from data included in several Pandas DataFrames
From pbpython.com
"""
from __future__ import print_function
import pandas as pd
import numpy as np
import argparse
from jinja2 import Environment, FileSystemLoader
from weasyprint import HTML
@chris1610
chris1610 / report-runner.py
Last active November 9, 2023 02:53
Pandas Pivot Table Reporting Example - pbpython.com
# -*- coding: utf-8 -*-
"""
Sample report generation script from pbpython.com
This program takes an input Excel file, reads it and turns it into a
pivot table.
The output is saved in multiple tabs in a new Excel file.
"""
#Parse 2014 MN Capital budget - https://www.revisor.mn.gov/laws/?year=2014&type=0&doctype=Chapter&id=294
#Store the summary in a DataFrame for eventual manipulation
from __future__ import print_function
import os.path
from collections import defaultdict
import string
import requests
from bs4 import BeautifulSoup
import pandas as pd
import matplotlib.pyplot as plt