Skip to main content

A tool for the Boston Globe for data cleaning

Project description

globestylizer

About state_abbr()

globestylizer is a Python library for use in the Boston Globe. It contains a module cleaner with a function called state_abbr and has pandas as a dependency.

The intended use case for this library is for cleaning a pandas Dataframe that contains state abbreviations that are not adherent to Globe style, and returning a copy of the Dataframe that is in Globe style.

Installation

In your virtual environment, for example pipenv, pipenv install globestylizer. Remember that this is dependent on pandas as well.

Usage

Import globestylizer's cleaner in your py file or Jupyter notebook: from globestylizer import cleaner

You can call the state_abbr function on any pandas Dataframe and it will parse the entire Dataframe for state abbreviations or full state names. It is case-insensitive so it can handle any variety of capitalizations. Here's example data:

State1 State2 Value
Alaska Alaska 15
AK AK 654
AL AL 45.32
Alabama Alabama 789
Tennessee Tennessee 15
Tenn. Tenn. 3
TN TN 31.2
WYOMING WYOMING 789
wyoming wyoming 455
WYoming WYoming 11
WY WY 2

Assuming you have a pandas Dataframe defined as df, you can call it as so:

abbreviated_df = cleaner.state_abbr(df)

And abbreviated_df will return:

State1 State2 Value
Alaska Alaska 15.0
Alaska Alaska 654.0
Ala. Ala. 45.32
Ala. Ala. 789.0
Tenn. Tenn. 15.0
Tenn. Tenn. 3.0
Tenn. Tenn. 31.2
Wyo. Wyo. 789.0
Wyo. Wyo. 455.0
Wyo. Wyo. 11.0
Wyo. Wyo. 2.0

You also have the option of parsing only selected columns. If you have state names as part of strings in other columns that you don't want abbreviated, pass in the columns that you do want abbreviated as a second argument. Assuming you have data as such, and only want to clean the column 'State2':

State1 State2 Value
Alaska Alaska 15
AK AK 654
AL AL 45.32
Alabama Alabama 789
Tennessee Tennessee 15
Tenn. Tenn. 3
TN TN 31.2
WYOMING WYOMING 789
wyoming wyoming 455
WYoming WYoming 11
WY WY 2

Pass in the column name as the second argument.

partially_abbreviated_df = cleaner.state_abbr(df, columns=['State2'])

And partially_abbreviated_df will return:

State1 State2 Value
Alaska Alaska 15.0
AK Alaska 654.0
AL Ala. 45.32
Alabama Ala. 789.0
Tennessee Tenn. 15.0
Tenn. Tenn. 3.0
TN Tenn. 31.2
WYOMING Wyo. 789.0
wyoming Wyo. 455.0
WYoming Wyo. 11.0
WY Wyo. 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

globestylizer-0.1.10.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

globestylizer-0.1.10-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file globestylizer-0.1.10.tar.gz.

File metadata

  • Download URL: globestylizer-0.1.10.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for globestylizer-0.1.10.tar.gz
Algorithm Hash digest
SHA256 c53df914a5153d47e001756f467d509913c061378e67f7c0c4b5e3f8c245b8d0
MD5 1c9445ca49d64c5196a5420091bd5706
BLAKE2b-256 759b7cbe7031b14fd33bb1e292f3f51d4f628df651628abaf4e869ee91af9b48

See more details on using hashes here.

File details

Details for the file globestylizer-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: globestylizer-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for globestylizer-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 256f82b1148c177270cafc1ec28971d7c47b19467ba171b0e0b8db00831e9519
MD5 e4a7c557cdd16c2fa9bdc391ec0d6eb6
BLAKE2b-256 472feffd7860900fd1fdf64fc09961fa1051590363f6f417454b92acfdbad380

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page