• Stars
    star
    103
  • Rank 333,046 (Top 7 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python utility to take a Pandas DataFrame and create a Powerpoint table

PandasToPowerpoint (pd2ppt)

Python utility to take a Pandas DataFrame and create a Powerpoint table

An example:

from pd2ppt import df_to_powerpoint
import pandas as pd

df = pd.DataFrame(
    {'District':['Hampshire', 'Dorset', 'Wiltshire', 'Worcestershire'],
     'Population':[25000, 500000, 735298, 12653],
     'Ratio':[1.56, 7.34, 3.67, 8.23]})

df_to_powerpoint(
    r"C:\Code\Powerpoint\test58.pptx", df, col_formatters=['', ',', '.2'],
    rounding=['', 3, ''])

Installation

git clone https://github.com/robintw/PandasToPowerpoint.git
cd PandasToPowerpoint
pip install --upgrade pip # optional (depends on setup)
pip install -r requirements.txt
python setup.py install

Documentation

df_to_table

Converts a Pandas DataFrame to a PowerPoint table on the given
Slide of a PowerPoint presentation.

The table is a standard Powerpoint table, and can easily be modified with
the Powerpoint tools, for example: resizing columns, changing formatting etc.

Parameters
----------
slide: ``pptx.slide.Slide``
    slide object from the python-pptx library containing the slide on which
    you want the table to appear

df: pandas ``DataFrame``
   DataFrame with the data

left: int, optional
   Position of the left-side of the table, either as an integer in cm, or
   as an instance of a pptx.util Length class (pptx.util.Inches for
   example). Defaults to 4cm.

top: int, optional
   Position of the top of the table, takes parameters as above.

width: int, optional
   Width of the table, takes parameters as above.

height: int, optional
   Height of the table, takes parameters as above.

col_formatters: list, optional
   A n_columns element long list containing format specifications for each
   column. For example ['', ',', '.2'] does no special formatting for the
   first column, uses commas as thousands separators in the second column,
   and formats the third column as a float with 2 decimal places.

rounding: list, optional
   A n_columns element long list containing a number for each integer
   column that requires rounding that is then multiplied by -1 and passed
   to round(). The practical upshot of this is that you can give something
   like ['', 3, ''], which does nothing for the 1st and 3rd columns (as
   they aren't integer values), but for the 2nd column, rounds away the 3
   right-hand digits (eg. taking 25437 to 25000).

name: str, optional
   A name to be given to the table in the Powerpoint file. This is not
   displayed, but can help extract the table later to make further changes.

Returns
-------
pptx.shapes.graphfrm.GraphicFrame
    The python-pptx table (GraphicFrame) object that was created (which can
    then be used to do further manipulation if desired)

df_to_powerpoint

Converts a Pandas DataFrame to a table in a new, blank PowerPoint
presentation.

Creates a new PowerPoint presentation with the given filename, with a single
slide containing a single table with the Pandas DataFrame data in it.

The table is a standard Powerpoint table, and can easily be modified with
the Powerpoint tools, for example: resizing columns, changing formatting
etc.

Parameters
----------
filename: Filename to save the PowerPoint presentation as

df: pandas ``DataFrame``
    DataFrame with the data

**kwargs:
    All other arguments that can be taken by ``df_to_table()`` (such as
    ``col_formatters`` or ``rounding``) can also be passed here.

Returns
-------
pptx.shapes.graphfrm.GraphicFrame
    The python-pptx table (GraphicFrame) object that was created (which can
    then be used to do further manipulation if desired)

UnitTests

To run unittests you can execute the following command:

make pytest

or

pytest -v --cov-report term-missing --cov=pd2ppt

You will need pytest installed in your environment via pip install -r requirements-test.txt

More Repositories

1

Py6S

A Python interface to the 6S Radiative Transfer Model
Python
164
star
2

BankClassify

Simple example of using a Naive Bayesian classification to classify entries in bank statements
Python
125
star
3

RPiNDVI

Raspberry PI NDVI Code
Python
61
star
4

AutoZotBib

JavaScript
37
star
5

LatLongToWRS

Python code to get a Landsat WRS-2 path and row from a latitude/longitude co-ordinate
Python
34
star
6

daterangeparser

Python module to parse human-style date ranges (eg. 15th-19th March 2011) to datetimes
Python
32
star
7

pywavethermo

Basic module to control the Worcester Wave thermostat from Python
Python
27
star
8

XArrayAndRasterio

Experimental code for loading/saving XArray DataArrays to Geographic Rasters using rasterio
Jupyter Notebook
22
star
9

PyProSAIL

Python interface to the ProSAIL leaf/canopy reflectance model
Fortran
21
star
10

XArray_PyConUK2018

Code and slides for my talk at PyCon UK 2018 on XArray
Jupyter Notebook
18
star
11

PyFMask

Python version of the FMask Landsat Cloud Masking code
Python
13
star
12

RastersRevealedTalk

Slides and resources for talk given at Rasters Revealed, 21st Feb 2017
Jupyter Notebook
9
star
13

offline_folium

Allows using folium without an internet connection
Python
9
star
14

DropboxBasedWordCount

Code to download revisions of files from Dropbox, then use texcount to do a word count of them
Jupyter Notebook
9
star
15

Python-DocSets

Python docsets for use with Dash (http://kapeli.com/dash/)
JavaScript
8
star
16

PyAURN

A Python module to import data from the UK Automatic Urban Rural Network (air pollution monitoring network)
Python
7
star
17

sqlalchemy-units-example

Example code from 'Pint + SQLAlchemy = Unit consistency and enforcement in your database' poster at PyData Global 2020
Python
7
star
18

LandsatUtils

Python
5
star
19

manifestoclouds

Creates word clouds from political party manifestos
Python
5
star
20

CloudFrequencyApp

CloudFrequency webapp, using Google App Engine
JavaScript
4
star
21

ParentZonePhotoDownloader

Downloads photos from a ParentZone account
Python
4
star
22

DunesGIS

ENVI/IDL and ArcGIS routines for processing DEMs of sand dunes from the DECAL model
Prolog
4
star
23

6S

6S with CMake files
Fortran
4
star
24

py6s-website

Website for Py6S
HTML
3
star
25

Web6S

Web-based interface to Py6S
Python
3
star
26

GDALUtils

Python
3
star
27

bib2coins

Utility to convert BibTeX files to COINS metadata (see http://ocoins.info/) for use in webpages
Python
3
star
28

RTWToolsForArcGIS

RTW Tools for ArcGIS
Python
3
star
29

rtwrtm

Monte Carlo Ray Tracing Radiative Transfer Model (RTM)
IDL
2
star
30

LeafletExample_IMD_Choropleth

Example Leaflet code for a choropleth map with auto-generated and auto-hiding legend
JavaScript
2
star
31

PyToENVI

Python module to easily allow you to display files in ENVI
Python
2
star
32

julian_timehop

Sends a daily 'Julian Timehop' email reminding me of things Julian did on this day in previous years
Python
2
star
33

LeafletExample_IMD_Choropleth_With_Limits

JavaScript
2
star
34

rtwtools-website

HTML
2
star
35

pytest_examples

Simple Pytest examples
Python
2
star
36

WernerModel

The Werner (1995) model and its extension, written for COMP6023 at the University of Southampton
Python
2
star
37

CW-ideas

Hack day project from CW21 working on collating and analysing collaborative ideas and hack day projects from previous Collaborations Workshops
HTML
2
star
38

VisAOT

Code for paper: Are visibility-derived AOT estimates suitable for parameterising satellite data atmospheric correction algorithms?
2
star
39

ProSAIL

New Python version of ProSAIL
Python
1
star
40

Academic-Website

My academic website - hosted at www.rtwilson.com/academic
PHP
1
star
41

BreathingSpacesWebmap

Web map for Breathing Spaces project
JavaScript
1
star
42

sse_powercuts

1
star
43

SESG6028Coursework2

Code for SESG6028 Coursework 2
C
1
star
44

FlaskTemperature

Flask app for reading temperature from W1 sensor on the RPi
Python
1
star
45

WeddingSite

Files for our wedding website
PHP
1
star
46

first_app

First app for RoR tutorial application
Ruby
1
star
47

FreeGISData

HTML
1
star
48

sample_app

RoR Tutorial Sample Application
Ruby
1
star
49

RWords

Search words in the SOWPODs dictionary in interesting ways
Ruby
1
star
50

Personal-Website

Source for my personal website - available at www.rtwilson.com/personal
PHP
1
star
51

RTWIDL

RTWTools for IDL - a library of useful IDL routines
IDL
1
star
52

CrestExtract

New version of Crest Extraction code in DunesGIS
Prolog
1
star
53

COMP3008Coursework

Code for my COMP3008 Coursework
R
1
star
54

TheatreScraper

Python
1
star
55

SESG6028Coursework3

Code for SESG6028 Coursework 3
C
1
star
56

RTWOBIA

Robin's Object-based Image Analysis software
Prolog
1
star
57

recipy-website

HTML
1
star
58

pandas-FSDR

Python
1
star
59

SESG6028Coursework3New

New (working?) version of SESG6028 Coursework 3
C
1
star
60

WoodgetDietrichWilson2019

Code for the Machine Learning analyses in Woodget, Dietrich and Wilson (2019)
Jupyter Notebook
1
star
61

SESG6028Coursework1

Coursework for SESG6028
C
1
star
62

PySun

Python sun.py as a proper module - originally from http://kortis.to/radix/python/code/Sun.py (Public Domain)
Python
1
star
63

IWVComparison

Code to run the validations & comparisons presented in 'A global comparison of integrated water vapour estimates from WMO radiosondes, AERONET sun photometers and GPS for the 17 year period from 1997 to 2013' by Wilson et al. Edit
R
1
star
64

AOT2PM

Python
1
star