Neat Panda
Neat Panda contains three main methods/functions, spread, gather and clean_columnames. The ideas for these methods are from the spread and gather functions in the R package tidyr and the make_clean_columns function in the R package janitor.
The spread function is syntactic sugar for the pandas library method pivot and the gather method is syntactic sugar for the pandas method melt.
Features
clean_column_names
import neat_panda
print(df.columns.tolist())
["Country ", "Sub$region", "Actual"]
df = df.clean_column_names()
print(df.columns.tolist())
["country", "sub_region", "actual"]
spread
R
library(tidyr)
library(dplyr)
library(gapminder)
gapminder2 <- gapminder %>% select(country, continent, year, pop)
gapminder3 <- gapminder2 %>% spread(key = year, value = pop)
head(gapminder3, n = 5)
Python
import neat_panda
from gapminder import gapminder
gapminder2 = gapminder[["country", "continent", "year", "pop"]]
gapminder3 = gapminder2.spread(key="year", value="pop")
gapminder3.head()
Output R
# A tibble: 5 x 14
country continent `1952` `1957` `1962` `1967` `1972` `1977` `1982` `1987` `1992` `1997` `2002` `2007`
<fct> <fct> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
1 Afghanistan Asia 8425333 9240934 10267083 11537966 13079460 14880372 12881816 13867957 16317921 22227415 25268405 31889923
2 Albania Europe 1282697 1476505 1728137 1984060 2263554 2509048 2780097 3075321 3326498 3428038 3508512 3600523
3 Algeria Africa 9279525 10270856 11000948 12760499 14760787 17152804 20033753 23254956 26298373 29072015 31287142 33333216
4 Angola Africa 4232095 4561361 4826015 5247469 5894858 6162675 7016384 7874230 8735988 9875024 10866106 12420476
5 Argentina Americas 17876956 19610538 21283783 22934225 24779799 26983828 29341374 31620918 33958947 36203463 38331121 40301927
Output Python
country continent 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 2002 2007
0 Afghanistan Asia 8425333 9240934 10267083 11537966 13079460 14880372 12881816 13867957 16317921 22227415 25268405 31889923
1 Albania Europe 1282697 1476505 1728137 1984060 2263554 2509048 2780097 3075321 3326498 3428038 3508512 3600523
2 Algeria Africa 9279525 10270856 11000948 12760499 14760787 17152804 20033753 23254956 26298373 29072015 31287142 33333216
3 Angola Africa 4232095 4561361 4826015 5247469 5894858 6162675 7016384 7874230 8735988 9875024 10866106 12420476
4 Argentina Americas 17876956 19610538 21283783 22934225 24779799 26983828 29341374 31620918 33958947 36203463 38331121 40301927
gather
R
library(tidyr)
# gapminder3 is obtained as above
gapminder4 <- gather(gapminder3, key="year", "value"="pop", 3:14)
# or
years <- c("1952", "1957", "1962", "1967", "1972", "1977", "1982", "1987", "1992", "1997", "2002", "2007")
gapminder4 <- gather(gapminder3, key="year", "value"="pop", years)
head(gapminder4, n = 5)
Python
import neat_panda
# gapminder3 is obtained as above
gapminder4 = gapminder3.gather(key="year", value="pop", columns=range(2, 13))
# or
gapminder4 = gapminder3.gather(key="year", value="pop", columns=range(0, 2), invert_columns=True)
# or
years = ["1952", "1957", "1962", "1967", "1972", "1977", "1982", "1987", "1992", "1997", "2002", "2007"]
gapminder4 = gapminder3.gather(key="year", value="pop", columns=years)
# or
gapminder4 = gapminder3.gather(key="year", value="pop", columns=["country", "continent"], invert_columns=True)
gapminder4.head()
Output R
# A tibble: 5 x 4
country continent year pop
<fct> <fct> <chr> <int>
1 Afghanistan Asia 1952 8425333
2 Albania Europe 1952 1282697
3 Algeria Africa 1952 9279525
4 Angola Africa 1952 4232095
5 Argentina Americas 1952 17876956
Output Python
country continent year pop
0 Afghanistan Asia 1952 8425333
1 Albania Europe 1952 1282697
2 Algeria Africa 1952 9279525
3 Angola Africa 1952 4232095
4 Argentina Americas 1952 17876956
Metadata
Release files for neat-panda 0.9.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| neat_panda-0.9.8.1.tar.gz | 13.2 kB | Without provenance | Details for neat_panda-0.9.8.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| neat_panda-0.9.8.1-py3-none-any.whl | Python 3 | none | any | Details for neat_panda-0.9.8.1-py3-none-any.whl |
Total release size: 28.0 kB
Release files / neat_panda-0.9.8.1.tar.gz
| Download URL | neat_panda-0.9.8.1.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76d6d54243e227fd81a7a0611d12ebb4868d9fcee66fc5d134ccf64f5c7cb359
|
|
BLAKE2b-256 checksum How to use checksums |
8ee44229b550335979578f5949aeff00c91384a8c2643bbfeba363385dd2ffe5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.3 CPython/3.8.1 Windows/10
|
Release files / neat_panda-0.9.8.1-py3-none-any.whl
| Download URL | neat_panda-0.9.8.1-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8c0a933e19d71c1ca60fd2f20ba3e01aef37497e78cca64cd00e4e751621cd3
|
|
BLAKE2b-256 checksum How to use checksums |
2e310230211aa39f129f48f31128861e56408a783c8dbab6527521eaf1e54441
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.3 CPython/3.8.1 Windows/10
|
Security for neat-panda 0.9.8.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.