Skip to content

Commit

Permalink
Initial commit for pandas-rose
Browse files Browse the repository at this point in the history
  • Loading branch information
blaylockbk committed Aug 1, 2023
0 parents commit 1a4b1c7
Show file tree
Hide file tree
Showing 17 changed files with 2,387 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Publish ${package_name} to PyPI / GitHub

on:
push:
tags:
- "20*"

jobs:
build-n-publish:
name: Build and publish to PyPI
runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.x"

- name: Build source and wheel distributions
run: |
python -m pip install --upgrade build twine
python -m build
twine check --strict dist/*
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}

- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false

- name: Get Asset name
run: |
export PKG=$(ls dist/ | grep tar)
set -- $PKG
echo "name=$1" >> $GITHUB_ENV
- name: Upload Release Asset (sdist) to GitHub
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/${{ env.name }}
asset_name: ${{ env.name }}
asset_content_type: application/zip
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
dist/

__pycache__/
.ipynb_checkpoints
*.py[cod]
*$py.class
*.log
env_pypi.yml
condaenv*
.venv*

.pytest_cache/

dist/*
build/*
*.egg-info
*.egg
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none",
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
8 changes: 8 additions & 0 deletions HOW_TO_RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# How to release `pandas-rose`


## Build the package locally

```
python -m build
```
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Brian K. Blaylock

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<div align=center>

<img src="images/pandas-rose.png" title="Bing Image Creator: Cartoon chunky panda hugging rose in the wind pixel art " width=200>

</div>

# Pandas Rose

This python package adds a custom Pandas accessor to generate polar wind rose plots from a Pandas dataframe.

I don't mean to compete with the wonderful [windrose](https://github.com/python-windrose/windrose) package already available, but that package has a little too much complexity for what I wanted. This package is meant to provide a minimal, simple interface to making wind rose plots. This is done by using Pandas methods `pd.cut` and `df.groupby` and using Matplotlib regular polar axes.

# Install

> ## TODO: Publish and Upload to PyPI
Install with pip. The requirements are only pandas, numpy, and matplotlib.

```bash
pip install pandas-rose
```

# Usage

Pandas-rose is simple.

```python
import pandas as pd
import rose

# df is a pandas dataframe with columns
# "wind_speed" and "wind_direction"
df = pd.DataFrame({
"wind_speed":[1,2,3,4],
"wind_direction":[20, 10, 190,300]
})

# Display a polar wind plot of the data
df.rose.plot()
```

![Alt text](images/sample_plot.png)

You can specify the pandas column to use for wind direction and wind speed. You may also change the number of sectors to bin the wind direction .

```python
df.rose.plot(
var_column="A", # name of variable column
dir_column="B", # name of direction column
sectors=8, # number of sectors (direction bins)
bins=range(0,30,5) # specify variable bins
normed=False # If True, values as percentage instead of counts
colors='Blues' # Name of matplotlib colormap or list of colors
)
```

There are two other accessors that give some information.

```python
# Display a dataframe of the binned values
df.rose.table(sectors=8)
```

![Alt text](images/sample_table.png)

```python
# Display the binned data as bar graph on regular axes.
df.rose.bar()
```

![Alt text](images/sample_bar.png)
Loading

0 comments on commit 1a4b1c7

Please sign in to comment.